make RGB and sRGB synonmous

We had a half-baked idea that RGB could mean generic RGB space and sRGB
would mean strict sRGB interpretation.

Unfortunately, this did not work well in practice. For example,
`icc_transform("srgb")` would tag the result as RGB rather than sRGB
(the converter didn't know it was writing sRGB pixels, it just saw
conversion to RGB with an ICC profile), and then later stages would do
unnecessary icc_imports, or worse, fail.

This patch makes RGB and sRGB strict synonyms. If you want to treat an
RGB image as something other than sRGB, you'll need to do it by hand
with the icc_ functions.

See

https://github.com/libvips/pyvips/issues/144

46212e92b1 (r34904985)

https://github.com/libvips/libvips/issues/1494
This commit is contained in:
John Cupitt 2019-12-22 11:40:09 +00:00
parent b964deb482
commit e48f45187b
10 changed files with 17 additions and 34 deletions

View File

@ -26,6 +26,7 @@
- support TIFF CIELAB images with alpha [angelmixu]
- support TIFF with premultiplied alpha in any band
- block metadata changes on shared images [pvdz]
- RGB and sRGB are synonmous
17/9/19 started 8.8.4
- improve compatibility with older imagemagick versions

View File

@ -493,9 +493,7 @@ static VipsColourRoute vips_colour_routes[] = {
* vips_colourspace_issupported:
* @image: input image
*
* Test if @image is in a colourspace that vips_colourspace() can process. For
* example, #VIPS_INTERPRETATION_RGB images are not in a well-defined
* colourspace, but #VIPS_INTERPRETATION_sRGB ones are.
* Test if @image is in a colourspace that vips_colourspace() can process.
*
* Returns: %TRUE if @image is in a supported colourspace.
*/

View File

@ -282,7 +282,7 @@ vips_icc_build( VipsObject *object )
case cmsSigRgbData:
colour->interpretation =
icc->depth == 8 ?
VIPS_INTERPRETATION_RGB :
VIPS_INTERPRETATION_sRGB :
VIPS_INTERPRETATION_RGB16;
colour->format =
icc->depth == 8 ?

View File

@ -326,7 +326,7 @@ vips_fits_get_header( VipsFits *fits, VipsImage *out )
if( format == VIPS_FORMAT_USHORT )
type = VIPS_INTERPRETATION_RGB16;
else
type = VIPS_INTERPRETATION_RGB;
type = VIPS_INTERPRETATION_sRGB;
}
else
type = VIPS_INTERPRETATION_MULTIBAND;

View File

@ -377,14 +377,8 @@ parse_header( Read *read )
im->Type = VIPS_INTERPRETATION_B_W;
break;
case RGBColorspace:
if( im->BandFmt == VIPS_FORMAT_USHORT )
im->Type = VIPS_INTERPRETATION_RGB16;
else
im->Type = VIPS_INTERPRETATION_RGB;
break;
case sRGBColorspace:
case RGBColorspace:
if( im->BandFmt == VIPS_FORMAT_USHORT )
im->Type = VIPS_INTERPRETATION_RGB16;
else

View File

@ -477,14 +477,8 @@ vips_foreign_load_magick7_parse( VipsForeignLoadMagick7 *magick7,
out->Type = VIPS_INTERPRETATION_B_W;
break;
case RGBColorspace:
if( out->BandFmt == VIPS_FORMAT_USHORT )
out->Type = VIPS_INTERPRETATION_RGB16;
else
out->Type = VIPS_INTERPRETATION_RGB;
break;
case sRGBColorspace:
case RGBColorspace:
if( out->BandFmt == VIPS_FORMAT_USHORT )
out->Type = VIPS_INTERPRETATION_RGB16;
else

View File

@ -332,7 +332,7 @@ readslide_attach_associated( ReadSlide *rslide, VipsImage *image )
openslide_get_associated_image_dimensions( rslide->osr,
*associated_name, &w, &h );
vips_image_init_fields( associated, w, h, 4, VIPS_FORMAT_UCHAR,
VIPS_CODING_NONE, VIPS_INTERPRETATION_RGB, 1.0, 1.0 );
VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB, 1.0, 1.0 );
vips_image_pipelinev( associated,
VIPS_DEMAND_STYLE_THINSTRIP, NULL );
@ -494,7 +494,7 @@ readslide_parse( ReadSlide *rslide, VipsImage *image )
}
vips_image_init_fields( image, w, h, 4, VIPS_FORMAT_UCHAR,
VIPS_CODING_NONE, VIPS_INTERPRETATION_RGB, 1.0, 1.0 );
VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB, 1.0, 1.0 );
for( properties = openslide_get_property_names( rslide->osr );
*properties != NULL; properties++ )

