more Radiance fixes

This commit is contained in:
John Cupitt 2009-03-24 14:18:06 +00:00
parent e6efeb27ea
commit 5f567320d2
23 changed files with 160 additions and 55 deletions

View File

@ -10,6 +10,8 @@
stable
- added Radiance write
- added im_float2rad()
- added IM_CODING_RAD, support where it makes sense (extract, flip, rotate,
etc.)
3/3/09 started 7.17.2
- im_magick2vips.c: allow funky bit depths, like 14 (thanks Mikkel)

2
TODO
View File

@ -2,8 +2,6 @@
- same for matio?
- doc strings would be nice, read the SWIG notes on this

View File

@ -466,6 +466,7 @@ typedef struct {
#define IM_CODING_NONE (0)
#define IM_CODING_LABQ (2)
#define IM_CODING_RAD (4)
#define IM_IMAGE_SIZEOF_ELEMENT(I) ((I)->Bbits >> 3)
#define IM_IMAGE_SIZEOF_PEL(I) \

View File

@ -188,7 +188,7 @@ im_float2rad( IMAGE *in, IMAGE *out )
if( in->Bands != 3 || in->BandFmt != IM_BANDFMT_FLOAT ||
in->Coding != IM_CODING_NONE ) {
im_error( "im_float2rad", "%s",
_( "not a 3-band float uncoded image" ) );
_( "3-band float uncoded only" ) );
return( -1 );
}
@ -197,6 +197,7 @@ im_float2rad( IMAGE *in, IMAGE *out )
out->Bands = 4;
out->BandFmt = IM_BANDFMT_UCHAR;
out->Bbits = im_bits_of_fmt( out->BandFmt );
out->Coding = IM_CODING_RAD;
if( im_wrapone( in, out,
(im_wrapone_fn) float2rad, NULL, NULL ) )

View File

@ -668,6 +668,17 @@ im_icc_export_depth( IMAGE *in, IMAGE *out, int depth,
in = t1;
}
/* Do IM_CODING_RAD.
*/
if( in->Coding == IM_CODING_RAD ) {
IMAGE *t1 = im_open_local( out, "im_icc_export:1", "p" );
if( !t1 || im_rad2float( in, t1 ) )
return( -1 );
in = t1;
}
/* Check input image.
*/
if( in->Bands != 3 || in->BandFmt != IM_BANDFMT_FLOAT ||
@ -789,6 +800,17 @@ im_icc_ac2rc( IMAGE *in, IMAGE *out, const char *profile_filename )
in = t1;
}
/* Do IM_CODING_RAD.
*/
if( in->Coding == IM_CODING_RAD ) {
IMAGE *t1 = im_open_local( out, "im_icc_export:1", "p" );
if( !t1 || im_rad2float( in, t1 ) )
return( -1 );
in = t1;
}
if( im_open_local_array( out, t, 2, "im_icc_ac2rc-2", "p" ) ||
im_Lab2XYZ_temp( in, t[0], IM_D50_X0, IM_D50_Y0, IM_D50_Z0 ) ||
im_lintra_vec( 3, mul, t[0], add, t[1] ) ||

View File

@ -173,9 +173,9 @@ im_rad2float( IMAGE *in, IMAGE *out )
/* Must be 4-band uchar.
*/
if( in->Bands != 4 || in->BandFmt != IM_BANDFMT_UCHAR ||
in->Coding != IM_CODING_NONE ) {
in->Coding != IM_CODING_RAD ) {
im_error( "im_rad2float", "%s",
_( "not a 4-band uchar uncoded image" ) );
_( "4-band uchar Radiance-coded images only" ) );
return( -1 );
}
@ -184,6 +184,7 @@ im_rad2float( IMAGE *in, IMAGE *out )
out->Bands = 3;
out->BandFmt = IM_BANDFMT_FLOAT;
out->Bbits = im_bits_of_fmt( out->BandFmt );
out->Coding = IM_CODING_NONE;
if( im_wrapone( in, out,
(im_wrapone_fn) rad2float, NULL, NULL ) )

