174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'ext/blurhash_decoder/blurhash_decoder.c', line 174
VALUE method_decode(VALUE self, VALUE blurhash, VALUE heigh, VALUE widt, VALUE punc) {
const char * hash = StringValuePtr(blurhash);
int height = NUM2INT(heigh);
int width = NUM2INT(widt);
int punch = NUM2INT(punc);
const char * output_file = "tmp/out.png";
const int nChannels = 4;
uint8_t * bytes = decode(hash, width, height, punch, nChannels);
if (!bytes) {
// fprintf(stderr, "%s is not a valid blurhash, decoding failed.\n", hash);
return 1;
}
if (stbi_write_png(output_file, width, height, nChannels, bytes, nChannels * width) == 0) {
// fprintf(stderr, "Failed to write PNG file %s\n", output_file);
return 1;
}
freePixelArray(bytes);
// fprintf(stdout, "Decoded blurhash successfully, wrote PNG file %s\n", output_file);
return 0;
// return rb_float_new(5); /* Convert C double to Ruby float */
}
|