From a00d85aef36050ffd29b46ed19e04a5af9a47488 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 31 Jul 2006 21:11:27 +0200 Subject: add tiff stitching --- src/DataImage.H | 2 +- src/DataImage.cxx | 15 +++++++++------ src/gipfel.cxx | 44 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 47 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/DataImage.H b/src/DataImage.H index a8fb100..1846857 100644 --- a/src/DataImage.H +++ b/src/DataImage.H @@ -30,7 +30,7 @@ class DataImage : public Fl_Widget { public: - DataImage(int X, int Y, int W, int H); + DataImage(int X, int Y, int W, int H, int channels=3); ~DataImage(); diff --git a/src/DataImage.cxx b/src/DataImage.cxx index 2f1ad80..21aa226 100644 --- a/src/DataImage.cxx +++ b/src/DataImage.cxx @@ -32,10 +32,10 @@ extern "C" { #include "DataImage.H" -DataImage::DataImage(int X, int Y, int W, int H): Fl_Widget(X, Y, W, H) { - d = 3; +DataImage::DataImage(int X, int Y, int W, int H, int channels): Fl_Widget(X, Y, W, H) { + d = channels; data = (uchar*) malloc(W * H * d); - memset(data, 200, W * H * d); + memset(data, 0, W * H * d); } DataImage::~DataImage() { @@ -53,6 +53,9 @@ DataImage::set_pixel(int x, int y, char r, char g, char b) { *(data+index+0) = r; *(data+index+1) = g; *(data+index+2) = b; + if (d == 4) { + *(data+index+3) = 255; + } return 0; } @@ -150,7 +153,7 @@ DataImage::write_jpeg(const char *file, int quality) { jpeg_start_compress(&cinfo, TRUE); - row_stride = w() * 3; /* JSAMPLEs per row in image_buffer */ + row_stride = w() * d; /* JSAMPLEs per row in image_buffer */ while (cinfo.next_scanline < cinfo.image_height) { row_pointer[0] = & data[cinfo.next_scanline * row_stride]; jpeg_write_scanlines(&cinfo, row_pointer, 1); @@ -182,10 +185,10 @@ DataImage::write_tiff(const char *file) { TIFFSetField(output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); TIFFSetField(output, TIFFTAG_BITSPERSAMPLE, 8); - TIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, 3); + TIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, d); // Actually write the image - if(TIFFWriteEncodedStrip(output, 0, data, w() * h() * 3) == 0){ + if(TIFFWriteEncodedStrip(output, 0, data, w() * h() * d) == 0){ fprintf(stderr, "Could not write image\n"); return 2; } diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 309ee9d..d8cea1c 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -62,7 +62,8 @@ Fl_Value_Input *i_view_lat, *i_view_long, *i_view_height; Fl_Box *b_viewpoint; Fl_Menu_Bar *mb; -int stitch(int stitch_w, int stitch_h, int argc, char **argv); +static int tiffstitch(int stitch_w, int stitch_h, int argc, char **argv); +static int stitch(int stitch_w, int stitch_h, int argc, char **argv); void set_values() { s_center->value(gipf->get_center_angle()); @@ -323,13 +324,13 @@ int main(int argc, char** argv) { char c, *sep, *tmp, **my_argv; char *view_point = NULL; int err, bflag = 0, dflag = 0, my_argc; - int stitch_flag = 0, stitch_w = 2000, stitch_h = 500; + int stitch_flag = 0, tiff_flag = 0, stitch_w = 2000, stitch_h = 500; Fl_Window *control_win, *view_win; Fl_Scroll *scroll; err = 0; - while ((c = getopt(argc, argv, "d:v:sw:b:")) != EOF) { + while ((c = getopt(argc, argv, "d:v:sw:b:t")) != EOF) { switch (c) { case 'h': usage(); @@ -344,6 +345,10 @@ int main(int argc, char** argv) { case 's': stitch_flag++; break; + case 't': + stitch_flag++; + tiff_flag++; + break; case 'w': stitch_w = atoi(optarg); break; @@ -369,7 +374,12 @@ int main(int argc, char** argv) { } if (stitch_flag) { - stitch(stitch_w, stitch_h, my_argc, my_argv); + if (tiff_flag) { + tiffstitch(stitch_w, stitch_h, my_argc, my_argv); + } else { + stitch(stitch_w, stitch_h, my_argc, my_argv); + } + exit(0); } Fl::get_system_colors(); @@ -417,7 +427,27 @@ int main(int argc, char** argv) { return Fl::run(); } -int stitch(int stitch_w, int stitch_h, int argc, char **argv) { +static int tiffstitch(int stitch_w, int stitch_h, int argc, char **argv) { + char buf[256]; + + for (int i=0; iload_image(argv[i]); + + st->resample(img, 0.0, 7.0); + snprintf(buf, sizeof(buf), "gipfel_%d.tiff", i); + img->write_tiff(buf); + delete st; + delete img; + } + + return 0; +} + + +static int stitch(int stitch_w, int stitch_h, int argc, char **argv) { Fl_Window *win; Fl_Scroll *scroll; Stitch *st = new Stitch(); @@ -435,7 +465,7 @@ int stitch(int stitch_w, int stitch_h, int argc, char **argv) { st->resample(img, 0.0, 7.0); img->write_jpeg("/tmp/bla.jpg", 90); - img->write_tiff("/tmp/bla.tiff"); Fl::run(); - exit(0); + + return 0; } -- cgit v1.2.3