-
Notifications
You must be signed in to change notification settings - Fork 62
-
I am looking at using Blurhash to get very small but nice blurred image previews : https://blurha.sh
The algorithm is quite simple and defined here: https://github.com/woltapp/blurhash/blob/master/Algorithm.md
There is a Ruby native Blurhash implementation, and it works fine using something like this:
image = Vips::Image.new_from_file(path)
Blurhash.encode(image.width, image.height, image.to_a.flatten)
Unfortunately this involves creating a huge array with all pixels and this is quite slow.
Do you think there is a way to have a more efficient implementation using Vips directly? I would be happy to have pointers, I am not really familiar with the low-level VIPS functions and if they can be used for this to avoid doing the computation using Ruby.
Thanks :)
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 4 comments
-
While it's still not the "using Vips directly", try resizing the image to 100x100 and see if it works enough well for you:
size = 100
image = Vips::Image.new_from_file(filename, access: :sequential)
image = image.resize(size.fdiv(image.width), vscale: size.fdiv(image.height))
Blurhash.encode(image.width, image.height, image.to_a.flatten)
Beta Was this translation helpful? Give feedback.
All reactions
-
I think the DCT would probably need to be implemented in C or C++. Let's tag this as an enhacement.
Beta Was this translation helpful? Give feedback.
All reactions
-
... an enhancement on libvips, I mean
Beta Was this translation helpful? Give feedback.
All reactions
-
@Nakilon Thanks for the suggestion, I am already doing a resize before calculating the blurhash to reduce the number of ruby allocations, but I think it can be even faster and memory-efficient :)
@jcupitt Ok, I was not sure it could be done, if vips gets primitives to do this it would be awesome!
Beta Was this translation helpful? Give feedback.