Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Jan 3, 2020
1 parent 19b628e commit 3ce23a0
Show file tree
Hide file tree
Showing 22 changed files with 60 additions and 15 deletions.
19 changes: 6 additions & 13 deletions 0001-Partially-fix-for-issue-703.patch
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,9 @@ index 1111111..2222222 100644

VipsRect s;

@@ -317,10 +332,8 @@ vips_reduceh_gen( VipsRegion *out_region, void *seq,

s.left = r->left * reduceh->hshrink;
@@ -319,8 +334,6 @@ vips_reduceh_gen( VipsRegion *out_region, void *seq,
s.top = r->top;
- s.width = r->width * reduceh->hshrink + reduceh->n_point;
+ s.width = r->width * reduceh->hshrink + reduceh->n_point - 1;
s.width = r->width * reduceh->hshrink + reduceh->n_point;
s.height = r->height;
- if( reduceh->centre )
- s.width += 1;
Expand Down Expand Up @@ -267,14 +264,12 @@ index 1111111..2222222 100644

VipsRect s;

@@ -533,20 +538,19 @@ vips_reducev_gen( VipsRegion *out_region, void *vseq,
s.left = r->left;
@@ -534,19 +539,18 @@ vips_reducev_gen( VipsRegion *out_region, void *vseq,
s.top = r->top * reducev->vshrink;
s.width = r->width;
- s.height = r->height * reducev->vshrink + reducev->n_point;
s.height = r->height * reducev->vshrink + reducev->n_point;
- if( reducev->centre )
- s.height += 1;
+ s.height = r->height * reducev->vshrink + reducev->n_point - 1;
if( vips_region_prepare( ir, &s ) )
return( -1 );

Expand Down Expand Up @@ -320,14 +315,12 @@ index 1111111..2222222 100644

VipsExecutor executor[MAX_PASS];
VipsRect s;
@@ -646,9 +654,7 @@ vips_reducev_vector_gen( VipsRegion *out_region, void *vseq,
s.left = r->left;
@@ -647,8 +655,6 @@ vips_reducev_vector_gen( VipsRegion *out_region, void *vseq,
s.top = r->top * reducev->vshrink;
s.width = r->width;
- s.height = r->height * reducev->vshrink + reducev->n_point;
s.height = r->height * reducev->vshrink + reducev->n_point;
- if( reducev->centre )
- s.height += 1;
+ s.height = r->height * reducev->vshrink + reducev->n_point - 1;
if( vips_region_prepare( ir, &s ) )
return( -1 );

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ G_MESSAGES_DEBUG=all ./test-single

# Generate an animated WebP image from the output of `./test-single`
./test-anim

# https://github.com/libvips/pyvips/issues/148
VIPS_CONCURRENCY=1 python3 test-resize.py input/radial.rgb.png
```

See [output/](output) directory.
Expand Down
Binary file added input/radial.rgb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/16x_pillow_reduce.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/16x_pillow_resize.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/16x_pillow_resize_gap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/16x_vips_reduce.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/16x_vips_resize.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/16x_vips_shrink.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/8x_pillow_reduce.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/8x_pillow_resize.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/8x_pillow_resize_gap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/8x_vips_reduce.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/8x_vips_resize.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/8x_vips_shrink.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/9.4x_pillow_resize.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/9.4x_pillow_resize_gap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/9.4x_vips_reduce.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/9.4x_vips_resize.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/9.4x_vips_shrink.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions test-resize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# https://github.com/libvips/pyvips/issues/148
import sys
import timeit
import pyvips
from PIL import Image

image = sys.argv[1]
number, repeat = 10, 3

pyvips.cache_set_max_mem(0)
im = pyvips.Image.new_from_file(image)
print(f'\nSize: {im.width}x{im.height}')
for scale in [8, 9.4, 16]:
for method, call in [
('shrink', lambda im, scale: im.shrink(scale, scale)),
('reduce', lambda im, scale: im.reduce(scale, scale, centre=True)),
('resize', lambda im, scale: im.resize(1/scale, vscale=1/scale)),
]:
fname = f'output/{scale}x_vips_{method}.png'
call(im, scale).write_to_file(fname)

time = min(timeit.repeat(
lambda: call(im, scale).write_to_memory(),
repeat=repeat, number=number)) / number
print(f'{fname}: {time:2.6f}s')


im = Image.open(image)
print(f'\nSize: {im.width}x{im.height}')
for scale in [8, 9.4, 16]:
for method, call in [
('reduce', lambda im, scale: im.reduce((scale, scale))),
('resize', lambda im, scale:
im.resize((round(im.width / scale), round(im.height / scale)), Image.LANCZOS)),
('resize_gap', lambda im, scale:
im.resize((round(im.width / scale), round(im.height / scale)),
Image.LANCZOS, reducing_gap=2.0)),
]:
try:
fname = f'output/{scale}x_pillow_{method}.png'
call(im, scale).save(fname)

time = min(timeit.repeat(
lambda: call(im, scale),
repeat=repeat, number=number)) / number
print(f'{fname}: {time:2.6f}s')
except TypeError:
# reduce doesn't work with float scales
pass
4 changes: 2 additions & 2 deletions test-single-pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
elif i == 7: im = im.rotate(90, expand=True).transpose(Image.FLIP_LEFT_RIGHT)
elif i == 4: im = im.rotate(180, expand=True).transpose(Image.FLIP_LEFT_RIGHT)

im.save('output-patch/Landscape_{}.jpg'.format(i))
im.save('output-patch/lanczos3/Landscape_{}.jpg'.format(i))

for i in range(1, 9):
im = Image.open('input/Portrait_{}.jpg'.format(i))
Expand All @@ -44,4 +44,4 @@
elif i == 7: im = im.rotate(90, expand=True).transpose(Image.FLIP_LEFT_RIGHT)
elif i == 4: im = im.rotate(180, expand=True).transpose(Image.FLIP_LEFT_RIGHT)

im.save('output-patch/Portrait_{}.jpg'.format(i))
im.save('output-patch/lanczos3/Portrait_{}.jpg'.format(i))

0 comments on commit 3ce23a0

Please sign in to comment.