auto rshift to 8 bits for 8-bit save

This commit is contained in:
John Cupitt 2013-05-28 10:32:37 +01:00
parent 964c415925
commit 69136b1d8c
5 changed files with 55 additions and 2 deletions

View File

@ -2,6 +2,7 @@
- vipsthumbnail lets you specify the sharpening mask
- turn off caching for im_copy()/vips_copy(), we use copy to stop sharing, and
it's cheap so caching doesn't help anyway
- auto rshift down to 8 bits on save, if necessary
14/5/13 started 7.32.4
- icc import and export could segv on very wide images

2
TODO
View File

@ -1,6 +1,4 @@
- save 16bit RGB as jpg, does not drop bottom 8 bits, should it?
- look at
There is an order 1 algorithm for doing medians over boxes (truly O(1)

View File

@ -4,6 +4,8 @@
* - add support for sequential reads
* 18/6/12
* - flatten alpha with vips_flatten()
* 28/5/13
* - auto rshift down to 8 bits during save
*/
/*
@ -1258,6 +1260,27 @@ vips_foreign_convert_saveable( VipsForeignSave *save )
in = out;
}
/* Shift down to 8 bits. Handy for 8-bit-only formats like jpeg.
*
* If the operation wants to write 8 bits for this format and this
* image is 16 bits or more and Type is RGB16 or GREY16 ...
* automatically shift down.
*/
if( vips_band_format_is8bit( class->format_table[in->BandFmt] ) &&
!vips_band_format_is8bit( in->BandFmt ) &&
(in->Type == VIPS_INTERPRETATION_RGB16 ||
in->Type == VIPS_INTERPRETATION_GREY16) ) {
VipsImage *out;
if( vips_rshift_const1( in, &out, 8, NULL ) ) {
g_object_unref( in );
return( -1 );
}
g_object_unref( in );
in = out;
}
/* Cast to the output format.
*/
{

View File

@ -526,6 +526,7 @@ int vips_image_write_line( VipsImage *image, int ypos, VipsPel *linebuffer );
gboolean vips_band_format_isint( VipsBandFormat format );
gboolean vips_band_format_isuint( VipsBandFormat format );
gboolean vips_band_format_is8bit( VipsBandFormat format );
gboolean vips_band_format_isfloat( VipsBandFormat format );
gboolean vips_band_format_iscomplex( VipsBandFormat format );

View File

@ -2447,6 +2447,36 @@ vips_band_format_isuint( VipsBandFormat format )
}
}
/**
* vips_band_format_is8bit:
* @format: format to test
*
* Return %TRUE if @format is uchar or schar.
*/
gboolean
vips_band_format_is8bit( VipsBandFormat format )
{
switch( format ) {
case VIPS_FORMAT_UCHAR:
case VIPS_FORMAT_CHAR:
return( TRUE );
case VIPS_FORMAT_USHORT:
case VIPS_FORMAT_SHORT:
case VIPS_FORMAT_UINT:
case VIPS_FORMAT_INT:
case VIPS_FORMAT_FLOAT:
case VIPS_FORMAT_DOUBLE:
case VIPS_FORMAT_COMPLEX:
case VIPS_FORMAT_DPCOMPLEX:
return( FALSE );
default:
g_assert( 0 );
return( -1 );
}
}
/**
* vips_band_format_isfloat:
* @format: format to test