boilerplate for webp read

This commit is contained in:
John Cupitt 2013-08-06 10:01:50 +01:00
parent addc48f70a
commit 1af06d5ac9
7 changed files with 466 additions and 0 deletions

View File

@ -528,6 +528,20 @@ if test x"$with_cfitsio" != "xno"; then
]) ])
fi fi
# libwebp
AC_ARG_WITH([libwebp],
AS_HELP_STRING([--without-libwebp], [build without libwebp (default: test)]))
if test x"$with_libwebp" != "xno"; then
PKG_CHECK_MODULES(LIBWEBP, libwebp,
[AC_DEFINE(HAVE_LIBWEBP,1,[define if you have libwebp installed.])
with_libwebp=yes
PACKAGES_USED="$PACKAGES_USED libwebp"],
[AC_MSG_WARN([libwebp not found; disabling libwebp support])
with_libwebp=no
])
fi
# pangoft2 # pangoft2
AC_ARG_WITH([pangoft2], AC_ARG_WITH([pangoft2],
AS_HELP_STRING([--without-pangoft2], AS_HELP_STRING([--without-pangoft2],
@ -759,6 +773,7 @@ file import with OpenSlide: $with_openslide
(requires openslide-3.3.0 or later) (requires openslide-3.3.0 or later)
file import with matio: $with_matio file import with matio: $with_matio
file import with cfitsio: $with_cfitsio file import with cfitsio: $with_cfitsio
file import/export with libwebp: $with_libwebp
text rendering with pangoft2: $with_pangoft2 text rendering with pangoft2: $with_pangoft2
file import/export with libpng: $with_png file import/export with libpng: $with_png
(requires libpng-1.2.9 or later) (requires libpng-1.2.9 or later)

View File

@ -50,6 +50,9 @@ libforeign_la_SOURCES = \
openslide2vips.h \ openslide2vips.h \
openslide2vips.c \ openslide2vips.c \
openslideload.c \ openslideload.c \
webp.h \
webpload.c \
webp2vips.c \
vips2jpeg.c \ vips2jpeg.c \
jpeg2vips.c \ jpeg2vips.c \
jpeg.h \ jpeg.h \

View File

@ -1609,6 +1609,8 @@ vips_foreign_operation_init( void )
extern GType vips_foreign_save_raw_fd_get_type( void ); extern GType vips_foreign_save_raw_fd_get_type( void );
extern GType vips_foreign_load_magick_get_type( void ); extern GType vips_foreign_load_magick_get_type( void );
extern GType vips_foreign_save_dz_get_type( void ); extern GType vips_foreign_save_dz_get_type( void );
extern GType vips_foreign_load_webp_file_get_type( void );
extern GType vips_foreign_load_webp_buffer_get_type( void );
vips_foreign_load_rad_get_type(); vips_foreign_load_rad_get_type();
vips_foreign_save_rad_get_type(); vips_foreign_save_rad_get_type();
@ -1645,6 +1647,11 @@ vips_foreign_operation_init( void )
vips_foreign_save_jpeg_mime_get_type(); vips_foreign_save_jpeg_mime_get_type();
#endif /*HAVE_JPEG*/ #endif /*HAVE_JPEG*/
#ifdef HAVE_LIBWEBP
vips_foreign_load_webp_file_get_type();
vips_foreign_load_webp_buffer_get_type();
#endif /*HAVE_LIBWEBP*/
#ifdef HAVE_TIFF #ifdef HAVE_TIFF
vips_foreign_load_tiff_get_type(); vips_foreign_load_tiff_get_type();
vips_foreign_save_tiff_get_type(); vips_foreign_save_tiff_get_type();
@ -2075,6 +2082,34 @@ vips_jpegsave( VipsImage *in, const char *filename, ... )
return( result ); return( result );
} }
/**
* vips_webpload:
* @filename: file to load
* @out: decompressed image
* @...: %NULL-terminated list of optional named arguments
*
* Optional arguments:
*
*
* Read a webp file into a VIPS image.
*
* See also:
*
* Returns: 0 on success, -1 on error.
*/
int
vips_webpload( const char *filename, VipsImage **out, ... )
{
va_list ap;
int result;
va_start( ap, out );
result = vips_call_split( "webpload", ap, filename, out );
va_end( ap );
return( result );
}
/** /**
* vips_openexrload: * vips_openexrload:
* @filename: file to load * @filename: file to load

50
libvips/foreign/webp.h Normal file
View File

@ -0,0 +1,50 @@
/* common defs for webp read/write
*/
/*
Copyright (C) 1991-2005 The National Gallery
This library 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.1 of the License, or (at your option) any later version.
This library 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 library; 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
*/
#ifndef VIPS_WEBP_H
#define VIPS_WEBP_H
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus*/
int vips__iswebp( const char *filename );
int vips__webp_read_file_header( const char *name, VipsImage *out );
int vips__webp_read_file( const char *name, VipsImage *out );
int vips__webp_read_buffer_header( void *buf, size_t len, VipsImage *out );
int vips__webp_read_buffer( void *buf, size_t len, VipsImage *out );
#ifdef __cplusplus
}
#endif /*__cplusplus*/
#endif /*VIPS_WEBP_H*/

View File

@ -0,0 +1,98 @@
/* read with libwebp
*
* 6/8/13
* - from webp2vips.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
*/
/*
#define DEBUG_VERBOSE
#define DEBUG
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#ifdef HAVE_LIBWEBP
#include <webp/decode.h>
#include <vips/vips.h>
#include "webp.h"
int
vips__iswebp( const char *filename )
{
unsigned char buf[2];
if( vips__get_bytes( filename, buf, 2 ) )
if( (int) buf[0] == 0xff && (int) buf[1] == 0xd8 )
return( 1 );
return( 0 );
}
int
vips__webp_read_file_header( const char *filename, VipsImage *out )
{
printf( "vips__webp_read_file_header\n" );
return( 0 );
}
int
vips__webp_read_file( const char *filename, VipsImage *out )
{
printf( "vips__webp_read_file\n" );
return( 0 );
}
int
vips__webp_read_buffer_header( void *buf, size_t len, VipsImage *out )
{
printf( "vips__webp_read_buffer_header\n" );
return( 0 );
}
int
vips__webp_read_buffer( void *buf, size_t len, VipsImage *out )
{
printf( "vips__webp_read_buffer\n" );
return( 0 );
}
#endif /*HAVE_LIBWEBP*/

262
libvips/foreign/webpload.c Normal file
View File

@ -0,0 +1,262 @@
/* load webp images
*
* 6/8/13
* - from webpload.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
*/
/*
#define DEBUG_VERBOSE
#define DEBUG
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#ifdef HAVE_LIBWEBP
#include <vips/vips.h>
#include "webp.h"
typedef struct _VipsForeignLoadWebp {
VipsForeignLoad parent_object;
} VipsForeignLoadWebp;
typedef VipsForeignLoadClass VipsForeignLoadWebpClass;
G_DEFINE_ABSTRACT_TYPE( VipsForeignLoadWebp, vips_foreign_load_webp,
VIPS_TYPE_FOREIGN_LOAD );
static VipsForeignFlags
vips_foreign_load_webp_get_flags( VipsForeignLoad *load )
{
/* The libwebp reader supports sequential read.
*/
return( VIPS_FOREIGN_SEQUENTIAL );
}
static int
vips_foreign_load_webp_build( VipsObject *object )
{
VipsForeignLoadWebp *webp = (VipsForeignLoadWebp *) object;
if( VIPS_OBJECT_CLASS( vips_foreign_load_webp_parent_class )->
build( object ) )
return( -1 );
return( 0 );
}
static void
vips_foreign_load_webp_class_init( VipsForeignLoadWebpClass *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 = "webpload_base";
object_class->description = _( "load webp" );
object_class->build = vips_foreign_load_webp_build;
load_class->get_flags = vips_foreign_load_webp_get_flags;
}
static void
vips_foreign_load_webp_init( VipsForeignLoadWebp *webp )
{
}
typedef struct _VipsForeignLoadWebpFile {
VipsForeignLoadWebp parent_object;
/* Filename for load.
*/
char *filename;
} VipsForeignLoadWebpFile;
typedef VipsForeignLoadWebpClass VipsForeignLoadWebpFileClass;
G_DEFINE_TYPE( VipsForeignLoadWebpFile, vips_foreign_load_webp_file,
vips_foreign_load_webp_get_type() );
static VipsForeignFlags
vips_foreign_load_webp_file_get_flags_filename( const char *filename )
{
/* The webp reader supports sequential read.
*/
return( VIPS_FOREIGN_SEQUENTIAL );
}
static gboolean
vips_foreign_load_webp_file_is_a( const char *filename )
{
return( vips__iswebp( filename ) );
}
static int
vips_foreign_load_webp_file_header( VipsForeignLoad *load )
{
VipsForeignLoadWebp *webp = (VipsForeignLoadWebp *) load;
VipsForeignLoadWebpFile *file = (VipsForeignLoadWebpFile *) load;
if( vips__webp_read_file_header( file->filename, load->out ) )
return( -1 );
return( 0 );
}
static int
vips_foreign_load_webp_file_load( VipsForeignLoad *load )
{
VipsForeignLoadWebp *webp = (VipsForeignLoadWebp *) load;
VipsForeignLoadWebpFile *file = (VipsForeignLoadWebpFile *) load;
if( vips__webp_read_file( file->filename, load->real ) )
return( -1 );
return( 0 );
}
static const char *webp_suffs[] = { ".webp", NULL };
static void
vips_foreign_load_webp_file_class_init( VipsForeignLoadWebpFileClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsForeignClass *foreign_class = (VipsForeignClass *) 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 = "webpload";
object_class->description = _( "load webp from file" );
foreign_class->suffs = webp_suffs;
load_class->get_flags_filename =
vips_foreign_load_webp_file_get_flags_filename;
load_class->is_a = vips_foreign_load_webp_file_is_a;
load_class->header = vips_foreign_load_webp_file_header;
load_class->load = vips_foreign_load_webp_file_load;
VIPS_ARG_STRING( class, "filename", 1,
_( "Filename" ),
_( "Filename to load from" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsForeignLoadWebpFile, filename ),
NULL );
}
static void
vips_foreign_load_webp_file_init( VipsForeignLoadWebpFile *file )
{
}
typedef struct _VipsForeignLoadWebpBuffer {
VipsForeignLoadWebp parent_object;
/* Load from a buffer.
*/
VipsArea *buf;
} VipsForeignLoadWebpBuffer;
typedef VipsForeignLoadWebpClass VipsForeignLoadWebpBufferClass;
G_DEFINE_TYPE( VipsForeignLoadWebpBuffer, vips_foreign_load_webp_buffer,
vips_foreign_load_webp_get_type() );
static int
vips_foreign_load_webp_buffer_header( VipsForeignLoad *load )
{
VipsForeignLoadWebp *webp = (VipsForeignLoadWebp *) load;
VipsForeignLoadWebpBuffer *buffer = (VipsForeignLoadWebpBuffer *) load;
if( vips__webp_read_buffer_header( buffer->buf->data,
buffer->buf->length, load->out ) )
return( -1 );
return( 0 );
}
static int
vips_foreign_load_webp_buffer_load( VipsForeignLoad *load )
{
VipsForeignLoadWebp *webp = (VipsForeignLoadWebp *) load;
VipsForeignLoadWebpBuffer *buffer = (VipsForeignLoadWebpBuffer *) load;
if( vips__webp_read_buffer( buffer->buf->data, buffer->buf->length,
load->real ) )
return( -1 );
return( 0 );
}
static void
vips_foreign_load_webp_buffer_class_init(
VipsForeignLoadWebpBufferClass *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 = "webpload_buffer";
object_class->description = _( "load webp from buffer" );
load_class->header = vips_foreign_load_webp_buffer_header;
load_class->load = vips_foreign_load_webp_buffer_load;
VIPS_ARG_BOXED( class, "buffer", 1,
_( "Buffer" ),
_( "Buffer to load from" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsForeignLoadWebpBuffer, buf ),
VIPS_TYPE_BLOB );
}
static void
vips_foreign_load_webp_buffer_init( VipsForeignLoadWebpBuffer *buffer )
{
}
#endif /*HAVE_LIBWEBP*/

View File

@ -319,6 +319,9 @@ int vips_jpegsave_buffer( VipsImage *in, void **buf, size_t *len, ... )
int vips_jpegsave_mime( VipsImage *in, ... ) int vips_jpegsave_mime( VipsImage *in, ... )
__attribute__((sentinel)); __attribute__((sentinel));
int vips_webpload( const char *filename, VipsImage **out, ... )
__attribute__((sentinel));
/** /**
* VipsForeignTiffCompression: * VipsForeignTiffCompression:
* @VIPS_FOREIGN_TIFF_COMPRESSION_NONE: no compression * @VIPS_FOREIGN_TIFF_COMPRESSION_NONE: no compression