add gif background colour as metadata

This commit is contained in:
John Cupitt 2021-02-20 04:52:02 +00:00
parent d6201fc32d
commit 8dc2db9789
6 changed files with 86 additions and 18 deletions

View File

@ -17,8 +17,9 @@
- hist_find outputs a double histogram for large images [erdmann]
- fix ref leaks in mosaicing package
- run libvips leak test in CI
- add vips_fitsload_source()m vips_niftiload_source()
- png load notes background colour as metadata [781545872]
- add vips_fitsload_source(), vips_niftiload_source()
- png and gif load note background colour as metadata [781545872]
- add vips_image_[set|get]_array_double()
22/12/20 start 8.10.6
- don't seek on bad file descriptors [kleisauke]

View File

@ -42,6 +42,8 @@
* 2/7/20
* - clip out of bounds images against canvas
* - fix PREVIOUS handling, again
* 19/2/21 781545872
* - read out background, if we can
*/
/*
@ -701,6 +703,7 @@ static int
vips_foreign_load_gif_set_header( VipsForeignLoadGif *gif, VipsImage *image )
{
const gint64 total_height = (gint64) gif->file->SHeight * gif->n;
ColorMapObject *map = gif->file->SColorMap;
if( total_height <= 0 ||
total_height > VIPS_MAX_COORD ) {
@ -745,6 +748,18 @@ vips_foreign_load_gif_set_header( VipsForeignLoadGif *gif, VipsImage *image )
if( gif->comment )
vips_image_set_string( image, "gif-comment", gif->comment );
if( map &&
gif->file->SBackGroundColor >= 0 &&
gif->file->SBackGroundColor < map->ColorCount ) {
double array[3];
array[0] = map->Colors[gif->file->SBackGroundColor].Red;
array[1] = map->Colors[gif->file->SBackGroundColor].Green;
array[2] = map->Colors[gif->file->SBackGroundColor].Blue;
vips_image_set_array_double( image, "background", array, 3 );
}
return( 0 );
}

View File

@ -302,14 +302,9 @@ vips_foreign_load_png_set_header( VipsForeignLoadPng *png, VipsImage *image )
break;
}
if( n > 0 ) {
GValue value = { 0 };
g_value_init( &value, VIPS_TYPE_ARRAY_DOUBLE );
vips_value_set_array_double( &value, array, n );
vips_image_set( image, "background", &value );
g_value_unset( &value );
}
if( n > 0 )
vips_image_set_array_double( image, "background",
array, n );
}
}

View File

@ -597,14 +597,9 @@ png2vips_header( Read *read, VipsImage *out )
break;
}
if( n > 0 ) {
GValue value = { 0 };
g_value_init( &value, VIPS_TYPE_ARRAY_DOUBLE );
vips_value_set_array_double( &value, array, n );
vips_image_set( out, "background", &value );
g_value_unset( &value );
}
if( n > 0 )
vips_image_set_array_double( out, "background",
array, n );
}
}
#endif

View File

@ -230,6 +230,10 @@ void vips_image_set_array_int( VipsImage *image, const char *name,
const int *array, int n );
int vips_image_get_array_int( VipsImage *image, const char *name,
int **out, int *n );
int vips_image_get_array_double( VipsImage *image, const char *name,
double **out, int *n );
void vips_image_set_array_double( VipsImage *image, const char *name,
const double *array, int n );
int vips_image_history_printf( VipsImage *image, const char *format, ... )
__attribute__((format(printf, 2, 3)));

View File

@ -1959,6 +1959,64 @@ vips_image_set_array_int( VipsImage *image, const char *name,
g_value_unset( &value );
}
/**
* vips_image_get_array_double: (method)
* @image: image to get the metadata from
* @name: metadata name
* @out: (transfer none): return pointer to array
* @n: (allow-none): return the number of elements here, optionally
*
* Gets @out from @im under the name @name.
* The field must be of type
* #VIPS_TYPE_ARRAY_INT.
*
* Do not free @out. @out is valid as long as @image is valid.
*
* Use vips_image_get_typeof() to test for the
* existence of a piece of metadata.
*
* See also: vips_image_get(), vips_image_set_image()
*
* Returns: 0 on success, -1 otherwise.
*/
int
vips_image_get_array_double( VipsImage *image, const char *name,
double **out, int *n )
{
GValue value = { 0 };
if( meta_get_value( image, name, VIPS_TYPE_ARRAY_DOUBLE, &value ) )
return( -1 );
*out = vips_value_get_array_double( &value, n );
g_value_unset( &value );
return( 0 );
}
/**
* vips_image_set_array_double: (method)
* @image: image to attach the metadata to
* @name: metadata name
* @array: (array length=n) (allow-none): array of doubles
* @n: the number of elements
*
* Attaches @array as a metadata item on @image as @name.
* A convenience function over vips_image_set().
*
* See also: vips_image_get_image(), vips_image_set().
*/
void
vips_image_set_array_double( VipsImage *image, const char *name,
const double *array, int n )
{
GValue value = { 0 };
g_value_init( &value, VIPS_TYPE_ARRAY_DOUBLE );
vips_value_set_array_double( &value, array, n );
vips_image_set( image, name, &value );
g_value_unset( &value );
}
/**
* vips_image_history_printf: (method)
* @image: add history line to this image