Skip to content
Permalink
Browse files

jpg stream output passes tests

  • Loading branch information
jcupitt committed Oct 12, 2019
1 parent d991b73 commit a2d57180b11f3238e6e1c45d7bac1218ec4cf6b4
Showing with 64 additions and 226 deletions.
  1. +0 −1 .gitignore
  2. +2 −0 libvips/include/vips/type.h
  3. +16 −8 libvips/iofuncs/stream.c
  4. +43 −5 libvips/iofuncs/type.c
  5. +2 −2 libvips/iofuncs/vips.c
  6. +1 −0 test/.gitignore
  7. +0 −210 test/test_descriptors
@@ -1,4 +1,3 @@
.pytest_cache
compile
.pytest_cache
a.out
@@ -161,6 +161,8 @@ VipsBlob *vips_blob_new( VipsCallbackFn free_fn,
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 );
void vips_blob_set( VipsBlob *blob,
VipsCallbackFn free_fn, const void *data, size_t length );
GType vips_blob_get_type(void);

/**
@@ -611,6 +611,10 @@ vips_stream_output_finalize( GObject *gobject )
VIPS_DEBUG_MSG( "vips_stream_output_finalize:\n" );

VIPS_FREEF( g_byte_array_unref, output->memory );
if( output->blob ) {
vips_area_unref( VIPS_AREA( output->blob ) );
output->blob = NULL;
}

G_OBJECT_CLASS( vips_stream_output_parent_class )->finalize( gobject );
}
@@ -639,7 +643,10 @@ vips_stream_output_build( VipsObject *object )

int fd;

if( (fd = vips_tracked_open( filename, MODE_WRITE )) == -1 ) {
/* 0644 is rw user, r group and other.
*/
if( (fd = vips_tracked_open( filename,
MODE_WRITE, 0644 )) == -1 ) {
vips_error_system( errno, STREAM_NAME( stream ),
"%s", _( "unable to open for write" ) );
return( -1 );
@@ -696,18 +703,22 @@ vips_stream_output_class_init( VipsStreamOutputClass *class )

class->write = vips_stream_output_write_real;

/* SET_ALWAYS means that blob is set by C and the obj system is not
* involved in creation or destruction. It can be read at any time.
*/
VIPS_ARG_BOXED( class, "blob", 1,
_( "Blob" ),
_( "Blob to save to" ),
VIPS_ARGUMENT_OPTIONAL_OUTPUT,
VIPS_ARGUMENT_SET_ALWAYS,
G_STRUCT_OFFSET( VipsStreamOutput, blob ),
VIPS_TYPE_BLOB );

}

static void
vips_stream_output_init( VipsStreamOutput *stream )
vips_stream_output_init( VipsStreamOutput *output )
{
output->blob = vips_blob_new( NULL, NULL, 0 );
}

/**
@@ -849,11 +860,8 @@ vips_stream_output_finish( VipsStreamOutput *output )
length = output->memory->len;
data = g_byte_array_free( output->memory, FALSE );
output->memory = NULL;

g_object_set( output,
"blob", vips_blob_new( (VipsCallbackFn) g_free,
data, length ),
NULL );
vips_blob_set( output->blob,
(VipsCallbackFn) g_free, data, length );
}

vips_stream_close( VIPS_STREAM( output ) );
@@ -171,6 +171,18 @@ vips_area_copy( VipsArea *area )
return( area );
}

void
vips_area_free( VipsArea *area )
{
if( area->free_fn &&
area->data ) {
area->free_fn( area->data, area );
area->free_fn = NULL;
}

area->data = NULL;
}

void
vips_area_unref( VipsArea *area )
{
@@ -191,11 +203,7 @@ vips_area_unref( VipsArea *area )
}

if( area->count == 0 ) {
if( area->free_fn && area->data ) {
area->free_fn( area->data, area );
area->data = NULL;
area->free_fn = NULL;
}
vips_area_free( area );

g_mutex_unlock( area->lock );

@@ -671,6 +679,36 @@ vips_blob_get( VipsBlob *blob, size_t *length )
length, NULL, NULL, NULL ) );
}

/* vips_blob_set:
* @blob: #VipsBlob to set
* @free_fn: (scope async) (allow-none): @data will be freed with this function
* @data: (array length=length) (element-type guint8) (transfer full): data to store
* @length: number of bytes in @data
*
* Any old data is freed and new data attached.
*
* It's sometimes useful to be able to create blobs as empty and then fill
* them later.
*
* See also: vips_blob_new().
*/
void
vips_blob_set( VipsBlob *blob,
VipsCallbackFn free_fn, const void *data, size_t length )
{
VipsArea *area = VIPS_AREA( blob );

g_mutex_lock( area->lock );

vips_area_free( area );

area->free_fn = free_fn;
area->length = length;
area->data = (void *) data;

g_mutex_unlock( area->lock );
}

/* Transform a blob to a G_TYPE_STRING.
*/
static void
@@ -208,7 +208,7 @@ vips__open_image_write( const char *filename, gboolean temp )

g_info( "vips__open_image_write: opening with O_TMPFILE" );
dirname = g_path_get_dirname( filename );
fd = vips_tracked_open( dirname, O_TMPFILE | O_RDWR , 0666 );
fd = vips_tracked_open( dirname, O_TMPFILE | O_RDWR , 0644 );
g_free( dirname );

if( fd < 0 )
@@ -230,7 +230,7 @@ vips__open_image_write( const char *filename, gboolean temp )

if( fd < 0 ) {
g_info( "vips__open_image_write: simple open" );
fd = vips_tracked_open( filename, flags, 0666 );
fd = vips_tracked_open( filename, flags, 0644 );
}

if( fd < 0 ) {
@@ -0,0 +1 @@
test_descriptors

This file was deleted.

0 comments on commit a2d5718

Please sign in to comment.
You can’t perform that action at this time.