Skip to content

Commit

Permalink
shrinkv: fix region stride handling
Browse files Browse the repository at this point in the history
Always use `VIPS_REGION_LSKIP()` to move down one line, as regions
may have non-contiguous scanlines.
  • Loading branch information
kleisauke committed Dec 15, 2024
1 parent 681a063 commit 621be56
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions libvips/resample/shrinkv.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ G_DEFINE_TYPE(VipsShrinkv, vips_shrinkv, VIPS_TYPE_RESAMPLE);
for (b = 0; b < BANDS; b++) { \
int sum = amend; \
unsigned char *restrict ptr = p + b; \
unsigned char *restrict end = ptr + (shrink->vshrink * sz); \
for (; ptr < end; ptr += sz) \
unsigned char *restrict end = ptr + (shrink->vshrink * ls); \
for (; ptr < end; ptr += ls) \
sum += *ptr; \
q[b] = (sum * multiplier) >> 24; \
} \
Expand All @@ -143,8 +143,8 @@ G_DEFINE_TYPE(VipsShrinkv, vips_shrinkv, VIPS_TYPE_RESAMPLE);
for (b = 0; b < BANDS; b++) { \
ACC_TYPE sum = amend; \
TYPE *restrict ptr = p + b; \
TYPE *restrict end = ptr + (shrink->vshrink * sz); \
for (; ptr < end; ptr += sz) \
TYPE *restrict end = ptr + (shrink->vshrink * ls); \
for (; ptr < end; ptr += ls) \
sum += *ptr; \
q[b] = sum / shrink->vshrink; \
} \
Expand All @@ -164,8 +164,8 @@ G_DEFINE_TYPE(VipsShrinkv, vips_shrinkv, VIPS_TYPE_RESAMPLE);
for (b = 0; b < bands; b++) { \
double sum = 0.0; \
TYPE *restrict ptr = p + b; \
TYPE *restrict end = ptr + (shrink->vshrink * sz); \
for (; ptr < end; ptr += sz) \
TYPE *restrict end = ptr + (shrink->vshrink * ls); \
for (; ptr < end; ptr += ls) \
sum += *ptr; \
q[b] = sum / shrink->vshrink; \
} \
Expand All @@ -183,7 +183,8 @@ vips_shrinkv_gen2(VipsShrinkv *shrink, VipsRegion *out_region, VipsRegion *ir,
VipsResample *resample = VIPS_RESAMPLE(shrink);
const int bands = resample->in->Bands *
(vips_band_format_iscomplex(resample->in->BandFmt) ? 2 : 1);
const int sz = width * bands;
const int ls = VIPS_REGION_LSKIP(ir) /
VIPS_IMAGE_SIZEOF_ELEMENT(resample->in);
VipsPel *out = VIPS_REGION_ADDR(out_region, left, top);
VipsPel *in = VIPS_REGION_ADDR(ir, left, top * shrink->vshrink);

Expand Down

0 comments on commit 621be56

Please sign in to comment.