better arg checking for hist_find_ndim
we were not checking the number of input bands move checks to _build thanks travisbell see https://github.com/libvips/libvips/issues/2634
This commit is contained in:
parent
5c249e0e8e
commit
68a8bf42a7
@ -1,3 +1,6 @@
|
||||
26/11/21 started 8.12.3
|
||||
- better arg checking for hist_find_ndim [travisbell]
|
||||
|
||||
26/11/21 started 8.12.2
|
||||
- make exif resuint optional and default to inch
|
||||
- win: don't set create time on inappropriate file descriptors [lovell]
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# also update the version number in the m4 macros below
|
||||
|
||||
AC_INIT([vips], [8.12.2], [vipsip@jiscmail.ac.uk])
|
||||
AC_INIT([vips], [8.12.3], [vipsip@jiscmail.ac.uk])
|
||||
# required for gobject-introspection
|
||||
AC_PREREQ([2.69])
|
||||
|
||||
@ -18,7 +18,7 @@ AC_CONFIG_MACRO_DIR([m4])
|
||||
# user-visible library versioning
|
||||
m4_define([vips_major_version], [8])
|
||||
m4_define([vips_minor_version], [12])
|
||||
m4_define([vips_micro_version], [2])
|
||||
m4_define([vips_micro_version], [3])
|
||||
m4_define([vips_version],
|
||||
[vips_major_version.vips_minor_version.vips_micro_version])
|
||||
|
||||
@ -41,7 +41,7 @@ VIPS_LIBS=""
|
||||
# binary interface changed: increment current, reset revision to 0
|
||||
# binary interface changes backwards compatible?: increment age
|
||||
# binary interface changes not backwards compatible?: reset age to 0
|
||||
LIBRARY_REVISION=2
|
||||
LIBRARY_REVISION=3
|
||||
LIBRARY_CURRENT=56
|
||||
LIBRARY_AGE=14
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
* - small celanups
|
||||
* 17/8/13
|
||||
* - redo as a class
|
||||
* 28/1/22 travisbell
|
||||
* - better arg checking
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -57,8 +59,6 @@ struct _VipsHistFindNDim;
|
||||
typedef struct {
|
||||
struct _VipsHistFindNDim *ndim;
|
||||
|
||||
int bins;
|
||||
int max_val;
|
||||
unsigned int ***data;
|
||||
} Histogram;
|
||||
|
||||
@ -69,6 +69,10 @@ typedef struct _VipsHistFindNDim {
|
||||
*/
|
||||
int bins;
|
||||
|
||||
/* Max pixel value for this format.
|
||||
*/
|
||||
int max_val;
|
||||
|
||||
/* Main image histogram. Subhists accumulate to this.
|
||||
*/
|
||||
Histogram *hist;
|
||||
@ -89,7 +93,6 @@ static Histogram *
|
||||
histogram_new( VipsHistFindNDim *ndim )
|
||||
{
|
||||
VipsImage *in = VIPS_STATISTIC( ndim )->ready;
|
||||
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( ndim );
|
||||
int bins = ndim->bins;
|
||||
|
||||
/* How many dimensions do we need to allocate?
|
||||
@ -104,14 +107,6 @@ histogram_new( VipsHistFindNDim *ndim )
|
||||
return( NULL );
|
||||
|
||||
hist->ndim = ndim;
|
||||
hist->bins = bins;
|
||||
hist->max_val = in->BandFmt == VIPS_FORMAT_UCHAR ? 256 : 65536;
|
||||
if( bins < 1 ||
|
||||
bins > hist->max_val ) {
|
||||
vips_error( class->nickname,
|
||||
_( "bins out of range [1,%d]" ), hist->max_val );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if( !(hist->data = VIPS_ARRAY( ndim, bins, unsigned int ** )) )
|
||||
return( NULL );
|
||||
@ -147,6 +142,25 @@ vips_hist_find_ndim_build( VipsObject *object )
|
||||
"out", vips_image_new(),
|
||||
NULL );
|
||||
|
||||
if( statistic->in ) {
|
||||
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( ndim );
|
||||
|
||||
if( statistic->in->Bands > 3 ) {
|
||||
vips_error( class->nickname,
|
||||
"%s", _( "image is not 1 - 3 bands" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
ndim->max_val =
|
||||
statistic->in->BandFmt == VIPS_FORMAT_UCHAR ? 256 : 65536;
|
||||
if( ndim->bins < 1 ||
|
||||
ndim->bins > ndim->max_val ) {
|
||||
vips_error( class->nickname,
|
||||
_( "bins out of range [1,%d]" ), ndim->max_val );
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* main hist made on first thread start.
|
||||
*/
|
||||
|
||||
@ -204,9 +218,9 @@ vips_hist_find_ndim_stop( VipsStatistic *statistic, void *seq )
|
||||
|
||||
int i, j, k;
|
||||
|
||||
for( i = 0; i < hist->bins; i++ )
|
||||
for( j = 0; j < hist->bins; j++ )
|
||||
for( k = 0; k < hist->bins; k++ )
|
||||
for( i = 0; i < ndim->bins; i++ )
|
||||
for( j = 0; j < ndim->bins; j++ )
|
||||
for( k = 0; k < ndim->bins; k++ )
|
||||
if( hist->data[i] && hist->data[i][j] ) {
|
||||
hist->data[i][j][k] +=
|
||||
sub_hist->data[i][j][k];
|
||||
@ -236,9 +250,10 @@ vips_hist_find_ndim_scan( VipsStatistic *statistic, void *seq,
|
||||
int x, int y, void *in, int n )
|
||||
{
|
||||
Histogram *hist = (Histogram *) seq;
|
||||
VipsHistFindNDim *ndim = (VipsHistFindNDim *) statistic;
|
||||
VipsImage *im = statistic->ready;
|
||||
int nb = im->Bands;
|
||||
double scale = (double) (hist->max_val + 1) / hist->bins;
|
||||
double scale = (double) (ndim->max_val + 1) / ndim->bins;
|
||||
int i, j, k;
|
||||
int index[3];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user