lilimg 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/lilimg/lilimg.c +81 -81
- data/lilimg.gemspec +1 -1
- metadata +1 -2
- data/example/label.jpg +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebd294b31f3e70b362e2ea3e65899816ce0a1329adaa5f54cef1a32d7b4d0c04
|
4
|
+
data.tar.gz: 8c66eacaa0835cbd9aaf83664a144e611d3bd749c1b68f0f87d1f80001a73ed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef5ef2c37a3fb2939f022fae50fe778239011c5161f775bc101b4b2a3bf85533e6e089b9f445bcc55a8e70c4d34f064014f0950750d6320570efc40f8fb64058
|
7
|
+
data.tar.gz: 4d42648b3210b1d0669ab2f21c178519c137bd2f5a9ad399d47190c8f67483836c593e8c5cbd570d9beacbbfba7464e2fddb201152c3da9e7db17913fbc79808
|
data/ext/lilimg/lilimg.c
CHANGED
@@ -1,82 +1,82 @@
|
|
1
|
-
#include "ruby.h"
|
2
|
-
|
3
|
-
#include <stdio.h>
|
4
|
-
#include <stdlib.h>
|
5
|
-
#include <string.h>
|
6
|
-
#include "nanojpeg.h"
|
7
|
-
#include "jo_gif.h"
|
8
|
-
|
9
|
-
unsigned char * rgb_to_rgba(unsigned char * buf, int w, int h) {
|
10
|
-
int newsize = 4 * w * h;
|
11
|
-
unsigned char * dest;
|
12
|
-
dest = malloc(newsize);
|
13
|
-
int s = 0, d = 0;
|
14
|
-
while (d < newsize) {
|
15
|
-
dest[d++] = buf[s++];
|
16
|
-
dest[d++] = buf[s++];
|
17
|
-
dest[d++] = buf[s++];
|
18
|
-
dest[d++] = 255; // fully opaque
|
19
|
-
}
|
20
|
-
|
21
|
-
return dest;
|
22
|
-
}
|
23
|
-
|
24
|
-
static VALUE jpeg_to_gif(VALUE self, VALUE buf) {
|
25
|
-
rb_check_type(buf, T_STRING);
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
jo_gif_t gif = jo_gif_start(fp, njGetWidth(), njGetHeight(), 0, maxColors);
|
64
|
-
jo_gif_frame(&gif, rgba, 0, 0);
|
65
|
-
jo_gif_end(&gif);
|
66
|
-
|
67
|
-
VALUE rstr;
|
68
|
-
rstr = rb_str_new(out, bufsize);
|
69
|
-
|
70
|
-
free(rgba);
|
71
|
-
free(out);
|
72
|
-
njDone();
|
73
|
-
|
74
|
-
return rstr;
|
75
|
-
}
|
76
|
-
|
77
|
-
VALUE Lilimg = Qnil;
|
78
|
-
|
79
|
-
void Init_lilimg() {
|
80
|
-
Lilimg = rb_define_module("Lilimg");
|
81
|
-
rb_define_module_function(Lilimg, "jpeg_to_gif", jpeg_to_gif, 1);
|
1
|
+
#include "ruby.h"
|
2
|
+
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <stdlib.h>
|
5
|
+
#include <string.h>
|
6
|
+
#include "nanojpeg.h"
|
7
|
+
#include "jo_gif.h"
|
8
|
+
|
9
|
+
unsigned char * rgb_to_rgba(unsigned char * buf, int w, int h) {
|
10
|
+
int newsize = 4 * w * h;
|
11
|
+
unsigned char * dest;
|
12
|
+
dest = malloc(newsize);
|
13
|
+
int s = 0, d = 0;
|
14
|
+
while (d < newsize) {
|
15
|
+
dest[d++] = buf[s++];
|
16
|
+
dest[d++] = buf[s++];
|
17
|
+
dest[d++] = buf[s++];
|
18
|
+
dest[d++] = 255; // fully opaque
|
19
|
+
}
|
20
|
+
|
21
|
+
return dest;
|
22
|
+
}
|
23
|
+
|
24
|
+
static VALUE jpeg_to_gif(VALUE self, VALUE buf) {
|
25
|
+
rb_check_type(buf, T_STRING);
|
26
|
+
|
27
|
+
int maxColors = 255;
|
28
|
+
int size = RSTRING_LEN(buf);
|
29
|
+
unsigned char * jpeg = (unsigned char *)StringValuePtr(buf);
|
30
|
+
|
31
|
+
if (jpeg[0] != 0xFF || jpeg[1] != 0xD8) {
|
32
|
+
rb_raise(rb_eRuntimeError, "Not a JPEG image (%x %x should be FF D8)!", jpeg[0], jpeg[1]);
|
33
|
+
return Qnil;
|
34
|
+
}
|
35
|
+
|
36
|
+
njInit();
|
37
|
+
|
38
|
+
if (njDecode(jpeg, size)) {
|
39
|
+
free((void*)jpeg);
|
40
|
+
rb_raise(rb_eRuntimeError, "Error decoding input file (size %d)", size);
|
41
|
+
return Qnil;
|
42
|
+
}
|
43
|
+
|
44
|
+
free((void*)jpeg);
|
45
|
+
|
46
|
+
unsigned char * pixels = njGetImage();
|
47
|
+
if (!pixels) {
|
48
|
+
rb_raise(rb_eRuntimeError, "Couldn't decode image.");
|
49
|
+
return Qnil;
|
50
|
+
}
|
51
|
+
|
52
|
+
char * out;
|
53
|
+
size_t bufsize;
|
54
|
+
FILE * fp = open_memstream(&out, &bufsize);
|
55
|
+
// FILE * fp = fopen("output.gif", "wb");
|
56
|
+
|
57
|
+
if (!fp) {
|
58
|
+
rb_raise(rb_eRuntimeError, "Cannot initialize memstream");
|
59
|
+
return Qnil;
|
60
|
+
}
|
61
|
+
|
62
|
+
unsigned char * rgba = rgb_to_rgba(pixels, njGetWidth(), njGetHeight());
|
63
|
+
jo_gif_t gif = jo_gif_start(fp, njGetWidth(), njGetHeight(), 0, maxColors);
|
64
|
+
jo_gif_frame(&gif, rgba, 0, 0);
|
65
|
+
jo_gif_end(&gif);
|
66
|
+
|
67
|
+
VALUE rstr;
|
68
|
+
rstr = rb_str_new(out, bufsize);
|
69
|
+
|
70
|
+
free(rgba);
|
71
|
+
free(out);
|
72
|
+
njDone();
|
73
|
+
|
74
|
+
return rstr;
|
75
|
+
}
|
76
|
+
|
77
|
+
VALUE Lilimg = Qnil;
|
78
|
+
|
79
|
+
void Init_lilimg() {
|
80
|
+
Lilimg = rb_define_module("Lilimg");
|
81
|
+
rb_define_module_function(Lilimg, "jpeg_to_gif", jpeg_to_gif, 1);
|
82
82
|
}
|
data/lilimg.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lilimg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Pollak
|
@@ -21,7 +21,6 @@ files:
|
|
21
21
|
- ".gitignore"
|
22
22
|
- Rakefile
|
23
23
|
- example/build.sh
|
24
|
-
- example/label.jpg
|
25
24
|
- example/test.c
|
26
25
|
- example/test.rb
|
27
26
|
- ext/lilimg/extconf.rb
|
data/example/label.jpg
DELETED
Binary file
|