Image: Codestyle changes
This commit is contained in:
parent
93c5ad0939
commit
a4ebf533a9
102
src/zm_image.cpp
102
src/zm_image.cpp
|
@ -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) {
|
||||
unsigned int new_width, new_height, new_colours, new_subpixelorder;
|
||||
|
||||
if ( !readjpg_dcinfo ) {
|
||||
if (!readjpg_dcinfo) {
|
||||
readjpg_dcinfo = new jpeg_decompress_struct;
|
||||
readjpg_dcinfo->err = jpeg_std_error(&jpg_err.pub);
|
||||
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;
|
||||
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));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( setjmp(jpg_err.setjmp_buffer) ) {
|
||||
if (setjmp(jpg_err.setjmp_buffer)) {
|
||||
jpeg_abort_decompress(readjpg_dcinfo);
|
||||
fclose(infile);
|
||||
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_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);
|
||||
jpeg_abort_decompress(readjpg_dcinfo);
|
||||
fclose(infile);
|
||||
|
@ -969,18 +969,18 @@ 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 */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
new_width = readjpg_dcinfo->image_width;
|
||||
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);
|
||||
}
|
||||
|
||||
switch ( p_colours ) {
|
||||
switch (p_colours) {
|
||||
case ZM_COLOUR_GRAY8:
|
||||
readjpg_dcinfo->out_color_space = JCS_GRAYSCALE;
|
||||
new_colours = ZM_COLOUR_GRAY8;
|
||||
|
@ -989,13 +989,13 @@ bool Image::ReadJpeg(const std::string &filename, unsigned int p_colours, unsign
|
|||
case ZM_COLOUR_RGB32:
|
||||
#ifdef JCS_EXTENSIONS
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
new_subpixelorder = ZM_SUBPIX_ORDER_ABGR;
|
||||
} else {
|
||||
|
@ -1010,7 +1010,7 @@ bool Image::ReadJpeg(const std::string &filename, unsigned int p_colours, unsign
|
|||
case ZM_COLOUR_RGB24:
|
||||
default:
|
||||
new_colours = ZM_COLOUR_RGB24;
|
||||
if ( p_subpixelorder == ZM_SUBPIX_ORDER_BGR ) {
|
||||
if (p_subpixelorder == ZM_SUBPIX_ORDER_BGR) {
|
||||
#ifdef JCS_EXTENSIONS
|
||||
readjpg_dcinfo->out_color_space = JCS_EXT_BGR;
|
||||
new_subpixelorder = ZM_SUBPIX_ORDER_BGR;
|
||||
|
@ -1034,7 +1034,7 @@ cinfo->out_color_space = JCS_RGB;
|
|||
break;
|
||||
} // 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.");
|
||||
jpeg_abort_decompress(readjpg_dcinfo);
|
||||
fclose(infile);
|
||||
|
@ -1044,13 +1044,12 @@ cinfo->out_color_space = JCS_RGB;
|
|||
jpeg_start_decompress(readjpg_dcinfo);
|
||||
|
||||
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);
|
||||
row_pointer += linesize;
|
||||
}
|
||||
|
||||
jpeg_finish_decompress(readjpg_dcinfo);
|
||||
|
||||
fclose(infile);
|
||||
|
||||
return true;
|
||||
|
@ -1080,34 +1079,37 @@ bool Image::WriteJpeg(const std::string &filename,
|
|||
const int &quality_override,
|
||||
SystemTimePoint timestamp,
|
||||
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);
|
||||
temp_image.Colourise(ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB);
|
||||
return temp_image.WriteJpeg(filename, quality_override, timestamp, on_blocking_abort);
|
||||
}
|
||||
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;
|
||||
int raw_fd = 0;
|
||||
|
||||
if ( !cinfo ) {
|
||||
if (!cinfo) {
|
||||
cinfo = writejpg_ccinfo[quality] = new jpeg_compress_struct;
|
||||
cinfo->err = jpeg_std_error(&jpg_err.pub);
|
||||
jpeg_create_compress(cinfo);
|
||||
}
|
||||
if ( !on_blocking_abort ) {
|
||||
if (!on_blocking_abort) {
|
||||
jpg_err.pub.error_exit = zm_jpeg_error_exit;
|
||||
jpg_err.pub.emit_message = zm_jpeg_emit_message;
|
||||
} else {
|
||||
jpg_err.pub.error_exit = zm_jpeg_error_silent;
|
||||
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);
|
||||
Debug(1, "Aborted a write mid-stream and %s and %d", (outfile == nullptr) ? "closing file" : "file not opened", raw_fd);
|
||||
if ( raw_fd )
|
||||
Debug(1,
|
||||
"Aborted a write mid-stream and %s and %d",
|
||||
(outfile == nullptr) ? "closing file" : "file not opened",
|
||||
raw_fd);
|
||||
if (raw_fd)
|
||||
close(raw_fd);
|
||||
if ( outfile )
|
||||
if (outfile)
|
||||
fclose(outfile);
|
||||
return false;
|
||||
}
|
||||
|
@ -1134,7 +1136,7 @@ bool Image::WriteJpeg(const std::string &filename,
|
|||
cinfo->image_width = width; /* image width and height, in pixels */
|
||||
cinfo->image_height = height;
|
||||
|
||||
switch ( colours ) {
|
||||
switch (colours) {
|
||||
case ZM_COLOUR_GRAY8:
|
||||
cinfo->input_components = 1;
|
||||
cinfo->in_color_space = JCS_GRAYSCALE;
|
||||
|
@ -1142,13 +1144,13 @@ bool Image::WriteJpeg(const std::string &filename,
|
|||
case ZM_COLOUR_RGB32:
|
||||
#ifdef JCS_EXTENSIONS
|
||||
cinfo->input_components = 4;
|
||||
if ( subpixelorder == ZM_SUBPIX_ORDER_RGBA ) {
|
||||
if (subpixelorder == ZM_SUBPIX_ORDER_RGBA) {
|
||||
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;
|
||||
} else if ( subpixelorder == ZM_SUBPIX_ORDER_ARGB ) {
|
||||
} else if (subpixelorder == ZM_SUBPIX_ORDER_ARGB) {
|
||||
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;
|
||||
} else {
|
||||
Warning("Unknwon subpixelorder %d", subpixelorder);
|
||||
|
@ -1165,7 +1167,7 @@ bool Image::WriteJpeg(const std::string &filename,
|
|||
case ZM_COLOUR_RGB24:
|
||||
default:
|
||||
cinfo->input_components = 3;
|
||||
if ( subpixelorder == ZM_SUBPIX_ORDER_BGR) {
|
||||
if (subpixelorder == ZM_SUBPIX_ORDER_BGR) {
|
||||
#ifdef JCS_EXTENSIONS
|
||||
cinfo->in_color_space = JCS_EXT_BGR;
|
||||
#else
|
||||
|
@ -1193,7 +1195,7 @@ cinfo->out_color_space = JCS_RGB;
|
|||
cinfo->dct_method = JDCT_FASTEST;
|
||||
|
||||
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());
|
||||
}
|
||||
// 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
|
||||
|
@ -1222,14 +1224,14 @@ cinfo->out_color_space = JCS_RGB;
|
|||
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,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0x00 };
|
||||
memcpy(&exiftimes[EXIFTIMES_OFFSET], timebuf,EXIFTIMES_LEN);
|
||||
0xff, 0x00};
|
||||
memcpy(&exiftimes[EXIFTIMES_OFFSET], timebuf, EXIFTIMES_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 */
|
||||
while ( cinfo->next_scanline < cinfo->image_height ) {
|
||||
while (cinfo->next_scanline < cinfo->image_height) {
|
||||
jpeg_write_scanlines(cinfo, &row_pointer, 1);
|
||||
row_pointer += linesize;
|
||||
}
|
||||
|
@ -1239,23 +1241,19 @@ cinfo->out_color_space = JCS_RGB;
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Image::DecodeJpeg(
|
||||
const JOCTET *inbuffer,
|
||||
int inbuffer_size,
|
||||
unsigned int p_colours,
|
||||
unsigned int p_subpixelorder)
|
||||
bool Image::DecodeJpeg(const JOCTET *inbuffer, int inbuffer_size, unsigned int p_colours, unsigned int p_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->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.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);
|
||||
return false;
|
||||
}
|
||||
|
@ -1264,7 +1262,7 @@ bool Image::DecodeJpeg(
|
|||
|
||||
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);
|
||||
jpeg_abort_decompress(decodejpg_dcinfo);
|
||||
return false;
|
||||
|
@ -1272,14 +1270,14 @@ bool Image::DecodeJpeg(
|
|||
|
||||
/* 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 */
|
||||
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);
|
||||
}
|
||||
|
||||
new_width = decodejpg_dcinfo->image_width;
|
||||
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",
|
||||
width, height, new_width, new_height);
|
||||
}
|
||||
|
@ -1293,13 +1291,13 @@ bool Image::DecodeJpeg(
|
|||
case ZM_COLOUR_RGB32:
|
||||
#ifdef JCS_EXTENSIONS
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
new_subpixelorder = ZM_SUBPIX_ORDER_ABGR;
|
||||
} else {
|
||||
|
@ -1314,7 +1312,7 @@ bool Image::DecodeJpeg(
|
|||
case ZM_COLOUR_RGB24:
|
||||
default:
|
||||
new_colours = ZM_COLOUR_RGB24;
|
||||
if ( p_subpixelorder == ZM_SUBPIX_ORDER_BGR ) {
|
||||
if (p_subpixelorder == ZM_SUBPIX_ORDER_BGR) {
|
||||
#ifdef JCS_EXTENSIONS
|
||||
decodejpg_dcinfo->out_color_space = JCS_EXT_BGR;
|
||||
new_subpixelorder = ZM_SUBPIX_ORDER_BGR;
|
||||
|
@ -1338,7 +1336,7 @@ cinfo->out_color_space = JCS_RGB;
|
|||
break;
|
||||
} // 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.");
|
||||
jpeg_abort_decompress(decodejpg_dcinfo);
|
||||
return false;
|
||||
|
@ -1347,7 +1345,7 @@ cinfo->out_color_space = JCS_RGB;
|
|||
jpeg_start_decompress(decodejpg_dcinfo);
|
||||
|
||||
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);
|
||||
row_pointer += linesize;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue