revise profile_load
seems to work!
This commit is contained in:
parent
9cc72ea1c1
commit
d2d63f4ac4
@ -58,58 +58,19 @@ typedef VipsOperationClass VipsProfileLoadClass;
|
|||||||
|
|
||||||
G_DEFINE_TYPE( VipsProfileLoad, vips_profile_load, VIPS_TYPE_OPERATION );
|
G_DEFINE_TYPE( VipsProfileLoad, vips_profile_load, VIPS_TYPE_OPERATION );
|
||||||
|
|
||||||
/* Created on first use from a base64 string in profiles.c.
|
static const void *
|
||||||
*/
|
vips_profile_fallback_get( const char *name, size_t *length )
|
||||||
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 )
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
VipsProfileFallback *fallback;
|
||||||
|
|
||||||
for( i = 0; vips__coded_profiles[i].name; i++ ) {
|
for( i = 0; (fallback = vips__profile_fallback_table[i]); 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;
|
|
||||||
|
|
||||||
if( g_ascii_strcasecmp( fallback->name, name ) == 0 ) {
|
if( g_ascii_strcasecmp( fallback->name, name ) == 0 ) {
|
||||||
*length = fallback->data_length;
|
if( length )
|
||||||
|
*length = fallback->length;
|
||||||
|
|
||||||
return( fallback->data );
|
return( fallback->data );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return( NULL );
|
return( NULL );
|
||||||
}
|
}
|
||||||
@ -131,7 +92,7 @@ vips_profile_load_build( VipsObject *object )
|
|||||||
if( g_ascii_strcasecmp( load->name, "none" ) == 0 ) {
|
if( g_ascii_strcasecmp( load->name, "none" ) == 0 ) {
|
||||||
profile = NULL;
|
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 );
|
profile = vips_blob_new( NULL, data, length );
|
||||||
}
|
}
|
||||||
else if( (data = vips__file_read_name( load->name,
|
else if( (data = vips__file_read_name( load->name,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "profiles.h"
|
#include "profiles.h"
|
||||||
|
|
||||||
static VipsCodedProfile vips__profile_cmyk = {
|
static VipsProfileFallback vips__profile_fallback_cmyk = {
|
||||||
"cmyk",
|
"cmyk",
|
||||||
961644,
|
961644,
|
||||||
{
|
{
|
||||||
@ -80146,7 +80146,7 @@ static VipsCodedProfile vips__profile_cmyk = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static VipsCodedProfile vips__profile_sRGB = {
|
static VipsProfileFallback vips__profile_fallback_sRGB = {
|
||||||
"sRGB",
|
"sRGB",
|
||||||
6922,
|
6922,
|
||||||
{
|
{
|
||||||
@ -80730,8 +80730,8 @@ static VipsCodedProfile vips__profile_sRGB = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VipsCodedProfile *vips__coded_profiles[] = {
|
VipsProfileFallback *vips__profile_fallback_table[] = {
|
||||||
&vips__profile_cmyk,
|
&vips__profile_fallback_cmyk,
|
||||||
&vips__profile_sRGB,
|
&vips__profile_fallback_sRGB,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
/* The fallback profiles, coded as a set of base64 strings, see
|
/* The fallback profiles, coded as a set of uchar arrays, see wrap-profiles.sh
|
||||||
* wrap-profiles.sh
|
|
||||||
*/
|
*/
|
||||||
typedef struct _VipsCodedProfile {
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef struct _VipsProfileFallback {
|
||||||
const char *name;
|
const char *name;
|
||||||
int length;
|
size_t length;
|
||||||
const unsigned char data[];
|
const unsigned char data[];
|
||||||
} VipsCodedProfile;
|
} VipsProfileFallback;
|
||||||
|
|
||||||
extern VipsCodedProfile *vips__coded_profiles[];
|
extern VipsProfileFallback *vips__profile_fallback_table[];
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ profile_names=
|
|||||||
for file in $in/*; do
|
for file in $in/*; do
|
||||||
root=${file%.icm}
|
root=${file%.icm}
|
||||||
base=${root##*/}
|
base=${root##*/}
|
||||||
profile_name=vips__profile_$base
|
profile_name=vips__profile_fallback_$base
|
||||||
profile_names="$profile_names $profile_name"
|
profile_names="$profile_names $profile_name"
|
||||||
echo "static VipsCodedProfile $profile_name = {" >> $out
|
echo "static VipsProfileFallback $profile_name = {" >> $out
|
||||||
echo " \"$base\"," >> $out
|
echo " \"$base\"," >> $out
|
||||||
echo " $(stat --format=%s $file)," >> $out
|
echo " $(stat --format=%s $file)," >> $out
|
||||||
echo " {" >> $out
|
echo " {" >> $out
|
||||||
@ -30,7 +30,7 @@ for file in $in/*; do
|
|||||||
echo >> $out
|
echo >> $out
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "VipsCodedProfile *vips__coded_profiles[] = {" >> $out
|
echo "VipsProfileFallback *vips__profile_fallback_table[] = {" >> $out
|
||||||
for profile_name in $profile_names; do
|
for profile_name in $profile_names; do
|
||||||
echo " &$profile_name," >> $out
|
echo " &$profile_name," >> $out
|
||||||
done
|
done
|
||||||
|
@ -461,7 +461,9 @@ class TestForeign:
|
|||||||
def test_webp(self):
|
def test_webp(self):
|
||||||
def webp_valid(im):
|
def webp_valid(im):
|
||||||
a = im(10, 10)
|
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.width == 550
|
||||||
assert im.height == 368
|
assert im.height == 368
|
||||||
assert im.bands == 3
|
assert im.bands == 3
|
||||||
@ -476,7 +478,7 @@ class TestForeign:
|
|||||||
im = pyvips.Image.new_from_file(WEBP_FILE)
|
im = pyvips.Image.new_from_file(WEBP_FILE)
|
||||||
buf = im.webpsave_buffer(lossless=True)
|
buf = im.webpsave_buffer(lossless=True)
|
||||||
im2 = pyvips.Image.new_from_buffer(buf, "")
|
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
|
# higher Q should mean a bigger buffer
|
||||||
b1 = im.webpsave_buffer(Q=10)
|
b1 = im.webpsave_buffer(Q=10)
|
||||||
|
Loading…
Reference in New Issue
Block a user