View File

@ -313,8 +313,6 @@ vips_foreign_load_ppm_parse_header( VipsForeignLoadPpm *ppm )
else {
if( ppm->format == VIPS_FORMAT_USHORT )
ppm->interpretation = VIPS_INTERPRETATION_RGB16;
else if( ppm->format == VIPS_FORMAT_UINT )
ppm->interpretation = VIPS_INTERPRETATION_RGB;
else
ppm->interpretation = VIPS_INTERPRETATION_sRGB;
}

View File

@ -443,12 +443,12 @@ vips_image_guess_format( const VipsImage *image )
break;
case VIPS_INTERPRETATION_sRGB:
case VIPS_INTERPRETATION_RGB:
format = VIPS_FORMAT_UCHAR;
break;
case VIPS_INTERPRETATION_XYZ:
case VIPS_INTERPRETATION_LAB:
case VIPS_INTERPRETATION_RGB:
case VIPS_INTERPRETATION_CMC:
case VIPS_INTERPRETATION_LCH:
case VIPS_INTERPRETATION_HSV:
@ -519,8 +519,7 @@ vips_image_get_interpretation( const VipsImage *image )
return( image->Type );
}
/* Try to pick a sane value for interpretation, assuming Type has been set
* incorrectly.
/* Try to guess a sane value for interpretation.
*/
static VipsInterpretation
vips_image_default_interpretation( const VipsImage *image )
@ -529,7 +528,7 @@ vips_image_default_interpretation( const VipsImage *image )
case VIPS_CODING_LABQ:
return( VIPS_INTERPRETATION_LABQ );
case VIPS_CODING_RAD:
return( VIPS_INTERPRETATION_RGB );
return( VIPS_INTERPRETATION_sRGB );
default:
break;
}
@ -578,7 +577,7 @@ vips_image_guess_interpretation( const VipsImage *image )
break;
case VIPS_CODING_RAD:
if( image->Type != VIPS_INTERPRETATION_RGB )
if( image->Type != VIPS_INTERPRETATION_sRGB )
sane = FALSE;
break;

View File

@ -230,9 +230,8 @@
* three-band float image of type #VIPS_INTERPRETATION_LAB should have its
* pixels interpreted as coordinates in CIE Lab space.
*
* These values are set by operations as hints to user-interfaces built on top
* of VIPS to help them show images to the user in a meaningful way.
* Operations do not use these values to decide their action.
* RGB and sRGB are treated in the same way. Use the colourspace functions if
* you want some other behaviour.
*
* The gaps in numbering are historical and must be maintained. Allocate
* new numbers from the end.
@ -959,7 +958,7 @@ vips_image_build( VipsObject *object )
if( image->Bands == 1 )
image->Type = VIPS_INTERPRETATION_B_W;
else if( image->Bands == 3 )
image->Type = VIPS_INTERPRETATION_RGB;
image->Type = VIPS_INTERPRETATION_sRGB;
else
image->Type = VIPS_INTERPRETATION_MULTIBAND;
@ -992,7 +991,7 @@ vips_image_build( VipsObject *object )
if( image->Bands == 1 )
image->Type = VIPS_INTERPRETATION_B_W;
else if( image->Bands == 3 )
image->Type = VIPS_INTERPRETATION_RGB;
image->Type = VIPS_INTERPRETATION_sRGB;
else
image->Type = VIPS_INTERPRETATION_MULTIBAND;
@ -3093,7 +3092,7 @@ vips_image_ispartial( VipsImage *image )
* @image: image to check
*
* Look at an image's interpretation and see if it has extra alpha bands. For
* example, a 4-band #VIPS_INTERPRETATION_RGB would, but a six-band
* example, a 4-band #VIPS_INTERPRETATION_sRGB would, but a six-band
* #VIPS_INTERPRETATION_MULTIBAND would not.
*
* Return %TRUE if @image has an alpha channel.