oil 0.2.0 → 0.3.0
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 +4 -4
- data/MIT-LICENSE +1 -1
- data/README.rdoc +0 -5
- data/Rakefile +1 -25
- data/ext/oil/jpeg.c +90 -97
- data/ext/oil/oil.c +6 -4
- data/ext/oil/oil_libjpeg.c +113 -0
- data/ext/oil/oil_libjpeg.h +58 -0
- data/ext/oil/oil_libpng.c +174 -0
- data/ext/oil/oil_libpng.h +59 -0
- data/ext/oil/oil_resample.c +1475 -0
- data/ext/oil/oil_resample.h +189 -0
- data/ext/oil/oil_resample_internal.h +59 -0
- data/ext/oil/oil_resample_sse2.c +1930 -0
- data/ext/oil/png.c +48 -119
- data/lib/oil.rb +1 -1
- data/oil.gemspec +39 -0
- data/test/test_jpeg.rb +3 -3
- data/test/test_png.rb +2 -2
- metadata +20 -12
- data/ext/oil/resample.c +0 -938
- data/ext/oil/resample.h +0 -119
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4b80d6ee9098f7a6d91cd5919d1e47667b3a7f7fdcb449c533c16f8a997acf5
|
|
4
|
+
data.tar.gz: 95fc3862a6bb8bb4dd9e0e795c43973cd507884b25d93c42211dc2006a302388
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d12b389c79ca87c3a052c771ebc7ce1b44fca4c35c72e0a0c91d9ac5ed3376c978679022c55e2df17ba355cc8950f3583f1f5ee43ca4b4c1abe48a9fe6b91ded
|
|
7
|
+
data.tar.gz: 0f8d360d64a3609f8cf924388759753f14dab0a82dc194d204c0f0c524b76004c616edf52e68129ecc5a4b220f8a80c5e21c1be57d699b9c3b4f558b32c44b03
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
|
@@ -44,11 +44,6 @@ Compile & run unit tests. Should show no warnings and no failing tests:
|
|
|
44
44
|
$ rake compile
|
|
45
45
|
$ rake test
|
|
46
46
|
|
|
47
|
-
Valgrind should not complain (ruby-1.9.3p125, compiled with -O3):
|
|
48
|
-
|
|
49
|
-
$ valgrind /path/to/ruby -Iext:test test/test_jpeg.rb
|
|
50
|
-
$ valgrind /path/to/ruby -Iext:test test/test_png.rb
|
|
51
|
-
|
|
52
47
|
Changes to the interpolator should be analyzed using ResampleScope:
|
|
53
48
|
|
|
54
49
|
https://github.com/jsummers/resamplescope
|
data/Rakefile
CHANGED
|
@@ -6,31 +6,7 @@ Rake::ExtensionTask.new('oil') do |ext|
|
|
|
6
6
|
ext.lib_dir = 'lib/oil'
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
s = Gem::Specification.
|
|
10
|
-
s.license = 'MIT'
|
|
11
|
-
s.summary = 'Resize JPEG and PNG images.'
|
|
12
|
-
s.description = 'Resize JPEG and PNG images, aiming for fast performance and low memory use.'
|
|
13
|
-
s.authors = ['Timothy Elliott']
|
|
14
|
-
s.email = 'tle@holymonkey.com'
|
|
15
|
-
s.files = %w{
|
|
16
|
-
Rakefile
|
|
17
|
-
README.rdoc
|
|
18
|
-
MIT-LICENSE
|
|
19
|
-
lib/oil.rb
|
|
20
|
-
ext/oil/resample.c
|
|
21
|
-
ext/oil/resample.h
|
|
22
|
-
ext/oil/jpeg.c
|
|
23
|
-
ext/oil/png.c
|
|
24
|
-
ext/oil/oil.c
|
|
25
|
-
ext/oil/extconf.rb
|
|
26
|
-
test/helper.rb
|
|
27
|
-
test/test_jpeg.rb
|
|
28
|
-
test/test_png.rb
|
|
29
|
-
}
|
|
30
|
-
s.homepage = 'http://github.com/ender672/oil'
|
|
31
|
-
s.extensions << 'ext/oil/extconf.rb'
|
|
32
|
-
s.extra_rdoc_files = ['README.rdoc']
|
|
33
|
-
end
|
|
9
|
+
s = Gem::Specification.load('oil.gemspec')
|
|
34
10
|
|
|
35
11
|
Gem::PackageTask.new(s){}
|
|
36
12
|
|
data/ext/oil/jpeg.c
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#include <ruby.h>
|
|
2
2
|
#include <ruby/st.h>
|
|
3
3
|
#include <jpeglib.h>
|
|
4
|
-
#include "
|
|
4
|
+
#include "oil_libjpeg.h"
|
|
5
5
|
|
|
6
6
|
#define READ_SIZE 1024
|
|
7
7
|
#define WRITE_SIZE 1024
|
|
@@ -170,8 +170,8 @@ struct readerdata {
|
|
|
170
170
|
int locked;
|
|
171
171
|
VALUE source_io;
|
|
172
172
|
VALUE buffer;
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
int scale_width;
|
|
174
|
+
int scale_height;
|
|
175
175
|
};
|
|
176
176
|
|
|
177
177
|
static void null_jdecompress(j_decompress_ptr dinfo) {}
|
|
@@ -220,14 +220,17 @@ static void skip_input_data(j_decompress_ptr dinfo, long num_bytes)
|
|
|
220
220
|
|
|
221
221
|
/* Ruby GC */
|
|
222
222
|
|
|
223
|
-
static void deallocate(
|
|
223
|
+
static void deallocate(void *ptr)
|
|
224
224
|
{
|
|
225
|
+
struct readerdata *reader = ptr;
|
|
225
226
|
jpeg_destroy_decompress(&reader->dinfo);
|
|
226
227
|
free(reader);
|
|
227
228
|
}
|
|
228
229
|
|
|
229
|
-
static void mark(
|
|
230
|
+
static void mark(void *ptr)
|
|
230
231
|
{
|
|
232
|
+
struct readerdata *reader = ptr;
|
|
233
|
+
|
|
231
234
|
if (!NIL_P(reader->source_io)) {
|
|
232
235
|
rb_gc_mark(reader->source_io);
|
|
233
236
|
}
|
|
@@ -237,11 +240,23 @@ static void mark(struct readerdata *reader)
|
|
|
237
240
|
}
|
|
238
241
|
}
|
|
239
242
|
|
|
243
|
+
static size_t memsize(const void *ptr)
|
|
244
|
+
{
|
|
245
|
+
return sizeof(struct readerdata);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
static const rb_data_type_t jpeg_reader_type = {
|
|
249
|
+
"Oil::JPEGReader",
|
|
250
|
+
{ mark, deallocate, memsize },
|
|
251
|
+
0, 0,
|
|
252
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
|
253
|
+
};
|
|
254
|
+
|
|
240
255
|
static VALUE allocate(VALUE klass)
|
|
241
256
|
{
|
|
242
257
|
struct readerdata *reader;
|
|
243
258
|
VALUE self;
|
|
244
|
-
self =
|
|
259
|
+
self = TypedData_Make_Struct(klass, struct readerdata, &jpeg_reader_type, reader);
|
|
245
260
|
|
|
246
261
|
jpeg_std_error(&reader->jerr);
|
|
247
262
|
reader->jerr.error_exit = error_exit;
|
|
@@ -293,7 +308,7 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
|
293
308
|
struct jpeg_decompress_struct *dinfo;
|
|
294
309
|
int i, marker_code;
|
|
295
310
|
|
|
296
|
-
|
|
311
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
297
312
|
dinfo = &reader->dinfo;
|
|
298
313
|
|
|
299
314
|
/* If source_io has already been set, then this is a re-used jpeg reader
|
|
@@ -315,10 +330,10 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
|
315
330
|
if(!NIL_P(markers)) {
|
|
316
331
|
Check_Type(markers, T_ARRAY);
|
|
317
332
|
for (i=0; i<RARRAY_LEN(markers); i++) {
|
|
318
|
-
if (!SYMBOL_P(
|
|
333
|
+
if (!SYMBOL_P(RARRAY_AREF(markers, i))) {
|
|
319
334
|
rb_raise(rb_eTypeError, "Marker code is not a symbol.");
|
|
320
335
|
}
|
|
321
|
-
marker_code = sym_to_marker_code(
|
|
336
|
+
marker_code = sym_to_marker_code(RARRAY_AREF(markers, i));
|
|
322
337
|
jpeg_save_markers(dinfo, marker_code, 0xFFFF);
|
|
323
338
|
}
|
|
324
339
|
}
|
|
@@ -344,9 +359,9 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
|
344
359
|
|
|
345
360
|
static VALUE num_components(VALUE self)
|
|
346
361
|
{
|
|
347
|
-
struct
|
|
348
|
-
|
|
349
|
-
return INT2FIX(dinfo
|
|
362
|
+
struct readerdata *reader;
|
|
363
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
364
|
+
return INT2FIX(reader->dinfo.num_components);
|
|
350
365
|
}
|
|
351
366
|
|
|
352
367
|
/*
|
|
@@ -361,9 +376,9 @@ static VALUE num_components(VALUE self)
|
|
|
361
376
|
|
|
362
377
|
static VALUE output_components(VALUE self)
|
|
363
378
|
{
|
|
364
|
-
struct
|
|
365
|
-
|
|
366
|
-
return INT2FIX(dinfo
|
|
379
|
+
struct readerdata *reader;
|
|
380
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
381
|
+
return INT2FIX(reader->dinfo.output_components);
|
|
367
382
|
}
|
|
368
383
|
|
|
369
384
|
/*
|
|
@@ -378,9 +393,9 @@ static VALUE output_components(VALUE self)
|
|
|
378
393
|
|
|
379
394
|
static VALUE out_color_components(VALUE self)
|
|
380
395
|
{
|
|
381
|
-
struct
|
|
382
|
-
|
|
383
|
-
return INT2FIX(dinfo
|
|
396
|
+
struct readerdata *reader;
|
|
397
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
398
|
+
return INT2FIX(reader->dinfo.out_color_components);
|
|
384
399
|
}
|
|
385
400
|
|
|
386
401
|
/*
|
|
@@ -399,11 +414,11 @@ static VALUE out_color_components(VALUE self)
|
|
|
399
414
|
|
|
400
415
|
static VALUE jpeg_color_space(VALUE self)
|
|
401
416
|
{
|
|
402
|
-
struct
|
|
417
|
+
struct readerdata *reader;
|
|
403
418
|
ID id;
|
|
404
419
|
|
|
405
|
-
|
|
406
|
-
id = j_color_space_to_id(dinfo
|
|
420
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
421
|
+
id = j_color_space_to_id(reader->dinfo.jpeg_color_space);
|
|
407
422
|
|
|
408
423
|
return ID2SYM(id);
|
|
409
424
|
}
|
|
@@ -418,11 +433,11 @@ static VALUE jpeg_color_space(VALUE self)
|
|
|
418
433
|
|
|
419
434
|
static VALUE out_color_space(VALUE self)
|
|
420
435
|
{
|
|
421
|
-
struct
|
|
436
|
+
struct readerdata *reader;
|
|
422
437
|
ID id;
|
|
423
438
|
|
|
424
|
-
|
|
425
|
-
id = j_color_space_to_id(dinfo
|
|
439
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
440
|
+
id = j_color_space_to_id(reader->dinfo.out_color_space);
|
|
426
441
|
|
|
427
442
|
return ID2SYM(id);
|
|
428
443
|
}
|
|
@@ -438,7 +453,7 @@ static VALUE set_out_color_space(VALUE self, VALUE cs)
|
|
|
438
453
|
{
|
|
439
454
|
struct readerdata *reader;
|
|
440
455
|
|
|
441
|
-
|
|
456
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
442
457
|
raise_if_locked(reader);
|
|
443
458
|
|
|
444
459
|
reader->dinfo.out_color_space = sym_to_j_color_space(cs);
|
|
@@ -458,9 +473,9 @@ static VALUE set_out_color_space(VALUE self, VALUE cs)
|
|
|
458
473
|
|
|
459
474
|
static VALUE image_width(VALUE self)
|
|
460
475
|
{
|
|
461
|
-
struct
|
|
462
|
-
|
|
463
|
-
return INT2FIX(dinfo
|
|
476
|
+
struct readerdata *reader;
|
|
477
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
478
|
+
return INT2FIX(reader->dinfo.image_width);
|
|
464
479
|
}
|
|
465
480
|
|
|
466
481
|
/*
|
|
@@ -475,9 +490,9 @@ static VALUE image_width(VALUE self)
|
|
|
475
490
|
|
|
476
491
|
static VALUE image_height(VALUE self)
|
|
477
492
|
{
|
|
478
|
-
struct
|
|
479
|
-
|
|
480
|
-
return INT2FIX(dinfo
|
|
493
|
+
struct readerdata *reader;
|
|
494
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
495
|
+
return INT2FIX(reader->dinfo.image_height);
|
|
481
496
|
}
|
|
482
497
|
|
|
483
498
|
/*
|
|
@@ -489,9 +504,9 @@ static VALUE image_height(VALUE self)
|
|
|
489
504
|
|
|
490
505
|
static VALUE output_width(VALUE self)
|
|
491
506
|
{
|
|
492
|
-
struct
|
|
493
|
-
|
|
494
|
-
return INT2FIX(dinfo
|
|
507
|
+
struct readerdata *reader;
|
|
508
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
509
|
+
return INT2FIX(reader->dinfo.output_width);
|
|
495
510
|
}
|
|
496
511
|
|
|
497
512
|
/*
|
|
@@ -503,9 +518,9 @@ static VALUE output_width(VALUE self)
|
|
|
503
518
|
|
|
504
519
|
static VALUE output_height(VALUE self)
|
|
505
520
|
{
|
|
506
|
-
struct
|
|
507
|
-
|
|
508
|
-
return INT2FIX(dinfo
|
|
521
|
+
struct readerdata *reader;
|
|
522
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
523
|
+
return INT2FIX(reader->dinfo.output_height);
|
|
509
524
|
}
|
|
510
525
|
|
|
511
526
|
/*
|
|
@@ -522,13 +537,15 @@ static VALUE output_height(VALUE self)
|
|
|
522
537
|
|
|
523
538
|
static VALUE markers(VALUE self)
|
|
524
539
|
{
|
|
540
|
+
struct readerdata *reader;
|
|
525
541
|
struct jpeg_decompress_struct *dinfo;
|
|
526
542
|
jpeg_saved_marker_ptr marker;
|
|
527
543
|
VALUE hash, ary, key, val;
|
|
528
544
|
|
|
529
545
|
hash = rb_hash_new();
|
|
530
546
|
|
|
531
|
-
|
|
547
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
548
|
+
dinfo = &reader->dinfo;
|
|
532
549
|
|
|
533
550
|
for (marker=dinfo->marker_list; marker; marker=marker->next) {
|
|
534
551
|
key = marker_code_to_sym(marker->marker);
|
|
@@ -555,9 +572,9 @@ static VALUE markers(VALUE self)
|
|
|
555
572
|
|
|
556
573
|
static VALUE scale_num(VALUE self)
|
|
557
574
|
{
|
|
558
|
-
struct
|
|
559
|
-
|
|
560
|
-
return INT2FIX(dinfo
|
|
575
|
+
struct readerdata *reader;
|
|
576
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
577
|
+
return INT2FIX(reader->dinfo.scale_num);
|
|
561
578
|
}
|
|
562
579
|
|
|
563
580
|
/*
|
|
@@ -573,7 +590,7 @@ static VALUE set_scale_num(VALUE self, VALUE scale_num)
|
|
|
573
590
|
{
|
|
574
591
|
struct readerdata *reader;
|
|
575
592
|
|
|
576
|
-
|
|
593
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
577
594
|
raise_if_locked(reader);
|
|
578
595
|
|
|
579
596
|
reader->dinfo.scale_num = NUM2INT(scale_num);
|
|
@@ -592,9 +609,9 @@ static VALUE set_scale_num(VALUE self, VALUE scale_num)
|
|
|
592
609
|
|
|
593
610
|
static VALUE scale_denom(VALUE self)
|
|
594
611
|
{
|
|
595
|
-
struct
|
|
596
|
-
|
|
597
|
-
return INT2FIX(dinfo
|
|
612
|
+
struct readerdata *reader;
|
|
613
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
614
|
+
return INT2FIX(reader->dinfo.scale_denom);
|
|
598
615
|
}
|
|
599
616
|
|
|
600
617
|
/*
|
|
@@ -613,7 +630,7 @@ static VALUE set_scale_denom(VALUE self, VALUE scale_denom)
|
|
|
613
630
|
{
|
|
614
631
|
struct readerdata *reader;
|
|
615
632
|
|
|
616
|
-
|
|
633
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
617
634
|
raise_if_locked(reader);
|
|
618
635
|
|
|
619
636
|
reader->dinfo.scale_denom = NUM2INT(scale_denom);
|
|
@@ -632,7 +649,7 @@ static VALUE set_scale_denom(VALUE self, VALUE scale_denom)
|
|
|
632
649
|
static VALUE scale_width(VALUE self)
|
|
633
650
|
{
|
|
634
651
|
struct readerdata *reader;
|
|
635
|
-
|
|
652
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
636
653
|
return INT2FIX(reader->scale_width);
|
|
637
654
|
}
|
|
638
655
|
|
|
@@ -647,7 +664,7 @@ static VALUE scale_width(VALUE self)
|
|
|
647
664
|
static VALUE set_scale_width(VALUE self, VALUE scale_width)
|
|
648
665
|
{
|
|
649
666
|
struct readerdata *reader;
|
|
650
|
-
|
|
667
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
651
668
|
raise_if_locked(reader);
|
|
652
669
|
reader->scale_width = NUM2INT(scale_width);
|
|
653
670
|
return scale_width;
|
|
@@ -664,7 +681,7 @@ static VALUE set_scale_width(VALUE self, VALUE scale_width)
|
|
|
664
681
|
static VALUE scale_height(VALUE self)
|
|
665
682
|
{
|
|
666
683
|
struct readerdata *reader;
|
|
667
|
-
|
|
684
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
668
685
|
return INT2FIX(reader->scale_height);
|
|
669
686
|
}
|
|
670
687
|
|
|
@@ -679,7 +696,7 @@ static VALUE scale_height(VALUE self)
|
|
|
679
696
|
static VALUE set_scale_height(VALUE self, VALUE scale_height)
|
|
680
697
|
{
|
|
681
698
|
struct readerdata *reader;
|
|
682
|
-
|
|
699
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
683
700
|
raise_if_locked(reader);
|
|
684
701
|
reader->scale_height = NUM2INT(scale_height);
|
|
685
702
|
return scale_height;
|
|
@@ -754,8 +771,7 @@ struct write_jpeg_args {
|
|
|
754
771
|
struct writerdata *writer;
|
|
755
772
|
unsigned char *inwidthbuf;
|
|
756
773
|
unsigned char *outwidthbuf;
|
|
757
|
-
struct
|
|
758
|
-
struct preprocess_xscaler xs;
|
|
774
|
+
struct oil_libjpeg ol;
|
|
759
775
|
};
|
|
760
776
|
|
|
761
777
|
static VALUE each2(struct write_jpeg_args *args)
|
|
@@ -763,12 +779,13 @@ static VALUE each2(struct write_jpeg_args *args)
|
|
|
763
779
|
struct writerdata *writer;
|
|
764
780
|
struct jpeg_decompress_struct *dinfo;
|
|
765
781
|
struct jpeg_compress_struct *cinfo;
|
|
766
|
-
unsigned char *outwidthbuf
|
|
767
|
-
|
|
768
|
-
uint32_t i, scalex, scaley;
|
|
782
|
+
unsigned char *outwidthbuf;
|
|
783
|
+
int i, scalex, scaley;
|
|
769
784
|
VALUE quality, markers;
|
|
785
|
+
struct oil_libjpeg *ol;
|
|
770
786
|
|
|
771
787
|
writer = args->writer;
|
|
788
|
+
ol = &args->ol;
|
|
772
789
|
outwidthbuf = args->outwidthbuf;
|
|
773
790
|
dinfo = &args->reader->dinfo;
|
|
774
791
|
cinfo = &writer->cinfo;
|
|
@@ -784,8 +801,6 @@ static VALUE each2(struct write_jpeg_args *args)
|
|
|
784
801
|
writer->cinfo.in_color_space = dinfo->out_color_space;
|
|
785
802
|
writer->cinfo.input_components = dinfo->output_components;
|
|
786
803
|
|
|
787
|
-
xinbuf = args->inwidthbuf;
|
|
788
|
-
|
|
789
804
|
jpeg_set_defaults(cinfo);
|
|
790
805
|
|
|
791
806
|
if (!NIL_P(args->opts)) {
|
|
@@ -806,12 +821,8 @@ static VALUE each2(struct write_jpeg_args *args)
|
|
|
806
821
|
}
|
|
807
822
|
}
|
|
808
823
|
|
|
809
|
-
for(i=
|
|
810
|
-
|
|
811
|
-
jpeg_read_scanlines(dinfo, (JSAMPARRAY)&xinbuf, 1);
|
|
812
|
-
preprocess_xscaler_scale(&args->xs, xinbuf, yinbuf);
|
|
813
|
-
}
|
|
814
|
-
yscaler_scale(&args->ys, outwidthbuf, i);
|
|
824
|
+
for(i=scaley; i>0; i--) {
|
|
825
|
+
oil_libjpeg_read_scanline(ol, outwidthbuf);
|
|
815
826
|
jpeg_write_scanlines(cinfo, (JSAMPARRAY)&outwidthbuf, 1);
|
|
816
827
|
}
|
|
817
828
|
|
|
@@ -820,24 +831,6 @@ static VALUE each2(struct write_jpeg_args *args)
|
|
|
820
831
|
return Qnil;
|
|
821
832
|
}
|
|
822
833
|
|
|
823
|
-
static enum oil_colorspace jpeg_cs_to_oil(J_COLOR_SPACE cs)
|
|
824
|
-
{
|
|
825
|
-
switch(cs) {
|
|
826
|
-
case JCS_GRAYSCALE:
|
|
827
|
-
return OIL_CS_G;
|
|
828
|
-
case JCS_RGB:
|
|
829
|
-
return OIL_CS_RGB;
|
|
830
|
-
case JCS_CMYK:
|
|
831
|
-
return OIL_CS_CMYK;
|
|
832
|
-
#ifdef JCS_EXTENSIONS
|
|
833
|
-
case JCS_EXT_RGBX:
|
|
834
|
-
return OIL_CS_RGBX;
|
|
835
|
-
#endif
|
|
836
|
-
default:
|
|
837
|
-
rb_raise(rb_eRuntimeError, "Color space not recognized.");
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
|
|
841
834
|
/*
|
|
842
835
|
* call-seq:
|
|
843
836
|
* reader.each(opts, &block) -> self
|
|
@@ -856,16 +849,14 @@ static VALUE each(int argc, VALUE *argv, VALUE self)
|
|
|
856
849
|
{
|
|
857
850
|
struct readerdata *reader;
|
|
858
851
|
struct writerdata writer;
|
|
859
|
-
int state;
|
|
852
|
+
int state, width_out, ret;
|
|
860
853
|
struct write_jpeg_args args;
|
|
861
|
-
unsigned char *
|
|
862
|
-
uint32_t width_in, width_out;
|
|
854
|
+
unsigned char *outwidthbuf;
|
|
863
855
|
VALUE opts;
|
|
864
|
-
enum oil_colorspace cs;
|
|
865
856
|
|
|
866
857
|
rb_scan_args(argc, argv, "01", &opts);
|
|
867
858
|
|
|
868
|
-
|
|
859
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
869
860
|
|
|
870
861
|
if (!reader->scale_width) {
|
|
871
862
|
reader->scale_width = reader->dinfo.output_width;
|
|
@@ -877,27 +868,29 @@ static VALUE each(int argc, VALUE *argv, VALUE self)
|
|
|
877
868
|
writer.cinfo.err = &reader->jerr;
|
|
878
869
|
jpeg_create_compress(&writer.cinfo);
|
|
879
870
|
|
|
880
|
-
cs = jpeg_cs_to_oil(reader->dinfo.out_color_space);
|
|
881
|
-
width_in = reader->dinfo.output_width;
|
|
882
871
|
width_out = reader->scale_width;
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
872
|
+
ret = oil_libjpeg_init(&args.ol, &reader->dinfo, width_out,
|
|
873
|
+
reader->scale_height);
|
|
874
|
+
if (ret!=0) {
|
|
875
|
+
jpeg_destroy_compress(&writer.cinfo);
|
|
876
|
+
rb_raise(rb_eRuntimeError, "Unable to allocate memory.");
|
|
877
|
+
}
|
|
878
|
+
outwidthbuf = malloc(width_out * OIL_CMP(args.ol.os.cs));
|
|
879
|
+
if (!outwidthbuf) {
|
|
880
|
+
oil_libjpeg_free(&args.ol);
|
|
881
|
+
jpeg_destroy_compress(&writer.cinfo);
|
|
882
|
+
rb_raise(rb_eRuntimeError, "Unable to allocate memory.");
|
|
883
|
+
}
|
|
888
884
|
|
|
889
885
|
args.reader = reader;
|
|
890
886
|
args.opts = opts;
|
|
891
887
|
args.writer = &writer;
|
|
892
|
-
args.inwidthbuf = inwidthbuf;
|
|
893
888
|
args.outwidthbuf = outwidthbuf;
|
|
894
889
|
reader->locked = 1;
|
|
895
890
|
rb_protect((VALUE(*)(VALUE))each2, (VALUE)&args, &state);
|
|
896
891
|
|
|
897
|
-
|
|
898
|
-
preprocess_xscaler_free(&args.xs);
|
|
892
|
+
oil_libjpeg_free(&args.ol);
|
|
899
893
|
free(outwidthbuf);
|
|
900
|
-
free(inwidthbuf);
|
|
901
894
|
jpeg_destroy_compress(&writer.cinfo);
|
|
902
895
|
|
|
903
896
|
if (state) {
|
data/ext/oil/oil.c
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#include <ruby.h>
|
|
2
|
-
#include "
|
|
2
|
+
#include "oil_resample.h"
|
|
3
3
|
|
|
4
4
|
static VALUE rb_fix_ratio(VALUE self, VALUE src_w, VALUE src_h, VALUE out_w, VALUE out_h)
|
|
5
5
|
{
|
|
6
|
-
|
|
6
|
+
int out_width, out_height;
|
|
7
7
|
VALUE ret;
|
|
8
|
+
|
|
8
9
|
out_width = NUM2INT(out_w);
|
|
9
10
|
out_height = NUM2INT(out_h);
|
|
10
|
-
|
|
11
|
-
ret =
|
|
11
|
+
oil_fix_ratio(NUM2INT(src_w), NUM2INT(src_h), &out_width, &out_height);
|
|
12
|
+
ret = rb_ary_new_capa(2);
|
|
12
13
|
rb_ary_push(ret, INT2FIX(out_width));
|
|
13
14
|
rb_ary_push(ret, INT2FIX(out_height));
|
|
14
15
|
return ret;
|
|
@@ -20,6 +21,7 @@ void Init_png();
|
|
|
20
21
|
void Init_oil()
|
|
21
22
|
{
|
|
22
23
|
VALUE mOil;
|
|
24
|
+
oil_global_init();
|
|
23
25
|
mOil = rb_const_get(rb_cObject, rb_intern("Oil"));
|
|
24
26
|
rb_define_singleton_method(mOil, "fix_ratio", rb_fix_ratio, 4);
|
|
25
27
|
Init_jpeg();
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2014-2019 Timothy Elliott
|
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
* in the Software without restriction, including without limitation the rights
|
|
6
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
* furnished to do so, subject to the following conditions:
|
|
9
|
+
*
|
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
|
11
|
+
* all copies or substantial portions of the Software.
|
|
12
|
+
*
|
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
* THE SOFTWARE.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include "oil_libjpeg.h"
|
|
23
|
+
#include <stdlib.h>
|
|
24
|
+
|
|
25
|
+
int oil_libjpeg_init(struct oil_libjpeg *ol,
|
|
26
|
+
struct jpeg_decompress_struct *dinfo, int out_width, int out_height)
|
|
27
|
+
{
|
|
28
|
+
int ret;
|
|
29
|
+
enum oil_colorspace cs;
|
|
30
|
+
|
|
31
|
+
ol->dinfo = dinfo;
|
|
32
|
+
|
|
33
|
+
cs = jpeg_cs_to_oil(dinfo->out_color_space);
|
|
34
|
+
if (cs == OIL_CS_UNKNOWN) {
|
|
35
|
+
return -1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
ol->inbuf = malloc(dinfo->output_width * dinfo->output_components);
|
|
39
|
+
if (!ol->inbuf) {
|
|
40
|
+
return -2;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
ret = oil_scale_init(&ol->os, dinfo->output_height, out_height,
|
|
44
|
+
dinfo->output_width, out_width, cs);
|
|
45
|
+
if (ret!=0) {
|
|
46
|
+
free(ol->inbuf);
|
|
47
|
+
return ret;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void oil_libjpeg_free(struct oil_libjpeg *ol)
|
|
54
|
+
{
|
|
55
|
+
if (ol->inbuf) {
|
|
56
|
+
free(ol->inbuf);
|
|
57
|
+
}
|
|
58
|
+
oil_scale_free(&ol->os);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
int oil_libjpeg_proccess_scanline_part(struct oil_libjpeg *ol)
|
|
62
|
+
{
|
|
63
|
+
if (!oil_scale_slots(&ol->os)) {
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
jpeg_read_scanlines(ol->dinfo, &ol->inbuf, 1);
|
|
68
|
+
oil_scale_in(&ol->os, ol->inbuf);
|
|
69
|
+
return oil_scale_slots(&ol->os) == 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
void oil_libjpeg_read_scanline(struct oil_libjpeg *ol, unsigned char *outbuf)
|
|
73
|
+
{
|
|
74
|
+
while (oil_scale_slots(&ol->os)) {
|
|
75
|
+
jpeg_read_scanlines(ol->dinfo, &ol->inbuf, 1);
|
|
76
|
+
oil_scale_in(&ol->os, ol->inbuf);
|
|
77
|
+
}
|
|
78
|
+
oil_scale_out(&ol->os, outbuf);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
enum oil_colorspace jpeg_cs_to_oil(J_COLOR_SPACE cs)
|
|
82
|
+
{
|
|
83
|
+
switch(cs) {
|
|
84
|
+
case JCS_GRAYSCALE:
|
|
85
|
+
return OIL_CS_G;
|
|
86
|
+
case JCS_RGB:
|
|
87
|
+
return OIL_CS_RGB;
|
|
88
|
+
case JCS_CMYK:
|
|
89
|
+
return OIL_CS_CMYK;
|
|
90
|
+
#ifdef JCS_EXTENSIONS
|
|
91
|
+
case JCS_EXT_RGBX:
|
|
92
|
+
case JCS_EXT_BGRX:
|
|
93
|
+
return OIL_CS_RGBX;
|
|
94
|
+
#endif
|
|
95
|
+
default:
|
|
96
|
+
return OIL_CS_UNKNOWN;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
J_COLOR_SPACE oil_cs_to_jpeg(enum oil_colorspace cs)
|
|
101
|
+
{
|
|
102
|
+
switch(cs) {
|
|
103
|
+
case OIL_CS_G:
|
|
104
|
+
return JCS_GRAYSCALE;
|
|
105
|
+
case OIL_CS_RGB:
|
|
106
|
+
return JCS_RGB;
|
|
107
|
+
case OIL_CS_CMYK:
|
|
108
|
+
return JCS_CMYK;
|
|
109
|
+
default:
|
|
110
|
+
return JCS_UNKNOWN;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|