spacing and google code style

This commit is contained in:
Isaac Connor 2019-09-17 10:31:48 -04:00
parent 4509c6a239
commit 9a3765f6aa
1 changed files with 191 additions and 207 deletions

View File

@ -937,15 +937,14 @@ cinfo->out_color_space = JCS_RGB;
Error("Failed requesting writeable buffer for reading JPEG image.");
jpeg_abort_decompress(cinfo);
fclose(infile);
return( false );
return false;
}
jpeg_start_decompress(cinfo);
JSAMPROW row_pointer; /* pointer to a single row */
int row_stride = width * colours; /* physical row width in buffer */
while ( cinfo->output_scanline < cinfo->output_height )
{
while ( cinfo->output_scanline < cinfo->output_height ) {
row_pointer = &buffer[cinfo->output_scanline * row_stride];
jpeg_read_scanlines(cinfo, &row_pointer, 1);
}
@ -954,7 +953,7 @@ cinfo->out_color_space = JCS_RGB;
fclose(infile);
return( true );
return true;
}
// Multiple calling formats to permit inclusion (or not) of non blocking, quality_override and timestamp (exif), with suitable defaults.
@ -977,7 +976,7 @@ bool Image::WriteJpeg(const char *filename, int quality_override, struct timeval
return Image::WriteJpeg(filename, quality_override, timestamp, false);
}
bool Image::WriteJpeg(const char *filename, int quality_override, struct timeval 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);
@ -1004,12 +1003,12 @@ bool Image::WriteJpeg(const char *filename, int quality_override, struct timeval
jpg_err.pub.emit_message = zm_jpeg_emit_silence;
if ( setjmp(jpg_err.setjmp_buffer) ) {
jpeg_abort_compress(cinfo);
Debug( 5, "Aborted a write mid-stream and %s and %d", (outfile == NULL) ? "closing file" : "file not opened", raw_fd );
Debug(1, "Aborted a write mid-stream and %s and %d", (outfile == NULL) ? "closing file" : "file not opened", raw_fd);
if ( raw_fd )
close(raw_fd);
if ( outfile )
fclose(outfile);
return ( false );
return false;
}
}
if ( need_create_comp )
@ -1023,11 +1022,11 @@ bool Image::WriteJpeg(const char *filename, int quality_override, struct timeval
} else {
raw_fd = open(filename, O_WRONLY|O_NONBLOCK|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if ( raw_fd < 0 )
return ( false );
return false;
outfile = fdopen(raw_fd, "wb");
if ( outfile == NULL ) {
close(raw_fd);
return( false );
return false;
}
}
@ -1038,13 +1037,10 @@ bool Image::WriteJpeg(const char *filename, int quality_override, struct timeval
switch (colours) {
case ZM_COLOUR_GRAY8:
{
cinfo->input_components = 1;
cinfo->in_color_space = JCS_GRAYSCALE;
break;
}
case ZM_COLOUR_RGB32:
{
#ifdef JCS_EXTENSIONS
cinfo->input_components = 4;
if ( subpixelorder == ZM_SUBPIX_ORDER_BGRA ) {
@ -1057,17 +1053,15 @@ bool Image::WriteJpeg(const char *filename, int quality_override, struct timeval
/* Assume RGBA */
cinfo->in_color_space = JCS_EXT_RGBX;
}
break;
#else
Error("libjpeg-turbo is required for JPEG encoding directly from RGB32 source");
jpeg_abort_compress(cinfo);
fclose(outfile);
return false;
#endif
break;
}
case ZM_COLOUR_RGB24:
default:
{
cinfo->input_components = 3;
if ( subpixelorder == ZM_SUBPIX_ORDER_BGR) {
#ifdef JCS_EXTENSIONS
@ -1090,8 +1084,7 @@ cinfo->out_color_space = JCS_RGB;
cinfo->in_color_space = JCS_RGB;
}
break;
}
}
} // end switch(colours)
jpeg_set_defaults(cinfo);
jpeg_set_quality(cinfo, quality, FALSE);
@ -1140,13 +1133,16 @@ 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;
struct jpeg_decompress_struct *cinfo = decodejpg_dcinfo;
if ( !cinfo )
{
if ( !cinfo ) {
cinfo = decodejpg_dcinfo = new jpeg_decompress_struct;
cinfo->err = jpeg_std_error( &jpg_err.pub );
jpg_err.pub.error_exit = zm_jpeg_error_exit;
@ -1154,20 +1150,19 @@ bool Image::DecodeJpeg( const JOCTET *inbuffer, int inbuffer_size, unsigned int
jpeg_create_decompress( cinfo );
}
if ( setjmp( jpg_err.setjmp_buffer ) )
{
if ( setjmp(jpg_err.setjmp_buffer) ) {
jpeg_abort_decompress(cinfo);
return( false );
return false;
}
zm_jpeg_mem_src(cinfo, inbuffer, inbuffer_size);
jpeg_read_header(cinfo, TRUE);
if ( cinfo->num_components != 1 && cinfo->num_components != 3 ) {
if ( (cinfo->num_components != 1) && (cinfo->num_components != 3) ) {
Error("Unexpected colours when reading jpeg image: %d", colours);
jpeg_abort_decompress(cinfo);
return( false );
return false;
}
/* Check if the image has at least one huffman table defined. If not, use the standard ones */
@ -1180,19 +1175,17 @@ bool Image::DecodeJpeg( const JOCTET *inbuffer, int inbuffer_size, unsigned int
new_height = cinfo->image_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) {
case ZM_COLOUR_GRAY8:
{
cinfo->out_color_space = JCS_GRAYSCALE;
new_colours = ZM_COLOUR_GRAY8;
new_subpixelorder = ZM_SUBPIX_ORDER_NONE;
break;
}
case ZM_COLOUR_RGB32:
{
#ifdef JCS_EXTENSIONS
new_colours = ZM_COLOUR_RGB32;
if ( p_subpixelorder == ZM_SUBPIX_ORDER_BGRA ) {
@ -1213,10 +1206,8 @@ bool Image::DecodeJpeg( const JOCTET *inbuffer, int inbuffer_size, unsigned int
#else
Warning("libjpeg-turbo is required for reading a JPEG directly into a RGB32 buffer, reading into a RGB24 buffer instead.");
#endif
}
case ZM_COLOUR_RGB24:
default:
{
new_colours = ZM_COLOUR_RGB24;
if ( p_subpixelorder == ZM_SUBPIX_ORDER_BGR ) {
#ifdef JCS_EXTENSIONS
@ -1240,13 +1231,12 @@ cinfo->out_color_space = JCS_RGB;
new_subpixelorder = ZM_SUBPIX_ORDER_RGB;
}
break;
}
} // end switch
if ( WriteBuffer(new_width, new_height, new_colours, new_subpixelorder) == NULL ) {
Error("Failed requesting writeable buffer for reading JPEG image.");
jpeg_abort_decompress(cinfo);
return( false );
return false;
}
jpeg_start_decompress(cinfo);
@ -1264,10 +1254,10 @@ cinfo->out_color_space = JCS_RGB;
}
bool Image::EncodeJpeg(JOCTET *outbuffer, int *outbuffer_size, int quality_override) 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.EncodeJpeg( outbuffer, outbuffer_size, quality_override ) );
return temp_image.EncodeJpeg(outbuffer, outbuffer_size, quality_override);
}
int quality = quality_override?quality_override:config.jpeg_stream_quality;
@ -1289,13 +1279,10 @@ bool Image::EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_over
switch (colours) {
case ZM_COLOUR_GRAY8:
{
cinfo->input_components = 1;
cinfo->in_color_space = JCS_GRAYSCALE;
break;
}
case ZM_COLOUR_RGB32:
{
#ifdef JCS_EXTENSIONS
cinfo->input_components = 4;
if ( subpixelorder == ZM_SUBPIX_ORDER_BGRA ) {
@ -1308,16 +1295,14 @@ bool Image::EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_over
/* Assume RGBA */
cinfo->in_color_space = JCS_EXT_RGBX;
}
break;
#else
Error("libjpeg-turbo is required for JPEG encoding directly from RGB32 source");
jpeg_abort_compress(cinfo);
return(false);
return false;
#endif
break;
}
case ZM_COLOUR_RGB24:
default:
{
cinfo->input_components = 3;
if ( subpixelorder == ZM_SUBPIX_ORDER_BGR ) {
#ifdef JCS_EXTENSIONS
@ -1325,7 +1310,7 @@ bool Image::EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_over
#else
Error("libjpeg-turbo is required for JPEG encoding directly from BGR24 source");
jpeg_abort_compress(cinfo);
return(false);
return false;
#endif
} else {
/* Assume RGB */
@ -1339,7 +1324,6 @@ cinfo->out_color_space = JCS_RGB;
cinfo->in_color_space = JCS_RGB;
}
break;
}
} // end switch
jpeg_set_defaults(cinfo);