spacing and google code style
This commit is contained in:
parent
4509c6a239
commit
9a3765f6aa
238
src/zm_image.cpp
238
src/zm_image.cpp
|
@ -802,25 +802,25 @@ bool Image::ReadRaw( const char *filename ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose( infile );
|
fclose(infile);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::WriteRaw( const char *filename ) const {
|
bool Image::WriteRaw(const char *filename) const {
|
||||||
FILE *outfile;
|
FILE *outfile;
|
||||||
if ( (outfile = fopen( filename, "wb" )) == NULL ) {
|
if ( (outfile = fopen(filename, "wb")) == NULL ) {
|
||||||
Error( "Can't open %s: %s", filename, strerror(errno) );
|
Error("Can't open %s: %s", filename, strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fwrite( buffer, size, 1, outfile ) != 1 ) {
|
if ( fwrite( buffer, size, 1, outfile ) != 1 ) {
|
||||||
Error( "Unable to write to '%s': %s", filename, strerror(errno) );
|
Error("Unable to write to '%s': %s", filename, strerror(errno));
|
||||||
fclose( outfile );
|
fclose(outfile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose( outfile );
|
fclose(outfile);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -885,13 +885,13 @@ bool Image::ReadJpeg(const char *filename, unsigned int p_colours, unsigned int
|
||||||
{
|
{
|
||||||
#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 ) {
|
||||||
cinfo->out_color_space = JCS_EXT_BGRX;
|
cinfo->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 ) {
|
||||||
cinfo->out_color_space = JCS_EXT_XRGB;
|
cinfo->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 ) {
|
||||||
cinfo->out_color_space = JCS_EXT_XBGR;
|
cinfo->out_color_space = JCS_EXT_XBGR;
|
||||||
new_subpixelorder = ZM_SUBPIX_ORDER_ABGR;
|
new_subpixelorder = ZM_SUBPIX_ORDER_ABGR;
|
||||||
} else {
|
} else {
|
||||||
|
@ -908,7 +908,7 @@ bool Image::ReadJpeg(const char *filename, unsigned int p_colours, unsigned int
|
||||||
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
|
||||||
cinfo->out_color_space = JCS_EXT_BGR;
|
cinfo->out_color_space = JCS_EXT_BGR;
|
||||||
new_subpixelorder = ZM_SUBPIX_ORDER_BGR;
|
new_subpixelorder = ZM_SUBPIX_ORDER_BGR;
|
||||||
|
@ -933,28 +933,27 @@ cinfo->out_color_space = JCS_RGB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(WriteBuffer(new_width, new_height, new_colours, new_subpixelorder) == NULL) {
|
if ( WriteBuffer(new_width, new_height, new_colours, new_subpixelorder) == NULL ) {
|
||||||
Error("Failed requesting writeable buffer for reading JPEG image.");
|
Error("Failed requesting writeable buffer for reading JPEG image.");
|
||||||
jpeg_abort_decompress( cinfo );
|
jpeg_abort_decompress(cinfo);
|
||||||
fclose( infile );
|
fclose(infile);
|
||||||
return( false );
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_start_decompress( cinfo );
|
jpeg_start_decompress(cinfo);
|
||||||
|
|
||||||
JSAMPROW row_pointer; /* pointer to a single row */
|
JSAMPROW row_pointer; /* pointer to a single row */
|
||||||
int row_stride = width * colours; /* physical row width in buffer */
|
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];
|
row_pointer = &buffer[cinfo->output_scanline * row_stride];
|
||||||
jpeg_read_scanlines( cinfo, &row_pointer, 1 );
|
jpeg_read_scanlines(cinfo, &row_pointer, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_finish_decompress( cinfo );
|
jpeg_finish_decompress(cinfo);
|
||||||
|
|
||||||
fclose( infile );
|
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.
|
// 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);
|
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 {
|
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);
|
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);
|
||||||
|
@ -985,66 +984,63 @@ bool Image::WriteJpeg(const char *filename, int quality_override, struct timeval
|
||||||
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];
|
struct jpeg_compress_struct *cinfo = writejpg_ccinfo[quality];
|
||||||
FILE *outfile =NULL;
|
FILE *outfile = NULL;
|
||||||
static int raw_fd = 0;
|
static int raw_fd = 0;
|
||||||
bool need_create_comp = false;
|
bool need_create_comp = false;
|
||||||
raw_fd = 0;
|
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);
|
||||||
need_create_comp=true;
|
need_create_comp = true;
|
||||||
}
|
}
|
||||||
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( 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)
|
if ( raw_fd )
|
||||||
close(raw_fd);
|
close(raw_fd);
|
||||||
if (outfile)
|
if ( outfile )
|
||||||
fclose( outfile );
|
fclose(outfile);
|
||||||
return ( false );
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (need_create_comp)
|
if ( need_create_comp )
|
||||||
jpeg_create_compress( cinfo );
|
jpeg_create_compress(cinfo);
|
||||||
|
|
||||||
if (! on_blocking_abort) {
|
if ( !on_blocking_abort ) {
|
||||||
if ( (outfile = fopen(filename, "wb")) == NULL ) {
|
if ( (outfile = fopen(filename, "wb")) == NULL ) {
|
||||||
Error( "Can't open %s for writing: %s", filename, strerror(errno) );
|
Error("Can't open %s for writing: %s", filename, strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
raw_fd = open(filename,O_WRONLY|O_NONBLOCK|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
raw_fd = open(filename, O_WRONLY|O_NONBLOCK|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||||
if (raw_fd < 0)
|
if ( raw_fd < 0 )
|
||||||
return ( false );
|
return false;
|
||||||
outfile = fdopen(raw_fd,"wb");
|
outfile = fdopen(raw_fd, "wb");
|
||||||
if (outfile == NULL) {
|
if ( outfile == NULL ) {
|
||||||
close(raw_fd);
|
close(raw_fd);
|
||||||
return( false );
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_stdio_dest( cinfo, outfile );
|
jpeg_stdio_dest(cinfo, outfile);
|
||||||
|
|
||||||
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_BGRA ) {
|
if ( subpixelorder == ZM_SUBPIX_ORDER_BGRA ) {
|
||||||
|
@ -1057,24 +1053,22 @@ bool Image::WriteJpeg(const char *filename, int quality_override, struct timeval
|
||||||
/* Assume RGBA */
|
/* Assume RGBA */
|
||||||
cinfo->in_color_space = JCS_EXT_RGBX;
|
cinfo->in_color_space = JCS_EXT_RGBX;
|
||||||
}
|
}
|
||||||
|
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 );
|
jpeg_abort_compress(cinfo);
|
||||||
fclose(outfile);
|
fclose(outfile);
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ZM_COLOUR_RGB24:
|
case ZM_COLOUR_RGB24:
|
||||||
default:
|
default:
|
||||||
{
|
|
||||||
cinfo->input_components = 3;
|
cinfo->input_components = 3;
|
||||||
if ( subpixelorder == ZM_SUBPIX_ORDER_BGR) {
|
if ( subpixelorder == ZM_SUBPIX_ORDER_BGR) {
|
||||||
#ifdef JCS_EXTENSIONS
|
#ifdef JCS_EXTENSIONS
|
||||||
cinfo->in_color_space = JCS_EXT_BGR;
|
cinfo->in_color_space = JCS_EXT_BGR;
|
||||||
#else
|
#else
|
||||||
Error("libjpeg-turbo is required for JPEG encoding directly from BGR24 source");
|
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
|
||||||
|
@ -1090,16 +1084,15 @@ cinfo->out_color_space = JCS_RGB;
|
||||||
cinfo->in_color_space = JCS_RGB;
|
cinfo->in_color_space = JCS_RGB;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
} // end switch(colours)
|
||||||
}
|
|
||||||
|
|
||||||
jpeg_set_defaults( cinfo );
|
jpeg_set_defaults(cinfo);
|
||||||
jpeg_set_quality( cinfo, quality, FALSE );
|
jpeg_set_quality(cinfo, quality, FALSE);
|
||||||
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 && text[0] ) {
|
if ( config.add_jpeg_comments && text[0] ) {
|
||||||
jpeg_write_marker( cinfo, JPEG_COM, (const JOCTET *)text, strlen(text) );
|
jpeg_write_marker(cinfo, JPEG_COM, (const JOCTET *)text, strlen(text));
|
||||||
}
|
}
|
||||||
// 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
|
||||||
// No timestamp just leave off the exif section.
|
// No timestamp just leave off the exif section.
|
||||||
|
@ -1123,14 +1116,14 @@ cinfo->out_color_space = JCS_RGB;
|
||||||
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; /* pointer to a single row */
|
JSAMPROW row_pointer; /* pointer to a single row */
|
||||||
int row_stride = cinfo->image_width * colours; /* physical row width in buffer */
|
int row_stride = cinfo->image_width * colours; /* physical row width in buffer */
|
||||||
while ( cinfo->next_scanline < cinfo->image_height ) {
|
while ( cinfo->next_scanline < cinfo->image_height ) {
|
||||||
row_pointer = &buffer[cinfo->next_scanline * row_stride];
|
row_pointer = &buffer[cinfo->next_scanline * row_stride];
|
||||||
jpeg_write_scanlines( cinfo, &row_pointer, 1 );
|
jpeg_write_scanlines(cinfo, &row_pointer, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_finish_compress(cinfo);
|
jpeg_finish_compress(cinfo);
|
||||||
|
@ -1140,13 +1133,16 @@ cinfo->out_color_space = JCS_RGB;
|
||||||
return true;
|
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;
|
unsigned int new_width, new_height, new_colours, new_subpixelorder;
|
||||||
struct jpeg_decompress_struct *cinfo = decodejpg_dcinfo;
|
struct jpeg_decompress_struct *cinfo = decodejpg_dcinfo;
|
||||||
|
|
||||||
if ( !cinfo )
|
if ( !cinfo ) {
|
||||||
{
|
|
||||||
cinfo = decodejpg_dcinfo = new jpeg_decompress_struct;
|
cinfo = decodejpg_dcinfo = new jpeg_decompress_struct;
|
||||||
cinfo->err = jpeg_std_error( &jpg_err.pub );
|
cinfo->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;
|
||||||
|
@ -1154,25 +1150,24 @@ bool Image::DecodeJpeg( const JOCTET *inbuffer, int inbuffer_size, unsigned int
|
||||||
jpeg_create_decompress( cinfo );
|
jpeg_create_decompress( cinfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( setjmp( jpg_err.setjmp_buffer ) )
|
if ( setjmp(jpg_err.setjmp_buffer) ) {
|
||||||
{
|
jpeg_abort_decompress(cinfo);
|
||||||
jpeg_abort_decompress( cinfo );
|
return false;
|
||||||
return( false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zm_jpeg_mem_src( cinfo, inbuffer, inbuffer_size );
|
zm_jpeg_mem_src(cinfo, inbuffer, inbuffer_size);
|
||||||
|
|
||||||
jpeg_read_header( cinfo, TRUE );
|
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 );
|
Error("Unexpected colours when reading jpeg image: %d", colours);
|
||||||
jpeg_abort_decompress( cinfo );
|
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 */
|
/* 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(cinfo->dc_huff_tbl_ptrs[0] == NULL) {
|
if ( cinfo->dc_huff_tbl_ptrs[0] == NULL ) {
|
||||||
zm_use_std_huff_tables(cinfo);
|
zm_use_std_huff_tables(cinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1180,28 +1175,26 @@ bool Image::DecodeJpeg( const JOCTET *inbuffer, int inbuffer_size, unsigned int
|
||||||
new_height = cinfo->image_height;
|
new_height = cinfo->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:
|
||||||
{
|
|
||||||
cinfo->out_color_space = JCS_GRAYSCALE;
|
cinfo->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 ) {
|
||||||
cinfo->out_color_space = JCS_EXT_BGRX;
|
cinfo->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 ) {
|
||||||
cinfo->out_color_space = JCS_EXT_XRGB;
|
cinfo->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 ) {
|
||||||
cinfo->out_color_space = JCS_EXT_XBGR;
|
cinfo->out_color_space = JCS_EXT_XBGR;
|
||||||
new_subpixelorder = ZM_SUBPIX_ORDER_ABGR;
|
new_subpixelorder = ZM_SUBPIX_ORDER_ABGR;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1213,12 +1206,10 @@ bool Image::DecodeJpeg( const JOCTET *inbuffer, int inbuffer_size, unsigned int
|
||||||
#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
|
||||||
cinfo->out_color_space = JCS_EXT_BGR;
|
cinfo->out_color_space = JCS_EXT_BGR;
|
||||||
new_subpixelorder = ZM_SUBPIX_ORDER_BGR;
|
new_subpixelorder = ZM_SUBPIX_ORDER_BGR;
|
||||||
|
@ -1240,34 +1231,33 @@ cinfo->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) == NULL) {
|
if ( WriteBuffer(new_width, new_height, new_colours, new_subpixelorder) == NULL ) {
|
||||||
Error("Failed requesting writeable buffer for reading JPEG image.");
|
Error("Failed requesting writeable buffer for reading JPEG image.");
|
||||||
jpeg_abort_decompress( cinfo );
|
jpeg_abort_decompress(cinfo);
|
||||||
return( false );
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_start_decompress( cinfo );
|
jpeg_start_decompress(cinfo);
|
||||||
|
|
||||||
JSAMPROW row_pointer; /* pointer to a single row */
|
JSAMPROW row_pointer; /* pointer to a single row */
|
||||||
int row_stride = width * colours; /* physical row width in buffer */
|
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];
|
row_pointer = &buffer[cinfo->output_scanline * row_stride];
|
||||||
jpeg_read_scanlines( cinfo, &row_pointer, 1 );
|
jpeg_read_scanlines(cinfo, &row_pointer, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_finish_decompress( cinfo );
|
jpeg_finish_decompress(cinfo);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_override ) const {
|
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 );
|
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.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;
|
int quality = quality_override?quality_override:config.jpeg_stream_quality;
|
||||||
|
@ -1276,56 +1266,51 @@ bool Image::EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_over
|
||||||
|
|
||||||
if ( !cinfo ) {
|
if ( !cinfo ) {
|
||||||
cinfo = encodejpg_ccinfo[quality] = new jpeg_compress_struct;
|
cinfo = encodejpg_ccinfo[quality] = new jpeg_compress_struct;
|
||||||
cinfo->err = jpeg_std_error( &jpg_err.pub );
|
cinfo->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_compress( cinfo );
|
jpeg_create_compress(cinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
zm_jpeg_mem_dest( cinfo, outbuffer, outbuffer_size );
|
zm_jpeg_mem_dest(cinfo, outbuffer, outbuffer_size);
|
||||||
|
|
||||||
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_BGRA) {
|
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 {
|
||||||
/* Assume RGBA */
|
/* Assume RGBA */
|
||||||
cinfo->in_color_space = JCS_EXT_RGBX;
|
cinfo->in_color_space = JCS_EXT_RGBX;
|
||||||
}
|
}
|
||||||
|
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 );
|
jpeg_abort_compress(cinfo);
|
||||||
return(false);
|
return false;
|
||||||
#endif
|
#endif
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ZM_COLOUR_RGB24:
|
case ZM_COLOUR_RGB24:
|
||||||
default:
|
default:
|
||||||
{
|
|
||||||
cinfo->input_components = 3;
|
cinfo->input_components = 3;
|
||||||
if(subpixelorder == ZM_SUBPIX_ORDER_BGR) {
|
if ( subpixelorder == ZM_SUBPIX_ORDER_BGR ) {
|
||||||
#ifdef JCS_EXTENSIONS
|
#ifdef JCS_EXTENSIONS
|
||||||
cinfo->in_color_space = JCS_EXT_BGR;
|
cinfo->in_color_space = JCS_EXT_BGR;
|
||||||
#else
|
#else
|
||||||
Error("libjpeg-turbo is required for JPEG encoding directly from BGR24 source");
|
Error("libjpeg-turbo is required for JPEG encoding directly from BGR24 source");
|
||||||
jpeg_abort_compress( cinfo );
|
jpeg_abort_compress(cinfo);
|
||||||
return(false);
|
return false;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* Assume RGB */
|
/* Assume RGB */
|
||||||
|
@ -1339,23 +1324,22 @@ cinfo->out_color_space = JCS_RGB;
|
||||||
cinfo->in_color_space = JCS_RGB;
|
cinfo->in_color_space = JCS_RGB;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
} // end switch
|
} // end switch
|
||||||
|
|
||||||
jpeg_set_defaults( cinfo );
|
jpeg_set_defaults(cinfo);
|
||||||
jpeg_set_quality( cinfo, quality, FALSE );
|
jpeg_set_quality(cinfo, quality, FALSE);
|
||||||
cinfo->dct_method = JDCT_FASTEST;
|
cinfo->dct_method = JDCT_FASTEST;
|
||||||
|
|
||||||
jpeg_start_compress( cinfo, TRUE );
|
jpeg_start_compress(cinfo, TRUE);
|
||||||
|
|
||||||
JSAMPROW row_pointer; /* pointer to a single row */
|
JSAMPROW row_pointer; /* pointer to a single row */
|
||||||
int row_stride = cinfo->image_width * colours; /* physical row width in buffer */
|
int row_stride = cinfo->image_width * colours; /* physical row width in buffer */
|
||||||
while ( cinfo->next_scanline < cinfo->image_height ) {
|
while ( cinfo->next_scanline < cinfo->image_height ) {
|
||||||
row_pointer = &buffer[cinfo->next_scanline * row_stride];
|
row_pointer = &buffer[cinfo->next_scanline * row_stride];
|
||||||
jpeg_write_scanlines( cinfo, &row_pointer, 1 );
|
jpeg_write_scanlines(cinfo, &row_pointer, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_finish_compress( cinfo );
|
jpeg_finish_compress(cinfo);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -4752,7 +4736,7 @@ __attribute__((noinline)) void zm_convert_rgb565_rgb(const uint8_t* col1, uint8_
|
||||||
/* RGB565 to RGBA - modified the one above */
|
/* RGB565 to RGBA - modified the one above */
|
||||||
__attribute__((noinline)) void zm_convert_rgb565_rgba(const uint8_t* col1, uint8_t* result, unsigned long count) {
|
__attribute__((noinline)) void zm_convert_rgb565_rgba(const uint8_t* col1, uint8_t* result, unsigned long count) {
|
||||||
unsigned int r,g,b;
|
unsigned int r,g,b;
|
||||||
for(unsigned int i=0; i < count; i++, col1 += 2, result += 4) {
|
for ( unsigned int i=0; i < count; i++, col1 += 2, result += 4 ) {
|
||||||
b = ((*col1)<<3)&0xf8;
|
b = ((*col1)<<3)&0xf8;
|
||||||
g = (((*(col1+1))<<5)|((*col1)>>3))&0xfc;
|
g = (((*(col1+1))<<5)|((*col1)>>3))&0xfc;
|
||||||
r = (*(col1+1))&0xf8;
|
r = (*(col1+1))&0xf8;
|
||||||
|
|
Loading…
Reference in New Issue