Image: Codestyle changes

This commit is contained in:
Peter Keresztes Schmidt 2021-09-12 11:38:44 +02:00 committed by Isaac Connor
parent 93c5ad0939
commit a4ebf533a9
1 changed files with 151 additions and 153 deletions

View File

@ -936,7 +936,7 @@ bool Image::WriteRaw(const char *filename) const {
bool Image::ReadJpeg(const std::string &filename, unsigned int p_colours, unsigned int p_subpixelorder) { bool Image::ReadJpeg(const std::string &filename, unsigned int p_colours, unsigned int p_subpixelorder) {
unsigned int new_width, new_height, new_colours, new_subpixelorder; unsigned int new_width, new_height, new_colours, new_subpixelorder;
if ( !readjpg_dcinfo ) { if (!readjpg_dcinfo) {
readjpg_dcinfo = new jpeg_decompress_struct; readjpg_dcinfo = new jpeg_decompress_struct;
readjpg_dcinfo->err = jpeg_std_error(&jpg_err.pub); readjpg_dcinfo->err = jpeg_std_error(&jpg_err.pub);
jpg_err.pub.error_exit = zm_jpeg_error_exit; jpg_err.pub.error_exit = zm_jpeg_error_exit;
@ -945,12 +945,12 @@ bool Image::ReadJpeg(const std::string &filename, unsigned int p_colours, unsign
} }
FILE *infile; FILE *infile;
if ( (infile = fopen(filename.c_str(), "rb")) == nullptr ) { if ((infile = fopen(filename.c_str(), "rb")) == nullptr) {
Error("Can't open %s: %s", filename.c_str(), strerror(errno)); Error("Can't open %s: %s", filename.c_str(), strerror(errno));
return false; return false;
} }
if ( setjmp(jpg_err.setjmp_buffer) ) { if (setjmp(jpg_err.setjmp_buffer)) {
jpeg_abort_decompress(readjpg_dcinfo); jpeg_abort_decompress(readjpg_dcinfo);
fclose(infile); fclose(infile);
return false; return false;
@ -958,9 +958,9 @@ bool Image::ReadJpeg(const std::string &filename, unsigned int p_colours, unsign
jpeg_stdio_src(readjpg_dcinfo, infile); jpeg_stdio_src(readjpg_dcinfo, infile);
jpeg_read_header(readjpg_dcinfo, TRUE); jpeg_read_header(readjpg_dcinfo, true);
if ( (readjpg_dcinfo->num_components != 1) && (readjpg_dcinfo->num_components != 3) ) { if ((readjpg_dcinfo->num_components != 1) && (readjpg_dcinfo->num_components != 3)) {
Error("Unexpected colours when reading jpeg image: %d", colours); Error("Unexpected colours when reading jpeg image: %d", colours);
jpeg_abort_decompress(readjpg_dcinfo); jpeg_abort_decompress(readjpg_dcinfo);
fclose(infile); fclose(infile);
@ -969,72 +969,72 @@ bool Image::ReadJpeg(const std::string &filename, unsigned int p_colours, unsign
/* Check if the image has at least one huffman table defined. If not, use the standard ones */ /* Check if the image has at least one huffman table defined. If not, use the standard ones */
/* This is required for the MJPEG capture palette of USB devices */ /* This is required for the MJPEG capture palette of USB devices */
if ( readjpg_dcinfo->dc_huff_tbl_ptrs[0] == nullptr ) { if (readjpg_dcinfo->dc_huff_tbl_ptrs[0] == nullptr) {
zm_use_std_huff_tables(readjpg_dcinfo); zm_use_std_huff_tables(readjpg_dcinfo);
} }
new_width = readjpg_dcinfo->image_width; new_width = readjpg_dcinfo->image_width;
new_height = readjpg_dcinfo->image_height; new_height = readjpg_dcinfo->image_height;
if ( (width != new_width) || (height != new_height) ) { if ((width != new_width) || (height != new_height)) {
Debug(9, "Image dimensions differ. Old: %ux%u New: %ux%u", width, height, new_width, new_height); Debug(9, "Image dimensions differ. Old: %ux%u New: %ux%u", width, height, new_width, new_height);
} }
switch ( p_colours ) { switch (p_colours) {
case ZM_COLOUR_GRAY8: case ZM_COLOUR_GRAY8:
readjpg_dcinfo->out_color_space = JCS_GRAYSCALE; readjpg_dcinfo->out_color_space = JCS_GRAYSCALE;
new_colours = ZM_COLOUR_GRAY8; new_colours = ZM_COLOUR_GRAY8;
new_subpixelorder = ZM_SUBPIX_ORDER_NONE; new_subpixelorder = ZM_SUBPIX_ORDER_NONE;
break; break;
case ZM_COLOUR_RGB32: case ZM_COLOUR_RGB32:
#ifdef JCS_EXTENSIONS #ifdef JCS_EXTENSIONS
new_colours = ZM_COLOUR_RGB32; new_colours = ZM_COLOUR_RGB32;
if ( p_subpixelorder == ZM_SUBPIX_ORDER_BGRA ) { if (p_subpixelorder == ZM_SUBPIX_ORDER_BGRA) {
readjpg_dcinfo->out_color_space = JCS_EXT_BGRX; readjpg_dcinfo->out_color_space = JCS_EXT_BGRX;
new_subpixelorder = ZM_SUBPIX_ORDER_BGRA; new_subpixelorder = ZM_SUBPIX_ORDER_BGRA;
} else if ( p_subpixelorder == ZM_SUBPIX_ORDER_ARGB ) { } else if (p_subpixelorder == ZM_SUBPIX_ORDER_ARGB) {
readjpg_dcinfo->out_color_space = JCS_EXT_XRGB; readjpg_dcinfo->out_color_space = JCS_EXT_XRGB;
new_subpixelorder = ZM_SUBPIX_ORDER_ARGB; new_subpixelorder = ZM_SUBPIX_ORDER_ARGB;
} else if ( p_subpixelorder == ZM_SUBPIX_ORDER_ABGR ) { } else if (p_subpixelorder == ZM_SUBPIX_ORDER_ABGR) {
readjpg_dcinfo->out_color_space = JCS_EXT_XBGR; readjpg_dcinfo->out_color_space = JCS_EXT_XBGR;
new_subpixelorder = ZM_SUBPIX_ORDER_ABGR; new_subpixelorder = ZM_SUBPIX_ORDER_ABGR;
} else { } else {
/* Assume RGBA */ /* Assume RGBA */
readjpg_dcinfo->out_color_space = JCS_EXT_RGBX; readjpg_dcinfo->out_color_space = JCS_EXT_RGBX;
new_subpixelorder = ZM_SUBPIX_ORDER_RGBA; new_subpixelorder = ZM_SUBPIX_ORDER_RGBA;
} }
break; break;
#else #else
Warning("libjpeg-turbo is required for reading a JPEG directly into a RGB32 buffer, reading into a RGB24 buffer instead."); Warning("libjpeg-turbo is required for reading a JPEG directly into a RGB32 buffer, reading into a RGB24 buffer instead.");
#endif #endif
case ZM_COLOUR_RGB24: case ZM_COLOUR_RGB24:
default: default:
new_colours = ZM_COLOUR_RGB24; new_colours = ZM_COLOUR_RGB24;
if ( p_subpixelorder == ZM_SUBPIX_ORDER_BGR ) { if (p_subpixelorder == ZM_SUBPIX_ORDER_BGR) {
#ifdef JCS_EXTENSIONS #ifdef JCS_EXTENSIONS
readjpg_dcinfo->out_color_space = JCS_EXT_BGR; readjpg_dcinfo->out_color_space = JCS_EXT_BGR;
new_subpixelorder = ZM_SUBPIX_ORDER_BGR; new_subpixelorder = ZM_SUBPIX_ORDER_BGR;
#else #else
Warning("libjpeg-turbo is required for reading a JPEG directly into a BGR24 buffer, reading into a RGB24 buffer instead."); Warning("libjpeg-turbo is required for reading a JPEG directly into a BGR24 buffer, reading into a RGB24 buffer instead.");
cinfo->out_color_space = JCS_RGB; cinfo->out_color_space = JCS_RGB;
new_subpixelorder = ZM_SUBPIX_ORDER_RGB; new_subpixelorder = ZM_SUBPIX_ORDER_RGB;
#endif #endif
} else { } else {
/* Assume RGB */ /* Assume RGB */
/* /*
#ifdef JCS_EXTENSIONS #ifdef JCS_EXTENSIONS
cinfo->out_color_space = JCS_EXT_RGB; cinfo->out_color_space = JCS_EXT_RGB;
#else #else
cinfo->out_color_space = JCS_RGB; cinfo->out_color_space = JCS_RGB;
#endif #endif
*/ */
readjpg_dcinfo->out_color_space = JCS_RGB; readjpg_dcinfo->out_color_space = JCS_RGB;
new_subpixelorder = ZM_SUBPIX_ORDER_RGB; new_subpixelorder = ZM_SUBPIX_ORDER_RGB;
} }
break; break;
} // end switch p_colours } // end switch p_colours
if ( WriteBuffer(new_width, new_height, new_colours, new_subpixelorder) == nullptr ) { if (WriteBuffer(new_width, new_height, new_colours, new_subpixelorder) == nullptr) {
Error("Failed requesting writeable buffer for reading JPEG image."); Error("Failed requesting writeable buffer for reading JPEG image.");
jpeg_abort_decompress(readjpg_dcinfo); jpeg_abort_decompress(readjpg_dcinfo);
fclose(infile); fclose(infile);
@ -1044,13 +1044,12 @@ cinfo->out_color_space = JCS_RGB;
jpeg_start_decompress(readjpg_dcinfo); jpeg_start_decompress(readjpg_dcinfo);
JSAMPROW row_pointer = buffer; JSAMPROW row_pointer = buffer;
while ( readjpg_dcinfo->output_scanline < readjpg_dcinfo->output_height ) { while (readjpg_dcinfo->output_scanline < readjpg_dcinfo->output_height) {
jpeg_read_scanlines(readjpg_dcinfo, &row_pointer, 1); jpeg_read_scanlines(readjpg_dcinfo, &row_pointer, 1);
row_pointer += linesize; row_pointer += linesize;
} }
jpeg_finish_decompress(readjpg_dcinfo); jpeg_finish_decompress(readjpg_dcinfo);
fclose(infile); fclose(infile);
return true; return true;
@ -1080,34 +1079,37 @@ bool Image::WriteJpeg(const std::string &filename,
const int &quality_override, const int &quality_override,
SystemTimePoint timestamp, SystemTimePoint timestamp,
bool on_blocking_abort) const { bool on_blocking_abort) const {
if ( config.colour_jpeg_files && (colours == ZM_COLOUR_GRAY8) ) { if (config.colour_jpeg_files && (colours == ZM_COLOUR_GRAY8)) {
Image temp_image(*this); Image temp_image(*this);
temp_image.Colourise(ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB); temp_image.Colourise(ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB);
return temp_image.WriteJpeg(filename, quality_override, timestamp, on_blocking_abort); return temp_image.WriteJpeg(filename, quality_override, timestamp, on_blocking_abort);
} }
int quality = quality_override ? quality_override : config.jpeg_file_quality; int quality = quality_override ? quality_override : config.jpeg_file_quality;
struct jpeg_compress_struct *cinfo = writejpg_ccinfo[quality]; jpeg_compress_struct *cinfo = writejpg_ccinfo[quality];
FILE *outfile = nullptr; FILE *outfile = nullptr;
int raw_fd = 0; int raw_fd = 0;
if ( !cinfo ) { if (!cinfo) {
cinfo = writejpg_ccinfo[quality] = new jpeg_compress_struct; cinfo = writejpg_ccinfo[quality] = new jpeg_compress_struct;
cinfo->err = jpeg_std_error(&jpg_err.pub); cinfo->err = jpeg_std_error(&jpg_err.pub);
jpeg_create_compress(cinfo); jpeg_create_compress(cinfo);
} }
if ( !on_blocking_abort ) { if (!on_blocking_abort) {
jpg_err.pub.error_exit = zm_jpeg_error_exit; jpg_err.pub.error_exit = zm_jpeg_error_exit;
jpg_err.pub.emit_message = zm_jpeg_emit_message; jpg_err.pub.emit_message = zm_jpeg_emit_message;
} else { } else {
jpg_err.pub.error_exit = zm_jpeg_error_silent; jpg_err.pub.error_exit = zm_jpeg_error_silent;
jpg_err.pub.emit_message = zm_jpeg_emit_silence; jpg_err.pub.emit_message = zm_jpeg_emit_silence;
if ( setjmp(jpg_err.setjmp_buffer) ) { if (setjmp(jpg_err.setjmp_buffer)) {
jpeg_abort_compress(cinfo); jpeg_abort_compress(cinfo);
Debug(1, "Aborted a write mid-stream and %s and %d", (outfile == nullptr) ? "closing file" : "file not opened", raw_fd); Debug(1,
if ( raw_fd ) "Aborted a write mid-stream and %s and %d",
(outfile == nullptr) ? "closing file" : "file not opened",
raw_fd);
if (raw_fd)
close(raw_fd); close(raw_fd);
if ( outfile ) if (outfile)
fclose(outfile); fclose(outfile);
return false; return false;
} }
@ -1134,58 +1136,58 @@ bool Image::WriteJpeg(const std::string &filename,
cinfo->image_width = width; /* image width and height, in pixels */ cinfo->image_width = width; /* image width and height, in pixels */
cinfo->image_height = height; cinfo->image_height = height;
switch ( colours ) { switch (colours) {
case ZM_COLOUR_GRAY8: case ZM_COLOUR_GRAY8:
cinfo->input_components = 1; cinfo->input_components = 1;
cinfo->in_color_space = JCS_GRAYSCALE; cinfo->in_color_space = JCS_GRAYSCALE;
break; break;
case ZM_COLOUR_RGB32: case ZM_COLOUR_RGB32:
#ifdef JCS_EXTENSIONS #ifdef JCS_EXTENSIONS
cinfo->input_components = 4; cinfo->input_components = 4;
if ( subpixelorder == ZM_SUBPIX_ORDER_RGBA ) { if (subpixelorder == ZM_SUBPIX_ORDER_RGBA) {
cinfo->in_color_space = JCS_EXT_RGBX; cinfo->in_color_space = JCS_EXT_RGBX;
} else if ( subpixelorder == ZM_SUBPIX_ORDER_BGRA ) { } else if (subpixelorder == ZM_SUBPIX_ORDER_BGRA) {
cinfo->in_color_space = JCS_EXT_BGRX; cinfo->in_color_space = JCS_EXT_BGRX;
} else if ( subpixelorder == ZM_SUBPIX_ORDER_ARGB ) { } else if (subpixelorder == ZM_SUBPIX_ORDER_ARGB) {
cinfo->in_color_space = JCS_EXT_XRGB; cinfo->in_color_space = JCS_EXT_XRGB;
} else if ( subpixelorder == ZM_SUBPIX_ORDER_ABGR ) { } else if (subpixelorder == ZM_SUBPIX_ORDER_ABGR) {
cinfo->in_color_space = JCS_EXT_XBGR; cinfo->in_color_space = JCS_EXT_XBGR;
} else { } else {
Warning("Unknwon subpixelorder %d", subpixelorder); Warning("Unknwon subpixelorder %d", subpixelorder);
/* Assume RGBA */ /* Assume RGBA */
cinfo->in_color_space = JCS_EXT_RGBX; cinfo->in_color_space = JCS_EXT_RGBX;
} }
break; break;
#else #else
Error("libjpeg-turbo is required for JPEG encoding directly from RGB32 source"); Error("libjpeg-turbo is required for JPEG encoding directly from RGB32 source");
jpeg_abort_compress(cinfo);
fclose(outfile);
return false;
#endif
case ZM_COLOUR_RGB24:
default:
cinfo->input_components = 3;
if (subpixelorder == ZM_SUBPIX_ORDER_BGR) {
#ifdef JCS_EXTENSIONS
cinfo->in_color_space = JCS_EXT_BGR;
#else
Error("libjpeg-turbo is required for JPEG encoding directly from BGR24 source");
jpeg_abort_compress(cinfo); jpeg_abort_compress(cinfo);
fclose(outfile); fclose(outfile);
return false; return false;
#endif #endif
case ZM_COLOUR_RGB24: } else {
default: /* Assume RGB */
cinfo->input_components = 3; /*
if ( subpixelorder == ZM_SUBPIX_ORDER_BGR) {
#ifdef JCS_EXTENSIONS
cinfo->in_color_space = JCS_EXT_BGR;
#else
Error("libjpeg-turbo is required for JPEG encoding directly from BGR24 source");
jpeg_abort_compress(cinfo);
fclose(outfile);
return false;
#endif
} else {
/* Assume RGB */
/*
#ifdef JCS_EXTENSIONS #ifdef JCS_EXTENSIONS
cinfo->out_color_space = JCS_EXT_RGB; cinfo->out_color_space = JCS_EXT_RGB;
#else #else
cinfo->out_color_space = JCS_RGB; cinfo->out_color_space = JCS_RGB;
#endif #endif
*/ */
cinfo->in_color_space = JCS_RGB; cinfo->in_color_space = JCS_RGB;
} }
break; break;
} // end switch(colours) } // end switch(colours)
jpeg_set_defaults(cinfo); jpeg_set_defaults(cinfo);
@ -1193,7 +1195,7 @@ cinfo->out_color_space = JCS_RGB;
cinfo->dct_method = JDCT_FASTEST; cinfo->dct_method = JDCT_FASTEST;
jpeg_start_compress(cinfo, TRUE); jpeg_start_compress(cinfo, TRUE);
if ( config.add_jpeg_comments && !annotation_.empty() ) { if (config.add_jpeg_comments && !annotation_.empty()) {
jpeg_write_marker(cinfo, JPEG_COM, reinterpret_cast<const JOCTET *>(annotation_.c_str()), annotation_.size()); jpeg_write_marker(cinfo, JPEG_COM, reinterpret_cast<const JOCTET *>(annotation_.c_str()), annotation_.size());
} }
// If we have a non-zero time (meaning a parameter was passed in), then form a simple exif segment with that time as DateTimeOriginal and SubsecTimeOriginal // If we have a non-zero time (meaning a parameter was passed in), then form a simple exif segment with that time as DateTimeOriginal and SubsecTimeOriginal
@ -1217,19 +1219,19 @@ cinfo->out_color_space = JCS_RGB;
snprintf(msbuf, sizeof msbuf, "%06d", static_cast<int32>(ts_usec.count())); snprintf(msbuf, sizeof msbuf, "%06d", static_cast<int32>(ts_usec.count()));
unsigned char exiftimes[82] = { unsigned char exiftimes[82] = {
0x45, 0x78, 0x69, 0x66, 0x00, 0x00, 0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x45, 0x78, 0x69, 0x66, 0x00, 0x00, 0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00,
0x69, 0x87, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x87, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x03, 0x90, 0x02, 0x00, 0x14, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x91, 0x92, 0x02, 0x00, 0x03, 0x90, 0x02, 0x00, 0x14, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x91, 0x92,
0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x00 }; 0xff, 0x00};
memcpy(&exiftimes[EXIFTIMES_OFFSET], timebuf,EXIFTIMES_LEN); memcpy(&exiftimes[EXIFTIMES_OFFSET], timebuf, EXIFTIMES_LEN);
memcpy(&exiftimes[EXIFTIMES_MS_OFFSET], msbuf, EXIFTIMES_MS_LEN); memcpy(&exiftimes[EXIFTIMES_MS_OFFSET], msbuf, EXIFTIMES_MS_LEN);
jpeg_write_marker(cinfo, EXIF_CODE, (const JOCTET *)exiftimes, sizeof(exiftimes)); jpeg_write_marker(cinfo, EXIF_CODE, (const JOCTET *) exiftimes, sizeof(exiftimes));
} }
JSAMPROW row_pointer = buffer; /* pointer to a single row */ JSAMPROW row_pointer = buffer; /* pointer to a single row */
while ( cinfo->next_scanline < cinfo->image_height ) { while (cinfo->next_scanline < cinfo->image_height) {
jpeg_write_scanlines(cinfo, &row_pointer, 1); jpeg_write_scanlines(cinfo, &row_pointer, 1);
row_pointer += linesize; row_pointer += linesize;
} }
@ -1239,23 +1241,19 @@ cinfo->out_color_space = JCS_RGB;
return true; return true;
} }
bool Image::DecodeJpeg( bool Image::DecodeJpeg(const JOCTET *inbuffer, int inbuffer_size, unsigned int p_colours, unsigned int p_subpixelorder)
const JOCTET *inbuffer,
int inbuffer_size,
unsigned int p_colours,
unsigned int p_subpixelorder)
{ {
unsigned int new_width, new_height, new_colours, new_subpixelorder; unsigned int new_width, new_height, new_colours, new_subpixelorder;
if ( !decodejpg_dcinfo ) { if (!decodejpg_dcinfo) {
decodejpg_dcinfo = new jpeg_decompress_struct; decodejpg_dcinfo = new jpeg_decompress_struct;
decodejpg_dcinfo->err = jpeg_std_error( &jpg_err.pub ); decodejpg_dcinfo->err = jpeg_std_error(&jpg_err.pub);
jpg_err.pub.error_exit = zm_jpeg_error_exit; jpg_err.pub.error_exit = zm_jpeg_error_exit;
jpg_err.pub.emit_message = zm_jpeg_emit_message; jpg_err.pub.emit_message = zm_jpeg_emit_message;
jpeg_create_decompress( decodejpg_dcinfo ); jpeg_create_decompress(decodejpg_dcinfo);
} }
if ( setjmp(jpg_err.setjmp_buffer) ) { if (setjmp(jpg_err.setjmp_buffer)) {
jpeg_abort_decompress(decodejpg_dcinfo); jpeg_abort_decompress(decodejpg_dcinfo);
return false; return false;
} }
@ -1264,7 +1262,7 @@ bool Image::DecodeJpeg(
jpeg_read_header(decodejpg_dcinfo, TRUE); jpeg_read_header(decodejpg_dcinfo, TRUE);
if ( (decodejpg_dcinfo->num_components != 1) && (decodejpg_dcinfo->num_components != 3) ) { if ((decodejpg_dcinfo->num_components != 1) && (decodejpg_dcinfo->num_components != 3)) {
Error("Unexpected colours when reading jpeg image: %d", colours); Error("Unexpected colours when reading jpeg image: %d", colours);
jpeg_abort_decompress(decodejpg_dcinfo); jpeg_abort_decompress(decodejpg_dcinfo);
return false; return false;
@ -1272,73 +1270,73 @@ bool Image::DecodeJpeg(
/* Check if the image has at least one huffman table defined. If not, use the standard ones */ /* Check if the image has at least one huffman table defined. If not, use the standard ones */
/* This is required for the MJPEG capture palette of USB devices */ /* This is required for the MJPEG capture palette of USB devices */
if ( decodejpg_dcinfo->dc_huff_tbl_ptrs[0] == nullptr ) { if (decodejpg_dcinfo->dc_huff_tbl_ptrs[0] == nullptr) {
zm_use_std_huff_tables(decodejpg_dcinfo); zm_use_std_huff_tables(decodejpg_dcinfo);
} }
new_width = decodejpg_dcinfo->image_width; new_width = decodejpg_dcinfo->image_width;
new_height = decodejpg_dcinfo->image_height; new_height = decodejpg_dcinfo->image_height;
if ( (width != new_width) || (height != new_height) ) { if ((width != new_width) || (height != new_height)) {
Debug(9, "Image dimensions differ. Old: %ux%u New: %ux%u", Debug(9, "Image dimensions differ. Old: %ux%u New: %ux%u",
width, height, new_width, new_height); width, height, new_width, new_height);
} }
switch (p_colours) { switch (p_colours) {
case ZM_COLOUR_GRAY8: case ZM_COLOUR_GRAY8:
decodejpg_dcinfo->out_color_space = JCS_GRAYSCALE; decodejpg_dcinfo->out_color_space = JCS_GRAYSCALE;
new_colours = ZM_COLOUR_GRAY8; new_colours = ZM_COLOUR_GRAY8;
new_subpixelorder = ZM_SUBPIX_ORDER_NONE; new_subpixelorder = ZM_SUBPIX_ORDER_NONE;
break; break;
case ZM_COLOUR_RGB32: case ZM_COLOUR_RGB32:
#ifdef JCS_EXTENSIONS #ifdef JCS_EXTENSIONS
new_colours = ZM_COLOUR_RGB32; new_colours = ZM_COLOUR_RGB32;
if ( p_subpixelorder == ZM_SUBPIX_ORDER_BGRA ) { if (p_subpixelorder == ZM_SUBPIX_ORDER_BGRA) {
decodejpg_dcinfo->out_color_space = JCS_EXT_BGRX; decodejpg_dcinfo->out_color_space = JCS_EXT_BGRX;
new_subpixelorder = ZM_SUBPIX_ORDER_BGRA; new_subpixelorder = ZM_SUBPIX_ORDER_BGRA;
} else if ( p_subpixelorder == ZM_SUBPIX_ORDER_ARGB ) { } else if (p_subpixelorder == ZM_SUBPIX_ORDER_ARGB) {
decodejpg_dcinfo->out_color_space = JCS_EXT_XRGB; decodejpg_dcinfo->out_color_space = JCS_EXT_XRGB;
new_subpixelorder = ZM_SUBPIX_ORDER_ARGB; new_subpixelorder = ZM_SUBPIX_ORDER_ARGB;
} else if ( p_subpixelorder == ZM_SUBPIX_ORDER_ABGR ) { } else if (p_subpixelorder == ZM_SUBPIX_ORDER_ABGR) {
decodejpg_dcinfo->out_color_space = JCS_EXT_XBGR; decodejpg_dcinfo->out_color_space = JCS_EXT_XBGR;
new_subpixelorder = ZM_SUBPIX_ORDER_ABGR; new_subpixelorder = ZM_SUBPIX_ORDER_ABGR;
} else { } else {
/* Assume RGBA */ /* Assume RGBA */
decodejpg_dcinfo->out_color_space = JCS_EXT_RGBX; decodejpg_dcinfo->out_color_space = JCS_EXT_RGBX;
new_subpixelorder = ZM_SUBPIX_ORDER_RGBA; new_subpixelorder = ZM_SUBPIX_ORDER_RGBA;
} }
break; break;
#else #else
Warning("libjpeg-turbo is required for reading a JPEG directly into a RGB32 buffer, reading into a RGB24 buffer instead."); Warning("libjpeg-turbo is required for reading a JPEG directly into a RGB32 buffer, reading into a RGB24 buffer instead.");
#endif #endif
case ZM_COLOUR_RGB24: case ZM_COLOUR_RGB24:
default: default:
new_colours = ZM_COLOUR_RGB24; new_colours = ZM_COLOUR_RGB24;
if ( p_subpixelorder == ZM_SUBPIX_ORDER_BGR ) { if (p_subpixelorder == ZM_SUBPIX_ORDER_BGR) {
#ifdef JCS_EXTENSIONS #ifdef JCS_EXTENSIONS
decodejpg_dcinfo->out_color_space = JCS_EXT_BGR; decodejpg_dcinfo->out_color_space = JCS_EXT_BGR;
new_subpixelorder = ZM_SUBPIX_ORDER_BGR; new_subpixelorder = ZM_SUBPIX_ORDER_BGR;
#else #else
Warning("libjpeg-turbo is required for reading a JPEG directly into a BGR24 buffer, reading into a RGB24 buffer instead."); Warning("libjpeg-turbo is required for reading a JPEG directly into a BGR24 buffer, reading into a RGB24 buffer instead.");
cinfo->out_color_space = JCS_RGB; cinfo->out_color_space = JCS_RGB;
new_subpixelorder = ZM_SUBPIX_ORDER_RGB; new_subpixelorder = ZM_SUBPIX_ORDER_RGB;
#endif #endif
} else { } else {
/* Assume RGB */ /* Assume RGB */
/* /*
#ifdef JCS_EXTENSIONS #ifdef JCS_EXTENSIONS
cinfo->out_color_space = JCS_EXT_RGB; cinfo->out_color_space = JCS_EXT_RGB;
#else #else
cinfo->out_color_space = JCS_RGB; cinfo->out_color_space = JCS_RGB;
#endif #endif
*/ */
decodejpg_dcinfo->out_color_space = JCS_RGB; decodejpg_dcinfo->out_color_space = JCS_RGB;
new_subpixelorder = ZM_SUBPIX_ORDER_RGB; new_subpixelorder = ZM_SUBPIX_ORDER_RGB;
} }
break; break;
} // end switch } // end switch
if ( WriteBuffer(new_width, new_height, new_colours, new_subpixelorder) == nullptr ) { if (WriteBuffer(new_width, new_height, new_colours, new_subpixelorder) == nullptr) {
Error("Failed requesting writeable buffer for reading JPEG image."); Error("Failed requesting writeable buffer for reading JPEG image.");
jpeg_abort_decompress(decodejpg_dcinfo); jpeg_abort_decompress(decodejpg_dcinfo);
return false; return false;
@ -1347,7 +1345,7 @@ cinfo->out_color_space = JCS_RGB;
jpeg_start_decompress(decodejpg_dcinfo); jpeg_start_decompress(decodejpg_dcinfo);
JSAMPROW row_pointer = buffer; /* pointer to a single row */ JSAMPROW row_pointer = buffer; /* pointer to a single row */
while ( decodejpg_dcinfo->output_scanline < decodejpg_dcinfo->output_height ) { while (decodejpg_dcinfo->output_scanline < decodejpg_dcinfo->output_height) {
jpeg_read_scanlines(decodejpg_dcinfo, &row_pointer, 1); jpeg_read_scanlines(decodejpg_dcinfo, &row_pointer, 1);
row_pointer += linesize; row_pointer += linesize;
} }