Skip to content

shrinkv: align chunking with shrinkh#4474

Merged
jcupitt merged 4 commits into
libvips:masterfrom
kleisauke:revert-da53d0e-attempt-2
May 10, 2025
Merged

shrinkv: align chunking with shrinkh#4474
jcupitt merged 4 commits into
libvips:masterfrom
kleisauke:revert-da53d0e-attempt-2

Conversation

@kleisauke

@kleisauke kleisauke commented Apr 20, 2025

Copy link
Copy Markdown
Member

i.e. read up to 16 (i.e. fatstrip) scanlines at a time.

Resolves: #4170.

@kleisauke

Copy link
Copy Markdown
Member Author

FWIW, we could also experiment with doing shrink{h,v} as part of reduce{h,v}. For example, a box filter could be implemented as:

--- a/libvips/resample/templates.h
+++ b/libvips/resample/templates.h
@@ -355,6 +355,14 @@ static double inline sinc_filter(double x)
 
 using VipsFilterFn = double (*)(double);
 
+double inline box_filter(double x)
+{
+	if (x > -0.5 && x <= 0.5)
+		return 1.0;
+
+	return 0.0;
+}
+
 template <VipsKernel K>
 static double inline filter(double x);

(untested)

However, I'm not sure how much work this would require and whether it would be performance-neutral.

@kleisauke kleisauke force-pushed the revert-da53d0e-attempt-2 branch from 2f33272 to c965a14 Compare April 26, 2025 11:47
@kleisauke kleisauke changed the title Revert "Better shrinkv chunking" shrinkv: align chunking with shrinkh Apr 26, 2025
@kleisauke

kleisauke commented Apr 26, 2025

Copy link
Copy Markdown
Member Author

I've found a solution that works for all these edge cases.

$ vips black huge.png 30000 30000 --bands 4
$ /usr/bin/time -f %M:%e vipsthumbnail huge.png -o x.png --size 1x1
344000:2.92
$ vips black x.jpg 6000 6000 --bands 3
$ cat issue-3538.py 
#!/usr/bin/env python3

import sys
import pyvips

image = pyvips.Image.new_from_file(sys.argv[1], access="sequential")
image = image.sharpen(sigma=8).resize(0.1)
image = image.copy_memory()
$ /usr/bin/time -f %M:%e ./issue-3538.py x.jpg
219252:4.25
$ vipsheader pexels-daniel-xavier-1239291.jpg
pexels-daniel-xavier-1239291.jpg: 6000x4000 uchar, 3 bands, srgb, jpegload
$ cat issue-3600.py
#!/usr/bin/env python3

import sys
import pyvips

image = pyvips.Image.new_from_file(sys.argv[1])
image = image.icc_transform("srgb", embedded=True)
image = image.rotate(1.4)
image = image.resize(float(sys.argv[2]))
image = image.copy_memory()
$ VIPS_CONCURRENCY=1 /usr/bin/time -f %M:%e ./issue-3600.py pexels-daniel-xavier-1239291.jpg 0.26
210344:0.71
$ VIPS_CONCURRENCY=1 /usr/bin/time -f %M:%e ./issue-3600.py pexels-daniel-xavier-1239291.jpg 0.24
209176:1.14

Still marked as draft, as I also need to do some benchmarks with this PR.

@kleisauke kleisauke force-pushed the revert-da53d0e-attempt-2 branch from d4a7a9d to 044c4ae Compare April 30, 2025 11:12
In preparation for the next commit.

This partially reverts commit 77e8451.
This partially reverts commit da53d0e.
i.e. read up to 16 (i.e. fatstrip) scanlines at a time.
@kleisauke kleisauke force-pushed the revert-da53d0e-attempt-2 branch from 044c4ae to 93cf3cd Compare April 30, 2025 12:03
kleisauke added a commit to kleisauke/vips-microbench that referenced this pull request May 4, 2025
@kleisauke

Copy link
Copy Markdown
Member Author

Benchmark results for this PR are available at:
https://github.com/kleisauke/vips-microbench/blob/master/results/pr-4474.md

On my AMD Ryzen 9 7900 workstation, it's approximately 2% - 6% slower than the master branch, as expected due to the reintroduction of the sum buffer.

This is ready for review now.

@kleisauke kleisauke marked this pull request as ready for review May 4, 2025 12:22
@jcupitt

jcupitt commented May 10, 2025

Copy link
Copy Markdown
Member

Great! This seems to work well for me.

I tried benchmarking against the slightly simpler version in 8.15 and there is a speed up for the C path (though it's not huge), so that's good.

@jcupitt jcupitt merged commit ec0b7fa into libvips:master May 10, 2025
6 checks passed
@kleisauke kleisauke deleted the revert-da53d0e-attempt-2 branch May 10, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High memory usage when resizing a large image to 1x1

2 participants