Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Optimized Blurhash #270

renchap started this conversation in Ideas
Discussion options

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 :)

You must be logged in to vote

Replies: 4 comments

Comment options

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)
You must be logged in to vote
0 replies
Comment options

I think the DCT would probably need to be implemented in C or C++. Let's tag this as an enhacement.

You must be logged in to vote
0 replies
Comment options

... an enhancement on libvips, I mean

You must be logged in to vote
0 replies
Comment options

@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!

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
Converted from issue

This discussion was converted from issue #235 on January 31, 2021 13:10.

AltStyle によって変換されたページ (->オリジナル) /