diff --git a/ChangeLog b/ChangeLog index 3a46e366ee..369782db79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +8.17.2 + +- rank: fix an off-by-one error [larsmaxfield] + 7/7/25 8.17.1 - fix API docs build with meson < 0.60 [lovell] diff --git a/libvips/morphology/morphology.c b/libvips/morphology/morphology.c index 7704cd5e18..92b51cc9d0 100644 --- a/libvips/morphology/morphology.c +++ b/libvips/morphology/morphology.c @@ -57,6 +57,7 @@ vips_morphology_class_init(VipsMorphologyClass *class) { GObjectClass *gobject_class = G_OBJECT_CLASS(class); VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS(class); + VipsOperationClass *operation_class = VIPS_OPERATION_CLASS(class); gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; @@ -64,6 +65,8 @@ vips_morphology_class_init(VipsMorphologyClass *class) vobject_class->nickname = "morphology"; vobject_class->description = _("morphological operations"); + operation_class->flags = VIPS_OPERATION_SEQUENTIAL; + /* Inputs set by subclassess. */ diff --git a/libvips/morphology/rank.c b/libvips/morphology/rank.c index 430b21580f..94f2e189aa 100644 --- a/libvips/morphology/rank.c +++ b/libvips/morphology/rank.c @@ -115,12 +115,9 @@ vips_rank_stop(void *vseq, void *a, void *b) VIPS_FREE(seq->sort); if (seq->hist && - in) { - int i; - - for (i = 0; i < in->Bands; i++) + in) + for (int i = 0; i < in->Bands; i++) VIPS_FREE(seq->hist[i]); - } VIPS_FREE(seq->hist); return 0; @@ -147,17 +144,13 @@ vips_rank_start(VipsImage *out, void *a, void *b) } if (rank->hist_path) { - int i; - - if (!(seq->hist = - VIPS_ARRAY(NULL, in->Bands, unsigned int *))) { + if (!(seq->hist = VIPS_ARRAY(NULL, in->Bands, unsigned int *))) { vips_rank_stop(seq, in, rank); return NULL; } - for (i = 0; i < in->Bands; i++) - if (!(seq->hist[i] = - VIPS_ARRAY(NULL, 256, unsigned int))) { + for (int i = 0; i < in->Bands; i++) + if (!(seq->hist[i] = VIPS_ARRAY(NULL, 256, unsigned int))) { vips_rank_stop(seq, in, rank); return NULL; } @@ -175,29 +168,26 @@ vips_rank_generate_uchar(VipsRegion *out_region, VipsImage *in = seq->ir->im; VipsRect *r = &out_region->valid; const int bands = in->Bands; - const int last = bands * (rank->width - 1); + const int lsk = VIPS_REGION_LSKIP(seq->ir); /* Get input and output pointers for this line. */ - VipsPel *restrict p = - VIPS_REGION_ADDR(seq->ir, r->left, r->top + y); - VipsPel *restrict q = - VIPS_REGION_ADDR(out_region, r->left, r->top + y); + VipsPel *restrict p = VIPS_REGION_ADDR(seq->ir, r->left, r->top + y); + VipsPel *restrict q = VIPS_REGION_ADDR(out_region, r->left, r->top + y); VipsPel *restrict p1; - int lsk; - int x, i, j, b; - - lsk = VIPS_REGION_LSKIP(seq->ir); /* Find histogram for the first output pixel. */ - for (b = 0; b < bands; b++) + for (int b = 0; b < bands; b++) memset(seq->hist[b], 0, 256 * sizeof(unsigned int)); p1 = p; - for (j = 0; j < rank->height; j++) { - for (i = 0, x = 0; x < rank->width; x++) - for (b = 0; b < bands; b++, i++) + for (int j = 0; j < rank->height; j++) { + int i; + + i = 0; + for (int x = 0; x < rank->width; x++) + for (int b = 0; b < bands; b++, i++) seq->hist[b][p1[i]] += 1; p1 += lsk; @@ -205,32 +195,31 @@ vips_rank_generate_uchar(VipsRegion *out_region, /* Loop for output pels. */ - for (x = 0; x < r->width; x++) { - for (b = 0; b < bands; b++) { + for (int x = 0; x < r->width; x++) { + for (int b = 0; b < bands; b++) { /* Calculate cumulative histogram -- the value is the * index at which we pass the rank. */ unsigned int *restrict hist = seq->hist[b]; int sum; - int i; - + int value; sum = 0; - for (i = 0; i < 256; i++) { - sum += hist[i]; + for (value = 0; value < 256; value++) { + sum += hist[value]; if (sum > rank->index) break; } - q[b] = i; + q[b] = value; - /* Adapt histogram -- remove the pels from - * the left hand column, add in pels for a - * new right-hand column. + /* Adapt histogram -- remove the pels from the left hand column, + * add in pels for a new right-hand column. */ + const int next = bands * rank->width; p1 = p + b; - for (j = 0; j < rank->height; j++) { + for (int j = 0; j < rank->height; j++) { hist[p1[0]] -= 1; - hist[p1[last]] += 1; + hist[p1[next]] += 1; p1 += lsk; } @@ -437,7 +426,7 @@ vips_rank_generate(VipsRegion *out_region, VipsRect s; int ls; - int x, y; + int x; int i, j, k; int upper, lower, mid; @@ -451,7 +440,7 @@ vips_rank_generate(VipsRegion *out_region, return -1; ls = VIPS_REGION_LSKIP(ir) / VIPS_IMAGE_SIZEOF_ELEMENT(in); - for (y = 0; y < r->height; y++) { + for (int y = 0; y < r->height; y++) { if (rank->hist_path) vips_rank_generate_uchar(out_region, seq, rank, y); else if (rank->index == 0) @@ -492,7 +481,8 @@ vips_rank_build(VipsObject *object) return -1; } rank->n = rank->width * rank->height; - if (rank->index < 0 || rank->index > rank->n - 1) { + if (rank->index < 0 || + rank->index > rank->n - 1) { vips_error(class->nickname, "%s", _("index out of range")); return -1; } diff --git a/meson.build b/meson.build index f34c3628da..d36bdd87f7 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('vips', 'c', 'cpp', - version: '8.17.1', + version: '8.17.2', meson_version: '>=0.55', default_options: [ # this is what glib uses (one of our required deps), so we use it too @@ -23,7 +23,7 @@ version_patch = version_parts[2] # 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 = 1 +library_revision = 2 library_current = 61 library_age = 19 library_version = '@0@.@1@.@2@'.format(library_current - library_age, library_age, library_revision) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy