oil 0.2.1 → 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/README.rdoc +0 -5
- data/Rakefile +1 -29
- data/ext/oil/jpeg.c +65 -48
- data/ext/oil/oil.c +2 -1
- data/ext/oil/oil_libjpeg.c +12 -3
- data/ext/oil/oil_libjpeg.h +1 -0
- data/ext/oil/oil_libpng.c +24 -11
- data/ext/oil/oil_libpng.h +1 -0
- data/ext/oil/oil_resample.c +1003 -540
- data/ext/oil/oil_resample.h +63 -23
- data/ext/oil/oil_resample_internal.h +59 -0
- data/ext/oil/oil_resample_sse2.c +1930 -0
- data/ext/oil/png.c +26 -19
- 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 +14 -9
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/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,35 +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/oil_resample.c
|
|
21
|
-
ext/oil/oil_resample.h
|
|
22
|
-
ext/oil/oil_libjpeg.c
|
|
23
|
-
ext/oil/oil_libjpeg.h
|
|
24
|
-
ext/oil/oil_libpng.c
|
|
25
|
-
ext/oil/oil_libpng.h
|
|
26
|
-
ext/oil/jpeg.c
|
|
27
|
-
ext/oil/png.c
|
|
28
|
-
ext/oil/oil.c
|
|
29
|
-
ext/oil/extconf.rb
|
|
30
|
-
test/helper.rb
|
|
31
|
-
test/test_jpeg.rb
|
|
32
|
-
test/test_png.rb
|
|
33
|
-
}
|
|
34
|
-
s.homepage = 'http://github.com/ender672/oil'
|
|
35
|
-
s.extensions << 'ext/oil/extconf.rb'
|
|
36
|
-
s.extra_rdoc_files = ['README.rdoc']
|
|
37
|
-
end
|
|
9
|
+
s = Gem::Specification.load('oil.gemspec')
|
|
38
10
|
|
|
39
11
|
Gem::PackageTask.new(s){}
|
|
40
12
|
|
data/ext/oil/jpeg.c
CHANGED
|
@@ -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;
|
|
@@ -839,7 +856,7 @@ static VALUE each(int argc, VALUE *argv, VALUE self)
|
|
|
839
856
|
|
|
840
857
|
rb_scan_args(argc, argv, "01", &opts);
|
|
841
858
|
|
|
842
|
-
|
|
859
|
+
TypedData_Get_Struct(self, struct readerdata, &jpeg_reader_type, reader);
|
|
843
860
|
|
|
844
861
|
if (!reader->scale_width) {
|
|
845
862
|
reader->scale_width = reader->dinfo.output_width;
|
data/ext/oil/oil.c
CHANGED
|
@@ -9,7 +9,7 @@ static VALUE rb_fix_ratio(VALUE self, VALUE src_w, VALUE src_h, VALUE out_w, VAL
|
|
|
9
9
|
out_width = NUM2INT(out_w);
|
|
10
10
|
out_height = NUM2INT(out_h);
|
|
11
11
|
oil_fix_ratio(NUM2INT(src_w), NUM2INT(src_h), &out_width, &out_height);
|
|
12
|
-
ret =
|
|
12
|
+
ret = rb_ary_new_capa(2);
|
|
13
13
|
rb_ary_push(ret, INT2FIX(out_width));
|
|
14
14
|
rb_ary_push(ret, INT2FIX(out_height));
|
|
15
15
|
return ret;
|
|
@@ -21,6 +21,7 @@ void Init_png();
|
|
|
21
21
|
void Init_oil()
|
|
22
22
|
{
|
|
23
23
|
VALUE mOil;
|
|
24
|
+
oil_global_init();
|
|
24
25
|
mOil = rb_const_get(rb_cObject, rb_intern("Oil"));
|
|
25
26
|
rb_define_singleton_method(mOil, "fix_ratio", rb_fix_ratio, 4);
|
|
26
27
|
Init_jpeg();
|
data/ext/oil/oil_libjpeg.c
CHANGED
|
@@ -58,11 +58,20 @@ void oil_libjpeg_free(struct oil_libjpeg *ol)
|
|
|
58
58
|
oil_scale_free(&ol->os);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
int oil_libjpeg_proccess_scanline_part(struct oil_libjpeg *ol)
|
|
62
62
|
{
|
|
63
|
-
|
|
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
|
+
}
|
|
64
71
|
|
|
65
|
-
|
|
72
|
+
void oil_libjpeg_read_scanline(struct oil_libjpeg *ol, unsigned char *outbuf)
|
|
73
|
+
{
|
|
74
|
+
while (oil_scale_slots(&ol->os)) {
|
|
66
75
|
jpeg_read_scanlines(ol->dinfo, &ol->inbuf, 1);
|
|
67
76
|
oil_scale_in(&ol->os, ol->inbuf);
|
|
68
77
|
}
|
data/ext/oil/oil_libjpeg.h
CHANGED
|
@@ -49,6 +49,7 @@ int oil_libjpeg_init(struct oil_libjpeg *ol,
|
|
|
49
49
|
void oil_libjpeg_free(struct oil_libjpeg *ol);
|
|
50
50
|
|
|
51
51
|
void oil_libjpeg_read_scanline(struct oil_libjpeg *ol, unsigned char *outbuf);
|
|
52
|
+
int oil_libjpeg_proccess_scanline_part(struct oil_libjpeg *ol);
|
|
52
53
|
|
|
53
54
|
enum oil_colorspace jpeg_cs_to_oil(J_COLOR_SPACE cs);
|
|
54
55
|
|
data/ext/oil/oil_libpng.c
CHANGED
|
@@ -34,7 +34,7 @@ static unsigned char **alloc_full_image_buf(int height, int rowbytes)
|
|
|
34
34
|
for (i=0; i<height; i++) {
|
|
35
35
|
imgbuf[i] = malloc(rowbytes);
|
|
36
36
|
if (!imgbuf[i]) {
|
|
37
|
-
for (j=0; j<i
|
|
37
|
+
for (j=0; j<i; j++) {
|
|
38
38
|
free(imgbuf[j]);
|
|
39
39
|
}
|
|
40
40
|
free(imgbuf);
|
|
@@ -75,7 +75,6 @@ int oil_libpng_init(struct oil_libpng *ol, png_structp rpng, png_infop rinfo,
|
|
|
75
75
|
ret = oil_scale_init(&ol->os, in_height, out_height, in_width,
|
|
76
76
|
out_width, cs);
|
|
77
77
|
if (ret!=0) {
|
|
78
|
-
free(ol->inbuf);
|
|
79
78
|
return ret;
|
|
80
79
|
}
|
|
81
80
|
|
|
@@ -112,33 +111,47 @@ void oil_libpng_free(struct oil_libpng *ol)
|
|
|
112
111
|
oil_scale_free(&ol->os);
|
|
113
112
|
}
|
|
114
113
|
|
|
115
|
-
static void read_scanline_interlaced(struct oil_libpng *ol
|
|
114
|
+
static void read_scanline_interlaced(struct oil_libpng *ol)
|
|
116
115
|
{
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
for (i=oil_scale_slots(&ol->os); i>0; i--) {
|
|
116
|
+
while (oil_scale_slots(&ol->os)) {
|
|
120
117
|
oil_scale_in(&ol->os, ol->inimage[ol->in_vpos++]);
|
|
121
118
|
}
|
|
122
119
|
}
|
|
123
120
|
|
|
124
|
-
static void read_scanline(struct oil_libpng *ol
|
|
121
|
+
static void read_scanline(struct oil_libpng *ol)
|
|
125
122
|
{
|
|
126
|
-
|
|
123
|
+
while (oil_scale_slots(&ol->os)) {
|
|
124
|
+
png_read_row(ol->rpng, ol->inbuf, NULL);
|
|
125
|
+
oil_scale_in(&ol->os, ol->inbuf);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
127
128
|
|
|
128
|
-
|
|
129
|
+
int oil_libpng_proccess_scanline_part(struct oil_libpng *ol)
|
|
130
|
+
{
|
|
131
|
+
if (!oil_scale_slots(&ol->os)) {
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
switch (png_get_interlace_type(ol->rpng, ol->rinfo)) {
|
|
136
|
+
case PNG_INTERLACE_NONE:
|
|
129
137
|
png_read_row(ol->rpng, ol->inbuf, NULL);
|
|
130
138
|
oil_scale_in(&ol->os, ol->inbuf);
|
|
139
|
+
break;
|
|
140
|
+
case PNG_INTERLACE_ADAM7:
|
|
141
|
+
oil_scale_in(&ol->os, ol->inimage[ol->in_vpos++]);
|
|
142
|
+
break;
|
|
131
143
|
}
|
|
144
|
+
return oil_scale_slots(&ol->os) == 0;
|
|
132
145
|
}
|
|
133
146
|
|
|
134
147
|
void oil_libpng_read_scanline(struct oil_libpng *ol, unsigned char *outbuf)
|
|
135
148
|
{
|
|
136
149
|
switch (png_get_interlace_type(ol->rpng, ol->rinfo)) {
|
|
137
150
|
case PNG_INTERLACE_NONE:
|
|
138
|
-
read_scanline(ol
|
|
151
|
+
read_scanline(ol);
|
|
139
152
|
break;
|
|
140
153
|
case PNG_INTERLACE_ADAM7:
|
|
141
|
-
read_scanline_interlaced(ol
|
|
154
|
+
read_scanline_interlaced(ol);
|
|
142
155
|
break;
|
|
143
156
|
}
|
|
144
157
|
oil_scale_out(&ol->os, outbuf);
|
data/ext/oil/oil_libpng.h
CHANGED
|
@@ -52,6 +52,7 @@ int oil_libpng_init(struct oil_libpng *ol, png_structp rpng, png_infop rinfo,
|
|
|
52
52
|
void oil_libpng_free(struct oil_libpng *ol);
|
|
53
53
|
|
|
54
54
|
void oil_libpng_read_scanline(struct oil_libpng *ol, unsigned char *outbuf);
|
|
55
|
+
int oil_libpng_proccess_scanline_part(struct oil_libpng *ol);
|
|
55
56
|
|
|
56
57
|
enum oil_colorspace png_cs_to_oil(png_byte cs);
|
|
57
58
|
|