move streamiw inside svgload
since that's the only place it is used
This commit is contained in:
parent
09325600ee
commit
73dd7eebe5
@ -64,11 +64,318 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
#include <vips/buf.h>
|
||||
#include <vips/internal.h>
|
||||
#include <vips/debug.h>
|
||||
|
||||
#ifdef HAVE_RSVG
|
||||
|
||||
/* A GInputStream that's actually a VipsStreami under the hood. This lets us
|
||||
* hook librsvg up to libvips using the GInputStream interface.
|
||||
*/
|
||||
|
||||
#define VIPS_TYPE_G_INPUT_STREAM (vips_g_input_stream_get_type())
|
||||
#define VIPS_G_INPUT_STREAM( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
|
||||
VIPS_TYPE_G_INPUT_STREAM, VipsGInputStream ))
|
||||
#define VIPS_G_INPUT_STREAM_CLASS( klass ) \
|
||||
(G_TYPE_CHECK_CLASS_CAST( (klass), \
|
||||
VIPS_TYPE_G_INPUT_STREAM, VipsGInputStreamClass))
|
||||
#define VIPS_IS_G_INPUT_STREAM( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_G_INPUT_STREAM ))
|
||||
#define VIPS_IS_G_INPUT_STREAM_CLASS( klass ) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_G_INPUT_STREAM ))
|
||||
#define VIPS_G_INPUT_STREAM_GET_CLASS( obj ) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
|
||||
VIPS_TYPE_G_INPUT_STREAM, VipsGInputStreamClass ))
|
||||
|
||||
/* GInputStream <--> VipsStreami
|
||||
*/
|
||||
typedef struct _VipsGInputStream {
|
||||
GInputStream parent_instance;
|
||||
|
||||
/*< private >*/
|
||||
|
||||
/* The VipsStreami we wrap.
|
||||
*/
|
||||
VipsStreami *streami;
|
||||
|
||||
} VipsGInputStream;
|
||||
|
||||
typedef struct _VipsGInputStreamClass {
|
||||
GInputStreamClass parent_class;
|
||||
|
||||
} VipsGInputStreamClass;
|
||||
|
||||
static void vips_g_input_stream_seekable_iface_init( GSeekableIface *iface );
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE( VipsGInputStream, vips_g_input_stream,
|
||||
G_TYPE_INPUT_STREAM, G_IMPLEMENT_INTERFACE( G_TYPE_SEEKABLE,
|
||||
vips_g_input_stream_seekable_iface_init ) )
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_STREAM
|
||||
};
|
||||
|
||||
static void
|
||||
vips_g_input_stream_get_property( GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec )
|
||||
{
|
||||
VipsGInputStream *gstream = VIPS_G_INPUT_STREAM( object );
|
||||
|
||||
switch( prop_id ) {
|
||||
case PROP_STREAM:
|
||||
g_value_set_object( value, gstream->streami );
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID( object, prop_id, pspec );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
vips_g_input_stream_set_property( GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec )
|
||||
{
|
||||
VipsGInputStream *gstream = VIPS_G_INPUT_STREAM( object );
|
||||
|
||||
switch( prop_id ) {
|
||||
case PROP_STREAM:
|
||||
gstream->streami = g_value_dup_object( value );
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID( object, prop_id, pspec );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
vips_g_input_stream_finalize( GObject *object )
|
||||
{
|
||||
VipsGInputStream *gstream = VIPS_G_INPUT_STREAM( object );
|
||||
|
||||
VIPS_FREEF( g_object_unref, gstream->streami );
|
||||
|
||||
G_OBJECT_CLASS( vips_g_input_stream_parent_class )->finalize( object );
|
||||
}
|
||||
|
||||
static goffset
|
||||
vips_g_input_stream_tell( GSeekable *seekable )
|
||||
{
|
||||
VipsStreami *streami = VIPS_G_INPUT_STREAM( seekable )->streami;
|
||||
|
||||
goffset pos;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_g_input_stream_tell:\n" );
|
||||
|
||||
pos = vips_streami_seek( streami, 0, SEEK_CUR );
|
||||
if( pos == -1 )
|
||||
return( 0 );
|
||||
|
||||
return( pos );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vips_g_input_stream_can_seek( GSeekable *seekable )
|
||||
{
|
||||
VipsStreami *streami = VIPS_G_INPUT_STREAM( seekable )->streami;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_g_input_stream_can_seek: %d\n",
|
||||
!streami->is_pipe );
|
||||
|
||||
return( !streami->is_pipe );
|
||||
}
|
||||
|
||||
static int
|
||||
seek_type_to_lseek( GSeekType type )
|
||||
{
|
||||
switch( type ) {
|
||||
default:
|
||||
case G_SEEK_CUR:
|
||||
return( SEEK_CUR );
|
||||
case G_SEEK_SET:
|
||||
return( SEEK_SET );
|
||||
case G_SEEK_END:
|
||||
return( SEEK_END );
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vips_g_input_stream_seek( GSeekable *seekable, goffset offset,
|
||||
GSeekType type, GCancellable *cancellable, GError **error )
|
||||
{
|
||||
VipsStreami *streami = VIPS_G_INPUT_STREAM( seekable )->streami;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_g_input_stream_seek: offset = %" G_GINT64_FORMAT
|
||||
", type = %d\n", offset, type );
|
||||
|
||||
if( vips_streami_seek( streami, offset,
|
||||
seek_type_to_lseek( type ) ) == -1 ) {
|
||||
g_set_error( error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_( "Error while seeking: %s" ),
|
||||
vips_error_buffer() );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vips_g_input_stream_can_truncate( GSeekable *seekable )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vips_g_input_stream_truncate( GSeekable *seekable, goffset offset,
|
||||
GCancellable *cancellable, GError **error )
|
||||
{
|
||||
g_set_error_literal( error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_SUPPORTED,
|
||||
_( "Cannot truncate VipsGInputStream" ) );
|
||||
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
static gssize
|
||||
vips_g_input_stream_read( GInputStream *stream, void *buffer, gsize count,
|
||||
GCancellable *cancellable, GError **error )
|
||||
{
|
||||
VipsStreami *streami;
|
||||
gssize res;
|
||||
|
||||
streami = VIPS_G_INPUT_STREAM( stream )->streami;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_g_input_stream_read: count: %zd\n", count );
|
||||
|
||||
if( g_cancellable_set_error_if_cancelled( cancellable, error ) )
|
||||
return( -1 );
|
||||
|
||||
if( (res = vips_streami_read( streami, buffer, count )) == -1 )
|
||||
g_set_error( error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_( "Error while reading: %s" ),
|
||||
vips_error_buffer() );
|
||||
|
||||
return( res );
|
||||
}
|
||||
|
||||
static gssize
|
||||
vips_g_input_stream_skip( GInputStream *stream, gsize count,
|
||||
GCancellable *cancellable, GError **error )
|
||||
{
|
||||
VipsStreami *streami;
|
||||
goffset start;
|
||||
goffset end;
|
||||
|
||||
streami = VIPS_G_INPUT_STREAM( stream )->streami;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_g_input_stream_skip: count: %zd\n", count );
|
||||
|
||||
if( g_cancellable_set_error_if_cancelled( cancellable, error ) )
|
||||
return( -1 );
|
||||
|
||||
start = vips_streami_seek( streami, 0, SEEK_CUR );
|
||||
if( start == -1 ) {
|
||||
g_set_error( error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_( "Error while seeking: %s" ),
|
||||
vips_error_buffer() );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
end = vips_streami_seek( streami, 0, SEEK_END );
|
||||
if( end == -1 ) {
|
||||
g_set_error( error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_( "Error while seeking: %s" ),
|
||||
vips_error_buffer() );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( end - start > count ) {
|
||||
end = vips_streami_seek( streami, count - (end - start),
|
||||
SEEK_CUR );
|
||||
if( end == -1 ) {
|
||||
g_set_error( error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_( "Error while seeking: %s" ),
|
||||
vips_error_buffer() );
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
return( end - start );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vips_g_input_stream_close( GInputStream *stream,
|
||||
GCancellable *cancellable, GError **error )
|
||||
{
|
||||
VipsGInputStream *gstream = VIPS_G_INPUT_STREAM( stream );
|
||||
|
||||
vips_streami_minimise( gstream->streami );
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_g_input_stream_seekable_iface_init( GSeekableIface *iface )
|
||||
{
|
||||
iface->tell = vips_g_input_stream_tell;
|
||||
iface->can_seek = vips_g_input_stream_can_seek;
|
||||
iface->seek = vips_g_input_stream_seek;
|
||||
iface->can_truncate = vips_g_input_stream_can_truncate;
|
||||
iface->truncate_fn = vips_g_input_stream_truncate;
|
||||
}
|
||||
|
||||
static void
|
||||
vips_g_input_stream_class_init( VipsGInputStreamClass *class )
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||
GInputStreamClass *istream_class = G_INPUT_STREAM_CLASS( class );
|
||||
|
||||
gobject_class->finalize = vips_g_input_stream_finalize;
|
||||
gobject_class->get_property = vips_g_input_stream_get_property;
|
||||
gobject_class->set_property = vips_g_input_stream_set_property;
|
||||
|
||||
istream_class->read_fn = vips_g_input_stream_read;
|
||||
istream_class->skip = vips_g_input_stream_skip;
|
||||
istream_class->close_fn = vips_g_input_stream_close;
|
||||
|
||||
g_object_class_install_property( gobject_class, PROP_STREAM,
|
||||
g_param_spec_object( "input",
|
||||
_( "Input" ),
|
||||
_( "Stream to wrap" ),
|
||||
VIPS_TYPE_STREAMI, G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS ) );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_g_input_stream_init( VipsGInputStream *gstream )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* g_input_stream_new_from_vips:
|
||||
* @streami: stream to wrap
|
||||
*
|
||||
* Create a new #GInputStream wrapping a #VipsStreami.
|
||||
*
|
||||
* Returns: a new #GInputStream
|
||||
*/
|
||||
static GInputStream *
|
||||
g_input_stream_new_from_vips( VipsStreami *streami )
|
||||
{
|
||||
return( g_object_new( VIPS_TYPE_G_INPUT_STREAM,
|
||||
"input", streami,
|
||||
NULL ) );
|
||||
}
|
||||
|
||||
#include <cairo.h>
|
||||
#include <librsvg/rsvg.h>
|
||||
|
||||
|
@ -217,43 +217,6 @@ size_t vips_streami_sniff_at_most( VipsStreami *streami,
|
||||
unsigned char *vips_streami_sniff( VipsStreami *streami, size_t length );
|
||||
gint64 vips_streami_size( VipsStreami *streami );
|
||||
|
||||
#define VIPS_TYPE_STREAMIW (vips_streamiw_get_type())
|
||||
#define VIPS_STREAMIW( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
|
||||
VIPS_TYPE_STREAMIW, VipsStreamiw ))
|
||||
#define VIPS_STREAMIW_CLASS( klass ) \
|
||||
(G_TYPE_CHECK_CLASS_CAST( (klass), \
|
||||
VIPS_TYPE_STREAMIW, VipsStreamiwClass))
|
||||
#define VIPS_IS_STREAMIW( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_STREAMIW ))
|
||||
#define VIPS_IS_STREAMIW_CLASS( klass ) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_STREAMIW ))
|
||||
#define VIPS_STREAMIW_GET_CLASS( obj ) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
|
||||
VIPS_TYPE_STREAMIW, VipsStreamiwClass ))
|
||||
|
||||
/* GInputStream <--> VipsStreami
|
||||
*/
|
||||
typedef struct _VipsStreamiw {
|
||||
GInputStream parent_instance;
|
||||
|
||||
/*< private >*/
|
||||
|
||||
/* The VipsStreami we wrap.
|
||||
*/
|
||||
VipsStreami *streami;
|
||||
|
||||
} VipsStreamiw;
|
||||
|
||||
typedef struct _VipsStreamiwClass {
|
||||
GInputStreamClass parent_class;
|
||||
|
||||
} VipsStreamiwClass;
|
||||
|
||||
GType vips_streamiw_get_type( void );
|
||||
|
||||
GInputStream *g_input_stream_new_from_vips( VipsStreami *streami );
|
||||
|
||||
#define VIPS_TYPE_STREAMO (vips_streamo_get_type())
|
||||
#define VIPS_STREAMO( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
|
||||
|
@ -3,7 +3,6 @@ noinst_LTLIBRARIES = libiofuncs.la
|
||||
libiofuncs_la_SOURCES = \
|
||||
stream.c \
|
||||
streami.c \
|
||||
streamiw.c \
|
||||
streamo.c \
|
||||
bufis.c \
|
||||
dbuf.c \
|
||||
|
@ -882,7 +882,8 @@ vips_streami_is_mappable( VipsStreami *streami )
|
||||
*/
|
||||
return( streami->data ||
|
||||
VIPS_STREAM( streami )->filename ||
|
||||
(streami->is_pipe && VIPS_STREAM( streami )->descriptor) );
|
||||
(streami->is_pipe &&
|
||||
VIPS_STREAM( streami )->descriptor) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,329 +0,0 @@
|
||||
/* GInputStream <--> VipsStreami
|
||||
*
|
||||
* Kleis Auke, 9/11/19
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
/* TODO
|
||||
*
|
||||
* - should we conditionally exclude this class? It's only needed for librsvg.
|
||||
* - it pulls in gio.h -- does this change our minimum version for glib?
|
||||
*/
|
||||
|
||||
/*
|
||||
#define VIPS_DEBUG
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /*HAVE_UNISTD_H*/
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
#include <vips/internal.h>
|
||||
#include <vips/debug.h>
|
||||
|
||||
static void vips_streamiw_seekable_iface_init( GSeekableIface *iface );
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE( VipsStreamiw, vips_streamiw, G_TYPE_INPUT_STREAM,
|
||||
G_IMPLEMENT_INTERFACE( G_TYPE_SEEKABLE,
|
||||
vips_streamiw_seekable_iface_init ) )
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_STREAM
|
||||
};
|
||||
|
||||
static void
|
||||
vips_streamiw_get_property( GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec )
|
||||
{
|
||||
VipsStreamiw *streamiw = VIPS_STREAMIW( object );
|
||||
|
||||
switch( prop_id ) {
|
||||
case PROP_STREAM:
|
||||
g_value_set_object( value, streamiw->streami );
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID( object, prop_id, pspec );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamiw_set_property( GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec )
|
||||
{
|
||||
VipsStreamiw *streamiw = VIPS_STREAMIW( object );
|
||||
|
||||
switch( prop_id ) {
|
||||
case PROP_STREAM:
|
||||
streamiw->streami = g_value_dup_object( value );
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID( object, prop_id, pspec );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamiw_finalize( GObject *object )
|
||||
{
|
||||
VipsStreamiw *streamiw = VIPS_STREAMIW( object );
|
||||
|
||||
VIPS_FREEF( g_object_unref, streamiw->streami );
|
||||
|
||||
G_OBJECT_CLASS( vips_streamiw_parent_class )->finalize( object );
|
||||
}
|
||||
|
||||
static goffset
|
||||
vips_streamiw_tell( GSeekable *seekable )
|
||||
{
|
||||
VipsStreami *streami = VIPS_STREAMIW( seekable )->streami;
|
||||
|
||||
goffset pos;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamiw_tell:\n" );
|
||||
|
||||
pos = vips_streami_seek( streami, 0, SEEK_CUR );
|
||||
if( pos == -1 )
|
||||
return( 0 );
|
||||
|
||||
return( pos );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vips_streamiw_can_seek( GSeekable *seekable )
|
||||
{
|
||||
VipsStreami *streami = VIPS_STREAMIW( seekable )->streami;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamiw_can_seek: %d\n", !streami->is_pipe );
|
||||
|
||||
return( !streami->is_pipe );
|
||||
}
|
||||
|
||||
static int
|
||||
seek_type_to_lseek( GSeekType type )
|
||||
{
|
||||
switch( type ) {
|
||||
default:
|
||||
case G_SEEK_CUR:
|
||||
return( SEEK_CUR );
|
||||
case G_SEEK_SET:
|
||||
return( SEEK_SET );
|
||||
case G_SEEK_END:
|
||||
return( SEEK_END );
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vips_streamiw_seek( GSeekable *seekable, goffset offset,
|
||||
GSeekType type, GCancellable *cancellable, GError **error )
|
||||
{
|
||||
VipsStreami *streami = VIPS_STREAMIW( seekable )->streami;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamiw_seek: offset = %" G_GINT64_FORMAT
|
||||
", type = %d\n", offset, type );
|
||||
|
||||
if( vips_streami_seek( streami, offset,
|
||||
seek_type_to_lseek( type ) ) == -1 ) {
|
||||
g_set_error( error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_( "Error while seeking: %s" ),
|
||||
vips_error_buffer() );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vips_streamiw_can_truncate( GSeekable *seekable )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vips_streamiw_truncate( GSeekable *seekable, goffset offset,
|
||||
GCancellable *cancellable, GError **error )
|
||||
{
|
||||
g_set_error_literal( error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_SUPPORTED,
|
||||
_( "Cannot truncate VipsStreamiw" ) );
|
||||
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
static gssize
|
||||
vips_streamiw_read( GInputStream *stream, void *buffer, gsize count,
|
||||
GCancellable *cancellable, GError **error )
|
||||
{
|
||||
VipsStreami *streami;
|
||||
gssize res;
|
||||
|
||||
streami = VIPS_STREAMIW( stream )->streami;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamiw_read: count: %zd\n", count );
|
||||
|
||||
if( g_cancellable_set_error_if_cancelled( cancellable, error ) )
|
||||
return( -1 );
|
||||
|
||||
if( (res = vips_streami_read( streami, buffer, count )) == -1 )
|
||||
g_set_error( error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_( "Error while reading: %s" ),
|
||||
vips_error_buffer() );
|
||||
|
||||
return( res );
|
||||
}
|
||||
|
||||
static gssize
|
||||
vips_streamiw_skip( GInputStream *stream, gsize count,
|
||||
GCancellable *cancellable, GError **error )
|
||||
{
|
||||
VipsStreami *streami;
|
||||
goffset start;
|
||||
goffset end;
|
||||
|
||||
streami = VIPS_STREAMIW( stream )->streami;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamiw_skip: count: %zd\n", count );
|
||||
|
||||
if( g_cancellable_set_error_if_cancelled( cancellable, error ) )
|
||||
return( -1 );
|
||||
|
||||
start = vips_streami_seek( streami, 0, SEEK_CUR );
|
||||
if( start == -1 ) {
|
||||
g_set_error( error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_( "Error while seeking: %s" ),
|
||||
vips_error_buffer() );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
end = vips_streami_seek( streami, 0, SEEK_END );
|
||||
if( end == -1 ) {
|
||||
g_set_error( error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_( "Error while seeking: %s" ),
|
||||
vips_error_buffer() );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( end - start > count ) {
|
||||
end = vips_streami_seek( streami, count - (end - start),
|
||||
SEEK_CUR );
|
||||
if( end == -1 ) {
|
||||
g_set_error( error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_( "Error while seeking: %s" ),
|
||||
vips_error_buffer() );
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
return( end - start );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vips_streamiw_close( GInputStream *stream,
|
||||
GCancellable *cancellable, GError **error )
|
||||
{
|
||||
VipsStreamiw *streamiw = VIPS_STREAMIW( stream );
|
||||
|
||||
vips_streami_minimise( streamiw->streami );
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamiw_seekable_iface_init( GSeekableIface *iface )
|
||||
{
|
||||
iface->tell = vips_streamiw_tell;
|
||||
iface->can_seek = vips_streamiw_can_seek;
|
||||
iface->seek = vips_streamiw_seek;
|
||||
iface->can_truncate = vips_streamiw_can_truncate;
|
||||
iface->truncate_fn = vips_streamiw_truncate;
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamiw_class_init( VipsStreamiwClass *class )
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||
GInputStreamClass *istream_class = G_INPUT_STREAM_CLASS( class );
|
||||
|
||||
gobject_class->finalize = vips_streamiw_finalize;
|
||||
gobject_class->get_property = vips_streamiw_get_property;
|
||||
gobject_class->set_property = vips_streamiw_set_property;
|
||||
|
||||
istream_class->read_fn = vips_streamiw_read;
|
||||
istream_class->skip = vips_streamiw_skip;
|
||||
istream_class->close_fn = vips_streamiw_close;
|
||||
|
||||
g_object_class_install_property( gobject_class, PROP_STREAM,
|
||||
g_param_spec_object( "input",
|
||||
_( "Input" ),
|
||||
_( "Stream to wrap" ),
|
||||
VIPS_TYPE_STREAMI, G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS ) );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamiw_init( VipsStreamiw *streamiw )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* g_input_stream_new_from_vips:
|
||||
* @streami: stream to wrap
|
||||
*
|
||||
* Create a new #GInputStream wrapping a #VipsStreami.
|
||||
*
|
||||
* Returns: a new #GInputStream
|
||||
*/
|
||||
GInputStream *
|
||||
g_input_stream_new_from_vips( VipsStreami *streami )
|
||||
{
|
||||
return( g_object_new( VIPS_TYPE_STREAMIW,
|
||||
"input", streami,
|
||||
NULL ) );
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user