summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DataImage.cxx198
-rw-r--r--src/GipfelWidget.H3
-rw-r--r--src/GipfelWidget.cxx15
-rw-r--r--src/Makefile.am4
-rw-r--r--src/OutputImage.H2
-rw-r--r--src/PreviewOutputImage.H (renamed from src/DataImage.H)34
-rw-r--r--src/PreviewOutputImage.cxx93
-rw-r--r--src/gipfel.cxx11
8 files changed, 133 insertions, 227 deletions
diff --git a/src/DataImage.cxx b/src/DataImage.cxx
deleted file mode 100644
index 21aa226..0000000
--- a/src/DataImage.cxx
+++ /dev/null
@@ -1,198 +0,0 @@
-//
-// DataImage routines.
-//
-// 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 <math.h>
-extern "C" {
-#include <jpeglib.h>
-#include <tiffio.h>
-}
-
-#include <Fl/fl_draw.h>
-
-#include "DataImage.H"
-
-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, 0, W * H * d);
-}
-
-DataImage::~DataImage() {
-
-}
-
-
-int
-DataImage::set_pixel(int x, int y, char r, char g, char b) {
- if (x < 0 || x >= w() || y < 0 || y >= h()) {
- return 1;
- }
-
- long index = (y * w() * d + (x * d)); // X/Y -> buf index
- *(data+index+0) = r;
- *(data+index+1) = g;
- *(data+index+2) = b;
- if (d == 4) {
- *(data+index+3) = 255;
- }
-
- return 0;
-}
-
-
-void
-DataImage::draw() {
- fl_push_clip(x(), y(), w(), h());
-
- fl_draw_image(data, x(), y(), w(), h(), d);
-
- fl_pop_clip();
-}
-
-int
-DataImage::get_pixel_bilinear(Fl_Image *img, double x, double y,
- char *r, char *g, char *b) {
-
-
-}
-
-int
-DataImage::get_pixel_nearest(Fl_Image *img, double x, double y,
- char *r, char *g, char *b) {
- if (isnan(x) || isnan(y)) {
- return 1;
- } else {
- return get_pixel(img, (int) rint(x), (int) rint(y), r, g, b);
- }
-}
-
-int
-DataImage::get_pixel(Fl_Image *img, int x, int y,
- char *r, char *g, char *b) {
- if ( img->d() == 0 ) {
- return 1;
- }
-
- if (x < 0 || x >=img->w() || y < 0 || y >= img->h()) {
- return 1;
- }
- long index = (y * img->w() * img->d()) + (x * img->d()); // X/Y -> buf index
- switch ( img->count() ) {
- case 1: { // bitmap
- const char *buf = img->data()[0];
- switch ( img->d() ) {
- case 1: { // 8bit
- *r = *g = *b = *(buf+index);
- break;
- }
- case 3: // 24bit
- *r = *(buf+index+0);
- *g = *(buf+index+1);
- *b = *(buf+index+2);
- break;
- default: // ??
- printf("Not supported: chans=%d\n", img->d());
- return 1;
- }
- break;
- }
- default: // ?? pixmap, bit vals
- printf("Not supported: count=%d\n", img->count());
- exit(1);
- }
-
- return 0;
-}
-
-
-int
-DataImage::write_jpeg(const char *file, int quality) {
- struct jpeg_compress_struct cinfo;
- struct jpeg_error_mgr jerr;
- FILE *outfile;
- JSAMPROW row_pointer[1];
- int row_stride;
-
- cinfo.err = jpeg_std_error(&jerr);
- jpeg_create_compress(&cinfo);
-
- if ((outfile = fopen(file, "wb")) == NULL) {
- fprintf(stderr, "can't open %s\n", file);
- return 1;
- }
-
- jpeg_stdio_dest(&cinfo, outfile);
- cinfo.image_width = w();
- cinfo.image_height = h();
- cinfo.input_components = 3; /* # of color components per pixel */
- cinfo.in_color_space = JCS_RGB;
-
- jpeg_set_defaults(&cinfo);
- jpeg_set_quality(&cinfo, quality, TRUE);
-
- jpeg_start_compress(&cinfo, TRUE);
-
- 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);
- }
-
- jpeg_finish_compress(&cinfo);
- fclose(outfile);
- jpeg_destroy_compress(&cinfo);
-
- return 0;
-}
-
-int
-DataImage::write_tiff(const char *file) {
- TIFF *output;
- uint32 width, height;
- char *raster;
-
- // Open the output image
- if((output = TIFFOpen(file, "w")) == NULL){
- fprintf(stderr, "can't open %s\n", file);
- return 1;
- }
-
- // Write the tiff tags to the file
- TIFFSetField(output, TIFFTAG_IMAGEWIDTH, w());
- TIFFSetField(output, TIFFTAG_IMAGELENGTH, h());
- TIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
- TIFFSetField(output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
- TIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
- TIFFSetField(output, TIFFTAG_BITSPERSAMPLE, 8);
- TIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, d);
-
- // Actually write the image
- if(TIFFWriteEncodedStrip(output, 0, data, w() * h() * d) == 0){
- fprintf(stderr, "Could not write image\n");
- return 2;
- }
-
- TIFFClose(output);
- return 0;
-}
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index 50cb10d..4e74cb4 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -52,6 +52,9 @@ class GipfelWidget : public Fl_Widget {
static int get_pixel_nearest(Fl_Image *img, double x, double y,
char *r, char *g, char *b);
+ static int get_pixel(Fl_Image *img, int x, int y,
+ char *r, char *g, char *b);
+
public:
GipfelWidget(int X,int Y,int W, int H);
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 34716e0..c4fe032 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -770,11 +770,18 @@ GipfelWidget::get_pixel(double a_view, double a_nick,
int
GipfelWidget::get_pixel_nearest(Fl_Image *img, double x, double y,
- char *r, char *g, char *b) {
- if (isnan(x) || isnan(y)) {
- return 1;
- }
+ char *r, char *g, char *b) {
+ if (isnan(x) || isnan(y)) {
+ return 1;
+ } else {
+ return get_pixel(img, (int) rint(x), (int) rint(y), r, g, b);
+ }
+}
+
+int
+GipfelWidget::get_pixel(Fl_Image *img, int x, int y,
+ char *r, char *g, char *b) {
if ( img->d() == 0 ) {
return 1;
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 466b772..b686716 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,7 +14,8 @@ gipfel_SOURCES = \
choose_hill.cxx \
Stitch.cxx \
OutputImage.cxx \
- JPEGOutputImage.cxx
+ JPEGOutputImage.cxx \
+ PreviewOutputImage.cxx
noinst_HEADERS = \
GipfelWidget.H \
@@ -30,4 +31,5 @@ noinst_HEADERS = \
Stitch.H \
OutputImage.H \
JPEGOutputImage.H \
+ PreviewOutputImage.H \
util.h
diff --git a/src/OutputImage.H b/src/OutputImage.H
index 9a99548..e7ab4e5 100644
--- a/src/OutputImage.H
+++ b/src/OutputImage.H
@@ -23,7 +23,7 @@
class OutputImage {
private:
- int w, h, initialized, line;
+ int W, H, initialized, line;
public:
OutputImage();
diff --git a/src/DataImage.H b/src/PreviewOutputImage.H
index 1846857..02e60c5 100644
--- a/src/DataImage.H
+++ b/src/PreviewOutputImage.H
@@ -17,39 +17,37 @@
// USA.
//
-#ifndef DATAIMAGE_H
-#define DATAIMAGE_H
+#ifndef PREVIEWOUTPUTIMAGE_H
+#define PREVIEWOUTPUTIMAGE_H
+
+#include <stdio.h>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Image.H>
-class DataImage : public Fl_Widget {
+#include "OutputImage.H"
+
+class PreviewOutputImage : OutputImage , public Fl_Widget {
private:
- int d;
uchar *data;
-
+ int d;
+ int row;
public:
- DataImage(int X, int Y, int W, int H, int channels=3);
+ PreviewOutputImage(int X, int Y, int W, int H);
- ~DataImage();
-
- int set_pixel(int x, int y, char r, char g, char b);
+ ~PreviewOutputImage();
void draw();
- int write_jpeg(const char *file, int quality);
-
- int write_tiff(const char *file);
+ protected:
+ int init_internal(int w, int h);
- static int get_pixel(Fl_Image *img, int x, int y,
- char *r, char *g, char *b);
+ int set_pixel_internal(int x, char r, char g, char b);
- static int get_pixel_bilinear(Fl_Image *img, double x, double y,
- char *r, char *g, char *b);
+ int next_line_internal();
- static int get_pixel_nearest(Fl_Image *img, double x, double y,
- char *r, char *g, char *b);
+ int done_internal();
};
#endif
diff --git a/src/PreviewOutputImage.cxx b/src/PreviewOutputImage.cxx
new file mode 100644
index 0000000..ba86edc
--- /dev/null
+++ b/src/PreviewOutputImage.cxx
@@ -0,0 +1,93 @@
+//
+// DataImage routines.
+//
+// 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 <Fl/Fl.H>
+#include <Fl/fl_draw.h>
+
+#include "PreviewOutputImage.H"
+
+PreviewOutputImage::PreviewOutputImage(int X, int Y, int W, int H): Fl_Widget(X, Y, W, H) {
+ d = 3;
+ data = NULL;
+}
+
+PreviewOutputImage::~PreviewOutputImage() {
+ if (data) {
+ free(data);
+ }
+}
+
+int
+PreviewOutputImage::init_internal(int w, int h) {
+ data = (uchar*) malloc(w * h * d);
+ memset(data, 0, w * h * d);
+ row = 0;
+ size(w, h);
+ return 0;
+}
+
+
+
+int
+PreviewOutputImage::set_pixel_internal(int x, char r, char g, char b) {
+ if (!data) {
+ return 1;
+ }
+
+ long index = (row * w() * d + (x * d));
+ *(data+index+0) = r;
+ *(data+index+1) = g;
+ *(data+index+2) = b;
+
+ return 0;
+}
+
+int
+PreviewOutputImage::next_line_internal() {
+ row++;
+ if (row % (h() / 100) == 0) {
+ redraw();
+ Fl::check();
+ }
+ return 0;
+}
+
+int
+PreviewOutputImage::done_internal() {
+ return 0;
+}
+
+void
+PreviewOutputImage::draw() {
+ if (!data) {
+ return;
+ }
+ fl_push_clip(x(), y(), w(), h());
+
+ fl_draw_image(data, x(), y(), w(), h(), d);
+
+ fl_pop_clip();
+}
+
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index 5cd170a..5dd69a7 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 "PreviewOutputImage.H"
#include "Stitch.H"
#include "choose_hill.H"
#include "../config.h"
@@ -448,18 +449,18 @@ 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 0
+
win = new Fl_Window(0,0, 1000, stitch_h);
scroll = new Fl_Scroll(0, 0, win->w(), win->h());
- PreviewOutputImage *img = new PreviewOutputImage();
+ PreviewOutputImage *img = new PreviewOutputImage(0, 0, stitch_w, stitch_h);
win->resizable(scroll);
win->show(0, argv);
- st->resample(img, 0.0, 7.0);
-#endif
- st->set_output((OutputImage*) new JPEGOutputImage("/tmp/bla.jpg", 90));
+ //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();
return 0;