Module: ENCODER

Included in:
BlurhashRuby
Defined in:
ext/blurhash_encoder/blurhash_encoder.c

Instance Method Summary collapse

Instance Method Details

#encode(path, x, y) ⇒ Object



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 path ,VALUE x, VALUE y) {
    int xComponents = NUM2INT(x);
    int yComponents = NUM2INT(y);

    const char * input_file = StringValuePtr(path);

    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));
}