summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-07-31 17:09:25 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-07-31 17:09:25 +0200
commitd258151391bead3a167f54068096a8d727ba273a (patch)
treeb0f8a81f227f3c6418b11ae77e1f2b785c09781e /src
parent3ad29069b15a21d1b9f3d965d70cecce8c650c4c (diff)
add jpeg write support to DataImage
Diffstat (limited to 'src')
-rw-r--r--src/DataImage.H2
-rw-r--r--src/DataImage.cxx41
-rw-r--r--src/gipfel.cxx2
3 files changed, 43 insertions, 2 deletions
diff --git a/src/DataImage.H b/src/DataImage.H
index ec3b1ec..49cd952 100644
--- a/src/DataImage.H
+++ b/src/DataImage.H
@@ -38,6 +38,8 @@ class DataImage : public Fl_Widget {
void draw();
+ int write_jpeg(const char *file, int quality);
+
static int get_pixel(Fl_Image *img, int x, int y,
char *r, char *g, char *b);
diff --git a/src/DataImage.cxx b/src/DataImage.cxx
index efc05e3..f7968b2 100644
--- a/src/DataImage.cxx
+++ b/src/DataImage.cxx
@@ -23,6 +23,9 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
+extern "C" {
+#include <jpeglib.h>
+}
#include <Fl/fl_draw.h>
@@ -31,7 +34,7 @@
DataImage::DataImage(int X, int Y, int W, int H): Fl_Widget(X, Y, W, H) {
d = 3;
data = (uchar*) malloc(W * H * d);
- memset(data, 0, W * H * d);
+ memset(data, 200, W * H * d);
}
DataImage::~DataImage() {
@@ -117,10 +120,44 @@ DataImage::get_pixel(Fl_Image *img, int x, int y,
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() * 3; /* 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;
+}
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index a5b0fc9..acdd1de 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -433,6 +433,8 @@ int stitch(int stitch_w, int stitch_h, int argc, char **argv) {
win->show(0, argv);
st->resample(img, 0.0, 7.0);
+
+ img->write_jpeg("/tmp/bla.jpg", 90);
Fl::run();
exit(0);
}