revise profile_load

seems to work!
This commit is contained in:
John Cupitt 2019-08-08 13:23:28 +01:00
parent 9cc72ea1c1
commit d2d63f4ac4
5 changed files with 27 additions and 62 deletions

View File

@ -58,58 +58,19 @@ typedef VipsOperationClass VipsProfileLoadClass;
G_DEFINE_TYPE( VipsProfileLoad, vips_profile_load, VIPS_TYPE_OPERATION );
/* Created on first use from a base64 string in profiles.c.
*/
typedef struct _VipsFallbackProfile {
const char *name;
void *data;
size_t data_length;
} VipsFallbackProfile;
static GSList *vips_fallback_profile_list = NULL;
static void *
vips_fallback_profile_get_init( void )
static const void *
vips_profile_fallback_get( const char *name, size_t *length )
{
int i;
VipsProfileFallback *fallback;
for( i = 0; vips__coded_profiles[i].name; i++ ) {
size_t data_length;
unsigned char *data;
VipsFallbackProfile *fallback;
if( !(data = vips__b64_decode(
vips__coded_profiles[i].data, &data_length )) )
return( NULL );
fallback = g_new( VipsFallbackProfile,1 );
fallback->name = vips__coded_profiles[i].name;
fallback->data = data;
fallback->data_length = data_length;
vips_fallback_profile_list = g_slist_prepend(
vips_fallback_profile_list, fallback );
}
return( NULL );
}
static void *
vips_fallback_profile_get( const char *name, size_t *length )
{
static GOnce once = G_ONCE_INIT;
GSList *p;
VIPS_ONCE( &once, (GThreadFunc) vips_fallback_profile_get_init, NULL );
for( p = vips_fallback_profile_list; p; p = p->next ) {
VipsFallbackProfile *fallback = (VipsFallbackProfile *) p->data;
for( i = 0; (fallback = vips__profile_fallback_table[i]); i++ )
if( g_ascii_strcasecmp( fallback->name, name ) == 0 ) {
*length = fallback->data_length;
if( length )
*length = fallback->length;
return( fallback->data );
}
}
return( NULL );
}
@ -131,7 +92,7 @@ vips_profile_load_build( VipsObject *object )
if( g_ascii_strcasecmp( load->name, "none" ) == 0 ) {
profile = NULL;
}
else if( (data = vips_fallback_profile_get( load->name, &length )) ) {
else if( (data = vips_profile_fallback_get( load->name, &length )) ) {
profile = vips_blob_new( NULL, data, length );
}
else if( (data = vips__file_read_name( load->name,

View File

@ -2,7 +2,7 @@
#include "profiles.h"
static VipsCodedProfile vips__profile_cmyk = {
static VipsProfileFallback vips__profile_fallback_cmyk = {
"cmyk",
961644,
{
@ -80146,7 +80146,7 @@ static VipsCodedProfile vips__profile_cmyk = {
}
};
static VipsCodedProfile vips__profile_sRGB = {
static VipsProfileFallback vips__profile_fallback_sRGB = {
"sRGB",
6922,
{
@ -80730,8 +80730,8 @@ static VipsCodedProfile vips__profile_sRGB = {
}
};
VipsCodedProfile *vips__coded_profiles[] = {
&vips__profile_cmyk,
&vips__profile_sRGB,
VipsProfileFallback *vips__profile_fallback_table[] = {
&vips__profile_fallback_cmyk,
&vips__profile_fallback_sRGB,
NULL
};

View File

@ -1,11 +1,13 @@
/* The fallback profiles, coded as a set of base64 strings, see
* wrap-profiles.sh
/* The fallback profiles, coded as a set of uchar arrays, see wrap-profiles.sh
*/
typedef struct _VipsCodedProfile {
#include <stddef.h>
typedef struct _VipsProfileFallback {
const char *name;
int length;
size_t length;
const unsigned char data[];
} VipsCodedProfile;
} VipsProfileFallback;
extern VipsCodedProfile *vips__coded_profiles[];
extern VipsProfileFallback *vips__profile_fallback_table[];

View File

@ -18,9 +18,9 @@ profile_names=
for file in $in/*; do
root=${file%.icm}
base=${root##*/}
profile_name=vips__profile_$base
profile_name=vips__profile_fallback_$base
profile_names="$profile_names $profile_name"
echo "static VipsCodedProfile $profile_name = {" >> $out
echo "static VipsProfileFallback $profile_name = {" >> $out
echo " \"$base\"," >> $out
echo " $(stat --format=%s $file)," >> $out
echo " {" >> $out
@ -30,7 +30,7 @@ for file in $in/*; do
echo >> $out
done
echo "VipsCodedProfile *vips__coded_profiles[] = {" >> $out
echo "VipsProfileFallback *vips__profile_fallback_table[] = {" >> $out
for profile_name in $profile_names; do
echo " &$profile_name," >> $out
done

View File

@ -461,7 +461,9 @@ class TestForeign:
def test_webp(self):
def webp_valid(im):
a = im(10, 10)
assert_almost_equal_objects(a, [71, 166, 236])
# different webp versions use different rounding systems leading
# to small variations
assert_almost_equal_objects(a, [71, 166, 236], threshold=2)
assert im.width == 550
assert im.height == 368
assert im.bands == 3
@ -476,7 +478,7 @@ class TestForeign:
im = pyvips.Image.new_from_file(WEBP_FILE)
buf = im.webpsave_buffer(lossless=True)
im2 = pyvips.Image.new_from_buffer(buf, "")
assert im.avg() == im2.avg()
assert abs(im.avg() - im2.avg()) < 1
# higher Q should mean a bigger buffer
b1 = im.webpsave_buffer(Q=10)