rfreeimage 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da114f86318598af6b06aa737c0fed85bf78887a
|
4
|
+
data.tar.gz: 662cebc27f59581a9629a1dc95ad834577d3f76b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24f80a22be77f83cbaf072b5d755f58fd0758eb17f3bb1dfff4ac4497c5d55a3da6c9c64341f999814a7ae469020a0a76aacc9adf142ba663ab217ae25acbb23
|
7
|
+
data.tar.gz: 07af6587e3247f9e74db0cab5471a34571fecef781704c58e675b27a1a463dcd8564de14f7394d38f038408b041b46f6047a7c50c7b4b561b9d19ab02f165d8c
|
data/ext/rfreeimage/extconf.rb
CHANGED
data/ext/rfreeimage/rfi_main.c
CHANGED
@@ -218,6 +218,53 @@ VALUE Image_save(VALUE self, VALUE file)
|
|
218
218
|
return Qnil;
|
219
219
|
}
|
220
220
|
|
221
|
+
VALUE Image_to_blob(VALUE self, VALUE type)
|
222
|
+
{
|
223
|
+
char *filetype;
|
224
|
+
struct native_image* img;
|
225
|
+
FIMEMORY *hmem;
|
226
|
+
BOOL result;
|
227
|
+
FREE_IMAGE_FORMAT out_fif;
|
228
|
+
VALUE ret;
|
229
|
+
BYTE *raw = NULL;
|
230
|
+
DWORD file_size;
|
231
|
+
|
232
|
+
Data_Get_Struct(self, struct native_image, img);
|
233
|
+
RFI_CHECK_IMG(img);
|
234
|
+
|
235
|
+
Check_Type(type, T_STRING);
|
236
|
+
filetype = rfi_value_to_str(type);
|
237
|
+
|
238
|
+
out_fif = FreeImage_GetFIFFromFormat(filetype);
|
239
|
+
free(filetype);
|
240
|
+
if (out_fif == FIF_UNKNOWN)
|
241
|
+
rb_raise(Class_RFIError, "Invalid format");
|
242
|
+
|
243
|
+
hmem = FreeImage_OpenMemory(0, 0);
|
244
|
+
if (!hmem)
|
245
|
+
rb_raise(rb_eIOError, "Fail to allocate blob");
|
246
|
+
if (out_fif == FIF_JPEG && img->bpp != 8 && img->bpp != 24) {
|
247
|
+
FIBITMAP *to_save = FreeImage_ConvertTo24Bits(img->handle);
|
248
|
+
result = FreeImage_SaveToMemory(out_fif, to_save, hmem, JPEG_BASELINE);
|
249
|
+
FreeImage_Unload(to_save);
|
250
|
+
} else {
|
251
|
+
result = FreeImage_SaveToMemory(out_fif, img->handle, hmem, 0);
|
252
|
+
}
|
253
|
+
|
254
|
+
if(!result) {
|
255
|
+
FreeImage_CloseMemory(hmem);
|
256
|
+
rb_raise(rb_eIOError, "Fail to save image to blob");
|
257
|
+
}
|
258
|
+
file_size = FreeImage_TellMemory(hmem);
|
259
|
+
FreeImage_SeekMemory(hmem, 0, SEEK_SET);
|
260
|
+
FreeImage_AcquireMemory(hmem, &raw, &file_size);
|
261
|
+
ret = rb_str_new((char*)raw, (long)file_size);
|
262
|
+
FreeImage_CloseMemory(hmem);
|
263
|
+
return ret;
|
264
|
+
}
|
265
|
+
|
266
|
+
|
267
|
+
|
221
268
|
|
222
269
|
VALUE Image_cols(VALUE self)
|
223
270
|
{
|
@@ -449,6 +496,49 @@ VALUE Image_ping_blob(VALUE self, VALUE blob)
|
|
449
496
|
return v;
|
450
497
|
}
|
451
498
|
|
499
|
+
VALUE Image_from_bytes(VALUE self, VALUE bytes, VALUE width,
|
500
|
+
VALUE height, VALUE stride, VALUE bpp)
|
501
|
+
{
|
502
|
+
long f_len;
|
503
|
+
int _bpp = NUM2INT(bpp);
|
504
|
+
char *ptr;
|
505
|
+
unsigned char *p;
|
506
|
+
int i;
|
507
|
+
int src_stride = NUM2INT(stride);
|
508
|
+
FIBITMAP *h;
|
509
|
+
|
510
|
+
ALLOC_NEW_IMAGE(v, img);
|
511
|
+
|
512
|
+
if (_bpp != 8 && _bpp != 32)
|
513
|
+
rb_raise(rb_eArgError, "bpp must be 8 or 32");
|
514
|
+
Check_Type(bytes, T_STRING);
|
515
|
+
f_len = RSTRING_LEN(bytes);
|
516
|
+
if (f_len < (long)src_stride * NUM2INT(height))
|
517
|
+
rb_raise(rb_eArgError, "buffer too small");
|
518
|
+
|
519
|
+
h = FreeImage_Allocate(NUM2INT(width), NUM2INT(height), _bpp, 0, 0, 0);
|
520
|
+
if (!h)
|
521
|
+
rb_raise(rb_eArgError, "fail to allocate image");
|
522
|
+
|
523
|
+
img->handle = h;
|
524
|
+
img->w = FreeImage_GetWidth(h);
|
525
|
+
img->h = FreeImage_GetHeight(h);
|
526
|
+
img->bpp = FreeImage_GetBPP(h);
|
527
|
+
img->stride = FreeImage_GetPitch(h);
|
528
|
+
img->fif = FIF_BMP;
|
529
|
+
|
530
|
+
/* up-side-down */
|
531
|
+
p = FreeImage_GetBits(img->handle);
|
532
|
+
ptr = RSTRING_PTR(bytes) + img->h * src_stride;
|
533
|
+
for(i = 0; i < img->h; i++) {
|
534
|
+
ptr -= src_stride;
|
535
|
+
memcpy(p, ptr, img->stride);
|
536
|
+
p += img->stride;
|
537
|
+
}
|
538
|
+
|
539
|
+
return v;
|
540
|
+
}
|
541
|
+
|
452
542
|
/* draw */
|
453
543
|
VALUE Image_draw_point(VALUE self, VALUE _x, VALUE _y, VALUE color, VALUE _size)
|
454
544
|
{
|
@@ -536,6 +626,7 @@ void Init_rfreeimage(void)
|
|
536
626
|
rb_define_method(Class_Image, "rotate", Image_rotate, 1);
|
537
627
|
rb_define_method(Class_Image, "resize", Image_resize, 2);
|
538
628
|
rb_define_method(Class_Image, "crop", Image_crop, 4);
|
629
|
+
rb_define_method(Class_Image, "to_blob", Image_to_blob, 1);
|
539
630
|
|
540
631
|
/* draw */
|
541
632
|
rb_define_method(Class_Image, "draw_point", Image_draw_point, 4);
|
@@ -544,4 +635,5 @@ void Init_rfreeimage(void)
|
|
544
635
|
rb_define_singleton_method(Class_Image, "ping", Image_ping, 1);
|
545
636
|
rb_define_singleton_method(Class_Image, "from_blob", Image_from_blob, -1);
|
546
637
|
rb_define_singleton_method(Class_Image, "ping_blob", Image_ping_blob, 1);
|
638
|
+
rb_define_singleton_method(Class_Image, "from_bytes", Image_from_bytes, 5);
|
547
639
|
}
|
data/lib/rfreeimage/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rfreeimage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuheng Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|