summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-08-03 20:45:57 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-08-03 20:45:57 +0200
commit6524c95bb8ea0339908ab9bff03211f8c42e77d9 (patch)
tree5edf64b415049d9a1f84a4e840adc6110e70c886
parent4894107e215fd13e8121bcdc3b610c4db7556689 (diff)
add TIFFOutputImage
-rw-r--r--src/JPEGOutputImage.cxx8
-rw-r--r--src/Makefile.am2
-rw-r--r--src/OutputImage.cxx179
-rw-r--r--src/TIFFOutputImage.H49
-rw-r--r--src/TIFFOutputImage.cxx110
-rw-r--r--src/gipfel.cxx95
6 files changed, 402 insertions, 41 deletions
diff --git a/src/JPEGOutputImage.cxx b/src/JPEGOutputImage.cxx
index 9e00458..3f7fd11 100644
--- a/src/JPEGOutputImage.cxx
+++ b/src/JPEGOutputImage.cxx
@@ -101,11 +101,13 @@ JPEGOutputImage::next_line_internal() {
int
JPEGOutputImage::done_internal() {
- next_line_internal();
jpeg_finish_compress(&cinfo);
- fclose(fp);
- fp = NULL;
jpeg_destroy_compress(&cinfo);
+
+ if (fp) {
+ fclose(fp);
+ fp = NULL;
+ }
if (row) {
free(row);
}
diff --git a/src/Makefile.am b/src/Makefile.am
index b686716..5577090 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,6 +15,7 @@ gipfel_SOURCES = \
Stitch.cxx \
OutputImage.cxx \
JPEGOutputImage.cxx \
+ TIFFOutputImage.cxx \
PreviewOutputImage.cxx
noinst_HEADERS = \
@@ -31,5 +32,6 @@ noinst_HEADERS = \
Stitch.H \
OutputImage.H \
JPEGOutputImage.H \
+ TIFFOutputImage.H \
PreviewOutputImage.H \
util.h
diff --git a/src/OutputImage.cxx b/src/OutputImage.cxx
new file mode 100644
index 0000000..52af058
--- /dev/null
+++ b/src/OutputImage.cxx
@@ -0,0 +1,179 @@
+//
+// Copyright 2006 by Johannes Hofmann
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "OutputImage.H"
+
+OutputImage::OutputImage() {
+ W = 0;
+ H = 0;
+ initialized = 0;
+}
+
+OutputImage::~OutputImage() {
+}
+
+int
+OutputImage::init(int w1, int h1) {
+ W = w1;
+ H = h1;
+ line = 0;
+ initialized = 1;
+
+ return init_internal(w1, h1);
+}
+
+
+int
+OutputImage::init_internal(int w1, int h1) {
+ return 0;
+}
+
+int
+OutputImage::set_pixel(int x, char r, char g, char b) {
+ if (!initialized || x < 0 || x >= W) {
+ return 1;
+ } else {
+ return set_pixel_internal(x, r, g, b);
+ }
+}
+
+int
+OutputImage::set_pixel_internal(int x, char r, char g, char b) {
+ return 0;
+}
+
+int
+OutputImage::next_line() {
+ if (!initialized || line++ >= H) {
+ return 1;
+ } else {
+ return next_line_internal();
+ }
+}
+
+int
+OutputImage::next_line_internal() {
+ return 0;
+}
+
+int
+OutputImage::done() {
+ if (!initialized) {
+ return 1;
+ } else {
+ next_line();
+ return done_internal();
+ }
+}
+
+int
+OutputImage::done_internal() {
+ return 0;
+}
+
+#define MAX_OUTPUT_IMAGES 16
+OutputImages::OutputImages() {
+ imgs = (OutputImage **) calloc(MAX_OUTPUT_IMAGES, sizeof(OutputImage *));
+ max_imgs = MAX_OUTPUT_IMAGES;
+}
+
+OutputImages::~OutputImages() {
+ free(imgs);
+}
+
+int
+OutputImages::add(OutputImage *img) {
+ for (int i=0; i<max_imgs;i++) {
+ if (imgs[i] == NULL) {
+ imgs[i] = img;
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+
+int
+OutputImages::remove(OutputImage *img) {
+ for (int i=0; i<max_imgs;i++) {
+ if (imgs[i] == img) {
+ imgs[i] = NULL;
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+int
+OutputImages::init(int w, int h) {
+ int ret = 0;
+
+ for (int i=0; i<max_imgs;i++) {
+ if (imgs[i]) {
+ ret += imgs[i]->init(w, h);
+ }
+ }
+
+ return ret;
+}
+
+int
+OutputImages::set_pixel(int x, char r, char g, char b) {
+ int ret = 0;
+
+ for (int i=0; i<max_imgs;i++) {
+ if (imgs[i]) {
+ ret += imgs[i]->set_pixel(x, r, g, b);
+ }
+ }
+
+ return ret;
+}
+
+int
+OutputImages::next_line() {
+ int ret = 0;
+
+ for (int i=0; i<max_imgs;i++) {
+ if (imgs[i]) {
+ ret += imgs[i]->next_line();
+ }
+ }
+
+ return ret;
+}
+
+int
+OutputImages::done() {
+ int ret = 0;
+
+ for (int i=0; i<max_imgs;i++) {
+ if (imgs[i]) {
+ ret += imgs[i]->done();
+ }
+ }
+
+ return ret;
+}
+
diff --git a/src/TIFFOutputImage.H b/src/TIFFOutputImage.H
new file mode 100644
index 0000000..3a14279
--- /dev/null
+++ b/src/TIFFOutputImage.H
@@ -0,0 +1,49 @@
+//
+// Copyright 2006 by Johannes Hofmann
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+
+#ifndef TIFFOUTPUTIMAGE_H
+#define TIFFOUTPUTIMAGE_H
+
+#include <stdio.h>
+#include <tiffio.h>
+
+#include "OutputImage.H"
+
+class TIFFOutputImage : OutputImage {
+ private:
+ unsigned char *row;
+ char *file;
+ TIFF *tiff;
+
+ public:
+ TIFFOutputImage(const char *file);
+
+ ~TIFFOutputImage();
+
+ protected:
+ int init_internal(int w, int h);
+
+ int set_pixel_internal(int x, char r, char g, char b);
+
+ int next_line_internal();
+
+ int done_internal();
+};
+
+#endif
diff --git a/src/TIFFOutputImage.cxx b/src/TIFFOutputImage.cxx
new file mode 100644
index 0000000..ed9213f
--- /dev/null
+++ b/src/TIFFOutputImage.cxx
@@ -0,0 +1,110 @@
+//
+// Copyright 2006 by Johannes Hofmann
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "TIFFOutputImage.H"
+
+TIFFOutputImage::TIFFOutputImage(const char *f) {
+ file = strdup(f);
+ tiff = NULL;
+ row = NULL;
+}
+
+TIFFOutputImage::~TIFFOutputImage() {
+ if (row) {
+ free(row);
+ }
+ if (file) {
+ free(file);
+ }
+}
+
+int
+TIFFOutputImage::init_internal(int w1, int h1) {
+ if (row) {
+ free(row);
+ row = NULL;
+ }
+
+ row = (unsigned char*) malloc(sizeof(char) * 4 * w1);
+ if (!row) {
+ perror("malloc");
+ return 1;
+ }
+ memset(row, 0, sizeof(char) * 4 * w1);
+
+ if (tiff) {
+ TIFFClose(tiff);
+ }
+
+ if((tiff = TIFFOpen(file, "w")) == NULL){
+ fprintf(stderr, "can't open %s\n", file);
+ return 1;
+ }
+
+ TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, w1);
+ TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, h1);
+ TIFFSetField(tiff, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
+ TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+ TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
+ TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8);
+ TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 4);
+
+ return 0;
+}
+
+int
+TIFFOutputImage::set_pixel_internal(int x, char r, char g, char b) {
+ row[x*4+0] = r;
+ row[x*4+1] = g;
+ row[x*4+2] = b;
+ row[x*4+3] = 255;
+
+ return 0;
+}
+
+int
+TIFFOutputImage::next_line_internal() {
+ int ret;
+ ret = TIFFWriteScanline(tiff, row, line-1, 0);
+ if (ret != 1) {
+ fprintf(stderr, "TIFFWriteScanline failed\n");
+ }
+ memset(row, 0, sizeof(char) * 4 * W);
+ return 0;
+}
+
+int
+TIFFOutputImage::done_internal() {
+ if (tiff) {
+ TIFFClose(tiff);
+ tiff = NULL;
+ }
+
+ if (row) {
+ free(row);
+ row = NULL;
+ }
+
+ return 0;
+}
+
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index 8e0e1b9..74b092a 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -42,6 +42,7 @@
#include "Fl_Search_Chooser.H"
#include "GipfelWidget.H"
#include "JPEGOutputImage.H"
+#include "TIFFOutputImage.H"
#include "PreviewOutputImage.H"
#include "Stitch.H"
#include "choose_hill.H"
@@ -63,7 +64,11 @@ Fl_Value_Input *i_view_lat, *i_view_long, *i_view_height;
Fl_Box *b_viewpoint;
Fl_Menu_Bar *mb;
-static int stitch(int stitch_w, int stitch_h, int argc, char **argv);
+#define STITCH_PREVIEW 1
+#define STITCH_JPEG 2
+#define STITCH_TIFF 4
+static int stitch(int stitch_w, int stitch_h, int type, const char *path,
+ int argc, char **argv);
void set_values() {
s_center->value(gipf->get_center_angle());
@@ -325,14 +330,16 @@ int main(int argc, char** argv) {
char *view_point = NULL;
int err, bflag = 0, dflag = 0, my_argc;
int stitch_flag = 0, stitch_w = 2000, stitch_h = 500;
+ int jpeg_flag = 0, tiff_flag = 0;
+ char *outpath;
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:h:j:t:")) != EOF) {
switch (c) {
- case 'h':
+ case '?':
usage();
exit(0);
break;
@@ -345,10 +352,18 @@ int main(int argc, char** argv) {
case 's':
stitch_flag++;
break;
+ case 'j':
+ jpeg_flag++;
+ outpath = optarg;
+ break;
+ case 't':
+ tiff_flag++;
+ outpath = optarg;
+ break;
case 'w':
stitch_w = atoi(optarg);
break;
- case 'b':
+ case 'h':
stitch_h = atoi(optarg);
break;
default:
@@ -370,7 +385,13 @@ int main(int argc, char** argv) {
}
if (stitch_flag) {
- stitch(stitch_w, stitch_h, my_argc, my_argv);
+ int type = STITCH_PREVIEW;
+ if (jpeg_flag) {
+ type = STITCH_JPEG;
+ } else if (tiff_flag) {
+ type = STITCH_TIFF;
+ }
+ stitch(stitch_w, stitch_h, type, outpath, my_argc, my_argv);
exit(0);
}
@@ -419,29 +440,7 @@ int main(int argc, char** argv) {
return Fl::run();
}
-#if 0
-static int tiffstitch(int stitch_w, int stitch_h, int argc, char **argv) {
- char buf[256];
-
- for (int i=0; i<argc; i++) {
- Stitch *st = new Stitch();
- DataImage *img = new DataImage(0, 0, stitch_w, stitch_h, 4);
-
- st->load_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;
-}
-#endif
-
-
-static int stitch(int stitch_w, int stitch_h, int argc, char **argv) {
+static int stitch(int stitch_w, int stitch_h, int type, const char *path, int argc, char **argv) {
Fl_Window *win;
Fl_Scroll *scroll;
Stitch *st = new Stitch();
@@ -449,19 +448,39 @@ static int stitch(int stitch_w, int stitch_h, int argc, char **argv) {
for (int i=0; i<argc; i++) {
st->load_image(argv[i]);
}
+
+ if (type == STITCH_JPEG) {
+
+ st->set_output((OutputImage*) new JPEGOutputImage(path, 90));
+ st->resample(stitch_w, stitch_h, 0.0, 7.0);
+
+ } else if (type == STITCH_TIFF) {
- win = new Fl_Window(0,0, stitch_w, stitch_h);
- scroll = new Fl_Scroll(0, 0, win->w(), win->h());
- PreviewOutputImage *img = new PreviewOutputImage(0, 0, stitch_w, stitch_h);
- win->resizable(scroll);
+ for (int i=0; i<argc; i++) {
+ char buf[1024];
+ char *dot;
- win->show(0, argv);
+ snprintf(buf, sizeof(buf), "%s/%s", path, argv[i]);
+ dot = strrchr(buf, '.');
+ *dot = '\0';
+ strncat(buf, ".tiff", sizeof(buf));
- st->set_output((OutputImage*) new JPEGOutputImage("/tmp/bla.jpg", 90));
- //st->set_output((OutputImage*) img);
- st->resample(stitch_w, stitch_h, 0.0, 7.0);
- img->redraw();
- Fl::run();
+ st->set_output(argv[i], (OutputImage*) new TIFFOutputImage(buf));
+ }
+
+ st->resample(stitch_w, stitch_h, 0.0, 7.0);
+
+ } else {
+ win = new Fl_Window(0,0, stitch_w, stitch_h);
+ scroll = new Fl_Scroll(0, 0, win->w(), win->h());
+ PreviewOutputImage *img = new PreviewOutputImage(0, 0, stitch_w, stitch_h);
+ win->resizable(scroll);
+ win->show(0, argv);
+ st->set_output((OutputImage*) img);
+ st->resample(stitch_w, stitch_h, 0.0, 7.0);
+ img->redraw();
+ Fl::run();
+ }
return 0;
}