From a7784b543b1bf2052b301457b5b7d4f64d20595e Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 18 May 2007 19:17:59 +0200 Subject: add 16bit output support --- src/JPEGOutputImage.H | 2 +- src/PreviewOutputImage.H | 2 +- src/TIFFOutputImage.H | 5 +++-- src/TIFFOutputImage.cxx | 27 ++++++++++++++++++--------- src/gipfel.cxx | 20 +++++++++++++------- 5 files changed, 36 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/JPEGOutputImage.H b/src/JPEGOutputImage.H index a4b8f47..06499ca 100644 --- a/src/JPEGOutputImage.H +++ b/src/JPEGOutputImage.H @@ -15,7 +15,7 @@ extern "C" { #include "OutputImage.H" -class JPEGOutputImage : OutputImage { +class JPEGOutputImage : public OutputImage { private: unsigned char *row; char *file; diff --git a/src/PreviewOutputImage.H b/src/PreviewOutputImage.H index cbd55a6..53b58db 100644 --- a/src/PreviewOutputImage.H +++ b/src/PreviewOutputImage.H @@ -14,7 +14,7 @@ #include "OutputImage.H" -class PreviewOutputImage : OutputImage , public Fl_Widget { +class PreviewOutputImage : public OutputImage , public Fl_Widget { private: uchar *data; int d; diff --git a/src/TIFFOutputImage.H b/src/TIFFOutputImage.H index ce61462..9b0f83b 100644 --- a/src/TIFFOutputImage.H +++ b/src/TIFFOutputImage.H @@ -12,14 +12,15 @@ #include "OutputImage.H" -class TIFFOutputImage : OutputImage { +class TIFFOutputImage : public OutputImage { private: + int bitspersample; unsigned char *row; char *file; TIFF *tiff; public: - TIFFOutputImage(const char *file); + TIFFOutputImage(const char *file, int b = 8); ~TIFFOutputImage(); diff --git a/src/TIFFOutputImage.cxx b/src/TIFFOutputImage.cxx index 156079c..b8effed 100644 --- a/src/TIFFOutputImage.cxx +++ b/src/TIFFOutputImage.cxx @@ -10,7 +10,8 @@ #include "TIFFOutputImage.H" -TIFFOutputImage::TIFFOutputImage(const char *f) { +TIFFOutputImage::TIFFOutputImage(const char *f, int b) { + bitspersample = (b==16)?16:8; file = strdup(f); tiff = NULL; row = NULL; @@ -32,12 +33,12 @@ TIFFOutputImage::init_internal(int w1, int h1) { row = NULL; } - row = (unsigned char*) malloc(sizeof(char) * 4 * w1); + row = (unsigned char*) malloc(sizeof(char) * (bitspersample / 8) * 4 * w1); if (!row) { perror("malloc"); return 1; } - memset(row, 0, sizeof(char) * 4 * w1); + memset(row, 0, sizeof(char) * (bitspersample / 8) * 4 * w1); if (tiff) { TIFFClose(tiff); @@ -54,7 +55,7 @@ TIFFOutputImage::init_internal(int w1, int h1) { TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, 1); - TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8); + TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, bitspersample); TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 4); return 0; @@ -62,17 +63,25 @@ TIFFOutputImage::init_internal(int w1, int h1) { int TIFFOutputImage::set_pixel_internal(int x, int r, int g, int b) { - row[x*4+0] = (unsigned char) (r / 255); - row[x*4+1] = (unsigned char) (g / 255); - row[x*4+2] = (unsigned char) (b / 255); - row[x*4+3] = 255; + if (bitspersample == 8) { + row[x*4+0] = (unsigned char) (r / 255); + row[x*4+1] = (unsigned char) (g / 255); + row[x*4+2] = (unsigned char) (b / 255); + row[x*4+3] = 255; + } else if (bitspersample == 16) { + unsigned short *row16 = (unsigned short*) row; + row16[x*4+0] = (unsigned short) r; + row16[x*4+1] = (unsigned short) g; + row16[x*4+2] = (unsigned short) b; + row16[x*4+3] = 65025; + } return 0; } int TIFFOutputImage::next_line_internal() { - TIFFWriteEncodedStrip(tiff, line -1 , row, W * 4); + TIFFWriteEncodedStrip(tiff, line - 1 , row, W * (bitspersample / 8) * 4); memset(row, 0, sizeof(char) * 4 * W); return 0; diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 9db0fce..3fbf945 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -54,7 +54,8 @@ Fl_Menu_Bar *mb; #define STITCH_JPEG 2 #define STITCH_TIFF 4 -static int stitch(GipfelWidget::sample_mode_t m ,int stitch_w, int stitch_h, +static int stitch(GipfelWidget::sample_mode_t m , int b_16, + int stitch_w, int stitch_h, double from, double to, int type, const char *path, int argc, char **argv); void set_values() { @@ -256,6 +257,7 @@ void usage() { " -d Use for GPS data.\n" " -u , Use distortion correction values k0,k1.\n" " -s Stitch mode.\n" + " -4 Create 16bit output (only with TIFF stitching).\n" " -r , Stitch range in degrees (e.g. 100.0,200.0).\n" " -b Use bilinear interpolation for stitching.\n" " -w Width of result image.\n" @@ -397,7 +399,7 @@ int main(int argc, char** argv) { int err, my_argc; int stitch_flag = 0, stitch_w = 2000, stitch_h = 500; int jpeg_flag = 0, tiff_flag = 0, distortion_flag = 0; - int bicubic_flag = 0; + int bicubic_flag = 0, b_16_flag = 0; double stitch_from = 0.0, stitch_to = 380.0; double dist_k0 = 0.0, dist_k1 = 0.0, dist_x0 = 0.0; char *outpath = "/tmp"; @@ -405,7 +407,7 @@ int main(int argc, char** argv) { err = 0; - while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:")) != EOF) { + while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:4")) != EOF) { switch (c) { case '?': usage(); @@ -420,6 +422,9 @@ int main(int argc, char** argv) { case 's': stitch_flag++; break; + case '4': + b_16_flag++; + break; case 'r': stitch_flag++; if (optarg && strcmp(optarg, ":")) { @@ -490,6 +495,7 @@ int main(int argc, char** argv) { } stitch(bicubic_flag?GipfelWidget::BICUBIC:GipfelWidget::NEAREST, + b_16_flag, stitch_w, stitch_h, stitch_from, stitch_to, type, outpath, my_argc, my_argv); @@ -548,7 +554,7 @@ int main(int argc, char** argv) { } static int -stitch(GipfelWidget::sample_mode_t m, +stitch(GipfelWidget::sample_mode_t m, int b_16, int stitch_w, int stitch_h, double from, double to, int type, const char *path, int argc, char **argv) { @@ -563,7 +569,7 @@ stitch(GipfelWidget::sample_mode_t m, if (type & STITCH_JPEG) { - st->set_output((OutputImage*) new JPEGOutputImage(path, 90)); + st->set_output(new JPEGOutputImage(path, 90)); st->resample(m, stitch_w, stitch_h, from, to); } else if (type & STITCH_TIFF) { @@ -577,7 +583,7 @@ stitch(GipfelWidget::sample_mode_t m, *dot = '\0'; strncat(buf, ".tiff", sizeof(buf)); - st->set_output(argv[i], (OutputImage*) new TIFFOutputImage(buf)); + st->set_output(argv[i], new TIFFOutputImage(buf, b_16?16:8)); } st->resample(m, stitch_w, stitch_h, from, to); @@ -590,7 +596,7 @@ stitch(GipfelWidget::sample_mode_t m, win->resizable(scroll); win->show(0, argv); - st->set_output((OutputImage*) img); + st->set_output(img); st->resample(m, stitch_w, stitch_h, from, to); -- cgit v1.2.3