View File

@ -54,6 +54,8 @@
* of JPEG write code)
* 15/2/08
* - added im__saveable_t ... so we can have CMYK JPEG write
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -130,12 +132,18 @@ im_copy_set_all( IMAGE *in, IMAGE *out,
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) {
im_error( "im_copy", "%s", _( "in must be uncoded" ) );
if( in->Coding != IM_CODING_NONE &&
in->Coding != IM_CODING_LABQ &&
in->Coding != IM_CODING_RAD ) {
im_error( "im_copy", "%s",
_( "in must be NONE, LABQ or RAD" ) );
return( -1 );
}
if( Coding != IM_CODING_NONE && Coding != IM_CODING_LABQ ) {
im_error( "im_copy", "%s", _( "Coding must be NONE or LABQ" ) );
if( Coding != IM_CODING_NONE &&
Coding != IM_CODING_LABQ &&
Coding != IM_CODING_RAD ) {
im_error( "im_copy", "%s",
_( "Coding must be NONE, LABQ or RAD" ) );
return( -1 );
}
if( BandFmt < 0 || BandFmt > IM_BANDFMT_DPCOMPLEX ) {
@ -359,7 +367,7 @@ im__convert_saveable( IMAGE *in, im__saveable_t saveable )
if( !(out = im_open( "convert-for-save", "p" )) )
return( NULL );
/* If this is a IM_CODING_LABQ, we can go straight to RGB.
/* If this is an IM_CODING_LABQ, we can go straight to RGB.
*/
if( in->Coding == IM_CODING_LABQ ) {
IMAGE *t = im_open_local( out, "conv:1", "p" );
@ -379,6 +387,21 @@ im__convert_saveable( IMAGE *in, im__saveable_t saveable )
in = t;
}
/* If this is an IM_CODING_RAD, we go to float RGB or XYZ. We should
* probably un-gamma-correct the RGB :(
*/
if( in->Coding == IM_CODING_RAD ) {
IMAGE *t;
if( !(t = im_open_local( out, "conv:1", "p" )) ||
im_rad2float( in, t ) ) {
im_close( out );
return( NULL );
}
in = t;
}
/* Get the bands right.
*/
if( in->Coding == IM_CODING_NONE ) {

View File

@ -39,6 +39,8 @@
* - nope, -ve the origin
* 17/7/04
* - added im_extract_bands(), remove many bands from image
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -175,7 +177,8 @@ im_extract_areabands( IMAGE *in, IMAGE *out,
return( -1 );
}
if( in->Coding != IM_CODING_NONE ) {
if( in->Coding != IM_CODING_LABQ ) {
if( in->Coding != IM_CODING_LABQ &&
in->Coding != IM_CODING_RAD ) {
im_error( "im_extract_areabands",
"%s", _( "unknown coding" ) );
return( -1 );
@ -184,8 +187,8 @@ im_extract_areabands( IMAGE *in, IMAGE *out,
/* We only do area extract for coding == labq.
*/
if( band != 0 || nbands != in->Bands ) {
im_error( "im_extract_areabands",
"%s", _( "can only extract areas from LABQ" ) );
im_error( "im_extract_areabands", "%s",
_( "only extract areas from LABQ and RAD" ) );
return( -1 );
}
}

View File

@ -16,6 +16,8 @@
* - rewritten
* 14/4/04
* - sets Xoffset / Yoffset
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -124,8 +126,11 @@ im_fliphor( IMAGE *in, IMAGE *out )
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) {
im_error( "im_fliphor", "%s", _( "in must be uncoded" ) );
if( in->Coding != IM_CODING_NONE &&
in->Coding != IM_CODING_LABQ &&
in->Coding != IM_CODING_RAD ) {
im_error( "im_fliphor", "%s",
_( "Coding must be NONE, LABQ or RAD" ) );
return( -1 );
}

View File

@ -18,6 +18,8 @@
* - ahem, memcpy() line size calc was wrong, occasional segvs
* 14/4/04
* - sets Xoffset / Yoffset
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -115,8 +117,11 @@ im_flipver( IMAGE *in, IMAGE *out )
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) {
im_errormsg( "im_flipver: in must be uncoded" );
if( in->Coding != IM_CODING_NONE &&
in->Coding != IM_CODING_LABQ &&
in->Coding != IM_CODING_RAD ) {
im_error( "im_flipver", "%s",
_( "Coding must be NONE, LABQ or RAD" ) );
return( -1 );
}

View File

@ -38,6 +38,8 @@
* - sets Xoffset / Yoffset
* 3/7/06
* - add sanity range checks
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -234,9 +236,11 @@ im_insert( IMAGE *main, IMAGE *sub, IMAGE *out, int x, int y )
im_error( "im_insert", "%s", _( "inputs differ in format" ) );
return( -1 );
}
if( main->Coding != IM_CODING_NONE && main->Coding != IM_CODING_LABQ ) {
if( main->Coding != IM_CODING_NONE &&
main->Coding != IM_CODING_RAD &&
main->Coding != IM_CODING_LABQ ) {
im_error( "im_insert", "%s",
_( "input should be uncoded or IM_CODING_LABQ" ) );
_( "Coding should be NONE, LABQ or RAD" ) );
return( -1 );
}
if( x > RANGE || x < -RANGE || y > RANGE || y < -RANGE ) {
@ -324,9 +328,11 @@ im_insert_noexpand( IMAGE *main, IMAGE *sub, IMAGE *out, int x, int y )
"%s", _( "inputs differ in format" ) );
return( -1 );
}
if( main->Coding != IM_CODING_NONE && main->Coding != IM_CODING_LABQ ) {
if( main->Coding != IM_CODING_NONE &&
main->Coding != IM_CODING_LABQ &&
main->Coding != IM_CODING_RAD ) {
im_error( "im_insert_noexpand", "%s",
_( "input should be uncoded or IM_CODING_LABQ" ) );
_( "Coding should be NONE, LABQ or RAD" ) );
return( -1 );
}
if( x > RANGE || x < -RANGE || y > RANGE || y < -RANGE ) {

View File

@ -23,6 +23,8 @@
* - adapted from im_rot90
* 14/4/04
* - sets Xoffset / Yoffset
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -135,9 +137,11 @@ im_rot180( IMAGE *in, IMAGE *out )
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) {
im_error( "im_rot180",
"%s", _( "uncoded or IM_CODING_LABQ only" ) );
if( in->Coding != IM_CODING_NONE &&
in->Coding != IM_CODING_LABQ &&
in->Coding != IM_CODING_RAD ) {
im_error( "im_rot180", "%s",
_( "Coding should be NONE, LABQ or RAD" ) );
return( -1 );
}
if( im_cp_desc( out, in ) )

View File

@ -24,6 +24,8 @@
* - speed-up ... replace memcpy() with a loop for small pixels
* 14/4/04
* - sets Xoffset / Yoffset
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -137,9 +139,11 @@ im_rot270( IMAGE *in, IMAGE *out )
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) {
im_error( "im_rot270",
"%s", _( "uncoded or IM_CODING_LABQ only" ) );
if( in->Coding != IM_CODING_NONE &&
in->Coding != IM_CODING_LABQ &&
in->Coding != IM_CODING_RAD ) {
im_error( "im_rot270", "%s",
_( "Coding should be NONE, LABQ or RAD" ) );
return( -1 );
}
if( im_cp_desc( out, in ) )

View File

@ -24,6 +24,8 @@
* - speed-up ... replace memcpy() with a loop for small pixels
* 14/4/04
* - sets Xoffset / Yoffset
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -137,9 +139,11 @@ im_rot90( IMAGE *in, IMAGE *out )
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) {
im_error( "im_rot90",
"%s", _( "uncoded or IM_CODING_LABQ only" ) );
if( in->Coding != IM_CODING_NONE &&
in->Coding != IM_CODING_LABQ &&
in->Coding != IM_CODING_RAD ) {
im_error( "im_rot90", "%s",
_( "Coding should be NONE, LABQ or RAD" ) );
return( -1 );
}
if( im_cp_desc( out, in ) )

View File

@ -23,6 +23,8 @@
* zoom on large images
* 3/8/02 JC
* - fall back to im_copy() for x & y factors == 1
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -324,7 +326,9 @@ im_zoom( IMAGE *in, IMAGE *out, int xfac, int yfac )
/* Check arguments.
*/
if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) {
if( in->Coding != IM_CODING_NONE &&
in->Coding != IM_CODING_LABQ &&
in->Coding != IM_CODING_RAD ) {
im_error( "im_zoom", "%s", _( "unknown coding type" ) );
return( -1 );
}

View File

@ -29,6 +29,8 @@
* - degenerate to im_copy() for 0/0/w/h
* 1/8/07
* - more general ... x and y can be negative
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -435,7 +437,9 @@ im_embed( IMAGE *in, IMAGE *out, int flag, int x, int y, int w, int h )
{
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) {
if( in->Coding != IM_CODING_NONE &&
in->Coding != IM_CODING_LABQ &&
in->Coding != IM_CODING_RAD ) {
im_error( "im_embed", "%s", _( "unknown image coding type" ) );
return( -1 );
}

View File

@ -142,6 +142,7 @@ im__image_pixel_length( IMAGE *im )
switch( im->Coding ) {
case IM_CODING_LABQ:
case IM_CODING_RAD:
case IM_CODING_NONE:
psize = (gint64) IM_IMAGE_SIZEOF_LINE( im ) * im->Ysize;
break;
@ -753,6 +754,8 @@ im_file2vips( const char *filename, IMAGE *im )
*/
if( im->Coding == IM_CODING_LABQ )
return( im );
if( im->Coding == IM_CODING_RAD )
return( im );
if( im->Coding != IM_CODING_NONE ) {
im_close( im );
im_error( "im_open", _( "unknown coding type" ) );

View File

@ -892,7 +892,7 @@ rad2vips_get_header( Read *read, FILE *fin, IMAGE *out )
out->BandFmt = IM_BANDFMT_UCHAR;
out->Bbits = im_bits_of_fmt( out->BandFmt );
out->Coding = IM_CODING_NONE;
out->Coding = IM_CODING_RAD;
out->Xres = 1.0;
out->Yres = read->aspect;
out->Xoffset = 0.0;
@ -1136,22 +1136,23 @@ vips2rad( IMAGE *in, const char *filename )
printf( "vips2rad: writing \"%s\"\n", filename );
#endif /*DEBUG*/
if( im_pincheck( in ) )
return( -1 );
if( in->Coding != IM_CODING_NONE ) {
im_error( "vip2rad", "%s", _( "uncoded only" ) );
return( -1 );
}
if( in->BandFmt == IM_BANDFMT_FLOAT &&
in->Bands == 3 ) {
in->Bands == 3 &&
in->Coding == IM_CODING_NONE ) {
IMAGE *t;
if( !(t = im_open_local( in, "vips2rad", "p" )) ||
im_float2rad( in, t ) ||
vips2rad( t, filename ) )
im_float2rad( in, t ) )
return( -1 );
return( 0 );
in = t;
}
if( im_pincheck( 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" ) );

View File

@ -18,6 +18,8 @@
* - im_flood_blob() added
* 5/12/06
* - im_invalidate() after paint
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -325,9 +327,11 @@ im_flood( IMAGE *im, int x, int y, PEL *ink, Rect *dout )
if( im_rwcheck( im ) )
return( -1 );
if( im->Coding != IM_CODING_NONE && im->Coding != IM_CODING_LABQ ) {
im_error( "im_flood",
"%s", _( "uncoded or IM_CODING_LABQ only" ) );
if( im->Coding != IM_CODING_NONE &&
im->Coding != IM_CODING_LABQ &&
im->Coding != IM_CODING_RAD ) {
im_error( "im_flood", "%s",
_( "Coding should be NONE, LABQ or RAD" ) );
return( -1 );
}
if( !(st = build_state( im, x, y, ink, dout )) )
@ -372,9 +376,11 @@ im_flood_blob( IMAGE *im, int x, int y, PEL *ink, Rect *dout )
if( im_rwcheck( im ) )
return( -1 );
if( im->Coding != IM_CODING_NONE && im->Coding != IM_CODING_LABQ ) {
im_error( "im_flood",
"%s", _( "uncoded or IM_CODING_LABQ only" ) );
if( im->Coding != IM_CODING_NONE &&
im->Coding != IM_CODING_LABQ &&
im->Coding != IM_CODING_RAD ) {
im_error( "im_flood", "%s",
_( "Coding should be NONE, LABQ or RAD" ) );
return( -1 );
}
if( !(st = build_state( im, x, y, ink, dout )) )

View File

@ -19,6 +19,8 @@
* - smarter pixel size calculations
* 5/12/06
* - im_invalidate() after paint
* 24/3/09
* - added IM_CODING_RAD support
*/
/*
@ -80,13 +82,15 @@ im_insertplace( IMAGE *big, IMAGE *small, int x, int y )
*/
if( big->BandFmt != small->BandFmt || big->Bands != small->Bands ||
big->Coding != small->Coding ) {
im_error( "im_insertplace",
"%s", _( "inputs differ in format" ) );
im_error( "im_insertplace", "%s",
_( "inputs differ in format" ) );
return( -1 );
}
if( big->Coding != IM_CODING_NONE && big->Coding != IM_CODING_LABQ ) {
if( big->Coding != IM_CODING_NONE &&
big->Coding != IM_CODING_LABQ &&
big->Coding != IM_CODING_RAD ) {
im_error( "im_insertplace", "%s",
_( "input should be uncoded or IM_CODING_LABQ" ) );
_( "Coding should be NONE, LABQ or RAD" ) );
return( -1 );
}

View File

@ -466,7 +466,8 @@ image_sanity( IMAGE *im )
if( im->BandFmt < -1 || im->BandFmt > IM_BANDFMT_DPCOMPLEX ||
(im->Coding != -1 &&
im->Coding != IM_CODING_NONE &&
im->Coding != IM_CODING_LABQ) ||
im->Coding != IM_CODING_LABQ &&
im->Coding != IM_CODING_RAD) ||
im->Type < -1 || im->Type > IM_TYPE_GREY16 ||
im->dtype > IM_PARTIAL || im->dhint > IM_ANY )
return( "bad enum value" );

View File

@ -145,6 +145,7 @@ im__image_pixel_length( IMAGE *im )
switch( im->Coding ) {
case IM_CODING_LABQ:
case IM_CODING_RAD:
case IM_CODING_NONE:
psize = (gint64) IM_IMAGE_SIZEOF_LINE( im ) * im->Ysize;
break;
@ -1043,6 +1044,7 @@ im_open_vips( const char *filename )
*/
switch( im->Coding ) {
case IM_CODING_LABQ:
case IM_CODING_RAD:
break;
case IM_CODING_NONE:

View File

@ -118,7 +118,8 @@ static const char *im_Coding[] = {
"IM_CODING_NONE",
"COLQUANT8",
"IM_CODING_LABQ",
"IM_CODING_LABQ_COMPRESSED"
"IM_CODING_LABQ_COMPRESSED",
"IM_CODING_RAD"
};
static const char *im_Compression[] = {