buckket / go-blurhash Goto Github PK
View Code? Open in Web Editor NEWA Blurhash implementation in pure Go (Decode/Encode)
License: GNU General Public License v3.0
A Blurhash implementation in pure Go (Decode/Encode)
License: GNU General Public License v3.0
Hello! I am using the library and have been for a while, but I've noticed for a while that it produces different (and arguably worse) results than the website implementation at blurha.sh
Please see my reference images. Any idea what could be going wrong?
Here is the generated blur hash and the difference in results:
LTIXH#ai5XRo0xRRnzR-4.M}-$V[
This library has the Encode API take in a pointer to image.Image (*image.Image
) instead of either the interface itself (which has an underlying value of a pointer) or a concrete struct such as *image.NRGBA
. This is usually a bad idea.
The lines that use this "pointer to interface" seem to only dereference the interface and not change it:
https://github.com/buckket/go-blurhash/blob/master/encode.go#L110-L111
height := (*rgba).Bounds().Max.Y
width := (*rgba).Bounds().Max.X
https://github.com/buckket/go-blurhash/blob/master/encode.go#L131
rt, gt, bt, _ := (*rgba).At(x, y).RGBA()
The library panics in case of uploading a broken image.
Relates to disintegration/imaging#165
package main
import (
"fmt"
"log"
"os"
"github.com/buckket/go-blurhash"
"golang.org/x/image/tiff"
)
func main() {
imageFile, err := os.Open("poc.tiff")
if err != nil {
log.Fatal(err)
}
loadedImage, err := tiff.Decode(imageFile)
if err != nil {
log.Fatal(err)
}
str, err := blurhash.Encode(4, 3, loadedImage) // Panic.
if err != nil {
log.Fatal(err)
}
fmt.Printf("Hash: %s\n", str)
}
panic: runtime error: index out of range [70] with length 65
goroutine 1 [running]:
image.(*Paletted).At(0xc000061d68?, 0x48a050?, 0x101c000061d98?)
/usr/local/go/src/image/image.go:1159 +0x9a
github.com/buckket/go-blurhash.multiplyBasisFunction({0x4dfb20, 0xc00002c2a0}, {0xc00014c000, 0x24, 0x1?}, 0x4, 0x3)
.../poc-blurhash/vendor/github.com/buckket/go-blurhash/encode.go:131 +0x207
github.com/buckket/go-blurhash.Encode(0x4, 0x3, {0x4dfb20, 0xc00002c2a0})
.../poc-blurhash/vendor/github.com/buckket/go-blurhash/encode.go:63 +0x22e
main.main()
.../poc-blurhash/main.go:23 +0xc9
exit status 2
The official implementation with documentation and explanations is now live at https://github.com/woltapp/blurhash, in case you want to link to it!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.