15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'ext/blurhash_encoder/blurhash_encoder.c', line 15
VALUE method_encode(VALUE self, VALUE x, VALUE y) {
int xComponents = NUM2INT(x);
int yComponents = NUM2INT(y);
const char * input_file = "tmp/in.png";
if(xComponents < 1 || xComponents > 8 || yComponents < 1 || yComponents > 8) {
fprintf(stderr, "Component counts must be between 1 and 8.\n");
return 1;
}
const char *hash = blurHashForFile(xComponents, yComponents, input_file);
if(!hash) {
fprintf(stderr, "Failed to load image file \"%s\".\n", input_file);
return 1;
}
return rb_str_new(hash, strlen(hash));
}
|