Merge branch 'master' into cmyk2srgb
This commit is contained in:
commit
8ded32ac20
@ -13,7 +13,9 @@
|
||||
- add vips_rect_overlapsrect()
|
||||
- composite is much faster at positioning subimages
|
||||
- dzsave has a new skip_blanks option
|
||||
- add CMYK as a supported colourspace
|
||||
- add vips_CMYK2XYZ() and vips_XYZ2CMYK(), plus associated routes
|
||||
- include cmyk and srgb fallback profiles
|
||||
- add vips_profile_load() and use it everywhere
|
||||
|
||||
4/1/19 started 8.7.4
|
||||
- fix memory leak in magickload [kleisauke]
|
||||
|
@ -32,8 +32,6 @@
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <vips/vips8>
|
||||
|
||||
VIPS_NAMESPACE_START
|
||||
|
@ -563,7 +563,7 @@ VImage::new_from_file( const char *name, VOption *options )
|
||||
}
|
||||
|
||||
VImage
|
||||
VImage::new_from_buffer( void *buf, size_t len, const char *option_string,
|
||||
VImage::new_from_buffer( const void *buf, size_t len, const char *option_string,
|
||||
VOption *options )
|
||||
{
|
||||
const char *operation_name;
|
||||
@ -588,6 +588,13 @@ VImage::new_from_buffer( void *buf, size_t len, const char *option_string,
|
||||
return( out );
|
||||
}
|
||||
|
||||
VImage
|
||||
VImage::new_from_buffer( const std::string &buf, const char *option_string,
|
||||
VOption *options )
|
||||
{
|
||||
return( new_from_buffer( buf.c_str(), buf.size(), option_string, options ) );
|
||||
}
|
||||
|
||||
VImage
|
||||
VImage::new_matrix( int width, int height )
|
||||
{
|
||||
|
@ -31,8 +31,8 @@
|
||||
#ifndef VIPS_VERROR_H
|
||||
#define VIPS_VERROR_H
|
||||
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
#include <cstring>
|
||||
#include <ostream>
|
||||
#include <exception>
|
||||
|
||||
#include <vips/vips.h>
|
||||
@ -43,7 +43,7 @@ class VIPS_CPLUSPLUS_API VError : public std::exception {
|
||||
std::string _what;
|
||||
|
||||
public:
|
||||
VError( std::string what ) : _what( what ) {}
|
||||
VError( const std::string &what ) : _what( what ) {}
|
||||
VError() : _what( vips_error_buffer() ) {}
|
||||
virtual ~VError() throw() {}
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <complex>
|
||||
#include <vector>
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
@ -327,6 +327,12 @@ public:
|
||||
return( vips_image_get_yoffset( get_image() ) );
|
||||
}
|
||||
|
||||
bool
|
||||
has_alpha() const
|
||||
{
|
||||
return( vips_image_hasalpha( get_image() ) );
|
||||
}
|
||||
|
||||
const char *
|
||||
filename() const
|
||||
{
|
||||
@ -407,7 +413,7 @@ public:
|
||||
const void *
|
||||
get_blob( const char *field, size_t *length ) const
|
||||
{
|
||||
void *value;
|
||||
const void *value;
|
||||
|
||||
if( vips_image_get_blob( this->get_image(), field,
|
||||
&value, length ) )
|
||||
@ -416,6 +422,12 @@ public:
|
||||
return( value );
|
||||
}
|
||||
|
||||
bool
|
||||
remove( const char *name ) const
|
||||
{
|
||||
return( vips_image_remove( get_image(), name ) );
|
||||
}
|
||||
|
||||
static VOption *
|
||||
option()
|
||||
{
|
||||
@ -458,7 +470,10 @@ public:
|
||||
return( VImage( image ) );
|
||||
}
|
||||
|
||||
static VImage new_from_buffer( void *buf, size_t len,
|
||||
static VImage new_from_buffer( const void *buf, size_t len,
|
||||
const char *option_string, VOption *options = 0 );
|
||||
|
||||
static VImage new_from_buffer( const std::string &buf,
|
||||
const char *option_string, VOption *options = 0 );
|
||||
|
||||
static VImage new_matrix( int width, int height );
|
||||
@ -495,6 +510,17 @@ public:
|
||||
return( new_from_image( to_vectorv( 1, pixel ) ) );
|
||||
}
|
||||
|
||||
VImage
|
||||
copy_memory() const
|
||||
{
|
||||
VipsImage *image;
|
||||
|
||||
if( !(image = vips_image_copy_memory( this->get_image() )) )
|
||||
throw( VError() );
|
||||
|
||||
return( VImage( image ) );
|
||||
}
|
||||
|
||||
VImage write( VImage out ) const;
|
||||
|
||||
void write_to_file( const char *name, VOption *options = 0 ) const;
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <complex>
|
||||
#include <vector>
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
|
@ -44,8 +44,8 @@
|
||||
|
||||
#include <vips/internal.h>
|
||||
|
||||
#include "pcolour.h"
|
||||
#include "profiles.h"
|
||||
#include "pcolour.h"
|
||||
|
||||
#ifdef HAVE_LCMS2
|
||||
|
||||
@ -60,61 +60,6 @@ typedef VipsColourCodeClass VipsCMYK2XYZClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsCMYK2XYZ, vips_CMYK2XYZ, VIPS_TYPE_OPERATION );
|
||||
|
||||
/* Created on first use from a base64 string in profiles.c.
|
||||
*/
|
||||
static void *vips_CMYK2XYZ_fallback_profile = NULL;
|
||||
static size_t vips_CMYK2XYZ_fallback_profile_length = 0;
|
||||
|
||||
static void *
|
||||
vips_CMYK2XYZ_get_fallback_profile_init( void )
|
||||
{
|
||||
size_t data_length;
|
||||
unsigned char *data;
|
||||
|
||||
if( !(data = vips__b64_decode( vips__coded_cmyk, &data_length )) )
|
||||
return( NULL );
|
||||
vips_CMYK2XYZ_fallback_profile = data;
|
||||
vips_CMYK2XYZ_fallback_profile_length = data_length;
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
static void *
|
||||
vips__CMYK2XYZ_get_fallback_profile( size_t *length )
|
||||
{
|
||||
GOnce once = G_ONCE_INIT;
|
||||
|
||||
VIPS_ONCE( &once,
|
||||
(GThreadFunc) vips_CMYK2XYZ_get_fallback_profile_init, NULL );
|
||||
|
||||
*length = vips_CMYK2XYZ_fallback_profile_length;
|
||||
|
||||
return( vips_CMYK2XYZ_fallback_profile );
|
||||
}
|
||||
|
||||
/* Shared with XYZ2CMYK.c.
|
||||
*/
|
||||
int
|
||||
vips_CMYK2XYZ_set_fallback_profile( VipsImage *image )
|
||||
{
|
||||
size_t data_length;
|
||||
unsigned char *data;
|
||||
|
||||
/* Already a profile? Do nothing. We could remove and replace non-CMYK
|
||||
* profiles I guess.
|
||||
*/
|
||||
if( vips_image_get_typeof( image, VIPS_META_ICC_NAME ) )
|
||||
return( 0 );
|
||||
|
||||
if( !(data = vips__CMYK2XYZ_get_fallback_profile( &data_length )) )
|
||||
return( -1 );
|
||||
|
||||
vips_image_set_blob( image, VIPS_META_ICC_NAME,
|
||||
NULL, data, data_length );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Our actual processing, as a VipsColourTransformFn.
|
||||
*/
|
||||
static int
|
||||
@ -141,7 +86,7 @@ vips_CMYK2XYZ_build( VipsObject *object )
|
||||
g_object_set( object, "out", out, NULL );
|
||||
|
||||
if( vips_copy( CMYK2XYZ->in, &t[0], NULL ) ||
|
||||
vips_CMYK2XYZ_set_fallback_profile( t[0] ) ||
|
||||
vips__profile_set( t[0], "cmyk" ) ||
|
||||
vips__colourspace_process_n( "CMYK2XYZ",
|
||||
t[0], &t[1], 4, vips_CMYK2XYZ_process ) ||
|
||||
vips_image_write( t[1], out ) )
|
||||
|
@ -1,13 +1,9 @@
|
||||
noinst_LTLIBRARIES = libcolour.la
|
||||
|
||||
if ENABLE_LCMS
|
||||
PROFILES = profiles.c profiles.h
|
||||
else
|
||||
PROFILES =
|
||||
endif
|
||||
|
||||
libcolour_la_SOURCES = \
|
||||
$(PROFILES) \
|
||||
profiles.c \
|
||||
profiles.h \
|
||||
profile_load.c \
|
||||
colour.c \
|
||||
pcolour.h \
|
||||
CMYK2XYZ.c \
|
||||
@ -43,7 +39,7 @@ libcolour_la_SOURCES = \
|
||||
scRGB2sRGB.c
|
||||
|
||||
profiles.c:
|
||||
./wrap_profiles.sh profiles profiles
|
||||
./wrap-profiles.sh profiles profiles.c
|
||||
|
||||
EXTRA_DIST = \
|
||||
profiles \
|
||||
|
@ -85,7 +85,7 @@ vips_XYZ2CMYK_build( VipsObject *object )
|
||||
g_object_set( object, "out", out, NULL );
|
||||
|
||||
if( vips_copy( XYZ2CMYK->in, &t[0], NULL ) ||
|
||||
vips_CMYK2XYZ_set_fallback_profile( t[0] ) ||
|
||||
vips__profile_set( t[0], "cmyk" ) ||
|
||||
vips__colourspace_process_n( "XYZ2CMYK",
|
||||
t[0], &t[1], 3, vips_XYZ2CMYK_process ) ||
|
||||
vips_image_write( t[1], out ) )
|
||||
|
@ -751,9 +751,10 @@ vips_colour_operation_init( void )
|
||||
extern GType vips_scRGB2XYZ_get_type( void );
|
||||
extern GType vips_scRGB2BW_get_type( void );
|
||||
extern GType vips_XYZ2scRGB_get_type( void );
|
||||
extern GType vips_scRGB2sRGB_get_type( void );
|
||||
extern GType vips_scRGB2sRGB_get_type( void );
|
||||
extern GType vips_CMYK2XYZ_get_type( void );
|
||||
extern GType vips_XYZ2CMYK_get_type( void );
|
||||
extern GType vips_profile_load_get_type( void );
|
||||
#ifdef HAVE_LCMS2
|
||||
extern GType vips_icc_import_get_type( void );
|
||||
extern GType vips_icc_export_get_type( void );
|
||||
@ -790,6 +791,7 @@ vips_colour_operation_init( void )
|
||||
vips_scRGB2sRGB_get_type();
|
||||
vips_CMYK2XYZ_get_type();
|
||||
vips_XYZ2CMYK_get_type();
|
||||
vips_profile_load_get_type();
|
||||
#ifdef HAVE_LCMS2
|
||||
vips_icc_import_get_type();
|
||||
vips_icc_export_get_type();
|
||||
|
@ -151,7 +151,9 @@ typedef struct _VipsIcc {
|
||||
VipsPCS pcs;
|
||||
int depth;
|
||||
|
||||
VipsBlob *in_blob;
|
||||
cmsHPROFILE in_profile;
|
||||
VipsBlob *out_blob;
|
||||
cmsHPROFILE out_profile;
|
||||
cmsUInt32Number in_icc_format;
|
||||
cmsUInt32Number out_icc_format;
|
||||
@ -181,6 +183,16 @@ vips_icc_dispose( GObject *gobject )
|
||||
VIPS_FREEF( cmsCloseProfile, icc->in_profile );
|
||||
VIPS_FREEF( cmsCloseProfile, icc->out_profile );
|
||||
|
||||
if( icc->in_blob ) {
|
||||
vips_area_unref( (VipsArea *) icc->in_blob );
|
||||
icc->in_blob = NULL;
|
||||
}
|
||||
|
||||
if( icc->out_blob ) {
|
||||
vips_area_unref( (VipsArea *) icc->out_blob );
|
||||
icc->out_blob = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS( vips_icc_parent_class )->dispose( gobject );
|
||||
}
|
||||
|
||||
@ -581,63 +593,50 @@ vips_image_expected_sig( VipsImage *image )
|
||||
return( expected_sig );
|
||||
}
|
||||
|
||||
static cmsHPROFILE
|
||||
vips_icc_load_profile_image( VipsImage *image )
|
||||
/* Get from an image.
|
||||
*/
|
||||
static VipsBlob *
|
||||
vips_icc_get_profile_image( VipsImage *image )
|
||||
{
|
||||
void *data;
|
||||
size_t data_length;
|
||||
cmsHPROFILE profile;
|
||||
const void *data;
|
||||
size_t size;
|
||||
|
||||
if( !vips_image_get_typeof( image, VIPS_META_ICC_NAME ) )
|
||||
return( NULL );
|
||||
if( vips_image_get_blob( image, VIPS_META_ICC_NAME, &data, &size ) )
|
||||
return( NULL );
|
||||
|
||||
if( vips_image_get_blob( image, VIPS_META_ICC_NAME,
|
||||
&data, &data_length ) ||
|
||||
!(profile = cmsOpenProfileFromMem( data, data_length )) ) {
|
||||
g_warning( "%s", _( "corrupt embedded profile" ) );
|
||||
return( vips_blob_new( NULL, data, size ) );
|
||||
}
|
||||
|
||||
/* Load a profile from a blob and check compatibility.
|
||||
*/
|
||||
static cmsHPROFILE
|
||||
vips_icc_load_profile_blob( VipsBlob *blob, VipsImage *image )
|
||||
{
|
||||
const void *data;
|
||||
size_t size;
|
||||
cmsHPROFILE profile;
|
||||
|
||||
data = vips_blob_get( blob, &size );
|
||||
if( !(profile = cmsOpenProfileFromMem( data, size )) ) {
|
||||
g_warning( "%s", _( "corrupt profile" ) );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if( vips_image_expected_bands( image ) !=
|
||||
vips_icc_profile_needs_bands( profile ) ) {
|
||||
if( image &&
|
||||
vips_image_expected_bands( image ) !=
|
||||
vips_icc_profile_needs_bands( profile ) ) {
|
||||
VIPS_FREEF( cmsCloseProfile, profile );
|
||||
g_warning( "%s", _( "profile incompatible with image" ) );
|
||||
return( NULL );
|
||||
}
|
||||
if( image &&
|
||||
vips_image_expected_sig( image ) !=
|
||||
cmsGetColorSpace( profile ) ) {
|
||||
VIPS_FREEF( cmsCloseProfile, profile );
|
||||
g_warning( "%s",
|
||||
_( "embedded profile incompatible with image" ) );
|
||||
return( NULL );
|
||||
}
|
||||
if( vips_image_expected_sig( image ) != cmsGetColorSpace( profile ) ) {
|
||||
VIPS_FREEF( cmsCloseProfile, profile );
|
||||
g_warning( "%s",
|
||||
_( "embedded profile colourspace differs from image" ) );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( profile );
|
||||
}
|
||||
|
||||
static cmsHPROFILE
|
||||
vips_icc_load_profile_file( const char *domain,
|
||||
VipsImage *image, const char *filename )
|
||||
{
|
||||
cmsHPROFILE profile;
|
||||
|
||||
if( !(profile = cmsOpenProfileFromFile( filename, "r" )) ) {
|
||||
vips_error( domain,
|
||||
_( "unable to open profile \"%s\"" ), filename );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if( vips_image_expected_bands( image ) !=
|
||||
vips_icc_profile_needs_bands( profile ) ) {
|
||||
VIPS_FREEF( cmsCloseProfile, profile );
|
||||
g_warning( _( "profile \"%s\" incompatible with image" ),
|
||||
filename );
|
||||
return( NULL );
|
||||
}
|
||||
if( vips_image_expected_sig( image ) != cmsGetColorSpace( profile ) ) {
|
||||
VIPS_FREEF( cmsCloseProfile, profile );
|
||||
g_warning( _( "profile \"%s\" colourspace "
|
||||
"differs from image" ), filename );
|
||||
_( "profile colourspace differs from image" ) );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
@ -660,23 +659,26 @@ vips_icc_import_build( VipsObject *object )
|
||||
* 1 0 image
|
||||
* 0 1 file
|
||||
* 1 1 image, then fall back to file
|
||||
*
|
||||
* see also import_build.
|
||||
*/
|
||||
|
||||
if( code->in &&
|
||||
(import->embedded ||
|
||||
!import->input_profile_filename) )
|
||||
icc->in_profile = vips_icc_load_profile_image( code->in );
|
||||
icc->in_blob = vips_icc_get_profile_image( code->in );
|
||||
|
||||
if( !icc->in_profile &&
|
||||
code->in &&
|
||||
if( !icc->in_blob &&
|
||||
import->input_profile_filename ) {
|
||||
icc->in_profile = vips_icc_load_profile_file( class->nickname,
|
||||
code->in, import->input_profile_filename );
|
||||
if( vips_profile_load( import->input_profile_filename,
|
||||
&icc->in_blob, NULL ) )
|
||||
return( -1 );
|
||||
import->used_fallback = TRUE;
|
||||
}
|
||||
|
||||
if( icc->in_blob &&
|
||||
code->in )
|
||||
icc->in_profile =
|
||||
vips_icc_load_profile_blob( icc->in_blob, code->in );
|
||||
|
||||
if( !icc->in_profile ) {
|
||||
vips_error( class->nickname, "%s", _( "no input profile" ) );
|
||||
return( -1 );
|
||||
@ -698,23 +700,19 @@ vips_icc_import_build( VipsObject *object )
|
||||
return( -1 );
|
||||
|
||||
/* If we used the fallback profile, we need to attach it to the PCS
|
||||
* image since the PCS image needs to know about a route back to
|
||||
* device space.
|
||||
* image, since the PCS image needs a route back to device space.
|
||||
*
|
||||
* In the same way, we don't remove the embedded input profile on
|
||||
* import.
|
||||
*/
|
||||
if( import->used_fallback ) {
|
||||
char *data;
|
||||
size_t length;
|
||||
|
||||
if( !(data = vips__file_read_name(
|
||||
import->input_profile_filename,
|
||||
vips__icc_dir(), &length )) )
|
||||
return( -1 );
|
||||
if( import->used_fallback &&
|
||||
icc->in_blob ) {
|
||||
const void *data;
|
||||
size_t size;
|
||||
|
||||
data = vips_blob_get( icc->in_blob, &size );
|
||||
vips_image_set_blob( colour->out, VIPS_META_ICC_NAME,
|
||||
(VipsCallbackFn) vips_free, data, length );
|
||||
NULL, data, size );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
@ -862,38 +860,27 @@ vips_icc_export_build( VipsObject *object )
|
||||
icc->in_profile = cmsCreateXYZProfile();
|
||||
|
||||
if( code->in &&
|
||||
!export->output_profile_filename &&
|
||||
vips_image_get_typeof( code->in, VIPS_META_ICC_NAME ) ) {
|
||||
void *data;
|
||||
size_t data_length;
|
||||
|
||||
if( vips_image_get_blob( code->in, VIPS_META_ICC_NAME,
|
||||
&data, &data_length ) ||
|
||||
!(icc->out_profile = cmsOpenProfileFromMem(
|
||||
data, data_length )) ) {
|
||||
vips_error( class->nickname,
|
||||
"%s", _( "unable to load embedded profile" ) );
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
else if( export->output_profile_filename ) {
|
||||
if( !(icc->out_profile = cmsOpenProfileFromFile(
|
||||
export->output_profile_filename, "r" )) ) {
|
||||
vips_error( class->nickname,
|
||||
_( "unable to open profile \"%s\"" ),
|
||||
export->output_profile_filename );
|
||||
return( -1 );
|
||||
}
|
||||
!export->output_profile_filename )
|
||||
icc->out_blob = vips_icc_get_profile_image( code->in );
|
||||
|
||||
if( !icc->out_blob &&
|
||||
export->output_profile_filename ) {
|
||||
if( vips_profile_load( export->output_profile_filename,
|
||||
&icc->out_blob, NULL ) )
|
||||
return( -1 );
|
||||
colour->profile_filename = export->output_profile_filename;
|
||||
}
|
||||
else {
|
||||
|
||||
if( icc->out_blob &&
|
||||
!(icc->out_profile =
|
||||
vips_icc_load_profile_blob( icc->out_blob, NULL )) ) {
|
||||
vips_error( class->nickname, "%s", _( "no output profile" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
vips_check_intent( class->nickname,
|
||||
icc->out_profile, icc->intent, LCMS_USED_AS_OUTPUT );
|
||||
if( icc->out_profile )
|
||||
vips_check_intent( class->nickname,
|
||||
icc->out_profile, icc->intent, LCMS_USED_AS_OUTPUT );
|
||||
|
||||
if( VIPS_OBJECT_CLASS( vips_icc_export_parent_class )->build( object ) )
|
||||
return( -1 );
|
||||
@ -1080,13 +1067,18 @@ vips_icc_transform_build( VipsObject *object )
|
||||
if( code->in &&
|
||||
(transform->embedded ||
|
||||
!transform->input_profile_filename) )
|
||||
icc->in_profile = vips_icc_load_profile_image( code->in );
|
||||
icc->in_blob = vips_icc_get_profile_image( code->in );
|
||||
|
||||
if( !icc->in_profile &&
|
||||
code->in &&
|
||||
if( !icc->in_blob &&
|
||||
transform->input_profile_filename )
|
||||
icc->in_profile = vips_icc_load_profile_file( class->nickname,
|
||||
code->in, transform->input_profile_filename );
|
||||
if( vips_profile_load( transform->input_profile_filename,
|
||||
&icc->in_blob, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
if( icc->in_blob &&
|
||||
code->in )
|
||||
icc->in_profile =
|
||||
vips_icc_load_profile_blob( icc->in_blob, code->in );
|
||||
|
||||
if( !icc->in_profile ) {
|
||||
vips_error( class->nickname, "%s", _( "no input profile" ) );
|
||||
@ -1094,17 +1086,21 @@ vips_icc_transform_build( VipsObject *object )
|
||||
}
|
||||
|
||||
if( transform->output_profile_filename ) {
|
||||
if( !(icc->out_profile = cmsOpenProfileFromFile(
|
||||
transform->output_profile_filename, "r" )) ) {
|
||||
vips_error( class->nickname,
|
||||
_( "unable to open profile \"%s\"" ),
|
||||
transform->output_profile_filename );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( vips_profile_load( transform->output_profile_filename,
|
||||
&icc->out_blob, NULL ) )
|
||||
return( -1 );
|
||||
colour->profile_filename = transform->output_profile_filename;
|
||||
}
|
||||
|
||||
if( icc->out_blob )
|
||||
icc->out_profile =
|
||||
vips_icc_load_profile_blob( icc->out_blob, NULL );
|
||||
|
||||
if( !icc->out_profile ) {
|
||||
vips_error( class->nickname, "%s", _( "no output profile" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
vips_check_intent( class->nickname,
|
||||
icc->in_profile, icc->intent, LCMS_USED_AS_INPUT );
|
||||
vips_check_intent( class->nickname,
|
||||
@ -1257,7 +1253,7 @@ vips_icc_ac2rc( VipsImage *in, VipsImage **out, const char *profile_filename )
|
||||
*/
|
||||
gboolean
|
||||
vips_icc_is_compatible_profile( VipsImage *image,
|
||||
void *data, size_t data_length )
|
||||
const void *data, size_t data_length )
|
||||
{
|
||||
cmsHPROFILE profile;
|
||||
|
||||
|
@ -216,8 +216,6 @@ extern float vips_v2Y_16[65536];
|
||||
void vips_col_make_tables_RGB_8( void );
|
||||
void vips_col_make_tables_RGB_16( void );
|
||||
|
||||
int vips_CMYK2XYZ_set_fallback_profile( VipsImage *image );
|
||||
|
||||
/* A colour-transforming function.
|
||||
*/
|
||||
typedef int (*VipsColourTransformFn)( VipsImage *in, VipsImage **out, ... );
|
||||
|
254
libvips/colour/profile_load.c
Normal file
254
libvips/colour/profile_load.c
Normal file
@ -0,0 +1,254 @@
|
||||
/* Load profiles as blobs.
|
||||
*
|
||||
* 10/1/19
|
||||
* - from CMYK2XYZ.c
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file is part of VIPS.
|
||||
|
||||
VIPS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <vips/internal.h>
|
||||
|
||||
#include "profiles.h"
|
||||
#include "pcolour.h"
|
||||
|
||||
typedef struct _VipsProfileLoad {
|
||||
VipsOperation parent_instance;
|
||||
|
||||
const char *name;
|
||||
VipsBlob *profile;
|
||||
|
||||
} VipsProfileLoad;
|
||||
|
||||
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 )
|
||||
{
|
||||
int i;
|
||||
|
||||
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 )
|
||||
{
|
||||
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( strcasecmp( fallback->name, name ) == 0 ) {
|
||||
*length = fallback->data_length;
|
||||
|
||||
return( fallback->data );
|
||||
}
|
||||
}
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
static int
|
||||
vips_profile_load_build( VipsObject *object )
|
||||
{
|
||||
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
|
||||
VipsProfileLoad *load = (VipsProfileLoad *) object;
|
||||
|
||||
size_t length;
|
||||
const void *data;
|
||||
VipsBlob *profile;
|
||||
|
||||
if( VIPS_OBJECT_CLASS( vips_profile_load_parent_class )->
|
||||
build( object ) )
|
||||
return( -1 );
|
||||
|
||||
if( strcasecmp( load->name, "none" ) == 0 ) {
|
||||
profile = NULL;
|
||||
}
|
||||
else if( (data = vips_fallback_profile_get( load->name, &length )) ) {
|
||||
profile = vips_blob_new( NULL, data, length );
|
||||
}
|
||||
else if( (data = vips__file_read_name( load->name,
|
||||
vips__icc_dir(), &length )) ) {
|
||||
profile = vips_blob_new( NULL, data, length );
|
||||
}
|
||||
else {
|
||||
vips_error( class->nickname,
|
||||
_( "unable to load profile \"%s\"" ), load->name );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
g_object_set( object, "profile", profile, NULL );
|
||||
|
||||
if( profile ) {
|
||||
vips_area_unref( (VipsArea *) profile );
|
||||
profile = NULL;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_profile_load_class_init( VipsProfileLoadClass *class )
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||
VipsObjectClass *object_class = (VipsObjectClass *) class;
|
||||
|
||||
gobject_class->set_property = vips_object_set_property;
|
||||
gobject_class->get_property = vips_object_get_property;
|
||||
|
||||
object_class->nickname = "profile_load";
|
||||
object_class->description = _( "load named ICC profile" );
|
||||
object_class->build = vips_profile_load_build;
|
||||
|
||||
VIPS_ARG_STRING( class, "name", 1,
|
||||
_( "Name" ),
|
||||
_( "Profile name" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsProfileLoad, name ),
|
||||
NULL );
|
||||
|
||||
VIPS_ARG_BOXED( class, "profile", 2,
|
||||
_( "Profile" ),
|
||||
_( "Loaded profile" ),
|
||||
VIPS_ARGUMENT_REQUIRED_OUTPUT,
|
||||
G_STRUCT_OFFSET( VipsProfileLoad, profile ),
|
||||
VIPS_TYPE_BLOB );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_profile_load_init( VipsProfileLoad *load )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_profile_load:
|
||||
* @name: name of profile to load
|
||||
* @profile: (out): loaded profile
|
||||
* @...: %NULL-terminated list of optional named arguments
|
||||
*
|
||||
* Load a named profile.
|
||||
*
|
||||
* Profiles are loaded from four sources:
|
||||
*
|
||||
* - The special name `"none"` means no profile. @profile will be %NULL in this
|
||||
* case.
|
||||
*
|
||||
* - @name can be the name of one of the ICC profiles embedded in libvips.
|
||||
* These names can be at least `"cmyk"` and `"srgb"`.
|
||||
*
|
||||
* - @name can be the full path to a file.
|
||||
*
|
||||
* - @name can be the name of an ICC profile in the system profile directory
|
||||
* for your platform.
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
*/
|
||||
int
|
||||
vips_profile_load( const char *name, VipsBlob **profile, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
va_start( ap, profile );
|
||||
result = vips_call_split( "profile_load", ap, name, profile );
|
||||
va_end( ap );
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
||||
/* Set (or remove) a named profile on an image.
|
||||
*/
|
||||
int
|
||||
vips__profile_set( VipsImage *image, const char *name )
|
||||
{
|
||||
VipsBlob *profile;
|
||||
void *data;
|
||||
size_t length;
|
||||
|
||||
if( vips_profile_load( name, &profile, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
if( profile ) {
|
||||
data = ((VipsArea *) profile)->data;
|
||||
length = ((VipsArea *) profile)->length;
|
||||
vips_image_set_blob( image, VIPS_META_ICC_NAME,
|
||||
(VipsCallbackFn) NULL, data, length );
|
||||
}
|
||||
else
|
||||
vips_image_remove( image, VIPS_META_ICC_NAME );
|
||||
|
||||
if( profile ) {
|
||||
vips_area_unref( (VipsArea *) profile );
|
||||
profile = NULL;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
/* coded files, generated automatically */
|
||||
|
||||
char *vips__coded_cmyk =
|
||||
#include "profiles.h"
|
||||
|
||||
VipsCodedProfile vips__coded_profiles[] = {
|
||||
{ "cmyk",
|
||||
"AA6sbGFyZ2wCIAAAcHJ0ckNNWUtMYWIgB94ACAAZAAwAKAA1YWNzcE1TRlQAAAAAAAAAAAAAAAAA"
|
||||
"AAAAAAAAAAAAAAEAAPbWAAEAAAAA0y1hcmdsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAPZGVzYwAAATgAAABpY3BydAAAAaQAAABnd3RwdAAAAgwAAAAUYmtw"
|
||||
@ -16872,4 +16875,130 @@ char *vips__coded_cmyk =
|
||||
"LjI5IDMuOTIgMy41NyAzLjIzIDMuMDUgMy40IDQuMjUgNC43NCAzLjc1IDIuNDggMS45NCAxLjcz"
|
||||
"IDEuNDYgMS40IDEuODMgMi41OCAyLjk0IDIuOTUgMi45NCAyLjk1IDIuOTggMy4zMiAzLjk5IDQu"
|
||||
"NDIgNC4yOCAzLjk0IDMuNDcgMy4xMyAzLjM1IDQuMjENCkVORF9EQVRBDQoNCg0KDQoNCgAA"
|
||||
;
|
||||
},
|
||||
{ "sRGB",
|
||||
"AAAbCmxjbXMCMAAAbW50clJHQiBYWVogB9QACAANAAwAEgAGYWNzcE1TRlQAAAAAbGNtcwAAAAAA"
|
||||
"AAAAAAAAAAAAAAAAAPbWAAEAAAAA0y1sY21zAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAMZG1uZAAAARQAAABqZGVzYwAAAYAAAAB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bMNcy1zTXNtc42zrbP"
|
||||
"N8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp22vvbgNwF3IrdEN2W"
|
||||
"3hzeot8p36/gNuC94UThzOJT4tvjY+Pr5HPk/OWE5g3mlucf56noMui86Ubp0Opb6uXrcOv77Ibt"
|
||||
"Ee2c7ijutO9A78zwWPDl8XLx//KM8xnzp/Q09ML1UPXe9m32+/eK+Bn4qPk4+cf6V/rn+3f8B/yY"
|
||||
"/Sn9uv5L/tz/bf//Y2hybQAAAAAAAwAAAACj1wAAVHsAAEzNAACZmgAAJmYAAA9cdGV4dAAAAABu"
|
||||
"byBjb3B5cmlnaHQsIHVzZSBmcmVlbHkACg=="
|
||||
},
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
@ -1,3 +1,10 @@
|
||||
/* header for coded files, generated automatically */
|
||||
/* The fallback profiles, coded as a set of base64 strings, see
|
||||
* wrap-profiles.sh
|
||||
*/
|
||||
typedef struct _VipsCodedProfile {
|
||||
const char *name;
|
||||
const char *data;
|
||||
} VipsCodedProfile;
|
||||
|
||||
extern VipsCodedProfile vips__coded_profiles[];
|
||||
|
||||
extern char *vips__coded_cmyk ;
|
||||
|
BIN
libvips/colour/profiles/sRGB.icm
Normal file
BIN
libvips/colour/profiles/sRGB.icm
Normal file
Binary file not shown.
@ -1,27 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# code up the binary files in $1 as a set of base64-encoded strings in $2
|
||||
# code up the binary files in $1 as a set of name / base64-encoded strings
|
||||
# in $2
|
||||
|
||||
in=$1
|
||||
out_c=$2.c
|
||||
out_h=$2.h
|
||||
out=$2
|
||||
|
||||
echo "/* coded files, generated automatically */" > $out_c
|
||||
echo "" >> $out_c
|
||||
echo "/* coded files, generated automatically */" > $out
|
||||
echo "" >> $out
|
||||
echo "#include \"profiles.h\"" >> $out
|
||||
echo "" >> $out
|
||||
echo "VipsCodedProfile vips__coded_profiles[] = {" >> $out
|
||||
for file in $in/*; do
|
||||
root=${file%.icm}
|
||||
base=${root##*/}
|
||||
echo char \*vips__coded_$base = >> $out_c
|
||||
base64 $file | sed 's/\(.*\)/"\1"/g' >> $out_c
|
||||
echo ';' >> $out_c
|
||||
echo " { \"$base\"," >> $out
|
||||
base64 $file | sed 's/\(.*\)/"\1"/g' >> $out
|
||||
echo " }," >> $out
|
||||
done
|
||||
|
||||
echo "/* header for coded files, generated automatically */" > $out_h
|
||||
echo "" >> $out_h
|
||||
for file in $in/*; do
|
||||
root=${file%.icm}
|
||||
base=${root##*/}
|
||||
echo extern char \*vips__coded_$base ';' >> $out_h
|
||||
done
|
||||
|
||||
|
||||
echo " { 0, 0 }" >> $out
|
||||
echo "};" >> $out
|
||||
|
@ -194,11 +194,8 @@ G_DEFINE_TYPE( VipsCast, vips_cast, VIPS_TYPE_CONVERSION );
|
||||
ITYPE * restrict p = (ITYPE *) in; \
|
||||
OTYPE * restrict q = (OTYPE *) out; \
|
||||
\
|
||||
for( x = 0; x < sz; x++ ) { \
|
||||
TEMP v = VIPS_FLOOR( p[x] ); \
|
||||
\
|
||||
q[x] = CAST( v ); \
|
||||
} \
|
||||
for( x = 0; x < sz; x++ ) \
|
||||
q[x] = CAST( p[x] ); \
|
||||
}
|
||||
|
||||
/* Cast complex types to an int type. Just take the real part.
|
||||
@ -208,10 +205,8 @@ G_DEFINE_TYPE( VipsCast, vips_cast, VIPS_TYPE_CONVERSION );
|
||||
OTYPE * restrict q = (OTYPE *) out; \
|
||||
\
|
||||
for( x = 0; x < sz; x++ ) { \
|
||||
TEMP v = VIPS_FLOOR( p[0] ); \
|
||||
\
|
||||
q[x] = CAST( p[0] ); \
|
||||
p += 2; \
|
||||
q[x] = CAST( v ); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ show_values( ExifData *data )
|
||||
* their default value and we won't know about it.
|
||||
*/
|
||||
static ExifData *
|
||||
vips_exif_load_data_without_fix( void *data, int length )
|
||||
vips_exif_load_data_without_fix( const void *data, int length )
|
||||
{
|
||||
ExifData *ed;
|
||||
|
||||
@ -458,17 +458,17 @@ vips_exif_resolution_from_image( ExifData *ed, VipsImage *image );
|
||||
int
|
||||
vips__exif_parse( VipsImage *image )
|
||||
{
|
||||
void *data;
|
||||
size_t length;
|
||||
const void *data;
|
||||
size_t size;
|
||||
ExifData *ed;
|
||||
VipsExifParams params;
|
||||
const char *str;
|
||||
|
||||
if( !vips_image_get_typeof( image, VIPS_META_EXIF_NAME ) )
|
||||
return( 0 );
|
||||
if( vips_image_get_blob( image, VIPS_META_EXIF_NAME, &data, &length ) )
|
||||
if( vips_image_get_blob( image, VIPS_META_EXIF_NAME, &data, &size ) )
|
||||
return( -1 );
|
||||
if( !(ed = vips_exif_load_data_without_fix( data, length )) )
|
||||
if( !(ed = vips_exif_load_data_without_fix( data, size )) )
|
||||
return( -1 );
|
||||
|
||||
#ifdef DEBUG_VERBOSE
|
||||
@ -1055,21 +1055,21 @@ vips_exif_set_thumbnail( ExifData *ed, VipsImage *im )
|
||||
/* Update EXIF thumbnail from metadata, if any.
|
||||
*/
|
||||
if( vips_image_get_typeof( im, "jpeg-thumbnail-data" ) ) {
|
||||
void *data;
|
||||
size_t length;
|
||||
const void *data;
|
||||
size_t size;
|
||||
|
||||
if( vips_image_get_blob( im, "jpeg-thumbnail-data",
|
||||
&data, &length ) )
|
||||
&data, &size ) )
|
||||
return( -1 );
|
||||
|
||||
/* Again, we should use the exif allocator attached to this
|
||||
* entry, but it is not exposed!
|
||||
*/
|
||||
if( length > 0 &&
|
||||
if( size > 0 &&
|
||||
data ) {
|
||||
ed->data = malloc( length );
|
||||
memcpy( ed->data, data, length );
|
||||
ed->size = length;
|
||||
ed->data = malloc( size );
|
||||
memcpy( ed->data, data, size );
|
||||
ed->size = size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1259,15 +1259,6 @@ vips__foreign_convert_saveable( VipsImage *in, VipsImage **ready,
|
||||
g_object_unref( in );
|
||||
|
||||
in = out;
|
||||
|
||||
/* We've imported to PCS, we must remove the embedded profile,
|
||||
* since it no longer matches the image.
|
||||
*
|
||||
* For example, when converting CMYK JPG to RGB PNG, we need
|
||||
* to remove the CMYK profile on import, or the png writer will
|
||||
* try to attach it when we write the image as RGB.
|
||||
*/
|
||||
vips_image_remove( in, VIPS_META_ICC_NAME );
|
||||
}
|
||||
|
||||
/* If this is something other than CMYK or RAD, eg. maybe a LAB image,
|
||||
@ -1518,7 +1509,7 @@ vips__foreign_convert_saveable( VipsImage *in, VipsImage **ready,
|
||||
* want to silently drop the profile in this case.
|
||||
*/
|
||||
if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) {
|
||||
void *data;
|
||||
const void *data;
|
||||
size_t length;
|
||||
|
||||
if( !vips_image_get_blob( in, VIPS_META_ICC_NAME,
|
||||
|
@ -75,7 +75,7 @@ typedef struct _VipsForeignSaveJpeg {
|
||||
*/
|
||||
int Q;
|
||||
|
||||
/* Profile to embed .. "none" means don't attach a profile.
|
||||
/* Profile to embed.
|
||||
*/
|
||||
char *profile;
|
||||
|
||||
@ -434,10 +434,9 @@ vips_foreign_save_jpeg_mime_init( VipsForeignSaveJpegMime *mime )
|
||||
*
|
||||
* Use @Q to set the JPEG compression factor. Default 75.
|
||||
*
|
||||
* Use @profile to give the filename of a profile to be embedded in the JPEG.
|
||||
* Use @profile to give the name of a profile to be embedded in the JPEG.
|
||||
* This does not affect the pixels which are written, just the way
|
||||
* they are tagged. You can use the special string "none" to mean
|
||||
* "don't attach a profile".
|
||||
* they are tagged. See vips_profile_load() for details on profile naming.
|
||||
*
|
||||
* If no profile is specified and the VIPS header
|
||||
* contains an ICC profile named #VIPS_META_ICC_NAME, the
|
||||
|
@ -332,8 +332,7 @@ vips_foreign_save_png_buffer_init( VipsForeignSavePngBuffer *buffer )
|
||||
*
|
||||
* Use @profile to give the filename of a profile to be embedded in the PNG.
|
||||
* This does not affect the pixels which are written, just the way
|
||||
* they are tagged. You can use the special string "none" to mean
|
||||
* "don't attach a profile".
|
||||
* they are tagged. See vips_profile_load() for details on profile naming.
|
||||
*
|
||||
* If @profile is specified and the VIPS header
|
||||
* contains an ICC profile named VIPS_META_ICC_NAME ("icc-profile-data"), the
|
||||
|
@ -509,8 +509,7 @@ vips_foreign_save_tiff_buffer_init( VipsForeignSaveTiffBuffer *buffer )
|
||||
*
|
||||
* Use @profile to give the filename of a profile to be embedded in the TIFF.
|
||||
* This does not affect the pixels which are written, just the way
|
||||
* they are tagged. You can use the special string "none" to mean
|
||||
* "don't attach a profile".
|
||||
* they are tagged. See vips_profile_load() for details on profile naming.
|
||||
*
|
||||
* If no profile is specified and the VIPS header
|
||||
* contains an ICC profile named #VIPS_META_ICC_NAME, the
|
||||
|
@ -196,8 +196,6 @@ typedef struct {
|
||||
struct jpeg_compress_struct cinfo;
|
||||
ErrorManager eman;
|
||||
JSAMPROW *row_pointer;
|
||||
char *profile_bytes;
|
||||
size_t profile_length;
|
||||
VipsImage *inverted;
|
||||
} Write;
|
||||
|
||||
@ -207,7 +205,6 @@ write_destroy( Write *write )
|
||||
jpeg_destroy_compress( &write->cinfo );
|
||||
VIPS_FREEF( fclose, write->eman.fp );
|
||||
VIPS_FREE( write->row_pointer );
|
||||
VIPS_FREE( write->profile_bytes );
|
||||
VIPS_UNREF( write->inverted );
|
||||
|
||||
g_free( write );
|
||||
@ -227,8 +224,6 @@ write_new( VipsImage *in )
|
||||
write->eman.pub.error_exit = vips__new_error_exit;
|
||||
write->eman.pub.output_message = vips__new_output_message;
|
||||
write->eman.fp = NULL;
|
||||
write->profile_bytes = NULL;
|
||||
write->profile_length = 0;
|
||||
write->inverted = NULL;
|
||||
|
||||
return( write );
|
||||
@ -358,35 +353,42 @@ write_profile_data (j_compress_ptr cinfo,
|
||||
static int
|
||||
write_profile_file( Write *write, const char *profile )
|
||||
{
|
||||
if( !(write->profile_bytes =
|
||||
vips__file_read_name( profile, vips__icc_dir(),
|
||||
&write->profile_length )) )
|
||||
VipsBlob *blob;
|
||||
|
||||
if( vips_profile_load( profile, &blob, NULL ) )
|
||||
return( -1 );
|
||||
write_profile_data( &write->cinfo,
|
||||
(JOCTET *) write->profile_bytes, write->profile_length );
|
||||
|
||||
if( blob ) {
|
||||
size_t length;
|
||||
const void *data = vips_blob_get( blob, &length );
|
||||
|
||||
write_profile_data( &write->cinfo, (JOCTET *) data, length );
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "write_profile_file: attached profile \"%s\"\n", profile );
|
||||
printf( "write_profile_file: "
|
||||
"attached profile \"%s\"\n", profile );
|
||||
#endif /*DEBUG*/
|
||||
|
||||
vips_area_unref( (VipsArea *) blob );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int
|
||||
write_profile_meta( Write *write )
|
||||
{
|
||||
void *data;
|
||||
size_t data_length;
|
||||
const void *data;
|
||||
size_t length;
|
||||
|
||||
if( vips_image_get_blob( write->in, VIPS_META_ICC_NAME,
|
||||
&data, &data_length ) )
|
||||
if( vips_image_get_blob( write->in,
|
||||
VIPS_META_ICC_NAME, &data, &length ) )
|
||||
return( -1 );
|
||||
|
||||
write_profile_data( &write->cinfo, data, data_length );
|
||||
write_profile_data( &write->cinfo, data, length );
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "write_profile_meta: attached %zd byte profile from header\n",
|
||||
data_length );
|
||||
length );
|
||||
#endif /*DEBUG*/
|
||||
|
||||
return( 0 );
|
||||
@ -598,10 +600,9 @@ write_vips( Write *write, int qfac, const char *profile,
|
||||
return( -1 );
|
||||
|
||||
/* A profile supplied as an argument overrides an embedded
|
||||
* profile. "none" means don't attach a profile.
|
||||
* profile.
|
||||
*/
|
||||
if( profile &&
|
||||
strcmp( profile, "none" ) != 0 &&
|
||||
if( profile &&
|
||||
write_profile_file( write, profile ) )
|
||||
return( -1 );
|
||||
if( !profile &&
|
||||
|
@ -325,24 +325,29 @@ struct _Wtiff {
|
||||
int image_height;
|
||||
};
|
||||
|
||||
/* Embed an ICC profile from a file.
|
||||
/* Write an ICC Profile from a file into the JPEG stream.
|
||||
*/
|
||||
static int
|
||||
embed_profile_file( TIFF *tif, const char *profile )
|
||||
{
|
||||
char *buffer;
|
||||
size_t length;
|
||||
VipsBlob *blob;
|
||||
|
||||
if( !(buffer = vips__file_read_name( profile,
|
||||
vips__icc_dir(), &length )) )
|
||||
if( vips_profile_load( profile, &blob, NULL ) )
|
||||
return( -1 );
|
||||
TIFFSetField( tif, TIFFTAG_ICCPROFILE, length, buffer );
|
||||
vips_free( buffer );
|
||||
|
||||
if( blob ) {
|
||||
size_t length;
|
||||
const void *data = vips_blob_get( blob, &length );
|
||||
|
||||
TIFFSetField( tif, TIFFTAG_ICCPROFILE, length, data );
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "vips2tiff: attached profile \"%s\"\n", profile );
|
||||
printf( "vips2tiff: attached profile \"%s\"\n", profile );
|
||||
#endif /*DEBUG*/
|
||||
|
||||
vips_area_unref( (VipsArea *) blob );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
@ -351,12 +356,12 @@ embed_profile_file( TIFF *tif, const char *profile )
|
||||
static int
|
||||
embed_profile_meta( TIFF *tif, VipsImage *im )
|
||||
{
|
||||
void *data;
|
||||
size_t data_length;
|
||||
const void *data;
|
||||
size_t length;
|
||||
|
||||
if( vips_image_get_blob( im, VIPS_META_ICC_NAME, &data, &data_length ) )
|
||||
if( vips_image_get_blob( im, VIPS_META_ICC_NAME, &data, &length ) )
|
||||
return( -1 );
|
||||
TIFFSetField( tif, TIFFTAG_ICCPROFILE, data_length, data );
|
||||
TIFFSetField( tif, TIFFTAG_ICCPROFILE, length, data );
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "vips2tiff: attached profile from meta\n" );
|
||||
@ -426,8 +431,7 @@ wtiff_layer_new( Wtiff *wtiff, Layer *above, int width, int height )
|
||||
static int
|
||||
wtiff_embed_profile( Wtiff *wtiff, TIFF *tif )
|
||||
{
|
||||
if( wtiff->icc_profile &&
|
||||
strcmp( wtiff->icc_profile, "none" ) != 0 &&
|
||||
if( wtiff->icc_profile &&
|
||||
embed_profile_file( tif, wtiff->icc_profile ) )
|
||||
return( -1 );
|
||||
|
||||
@ -442,15 +446,14 @@ wtiff_embed_profile( Wtiff *wtiff, TIFF *tif )
|
||||
static int
|
||||
wtiff_embed_xmp( Wtiff *wtiff, TIFF *tif )
|
||||
{
|
||||
void *data;
|
||||
size_t data_length;
|
||||
const void *data;
|
||||
size_t size;
|
||||
|
||||
if( !vips_image_get_typeof( wtiff->im, VIPS_META_XMP_NAME ) )
|
||||
return( 0 );
|
||||
if( vips_image_get_blob( wtiff->im, VIPS_META_XMP_NAME,
|
||||
&data, &data_length ) )
|
||||
if( vips_image_get_blob( wtiff->im, VIPS_META_XMP_NAME, &data, &size ) )
|
||||
return( -1 );
|
||||
TIFFSetField( tif, TIFFTAG_XMLPACKET, data_length, data );
|
||||
TIFFSetField( tif, TIFFTAG_XMLPACKET, size, data );
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "vips2tiff: attached XMP from meta\n" );
|
||||
@ -462,27 +465,27 @@ wtiff_embed_xmp( Wtiff *wtiff, TIFF *tif )
|
||||
static int
|
||||
wtiff_embed_iptc( Wtiff *wtiff, TIFF *tif )
|
||||
{
|
||||
void *data;
|
||||
size_t data_length;
|
||||
const void *data;
|
||||
size_t size;
|
||||
|
||||
if( !vips_image_get_typeof( wtiff->im, VIPS_META_IPTC_NAME ) )
|
||||
return( 0 );
|
||||
if( vips_image_get_blob( wtiff->im, VIPS_META_IPTC_NAME,
|
||||
&data, &data_length ) )
|
||||
&data, &size ) )
|
||||
return( -1 );
|
||||
|
||||
/* For no very good reason, libtiff stores IPTC as an array of
|
||||
* long, not byte.
|
||||
*/
|
||||
if( data_length & 3 ) {
|
||||
if( size & 3 ) {
|
||||
g_warning( "%s", _( "rounding up IPTC data length" ) );
|
||||
data_length /= 4;
|
||||
data_length += 1;
|
||||
size /= 4;
|
||||
size += 1;
|
||||
}
|
||||
else
|
||||
data_length /= 4;
|
||||
size /= 4;
|
||||
|
||||
TIFFSetField( tif, TIFFTAG_RICHTIFFIPTC, data_length, data );
|
||||
TIFFSetField( tif, TIFFTAG_RICHTIFFIPTC, size, data );
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "vips2tiff: attached IPTC from meta\n" );
|
||||
@ -494,15 +497,15 @@ wtiff_embed_iptc( Wtiff *wtiff, TIFF *tif )
|
||||
static int
|
||||
wtiff_embed_photoshop( Wtiff *wtiff, TIFF *tif )
|
||||
{
|
||||
void *data;
|
||||
size_t data_length;
|
||||
const void *data;
|
||||
size_t size;
|
||||
|
||||
if( !vips_image_get_typeof( wtiff->im, VIPS_META_PHOTOSHOP_NAME ) )
|
||||
return( 0 );
|
||||
if( vips_image_get_blob( wtiff->im,
|
||||
VIPS_META_PHOTOSHOP_NAME, &data, &data_length ) )
|
||||
VIPS_META_PHOTOSHOP_NAME, &data, &size ) )
|
||||
return( -1 );
|
||||
TIFFSetField( tif, TIFFTAG_PHOTOSHOP, data_length, data );
|
||||
TIFFSetField( tif, TIFFTAG_PHOTOSHOP, size, data );
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "vips2tiff: attached photoshop data from meta\n" );
|
||||
|
@ -410,7 +410,7 @@ vips_webp_set_count( VipsWebPWrite *write, int loop_count )
|
||||
|
||||
static int
|
||||
vips_webp_set_chunk( VipsWebPWrite *write,
|
||||
const char *webp_name, void *data, size_t length )
|
||||
const char *webp_name, const void *data, size_t length )
|
||||
{
|
||||
WebPData chunk;
|
||||
|
||||
@ -440,7 +440,7 @@ vips_webp_add_chunks( VipsWebPWrite *write, VipsImage *image )
|
||||
const char *webp_name = vips__webp_names[i].webp;
|
||||
|
||||
if( vips_image_get_typeof( image, vips_name ) ) {
|
||||
void *data;
|
||||
const void *data;
|
||||
size_t length;
|
||||
|
||||
if( vips_image_get_blob( image,
|
||||
|
@ -1067,71 +1067,72 @@ write_vips( Write *write,
|
||||
VIPS_RINT( in->Xres * 1000 ), VIPS_RINT( in->Yres * 1000 ),
|
||||
PNG_RESOLUTION_METER );
|
||||
|
||||
/* Set ICC Profile.
|
||||
/* Metadata
|
||||
*/
|
||||
if( profile &&
|
||||
!strip ) {
|
||||
if( strcmp( profile, "none" ) != 0 ) {
|
||||
void *data;
|
||||
if( !strip ) {
|
||||
if( profile ) {
|
||||
VipsBlob *blob;
|
||||
|
||||
if( vips_profile_load( profile, &blob, NULL ) )
|
||||
return( -1 );
|
||||
if( blob ) {
|
||||
size_t length;
|
||||
const void *data = vips_blob_get( blob, &length );
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "write_vips: attaching %zd bytes "
|
||||
"of ICC profile\n", length );
|
||||
#endif /*DEBUG*/
|
||||
|
||||
png_set_iCCP( write->pPng, write->pInfo,
|
||||
"icc", PNG_COMPRESSION_TYPE_BASE,
|
||||
data, length );
|
||||
|
||||
vips_area_unref( (VipsArea *) blob );
|
||||
}
|
||||
}
|
||||
else if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) {
|
||||
const void *data;
|
||||
size_t length;
|
||||
|
||||
if( !(data = vips__file_read_name( profile,
|
||||
vips__icc_dir(), &length )) )
|
||||
if( vips_image_get_blob( in, VIPS_META_ICC_NAME,
|
||||
&data, &length ) )
|
||||
return( -1 );
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "write_vips: "
|
||||
"attaching %zd bytes of ICC profile\n",
|
||||
length );
|
||||
printf( "write_vips: attaching %zd bytes "
|
||||
"of ICC profile\n", length );
|
||||
#endif /*DEBUG*/
|
||||
|
||||
png_set_iCCP( write->pPng, write->pInfo, "icc",
|
||||
png_set_iCCP( write->pPng, write->pInfo, "icc",
|
||||
PNG_COMPRESSION_TYPE_BASE, data, length );
|
||||
|
||||
}
|
||||
}
|
||||
else if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) &&
|
||||
!strip ) {
|
||||
void *data;
|
||||
size_t length;
|
||||
|
||||
if( vips_image_get_blob( in, VIPS_META_ICC_NAME,
|
||||
&data, &length ) )
|
||||
return( -1 );
|
||||
if( vips_image_get_typeof( in, VIPS_META_XMP_NAME ) ) {
|
||||
const void *data;
|
||||
size_t length;
|
||||
char *str;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "write_vips: attaching %zd bytes of ICC profile\n",
|
||||
length );
|
||||
#endif /*DEBUG*/
|
||||
/* XMP is attached as a BLOB with no null-termination.
|
||||
* We must re-add this.
|
||||
*/
|
||||
if( vips_image_get_blob( in,
|
||||
VIPS_META_XMP_NAME, &data, &length ) )
|
||||
return( -1 );
|
||||
|
||||
png_set_iCCP( write->pPng, write->pInfo, "icc",
|
||||
PNG_COMPRESSION_TYPE_BASE, data, length );
|
||||
}
|
||||
str = g_malloc( length + 1 );
|
||||
vips_strncpy( str, data, length + 1 );
|
||||
vips__png_set_text( write->pPng, write->pInfo,
|
||||
"XML:com.adobe.xmp", str );
|
||||
g_free( str );
|
||||
}
|
||||
|
||||
if( vips_image_get_typeof( in, VIPS_META_XMP_NAME ) ) {
|
||||
void *data;
|
||||
size_t length;
|
||||
char *str;
|
||||
|
||||
/* XMP is attached as a BLOB with no null-termination. We
|
||||
* must re-add this.
|
||||
*/
|
||||
if( vips_image_get_blob( in,
|
||||
VIPS_META_XMP_NAME, &data, &length ) )
|
||||
if( vips_image_map( in,
|
||||
write_png_comment, write ) )
|
||||
return( -1 );
|
||||
|
||||
str = g_malloc( length + 1 );
|
||||
vips_strncpy( str, data, length + 1 );
|
||||
vips__png_set_text( write->pPng, write->pInfo,
|
||||
"XML:com.adobe.xmp", str );
|
||||
g_free( str );
|
||||
}
|
||||
|
||||
/* Set any "png-comment-xx-yyy" metadata items.
|
||||
*/
|
||||
if( vips_image_map( in,
|
||||
write_png_comment, write ) )
|
||||
return( -1 );
|
||||
|
||||
#ifdef HAVE_IMAGEQUANT
|
||||
if( palette ) {
|
||||
VipsImage *im_index;
|
||||
|
@ -172,6 +172,8 @@ int vips_CMYK2XYZ( VipsImage *in, VipsImage **out, ... )
|
||||
int vips_XYZ2CMYK( VipsImage *in, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int vips_profile_load( const char *name, VipsBlob **profile, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_icc_present( void );
|
||||
int vips_icc_transform( VipsImage *in, VipsImage **out,
|
||||
const char *output_profile, ... )
|
||||
@ -183,7 +185,7 @@ int vips_icc_export( VipsImage *in, VipsImage **out, ... )
|
||||
int vips_icc_ac2rc( VipsImage *in, VipsImage **out,
|
||||
const char *profile_filename );
|
||||
gboolean vips_icc_is_compatible_profile( VipsImage *image,
|
||||
void *data, size_t data_length );
|
||||
const void *data, size_t data_length );
|
||||
|
||||
int vips_dE76( VipsImage *left, VipsImage *right, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
|
@ -194,11 +194,12 @@ void vips_image_set_area( VipsImage *image,
|
||||
int vips_image_get_area( const VipsImage *image,
|
||||
const char *name, void **data );
|
||||
void vips_image_set_blob( VipsImage *image,
|
||||
const char *name, VipsCallbackFn free_fn, void *data, size_t length );
|
||||
const char *name,
|
||||
VipsCallbackFn free_fn, const void *data, size_t length );
|
||||
void vips_image_set_blob_copy( VipsImage *image,
|
||||
const char *name, const void *data, size_t length );
|
||||
int vips_image_get_blob( const VipsImage *image, const char *name,
|
||||
void **data, size_t *length );
|
||||
int vips_image_get_blob( const VipsImage *image,
|
||||
const char *name, const void **data, size_t *length );
|
||||
|
||||
int vips_image_get_int( const VipsImage *image, const char *name, int *out );
|
||||
void vips_image_set_int( VipsImage *image, const char *name, int i );
|
||||
|
@ -269,6 +269,8 @@ void vips__reorder_clear( VipsImage *image );
|
||||
VipsWindow *vips_window_take( VipsWindow *window,
|
||||
VipsImage *im, int top, int height );
|
||||
|
||||
int vips__profile_set( VipsImage *image, const char *name );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus*/
|
||||
|
@ -158,9 +158,9 @@ typedef struct _VipsBlob {
|
||||
} VipsBlob;
|
||||
|
||||
VipsBlob *vips_blob_new( VipsCallbackFn free_fn,
|
||||
const void *data, size_t size );
|
||||
VipsBlob *vips_blob_copy( const void *data, size_t size );
|
||||
const void *vips_blob_get( VipsBlob *blob, size_t *size );
|
||||
const void *data, size_t length );
|
||||
VipsBlob *vips_blob_copy( const void *data, size_t length );
|
||||
const void *vips_blob_get( VipsBlob *blob, size_t *length );
|
||||
GType vips_blob_get_type(void);
|
||||
|
||||
/**
|
||||
@ -224,7 +224,7 @@ void vips_value_set_ref_string( GValue *value, const char *str );
|
||||
|
||||
void *vips_value_get_blob( const GValue *value, size_t *length );
|
||||
void vips_value_set_blob( GValue *value,
|
||||
VipsCallbackFn free_fn, void *data, size_t length );
|
||||
VipsCallbackFn free_fn, const void *data, size_t length );
|
||||
void vips_value_set_blob_free( GValue *value, void *data, size_t length );
|
||||
|
||||
void vips_value_set_array( GValue *value,
|
||||
|
@ -1365,13 +1365,13 @@ vips_image_get_area( const VipsImage *image, const char *name, void **data )
|
||||
* See also: vips_image_get_blob(), vips_image_set().
|
||||
*/
|
||||
void
|
||||
vips_image_set_blob( VipsImage *image,
|
||||
const char *name, VipsCallbackFn free_fn, void *data, size_t length )
|
||||
vips_image_set_blob( VipsImage *image, const char *name,
|
||||
VipsCallbackFn free_fn, const void *data, size_t size )
|
||||
{
|
||||
GValue value = { 0 };
|
||||
|
||||
g_value_init( &value, VIPS_TYPE_BLOB );
|
||||
vips_value_set_blob( &value, free_fn, data, length );
|
||||
vips_value_set_blob( &value, free_fn, data, size );
|
||||
vips_image_set( image, name, &value );
|
||||
g_value_unset( &value );
|
||||
}
|
||||
@ -1431,7 +1431,7 @@ vips_image_set_blob_copy( VipsImage *image,
|
||||
*/
|
||||
int
|
||||
vips_image_get_blob( const VipsImage *image, const char *name,
|
||||
void **data, size_t *length )
|
||||
const void **data, size_t *length )
|
||||
{
|
||||
GValue value_copy = { 0 };
|
||||
|
||||
|
@ -376,6 +376,9 @@ void *
|
||||
vips_area_get_data( VipsArea *area,
|
||||
size_t *length, int *n, GType *type, size_t *sizeof_type )
|
||||
{
|
||||
if( !area )
|
||||
return( NULL );
|
||||
|
||||
if( length )
|
||||
*length = area->length;
|
||||
if( n )
|
||||
@ -599,8 +602,8 @@ vips_ref_string_get_type( void )
|
||||
/**
|
||||
* vips_blob_new:
|
||||
* @free_fn: (scope async) (allow-none): @data will be freed with this function
|
||||
* @data: (array length=size) (element-type guint8) (transfer full): data to store
|
||||
* @size: number of bytes in @data
|
||||
* @data: (array length=length) (element-type guint8) (transfer full): data to store
|
||||
* @length: number of bytes in @data
|
||||
*
|
||||
* Like vips_area_new(), but track a length as well. The returned #VipsBlob
|
||||
* takes ownership of @data and will free it with @free_fn. Pass NULL for
|
||||
@ -614,20 +617,20 @@ vips_ref_string_get_type( void )
|
||||
* Returns: (transfer full): the new #VipsBlob.
|
||||
*/
|
||||
VipsBlob *
|
||||
vips_blob_new( VipsCallbackFn free_fn, const void *data, size_t size )
|
||||
vips_blob_new( VipsCallbackFn free_fn, const void *data, size_t length )
|
||||
{
|
||||
VipsArea *area;
|
||||
|
||||
area = vips_area_new( free_fn, (void *) data );
|
||||
area->length = size;
|
||||
area->length = length;
|
||||
|
||||
return( (VipsBlob *) area );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_blob_copy:
|
||||
* @data: (array length=size) (element-type guint8) (transfer none): data to store
|
||||
* @size: number of bytes in @data
|
||||
* @data: (array length=length) (element-type guint8) (transfer none): data to store
|
||||
* @length: number of bytes in @data
|
||||
*
|
||||
* Like vips_blob_new(), but take a copy of the data. Useful for bindings
|
||||
* which strugle with callbacks.
|
||||
@ -637,15 +640,15 @@ vips_blob_new( VipsCallbackFn free_fn, const void *data, size_t size )
|
||||
* Returns: (transfer full): the new #VipsBlob.
|
||||
*/
|
||||
VipsBlob *
|
||||
vips_blob_copy( const void *data, size_t size )
|
||||
vips_blob_copy( const void *data, size_t length )
|
||||
{
|
||||
void *data_copy;
|
||||
VipsArea *area;
|
||||
|
||||
data_copy = vips_malloc( NULL, size );
|
||||
memcpy( data_copy, data, size );
|
||||
data_copy = vips_malloc( NULL, length );
|
||||
memcpy( data_copy, data, length );
|
||||
area = vips_area_new( (VipsCallbackFn) g_free, data_copy );
|
||||
area->length = size;
|
||||
area->length = length;
|
||||
|
||||
return( (VipsBlob *) area );
|
||||
}
|
||||
@ -653,19 +656,19 @@ vips_blob_copy( const void *data, size_t size )
|
||||
/**
|
||||
* vips_blob_get:
|
||||
* @blob: #VipsBlob to fetch from
|
||||
* @size: return number of bytes of data
|
||||
* @length: return number of bytes of data
|
||||
*
|
||||
* Get the data from a #VipsBlob.
|
||||
*
|
||||
* See also: vips_blob_new().
|
||||
*
|
||||
* Returns: (array length=size) (element-type guint8) (transfer none): the data
|
||||
* Returns: (array length=length) (element-type guint8) (transfer none): the data
|
||||
*/
|
||||
const void *
|
||||
vips_blob_get( VipsBlob *blob, size_t *size )
|
||||
vips_blob_get( VipsBlob *blob, size_t *length )
|
||||
{
|
||||
return( vips_area_get_data( VIPS_AREA( blob ),
|
||||
size, NULL, NULL, NULL ) );
|
||||
length, NULL, NULL, NULL ) );
|
||||
}
|
||||
|
||||
/* Transform a blob to a G_TYPE_STRING.
|
||||
@ -674,12 +677,12 @@ static void
|
||||
transform_blob_g_string( const GValue *src_value, GValue *dest_value )
|
||||
{
|
||||
void *blob;
|
||||
size_t blob_length;
|
||||
size_t length;
|
||||
char buf[256];
|
||||
|
||||
blob = vips_value_get_blob( src_value, &blob_length );
|
||||
blob = vips_value_get_blob( src_value, &length );
|
||||
vips_snprintf( buf, 256, "VIPS_TYPE_BLOB, data = %p, length = %zd",
|
||||
blob, blob_length );
|
||||
blob, length );
|
||||
g_value_set_string( dest_value, buf );
|
||||
}
|
||||
|
||||
@ -689,11 +692,11 @@ static void
|
||||
transform_blob_save_string( const GValue *src_value, GValue *dest_value )
|
||||
{
|
||||
void *blob;
|
||||
size_t blob_length;
|
||||
size_t length;
|
||||
char *b64;
|
||||
|
||||
blob = vips_value_get_blob( src_value, &blob_length );
|
||||
if( (b64 = vips__b64_encode( blob, blob_length )) ) {
|
||||
blob = vips_value_get_blob( src_value, &length );
|
||||
if( (b64 = vips__b64_encode( blob, length )) ) {
|
||||
vips_value_set_save_string( dest_value, b64 );
|
||||
vips_free( b64 );
|
||||
}
|
||||
@ -709,12 +712,12 @@ transform_save_string_blob( const GValue *src_value, GValue *dest_value )
|
||||
{
|
||||
const char *b64;
|
||||
void *blob;
|
||||
size_t blob_length;
|
||||
size_t length;
|
||||
|
||||
b64 = vips_value_get_save_string( src_value );
|
||||
if( (blob = vips__b64_decode( b64, &blob_length )) )
|
||||
if( (blob = vips__b64_decode( b64, &length )) )
|
||||
vips_value_set_blob( dest_value,
|
||||
(VipsCallbackFn) vips_free, blob, blob_length );
|
||||
(VipsCallbackFn) vips_free, blob, length );
|
||||
else
|
||||
/* No error return from transform, but we should set it to
|
||||
* something.
|
||||
@ -1556,7 +1559,7 @@ vips_value_set_ref_string( GValue *value, const char *str )
|
||||
* @length: length of memory area
|
||||
*
|
||||
* Sets @value to hold a @data. When @value is freed, @data will be
|
||||
* freed with @free_fn. @value also holds a note of the length of the memory
|
||||
* freed with @free_fn. @value also holds a note of the size of the memory
|
||||
* area.
|
||||
*
|
||||
* blobs are things like ICC profiles or EXIF data. They are relocatable, and
|
||||
@ -1567,7 +1570,7 @@ vips_value_set_ref_string( GValue *value, const char *str )
|
||||
*/
|
||||
void
|
||||
vips_value_set_blob( GValue *value,
|
||||
VipsCallbackFn free_fn, void *data, size_t length )
|
||||
VipsCallbackFn free_fn, const void *data, size_t length )
|
||||
{
|
||||
VipsBlob *blob;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user