png fix, doc fixes

This commit is contained in:
John Cupitt 2010-02-05 13:32:08 +00:00
parent aace4d6ee6
commit f9b29783f5
17 changed files with 192 additions and 68 deletions

View File

@ -33,6 +33,7 @@
- im_insert*() bandalike and formatalike
- im_*join() bandalike and formatalike
- im_ri2c() bandalike
- im_vips2png() saves 16-bit PNGs if necessary
26/11/09 started 7.20.3
- updated en_GB.po translation

6
TODO
View File

@ -1,6 +1,8 @@
- im_mat2vips() needs to be exposed so we can document the matlab reader
- vipsthumbnail should let you supply an interpolator instead of bilinear
any others?
eg. --interpolator "yafrsmooth{2}"
make the sharpening optional?
- im__convert_saveable() (in im_copy.c) always makes an 8-bit image

View File

@ -117,15 +117,9 @@ imb_LabQ2Lab( PEL *inp, float *outbuf, int n )
int
im_LabQ2Lab( IMAGE *in, IMAGE *out )
{
/* check for coded Lab type
*/
if( in->Coding != IM_CODING_LABQ ) {
im_error( "im_LabQ2Lab", "%s", _( "not a LabQ image" ) );
if( im_check_coding_labq( "im_LabQ2Lab", in ) )
return( -1 );
}
/* set up output image
*/
if( im_cp_desc( out, in ) )
return( -1 );
out->Bands = 3;

View File

@ -101,13 +101,8 @@ imb_LabQ2LabS( unsigned char *in, signed short *out, int n )
int
im_LabQ2LabS( IMAGE *in, IMAGE *out )
{
/* check for coded Lab type
*/
if( in->Coding != IM_CODING_LABQ ) {
im_error( "im_LabQ2LabS", "%s",
_( "not a packed Lab image" ) );
if( im_check_coding_labq( "im_LabQ2LabS", in ) )
return( -1 );
}
/* set up output image
*/

View File

@ -171,11 +171,8 @@ im_LabQ2disp_table( IMAGE *in, IMAGE *out, void *table )
{
CalibrateInfo *cal = (CalibrateInfo *) table;
if ( in->Coding != IM_CODING_LABQ ) {
im_error( "im_LabQ2Lab", "%s",
_( "not a packed Lab image" ) );
return( -1 );
}
if( im_check_coding_labq( "im_LabQ2disp", in ) )
return( -1 );
if( im_cp_desc( out, in ) )
return( -1 );

View File

@ -386,12 +386,19 @@ im_copy_native( IMAGE *in, IMAGE *out, gboolean is_msb_first )
return( im_copy( in, out ) );
}
/* Convert to a saveable format. im__saveable_t gives the general type of image
/* Convert to a saveable format.
*
* im__saveable_t gives the general type of image
* we make: vanilla 1/3 bands (PPM), with an optional alpha (like PNG), or
* with CMYK as an option (like JPEG). Need to im_close() the return IMAGE.
* with CMYK as an option (like JPEG).
*
* sixteen TRUE means 16 bit uchar is OK as well (eg. PNG), otherwise we
* always cast down to u8.
*
* Need to im_close() the result IMAGE.
*/
IMAGE *
im__convert_saveable( IMAGE *in, im__saveable_t saveable )
im__convert_saveable( IMAGE *in, im__saveable_t saveable, gboolean sixteen )
{
IMAGE *out;
@ -566,12 +573,18 @@ im__convert_saveable( IMAGE *in, im__saveable_t saveable )
in = t[1];
}
/* Clip to uchar if not there already.
/* Clip to uchar/ushort if not there already.
*/
if( in->BandFmt != IM_BANDFMT_UCHAR ) {
if( (sixteen &&
in->BandFmt != IM_BANDFMT_UCHAR &&
in->BandFmt != IM_BANDFMT_USHORT) ||
(!sixteen &&
in->BandFmt != IM_BANDFMT_UCHAR) ) {
IMAGE *t = im_open_local( out, "conv:1", "p" );
VipsBandFmt fmt = sixteen && IM_IMAGE_SIZEOF_ELEMENT( in ) > 1 ?
IM_BANDFMT_USHORT : IM_BANDFMT_UCHAR;
if( !t || im_clip2fmt( in, t, IM_BANDFMT_UCHAR ) ) {
if( !t || im_clip2fmt( in, t, fmt ) ) {
im_close( out );
return( NULL );
}

View File

@ -60,8 +60,8 @@
* it automatically appears in all VIPS user-interfaces. It will also be
* transparently supported by im_open().
*
* VIPS comes with loaders for TIFF, JPEG, PNG, Analyze, PPM, OpenEXR, CSV,
* Matlab, RAW, VIPS and one that wraps libMagick.
* VIPS comes with VipsFormat for TIFF, JPEG, PNG, Analyze, PPM, OpenEXR, CSV,
* Matlab, Radiance, RAW, VIPS and one that wraps libMagick.
*/
/**

View File

@ -61,7 +61,7 @@
* Use functions like im_copy_morph() to set the pixel type, byte ordering
* and so on.
*
* See also: im_vips2raw().
* See also: #VipsFormat, im_vips2raw().
*
* Returns: 0 on success, -1 on error.
*/

View File

@ -230,7 +230,7 @@ write_new( IMAGE *in )
return( NULL );
memset( write, 0, sizeof( Write ) );
if( !(write->in = im__convert_saveable( in, IM__RGB_CMYK )) ) {
if( !(write->in = im__convert_saveable( in, IM__RGB_CMYK, FALSE )) ) {
im_error( "im_vips2jpeg",
"%s", _( "unable to convert to saveable format" ) );
write_destroy( write );

View File

@ -14,6 +14,7 @@
* - use im_wbuffer() API for BG writes
* 4/2/10
* - gtkdoc
* - fixed 16-bit save
*/
/*
@ -127,9 +128,9 @@ write_new( IMAGE *in )
return( NULL );
memset( write, 0, sizeof( Write ) );
if( !(write->in = im__convert_saveable( in, IM__RGBA )) ) {
if( !(write->in = im__convert_saveable( in, IM__RGBA, TRUE )) ) {
im_error( "im_vips2png",
"%s", _( "unable to convert to RGB for save" ) );
"%s", _( "unable to convert to saveable format" ) );
write_destroy( write );
return( NULL );
}
@ -196,7 +197,8 @@ write_vips( Write *write, int compress, int interlace )
int i, nb_passes;
g_assert( in->BandFmt == IM_BANDFMT_UCHAR );
g_assert( in->BandFmt == IM_BANDFMT_UCHAR ||
in->BandFmt == IM_BANDFMT_USHORT );
g_assert( in->Coding == IM_CODING_NONE );
g_assert( in->Bands > 0 && in->Bands < 5 );
@ -296,7 +298,8 @@ write_vips( Write *write, int compress, int interlace )
* There is no support for attaching ICC profiles to PNG images.
*
* The image is automatically converted to RGB, RGBA, Monochrome or Mono +
* alpha before saving.
* alpha before saving. Images with more than one byte per band element are
* saved as 16-bit PNG, others are saved as 8-bit PNG.
*
* Example:
*

View File

@ -116,7 +116,7 @@ write_block( REGION *region, Rect *area, void *a, void *b )
* Writes the pixels in @in to the file descriptor. It's handy for writing
* writers for other formats.
*
* See also: im_raw2vips().
* See also: #VipsFormat, im_raw2vips().
*
* Returns: 0 on success, -1 on error.
*/

View File

@ -103,7 +103,7 @@ read_new( const char *filename, IMAGE *out )
read->var = NULL;
if( !(read->mat = Mat_Open( filename, MAT_ACC_RDONLY )) ) {
im_error( "mat2vips",
im_error( "im_mat2vips",
_( "unable to open \"%s\"" ), filename );
read_destroy( read );
return( NULL );
@ -111,7 +111,7 @@ read_new( const char *filename, IMAGE *out )
for(;;) {
if( !(read->var = Mat_VarReadNextInfo( read->mat )) ) {
im_error( "mat2vips",
im_error( "im_mat2vips",
_( "no matrix variables in \"%s\"" ),
filename );
read_destroy( read );
@ -119,7 +119,7 @@ read_new( const char *filename, IMAGE *out )
}
#ifdef DEBUG
printf( "mat2vips: seen:\n" );
printf( "im_mat2vips: seen:\n" );
printf( "var->name == %s\n", read->var->name );
printf( "var->class_type == %d\n", read->var->class_type );
printf( "var->rank == %d\n", read->var->rank );
@ -170,7 +170,8 @@ mat2vips_get_header( matvar_t *var, IMAGE *im )
break;
default:
im_error( "mat2vips", _( "unsupported rank %d\n" ), var->rank );
im_error( "im_mat2vips",
_( "unsupported rank %d\n" ), var->rank );
return( -1 );
}
@ -183,7 +184,7 @@ mat2vips_get_header( matvar_t *var, IMAGE *im )
if( mat2vips_formats[i][0] == var->class_type )
break;
if( i == IM_NUMBER( mat2vips_formats ) ) {
im_error( "mat2vips", _( "unsupported class type %d\n" ),
im_error( "im_mat2vips", _( "unsupported class type %d\n" ),
var->class_type );
return( -1 );
}
@ -230,7 +231,8 @@ mat2vips_get_data( mat_t *mat, matvar_t *var, IMAGE *im )
const int is = es * im->Xsize * im->Ysize;
if( Mat_VarReadDataAll( mat, var ) ) {
im_error( "mat2vips", "%s", _( "Mat_VarReadDataAll failed" ) );
im_error( "im_mat2vips", "%s",
_( "Mat_VarReadDataAll failed" ) );
return( -1 );
}
if( im_outcheck( im ) ||
@ -272,8 +274,24 @@ mat2vips_get_data( mat_t *mat, matvar_t *var, IMAGE *im )
return( 0 );
}
static int
mat2vips( const char *filename, IMAGE *out )
/**
* im_mat2vips:
* @filename: file to load
* @out: image to write to
*
* Read a Matlab save file into a VIPS image.
*
* This operation searches the save
* file for the first array variable with between 1 and 3 dimensions and loads
* it as an image. It will not handle complex images. It does not handle
* sparse matrices.
*
* See also: #VipsFormat.
*
* Returns: 0 on success, -1 on error.
*/
int
im_mat2vips( const char *filename, IMAGE *out )
{
Read *read;
@ -323,7 +341,7 @@ vips_format_mat_class_init( VipsFormatMatClass *class )
format_class->is_a = ismat;
format_class->header = mat2vips_header;
format_class->load = mat2vips;
format_class->load = im_mat2vips;
format_class->save = NULL;
format_class->suffs = mat_suffs;
}

View File

@ -881,8 +881,8 @@ rad2vips_get_header( Read *read, FILE *fin, IMAGE *out )
if( getheader( fin, (gethfunc *) rad2vips_process_line, read ) ||
!fgetsresolu( &read->rs, fin ) ) {
im_error( "rad2vips",
"%s", _( "error reading radiance header" ) );
im_error( "im_rad2vips", "%s",
_( "error reading radiance header" ) );
return( -1 );
}
out->Xsize = scanlen( &read->rs );
@ -963,7 +963,7 @@ rad2vips_get_data( Read *read, FILE *fin, IMAGE *im )
for( y = 0; y < im->Ysize; y++ ) {
if( freadcolrs( read->buf, im->Xsize, fin ) ) {
im_error( "rad2vips", "%s", _( "read error" ) );
im_error( "im_rad2vips", "%s", _( "read error" ) );
return( -1 );
}
if( im_writeline( y, im, (void *) read->buf ) )
@ -973,8 +973,31 @@ rad2vips_get_data( Read *read, FILE *fin, IMAGE *im )
return( 0 );
}
static int
rad2vips( const char *filename, IMAGE *out )
/**
* im_rad2vips:
* @filename: file to load
* @out: image to write to
*
* Read a Radiance (HDR) file into a VIPS image.
*
* Radiance files are read as #IM_CODING_RAD. They have one byte for each of
* red, green and blue, and one byte of shared exponent. Some operations (like
* im_extract_area()) can work directly with images in this format, but
* mmany (all the arithmetic operations, for example) will not. unpack
* #IM_CODING_RAD images to 3 band float with im_rad2float() if you want to do
* arithmetic on them.
*
* This operation ignores some header fields, like VIEW and DATE. It will not
* rotate/flip as the FORMAT string asks.
*
* Sections of this reader from Greg Ward and Radiance with kind permission.
*
* See also: #VipsFormat, im_rad2float(), im_vips2rad().
*
* Returns: 0 on success, -1 on error.
*/
int
im_rad2vips( const char *filename, IMAGE *out )
{
Read *read;
@ -1126,13 +1149,28 @@ vips2rad_put_data( Write *write )
return( 0 );
}
static int
vips2rad( IMAGE *in, const char *filename )
/**
* im_vips2rad:
* @in: image to save
* @filename: file to write to
*
* Write a VIPS image in Radiance (HDR) format.
*
* This operation needs an #IM_CODING_RAD image, or a three-band float image.
*
* Sections of this reader from Greg Ward and Radiance with kind permission.
*
* See also: #VipsFormat, im_float2rad(), im_rad2vips().
*
* Returns: 0 on success, -1 on error.
*/
int
im_vips2rad( IMAGE *in, const char *filename )
{
Write *write;
#ifdef DEBUG
printf( "vips2rad: writing \"%s\"\n", filename );
printf( "im_vips2rad: writing \"%s\"\n", filename );
#endif /*DEBUG*/
if( in->BandFmt == IM_BANDFMT_FLOAT &&
@ -1140,23 +1178,16 @@ vips2rad( IMAGE *in, const char *filename )
in->Coding == IM_CODING_NONE ) {
IMAGE *t;
if( !(t = im_open_local( in, "vips2rad", "p" )) ||
if( !(t = im_open_local( in, "im_vips2rad", "p" )) ||
im_float2rad( in, t ) )
return( -1 );
in = t;
}
if( im_pincheck( in ) )
if( im_pincheck( in ) ||
im_check_coding_rad( "im_vips2rad", in ) )
return( -1 );
if( in->Coding != IM_CODING_RAD ) {
im_error( "vip2rad", "%s", _( "Radiance coding only" ) );
return( -1 );
}
if( in->BandFmt != IM_BANDFMT_UCHAR || in->Bands != 4 ) {
im_error( "vip2rad", "%s", _( "4 band uchar only" ) );
return( -1 );
}
if( !(write = write_new( in, filename )) )
return( -1 );
if( vips2rad_put_header( write ) ||
@ -1187,8 +1218,8 @@ vips_format_rad_class_init( VipsFormatRadClass *class )
format_class->is_a = israd;
format_class->header = rad2vips_header;
format_class->load = rad2vips;
format_class->save = vips2rad;
format_class->load = im_rad2vips;
format_class->save = im_vips2rad;
format_class->suffs = rad_suffs;
}

View File

@ -46,6 +46,8 @@ int im_poutcheck( IMAGE *im );
int im_check_uncoded( const char *domain, IMAGE *im );
int im_check_coding_known( const char *domain, IMAGE *im );
int im_check_coding_labq( const char *domain, IMAGE *im );
int im_check_coding_rad( const char *domain, IMAGE *im );
int im_check_coding_same( const char *domain, IMAGE *im1, IMAGE *im2 );
int im_check_mono( const char *domain, IMAGE *im );
int im_check_bands_1or3( const char *domain, IMAGE *in );

View File

@ -117,27 +117,42 @@ VipsFormatFlags vips_format_get_flags( VipsFormatClass *format,
int vips_format_read( const char *filename, IMAGE *out );
int vips_format_write( IMAGE *in, const char *filename );
/* Low-level read/write operations.
*/
int im_jpeg2vips( const char *filename, IMAGE *out );
int im_vips2jpeg( IMAGE *in, const char *filename );
int im_vips2mimejpeg( IMAGE *in, int qfac );
int im_vips2bufjpeg( IMAGE *in, IMAGE *out, int qfac, char **obuf, int *olen );
int im_vips2tiff( IMAGE *in, const char *filename );
int im_tiff2vips( const char *filename, IMAGE *out );
int im_vips2tiff( IMAGE *in, const char *filename );
int im_tile_cache( IMAGE *in, IMAGE *out,
int tile_width, int tile_height, int max_tiles );
int im_magick2vips( const char *filename, IMAGE *out );
int im_png2vips( const char *filename, IMAGE *out );
int im_exr2vips( const char *filename, IMAGE *out );
int im_ppm2vips( const char *filename, IMAGE *out );
int im_vips2ppm( IMAGE *in, const char *filename );
int im_analyze2vips( const char *filename, IMAGE *out );
int im_vips2csv( IMAGE *in, const char *filename );
int im_csv2vips( const char *filename, IMAGE *out );
int im_vips2csv( IMAGE *in, const char *filename );
int im_png2vips( const char *filename, IMAGE *out );
int im_vips2png( IMAGE *in, const char *filename );
int im_raw2vips( const char *filename, IMAGE *out,
int width, int height, int bpp, int offset );
int im_vips2raw( IMAGE *in, int fd );
int im_mat2vips( const char *filename, IMAGE *out );
int im_rad2vips( const char *filename, IMAGE *out );
int im_vips2rad( IMAGE *in, const char *filename );
#ifdef __cplusplus
}
#endif /*__cplusplus*/

View File

@ -131,7 +131,8 @@ typedef enum {
IM__RGB_CMYK /* 1, 3 or 4 bands (like JPEG) */
} im__saveable_t;
IMAGE *im__convert_saveable( IMAGE *in, im__saveable_t saveable );
IMAGE *im__convert_saveable( IMAGE *in,
im__saveable_t saveable, gboolean sixteen );
void im__link_make( IMAGE *parent, IMAGE *child );
void im__link_break_all( IMAGE *im );

View File

@ -589,6 +589,58 @@ im_check_coding_known( const char *domain, IMAGE *im )
return( 0 );
}
/**
* im_check_coding_rad:
* @domain: the originating domain for the error message
* @im: image to check
*
* Check that the image is in Radiance coding.
* If not, set an error message
* and return non-zero.
*
* See also: im_error().
*
* Returns: 0 on OK, or -1 on error.
*/
int
im_check_coding_rad( const char *domain, IMAGE *im )
{
if( im->Coding != IM_CODING_RAD ||
im->BandFmt != IM_BANDFMT_UCHAR ||
im->Bands != 4 ) {
im_error( domain, "%s", _( "Radiance coding only" ) );
return( -1 );
}
return( 0 );
}
/**
* im_check_coding_labq:
* @domain: the originating domain for the error message
* @im: image to check
*
* Check that the image is in LABQ coding.
* If not, set an error message
* and return non-zero.
*
* See also: im_error().
*
* Returns: 0 on OK, or -1 on error.
*/
int
im_check_coding_labq( const char *domain, IMAGE *im )
{
if( im->Coding != IM_CODING_LABQ ||
im->BandFmt != IM_BANDFMT_UCHAR ||
im->Bands != 4 ) {
im_error( domain, "%s", _( "LABQ coding only" ) );
return( -1 );
}
return( 0 );
}
/**
* im_check_mono:
* @domain: the originating domain for the error message