Merge remote-tracking branch 'origin/master'

This commit is contained in:
John Cupitt 2013-10-02 05:21:32 +01:00
commit 90c7e6a291
4 changed files with 28 additions and 10 deletions

View File

@ -1987,6 +1987,7 @@ vips_jpegload( const char *filename, VipsImage **out, ... )
* *
* @Q: quality factor * @Q: quality factor
* @profile: attach this ICC profile * @profile: attach this ICC profile
* @optimize_coding: compute optimal Huffman coding tables
* *
* Write a VIPS image to a file as JPEG. * Write a VIPS image to a file as JPEG.
* *
@ -2039,6 +2040,7 @@ vips_jpegsave( VipsImage *in, const char *filename, ... )
* *
* @Q: JPEG quality factor * @Q: JPEG quality factor
* @profile: attach this ICC profile * @profile: attach this ICC profile
* @optimize_coding: compute optimal Huffman coding tables
* *
* As vips_jpegsave(), but save to a memory buffer. * As vips_jpegsave(), but save to a memory buffer.
* *
@ -2087,6 +2089,7 @@ vips_jpegsave_buffer( VipsImage *in, void **buf, size_t *len, ... )
* *
* @Q: JPEG quality factor * @Q: JPEG quality factor
* @profile: attach this ICC profile * @profile: attach this ICC profile
* @optimize_coding: compute optimal Huffman coding tables
* *
* As vips_jpegsave(), but save as a mime jpeg on stdout. * As vips_jpegsave(), but save as a mime jpeg on stdout.
* *

View File

@ -54,9 +54,9 @@ void vips__new_output_message( j_common_ptr cinfo );
void vips__new_error_exit( j_common_ptr cinfo ); void vips__new_error_exit( j_common_ptr cinfo );
int vips__jpeg_write_file( VipsImage *in, int vips__jpeg_write_file( VipsImage *in,
const char *filename, int Q, const char *profile ); const char *filename, int Q, const char *profile, gboolean optimize_coding );
int vips__jpeg_write_buffer( VipsImage *in, int vips__jpeg_write_buffer( VipsImage *in,
void **obuf, size_t *olen, int Q, const char *profile ); void **obuf, size_t *olen, int Q, const char *profile, gboolean optimize_coding );
int vips__isjpeg( const char *filename ); int vips__isjpeg( const char *filename );
int vips__jpeg_read_file( const char *name, VipsImage *out, int vips__jpeg_read_file( const char *name, VipsImage *out,

View File

@ -89,6 +89,10 @@ typedef struct _VipsForeignSaveJpeg {
*/ */
char *profile; char *profile;
/* Compute optimal Huffman coding tables.
*/
gboolean optimize_coding;
} VipsForeignSaveJpeg; } VipsForeignSaveJpeg;
typedef VipsForeignSaveClass VipsForeignSaveJpegClass; typedef VipsForeignSaveClass VipsForeignSaveJpegClass;
@ -134,6 +138,13 @@ vips_foreign_save_jpeg_class_init( VipsForeignSaveJpegClass *class )
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveJpeg, profile ), G_STRUCT_OFFSET( VipsForeignSaveJpeg, profile ),
NULL ); NULL );
VIPS_ARG_BOOL( class, "optimize_coding", 12,
_( "optimize_coding" ),
_( "Compute optimal Huffman coding tables" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveJpeg, optimize_coding ),
FALSE );
} }
static void static void
@ -168,7 +179,7 @@ vips_foreign_save_jpeg_file_build( VipsObject *object )
return( -1 ); return( -1 );
if( vips__jpeg_write_file( save->ready, file->filename, if( vips__jpeg_write_file( save->ready, file->filename,
jpeg->Q, jpeg->profile ) ) jpeg->Q, jpeg->profile, jpeg->optimize_coding ) )
return( -1 ); return( -1 );
return( 0 ); return( 0 );
@ -233,7 +244,7 @@ vips_foreign_save_jpeg_buffer_build( VipsObject *object )
return( -1 ); return( -1 );
if( vips__jpeg_write_buffer( save->ready, if( vips__jpeg_write_buffer( save->ready,
&obuf, &olen, jpeg->Q, jpeg->profile ) ) &obuf, &olen, jpeg->Q, jpeg->profile, jpeg->optimize_coding ) )
return( -1 ); return( -1 );
area = vips_area_new_blob( (VipsCallbackFn) vips_free, obuf, olen ); area = vips_area_new_blob( (VipsCallbackFn) vips_free, obuf, olen );
@ -294,7 +305,7 @@ vips_foreign_save_jpeg_mime_build( VipsObject *object )
return( -1 ); return( -1 );
if( vips__jpeg_write_buffer( save->ready, if( vips__jpeg_write_buffer( save->ready,
&obuf, &olen, jpeg->Q, jpeg->profile ) ) &obuf, &olen, jpeg->Q, jpeg->profile, jpeg->optimize_coding ) )
return( -1 ); return( -1 );
printf( "Content-length: %zd\r\n", olen ); printf( "Content-length: %zd\r\n", olen );

View File

@ -847,7 +847,7 @@ write_jpeg_block( REGION *region, Rect *area, void *a )
/* Write a VIPS image to a JPEG compress struct. /* Write a VIPS image to a JPEG compress struct.
*/ */
static int static int
write_vips( Write *write, int qfac, const char *profile ) write_vips( Write *write, int qfac, const char *profile, gboolean optimize_coding )
{ {
VipsImage *in; VipsImage *in;
J_COLOR_SPACE space; J_COLOR_SPACE space;
@ -900,6 +900,10 @@ write_vips( Write *write, int qfac, const char *profile )
jpeg_set_defaults( &write->cinfo ); jpeg_set_defaults( &write->cinfo );
jpeg_set_quality( &write->cinfo, qfac, TRUE ); jpeg_set_quality( &write->cinfo, qfac, TRUE );
/* Compute optimal Huffman coding tables.
*/
write->cinfo.optimize_coding = optimize_coding;
/* Build compress tables. /* Build compress tables.
*/ */
jpeg_start_compress( &write->cinfo, TRUE ); jpeg_start_compress( &write->cinfo, TRUE );
@ -942,7 +946,7 @@ write_vips( Write *write, int qfac, const char *profile )
*/ */
int int
vips__jpeg_write_file( VipsImage *in, vips__jpeg_write_file( VipsImage *in,
const char *filename, int Q, const char *profile ) const char *filename, int Q, const char *profile, gboolean optimize_coding )
{ {
Write *write; Write *write;
@ -972,7 +976,7 @@ vips__jpeg_write_file( VipsImage *in,
/* Convert! /* Convert!
*/ */
if( write_vips( write, Q, profile ) ) { if( write_vips( write, Q, profile, optimize_coding ) ) {
write_destroy( write ); write_destroy( write );
return( -1 ); return( -1 );
} }
@ -1218,7 +1222,7 @@ buf_dest( j_compress_ptr cinfo, void **obuf, size_t *olen )
int int
vips__jpeg_write_buffer( VipsImage *in, vips__jpeg_write_buffer( VipsImage *in,
void **obuf, size_t *olen, int Q, const char *profile ) void **obuf, size_t *olen, int Q, const char *profile, gboolean optimize_coding )
{ {
Write *write; Write *write;
@ -1247,7 +1251,7 @@ vips__jpeg_write_buffer( VipsImage *in,
/* Convert! /* Convert!
*/ */
if( write_vips( write, Q, profile ) ) { if( write_vips( write, Q, profile, optimize_coding ) ) {
write_destroy( write ); write_destroy( write );
return( -1 ); return( -1 );