summaryrefslogtreecommitdiff
path: root/src/DataImage.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/DataImage.cxx')
-rw-r--r--src/DataImage.cxx41
1 files changed, 39 insertions, 2 deletions
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;
+}