From 9493ea7e29971619bda47759f0f7c3e21ad5a65f Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 8 Nov 2011 09:06:13 +0000 Subject: [PATCH] sync --- TODO | 7 +----- libvips/arithmetic/stats.c | 22 +++++++++++------ libvips/include/vips/image.h | 1 + libvips/iofuncs/image.c | 47 +++++++++++++++++++++++++++++++++--- 4 files changed, 61 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index c10f54fe..ceef3884 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,4 @@ -- max is broken - - $ ~/vips-7.26/bin/vips-7.26 vips im_max sarto_ng.tif - 255 - $ vips max sarto_ng.tif - 165.000000 +- im_open_local() is broken? try Adam's prog under 7.27 diff --git a/libvips/arithmetic/stats.c b/libvips/arithmetic/stats.c index 77e35c5d..acad1f70 100644 --- a/libvips/arithmetic/stats.c +++ b/libvips/arithmetic/stats.c @@ -74,10 +74,14 @@ * @out: image of statistics * * Find many image statistics in a single pass through the data. @out is a - * one-band #VIPS_FORMAT_DOUBLE image - * of 6 columns by n + 1 (where n is number of bands in image @in) + * one-band #VIPS_FORMAT_DOUBLE image of at least 10 columns by n + 1 + * (where n is number of bands in image @in) * rows. Columns are statistics, and are, in order: minimum, maximum, sum, - * sum of squares, mean, standard deviation. Row 0 has statistics for all + * sum of squares, mean, standard deviation, x coordinate of minimum, y + * coordinate of minimum, x coordinate of maximum, y coordinate of maximum. + * Later versions of VipsStats may add more columns. + * + * Row 0 has statistics for all * bands together, row 1 has stats for band 1, and so on. * * See also: #VipsAvg, #VipsMin, and friends. @@ -90,9 +94,6 @@ typedef struct _VipsStats { VipsImage *out; - or build out and use that as an array? - - double **stats; } VipsStats; typedef VipsStatisticClass VipsStatsClass; @@ -108,6 +109,14 @@ vips_stats_build( VipsObject *object ) gint64 vals; double average; + if( statistic->in ) { + int bands = vips_image_get_bands( statistic->in->Bands ); + + g_object_set( object, + "out", vips_image_new_array( 10, bands + 1 ), + NULL ); + } + if( VIPS_OBJECT_CLASS( vips_stats_parent_class )->build( object ) ) return( -1 ); @@ -121,7 +130,6 @@ vips_stats_build( VipsObject *object ) average = stats->sum / vals; if( vips_bandfmt_iscomplex( vips_image_get_format( statistic->in ) ) ) average = sqrt( average ); - g_object_set( object, "out", average, NULL ); return( 0 ); } diff --git a/libvips/include/vips/image.h b/libvips/include/vips/image.h index d2902a17..dcba6a24 100644 --- a/libvips/include/vips/image.h +++ b/libvips/include/vips/image.h @@ -469,6 +469,7 @@ VipsImage *vips_image_new_from_file_raw( const char *filename, int xsize, int ysize, int bands, int offset ); VipsImage *vips_image_new_from_memory( void *buffer, int xsize, int ysize, int bands, VipsBandFormat bandfmt ); +VipsImage *vips_image_new_array( int xsize, int ysize ); void vips_image_set_delete_on_close( VipsImage *image, gboolean delete_on_close ); VipsImage *vips_image_new_disc_temp( const char *format ); diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 039a8795..14e6ee53 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -1615,6 +1615,47 @@ vips_image_new_from_memory( void *buffer, return( image ); } +/** + * vips_image_new_array: + * @xsize: image width + * @ysize: image height + * + * This convenience function makes an image which is an array: a one-band + * VIPS_FORMAT_DOUBLE image held in memory. + * + * Use VIPS_IMAGE_ADDR() to address pixels in the image. + * + * Returns: the new #VipsImage, or %NULL on error. + */ +VipsImage * +vips_image_new_array( int xsize, int ysize ) +{ + VipsImage *image; + + vips_check_init(); + + image = VIPS_IMAGE( g_object_new( VIPS_TYPE_IMAGE, NULL ) ); + g_object_set( image, + "filename", "vips_image_new_array", + "mode", "t", + "width", xsize, + "height", ysize, + "bands", 1, + "format", VIPS_FORMAT_DOUBLE, + NULL ); + if( vips_object_build( VIPS_OBJECT( image ) ) ) { + VIPS_UNREF( image ); + return( NULL ); + } + + if( vips__image_write_prepare( image ) ) { + g_object_unref( image ); + return( NULL ); + } + + return( image ); +} + /** * vips_image_set_delete_on_close: * @image: image to set @@ -1843,10 +1884,10 @@ vips__image_write_prepare( VipsImage *image ) case VIPS_IMAGE_SETBUF: /* Allocate memory. */ - if( !image->data ) - if( !(image->data = vips_tracked_malloc( + if( !image->data && + !(image->data = vips_tracked_malloc( VIPS_IMAGE_SIZEOF_IMAGE( image ))) ) - return( -1 ); + return( -1 ); break;