6 #include "GmshConfig.h"
10 #if !defined(HAVE_LIBJPEG)
14 Msg::Error(
"This version of Gmsh was compiled without JPEG support");
24 static void my_output_message(j_common_ptr cinfo)
26 char buffer[JMSG_LENGTH_MAX];
28 (*cinfo->err->format_message)(cinfo, buffer);
36 Msg::Error(
"JPEG only implemented for GL_RGB and GL_UNSIGNED_BYTE");
40 struct jpeg_compress_struct cinfo;
41 struct jpeg_error_mgr jerr;
42 cinfo.err = jpeg_std_error(&jerr);
43 cinfo.err->output_message = my_output_message;
45 jpeg_create_compress(&cinfo);
46 jpeg_stdio_dest(&cinfo, outfile);
47 cinfo.image_width = buffer->
getWidth();
49 cinfo.input_components = 3;
50 cinfo.in_color_space = JCS_RGB;
51 jpeg_set_defaults(&cinfo);
52 jpeg_set_quality(&cinfo, quality,
TRUE);
53 cinfo.optimize_coding =
TRUE;
54 cinfo.smoothing_factor = smoothing;
55 jpeg_start_compress(&cinfo,
TRUE);
57 unsigned char *pixels = (
unsigned char *)buffer->
getPixels();
58 JSAMPROW row_pointer[1];
59 int row_stride = cinfo.image_width * cinfo.input_components;
60 int i = cinfo.image_height - 1;
62 row_pointer[0] = &pixels[i * row_stride];
63 (void)jpeg_write_scanlines(&cinfo, row_pointer, 1);
66 jpeg_finish_compress(&cinfo);
67 jpeg_destroy_compress(&cinfo);