add heifload_buffer
This commit is contained in:
parent
3d768ef635
commit
07e5f30829
@ -1829,6 +1829,7 @@ vips_foreign_operation_init( void )
|
||||
extern GType vips_foreign_load_svg_buffer_get_type( void );
|
||||
extern GType vips_foreign_load_heif_get_type( void );
|
||||
extern GType vips_foreign_load_heif_file_get_type( void );
|
||||
extern GType vips_foreign_load_heif_buffer_get_type( void );
|
||||
extern GType vips_foreign_load_nifti_get_type( void );
|
||||
extern GType vips_foreign_save_nifti_get_type( void );
|
||||
extern GType vips_foreign_load_gif_get_type( void );
|
||||
@ -1961,6 +1962,7 @@ vips_foreign_operation_init( void )
|
||||
#ifdef HAVE_HEIF
|
||||
vips_foreign_load_heif_get_type();
|
||||
vips_foreign_load_heif_file_get_type();
|
||||
vips_foreign_load_heif_buffer_get_type();
|
||||
#endif /*HAVE_HEIF*/
|
||||
|
||||
vips__foreign_load_operation =
|
||||
|
@ -636,6 +636,78 @@ vips_foreign_load_heif_file_init( VipsForeignLoadHeifFile *file )
|
||||
{
|
||||
}
|
||||
|
||||
typedef struct _VipsForeignLoadHeifBuffer {
|
||||
VipsForeignLoadHeif parent_object;
|
||||
|
||||
/* Load from a buffer.
|
||||
*/
|
||||
VipsArea *buf;
|
||||
|
||||
} VipsForeignLoadHeifBuffer;
|
||||
|
||||
typedef VipsForeignLoadHeifClass VipsForeignLoadHeifBufferClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsForeignLoadHeifBuffer, vips_foreign_load_heif_buffer,
|
||||
vips_foreign_load_heif_get_type() );
|
||||
|
||||
static gboolean
|
||||
vips_foreign_load_heif_buffer_is_a( const void *buf, size_t len )
|
||||
{
|
||||
return( vips_foreign_load_heif_is_a( buf, len ) );
|
||||
}
|
||||
|
||||
static int
|
||||
vips_foreign_load_heif_buffer_header( VipsForeignLoad *load )
|
||||
{
|
||||
VipsForeignLoadHeif *heif = (VipsForeignLoadHeif *) load;
|
||||
VipsForeignLoadHeifBuffer *buffer = (VipsForeignLoadHeifBuffer *) load;
|
||||
|
||||
struct heif_error error;
|
||||
|
||||
error = heif_context_read_from_memory( heif->ctx,
|
||||
buffer->buf->data, buffer->buf->length, NULL );
|
||||
if( error.code ) {
|
||||
vips_heif_error( error );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( VIPS_FOREIGN_LOAD_CLASS(
|
||||
vips_foreign_load_heif_buffer_parent_class )->header( load ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_foreign_load_heif_buffer_class_init(
|
||||
VipsForeignLoadHeifBufferClass *class )
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||
VipsObjectClass *object_class = (VipsObjectClass *) class;
|
||||
VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) class;
|
||||
|
||||
gobject_class->set_property = vips_object_set_property;
|
||||
gobject_class->get_property = vips_object_get_property;
|
||||
|
||||
object_class->nickname = "heifload_buffer";
|
||||
|
||||
load_class->is_a_buffer = vips_foreign_load_heif_buffer_is_a;
|
||||
load_class->header = vips_foreign_load_heif_buffer_header;
|
||||
|
||||
VIPS_ARG_BOXED( class, "buffer", 1,
|
||||
_( "Buffer" ),
|
||||
_( "Buffer to load from" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsForeignLoadHeifBuffer, buf ),
|
||||
VIPS_TYPE_BLOB );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_foreign_load_heif_buffer_init( VipsForeignLoadHeifBuffer *buffer )
|
||||
{
|
||||
}
|
||||
|
||||
#endif /*HAVE_HEIF*/
|
||||
|
||||
/**
|
||||
@ -682,3 +754,47 @@ vips_heifload( const char *filename, VipsImage **out, ... )
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_heifload_buffer:
|
||||
* @buf: (array length=len) (element-type guint8): memory area to load
|
||||
* @len: (type gsize): size of memory area
|
||||
* @out: (out): image to write
|
||||
* @...: %NULL-terminated list of optional named arguments
|
||||
*
|
||||
* Optional arguments:
|
||||
*
|
||||
* * @page: %gint, page (top-level image number) to read
|
||||
* * @n: %gint, load this many pages
|
||||
* * @ignore_transformations: %gboolean, ignore image transformations
|
||||
*
|
||||
* Read a HEIF image file into a VIPS image.
|
||||
* Exactly as
|
||||
* vips_heifload(), but read from a memory buffer.
|
||||
*
|
||||
* You must not free the buffer while @out is active. The
|
||||
* #VipsObject::postclose signal on @out is a good place to free.
|
||||
*
|
||||
* See also: vips_heifload().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
vips_heifload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
||||
{
|
||||
va_list ap;
|
||||
VipsBlob *blob;
|
||||
int result;
|
||||
|
||||
/* We don't take a copy of the data or free it.
|
||||
*/
|
||||
blob = vips_blob_new( NULL, buf, len );
|
||||
|
||||
va_start( ap, out );
|
||||
result = vips_call_split( "heifload_buffer", ap, blob, out );
|
||||
va_end( ap );
|
||||
|
||||
vips_area_unref( VIPS_AREA( blob ) );
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
@ -562,6 +562,8 @@ int vips_gifload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
||||
|
||||
int vips_heifload( const char *filename, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_heifload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int vips_niftiload( const char *filename, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
|
Loading…
Reference in New Issue
Block a user