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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68b5a6cb1f7c1957b31d1ce13a7ba276ad854a4c8580b5ad61593ec7c728ccca
4
- data.tar.gz: 982d1a5b187ecfdcf550518a5a164a3f5c58e25db4eae6cc8b6fe502971eed7b
3
+ metadata.gz: ebd294b31f3e70b362e2ea3e65899816ce0a1329adaa5f54cef1a32d7b4d0c04
4
+ data.tar.gz: 8c66eacaa0835cbd9aaf83664a144e611d3bd749c1b68f0f87d1f80001a73ed8
5
5
  SHA512:
6
- metadata.gz: c110b0725fea93f1b169fb877f942ce5a0bfa92d87ef4c499c0f4e1893c9a9944b9ad6c6ec825c119dafff8c30828e45fe752c87672b496737388b409ea9b779
7
- data.tar.gz: 63d3de3e44245edfa56393a20db2a38f23995711d0216fe55fbb3d9b3684992142ca118319e3d59679a3137d80907b032e65e87740ed9896420644b80bec9e12
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
- int size = RSTRING_LEN(buf);
27
- unsigned char * jpeg = (unsigned char *)StringValuePtr(buf);
28
-
29
- if (jpeg[0] != 0xFF || jpeg[1] != 0xD8) {
30
- rb_raise(rb_eRuntimeError, "Not a JPEG image (%x %x should be FF D8)!", jpeg[0], jpeg[1]);
31
- return Qnil;
32
- }
33
-
34
- njInit();
35
-
36
- if (njDecode(jpeg, size)) {
37
- free((void*)jpeg);
38
- rb_raise(rb_eRuntimeError, "Error decoding input file (size %d)", size);
39
- return Qnil;
40
- }
41
-
42
- free((void*)jpeg);
43
-
44
- unsigned char * pixels = njGetImage();
45
- if (!pixels) {
46
- rb_raise(rb_eRuntimeError, "Couldn't decode image.");
47
- return Qnil;
48
- }
49
-
50
- char * out;
51
- size_t bufsize;
52
- FILE * fp = open_memstream(&out, &bufsize);
53
- // FILE * fp = fopen("output.gif", "wb");
54
-
55
- if (!fp) {
56
- rb_raise(rb_eRuntimeError, "Cannot initialize memstream");
57
- return Qnil;
58
- }
59
-
60
- unsigned char * rgba = rgb_to_rgba(pixels, njGetWidth(), njGetHeight());
61
- int maxColors = 8;
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'lilimg'
5
- s.version = '0.0.6'
5
+ s.version = '0.0.7'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ['Tomas Pollak']
8
8
  s.email = ['tomas@forkhq.com']
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.6
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