From 34bb1fc83c2bd8669fd7c661ca2d65a286cbeada Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 6 Jul 2018 11:53:35 +0100 Subject: [PATCH] save framework done --- libvips/foreign/niftiload.c | 2 ++ libvips/foreign/niftisave.c | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/libvips/foreign/niftiload.c b/libvips/foreign/niftiload.c index a649c868..6523f7d1 100644 --- a/libvips/foreign/niftiload.c +++ b/libvips/foreign/niftiload.c @@ -41,6 +41,8 @@ * - for uncompressed images, we could do direct mapping of the input * - perhaps we could stream compressed images? but only if ext is defined at * the start of the file + * (yes, file format is magic number, 348-byte header, extension data, + * pixel data, then all gz'd) * - we could use the much faster byteswap in glib? * - I have not been able to test the ext stuff :( * diff --git a/libvips/foreign/niftisave.c b/libvips/foreign/niftisave.c index e5e2cd9a..f40f5b85 100644 --- a/libvips/foreign/niftisave.c +++ b/libvips/foreign/niftisave.c @@ -58,6 +58,8 @@ typedef struct _VipsForeignSaveNifti { */ char *filename; + nifti_image *nim; + } VipsForeignSaveNifti; typedef VipsForeignSaveClass VipsForeignSaveNiftiClass; @@ -65,6 +67,26 @@ typedef VipsForeignSaveClass VipsForeignSaveNiftiClass; G_DEFINE_TYPE( VipsForeignSaveNifti, vips_foreign_save_nifti, VIPS_TYPE_FOREIGN_SAVE ); +static void +vips_foreign_save_nifti_dispose( GObject *gobject ) +{ + VipsForeignLoadNifti *nifti = (VipsForeignLoadNifti *) gobject; + + VIPS_FREEF( nifti_image_free, nifti->nim ); + + G_OBJECT_CLASS( vips_foreign_load_nifti_parent_class )-> + dispose( gobject ); +} + +static int +vips_foreign_save_nifti_make_header( VipsForeignSaveNifti *nifti, + struct nifti_1_header *nhdr ) +{ + + + return( 0 ); +} + static int vips_foreign_save_nifti_build( VipsObject *object ) { @@ -73,10 +95,33 @@ vips_foreign_save_nifti_build( VipsObject *object ) VipsImage **t = (VipsImage **) vips_object_local_array( VIPS_OBJECT( nifti ), 2 ); + struct nifti_1_header nhdr; + if( VIPS_OBJECT_CLASS( vips_foreign_save_nifti_parent_class )-> build( object ) ) return( -1 ); + if( vips_foreign_save_nifti_make_header( nifti, &nhdr ) ) + return( -1 ); + + if( !(nifti->nim = nifti_convert_nhdr2nim( nhdr, nifti->filename )) ) + return( -1 ); + + /* set ext, plus other stuff + */ + + if( !(nim->data = vips_image_write_memory( save->ready, NULL )) ) + return( -1 ); + + /* No return code!??!?!! + */ + nifti_image_write( nifti->nim ); + + /* We must free and NULL the pointer or nifti will try to free it for + * us. + */ + VIPS_FREE( nim->data ); + return( 0 ); } @@ -106,6 +151,7 @@ vips_foreign_save_nifti_class_init( VipsForeignSaveNiftiClass *class ) VipsForeignClass *foreign_class = (VipsForeignClass *) class; VipsForeignSaveClass *save_class = (VipsForeignSaveClass *) class; + gobject_class->dispose = vips_foreign_save_nifti_dispose; gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property;