libjpeg-ruby 0.7.1 → 0.7.2
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/ext/jpeg/jpeg.c +481 -18
- data/lib/jpeg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f282952f089529770d21cff48005d0f9bb3c6b2e5de455bcf0d790c534352f96
|
4
|
+
data.tar.gz: 8e108130fd9a5c5fcf2b1fbdd63f3920ab17e37a1d0713abc9b38ac85dc33d19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70a9a93564144bfd271139316ef2b1b3456516d92b860d7bcf4574503b5393b9d228194948a7651ff53b7e970384ab228a29cac29516082862e06d20e9d5fefd
|
7
|
+
data.tar.gz: df0519c734dd9e1083e29407224fd2cb65a24e9532e90d7f83792179e23a79176c3196b968454f0864baf64e64606561ea2181837fce67936cd1f4568803d1bc
|
data/ext/jpeg/jpeg.c
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
#define SET_FLAG(ptr, msk) ((ptr)->flags |= (msk))
|
35
35
|
#define CLR_FLAG(ptr, msk) ((ptr)->flags &= ~(msk))
|
36
36
|
#define TEST_FLAG(ptr, msk) ((ptr)->flags & (msk))
|
37
|
-
#define TEST_FLAG_ALL(ptr, msk) (((ptr)->flags & (msk)) == msk)
|
37
|
+
#define TEST_FLAG_ALL(ptr, msk) (((ptr)->flags & (msk)) == (msk))
|
38
38
|
|
39
39
|
#define FMT_YUV422 1
|
40
40
|
#define FMT_RGB565 2
|
@@ -50,6 +50,8 @@
|
|
50
50
|
#define JPEG_APP1 0xe1 /* Exif marker */
|
51
51
|
|
52
52
|
#define N(x) (sizeof(x)/sizeof(*x))
|
53
|
+
#define SWAP(a,b,t) \
|
54
|
+
do {t c; c = (a); (a) = (b); (b) = c;} while (0)
|
53
55
|
|
54
56
|
#define RUNTIME_ERROR(msg) rb_raise(rb_eRuntimeError, (msg))
|
55
57
|
#define ARGUMENT_ERROR(msg) rb_raise(rb_eArgError, (msg))
|
@@ -254,7 +256,8 @@ static const char* encoder_opts_keys[] = {
|
|
254
256
|
"pixel_format", // {str}
|
255
257
|
"quality", // {integer}
|
256
258
|
"scale", // {rational} or {float}
|
257
|
-
"dct_method"
|
259
|
+
"dct_method", // {str}
|
260
|
+
"orientation" // {integer}
|
258
261
|
};
|
259
262
|
|
260
263
|
static ID encoder_opts_ids[N(encoder_opts_keys)];
|
@@ -272,6 +275,8 @@ typedef struct {
|
|
272
275
|
|
273
276
|
JSAMPARRAY array;
|
274
277
|
JSAMPROW rows;
|
278
|
+
|
279
|
+
int orientation;
|
275
280
|
} jpeg_encode_t;
|
276
281
|
|
277
282
|
static const char* decoder_opts_keys[] = {
|
@@ -306,7 +311,6 @@ typedef struct {
|
|
306
311
|
typedef struct {
|
307
312
|
int flags;
|
308
313
|
int format;
|
309
|
-
int orientation;
|
310
314
|
|
311
315
|
J_COLOR_SPACE out_color_space;
|
312
316
|
int scale_num;
|
@@ -327,6 +331,11 @@ typedef struct {
|
|
327
331
|
|
328
332
|
struct jpeg_decompress_struct cinfo;
|
329
333
|
ext_error_t err_mgr;
|
334
|
+
|
335
|
+
struct {
|
336
|
+
int value;
|
337
|
+
VALUE buf;
|
338
|
+
} orientation;
|
330
339
|
} jpeg_decode_t;
|
331
340
|
|
332
341
|
|
@@ -413,8 +422,6 @@ rb_encoder_alloc(VALUE self)
|
|
413
422
|
ptr = ALLOC(jpeg_encode_t);
|
414
423
|
memset(ptr, 0, sizeof(*ptr));
|
415
424
|
|
416
|
-
ptr->dct_method = JDCT_FASTEST;
|
417
|
-
|
418
425
|
return Data_Wrap_Struct(encoder_klass, 0, rb_encoder_free, ptr);
|
419
426
|
}
|
420
427
|
|
@@ -560,6 +567,25 @@ set_encoder_context(jpeg_encode_t* ptr, int wd, int ht, VALUE opt)
|
|
560
567
|
ARGUMENT_ERROR("Unsupportd :dct_method option value.");
|
561
568
|
}
|
562
569
|
|
570
|
+
/*
|
571
|
+
* eval orientation option
|
572
|
+
*/
|
573
|
+
switch (TYPE(opts[4])) {
|
574
|
+
case T_UNDEF:
|
575
|
+
ptr->orientation = 0;
|
576
|
+
break;
|
577
|
+
|
578
|
+
case T_FIXNUM:
|
579
|
+
ptr->orientation = FIX2INT(opts[4]);
|
580
|
+
if (ptr->orientation < 1 || ptr->orientation > 8) {
|
581
|
+
RANGE_ERROR("orientation is ouf range");
|
582
|
+
}
|
583
|
+
break;
|
584
|
+
|
585
|
+
default:
|
586
|
+
ARGUMENT_ERROR("Unsupportd :orientation option value.");
|
587
|
+
}
|
588
|
+
|
563
589
|
/*
|
564
590
|
* set context
|
565
591
|
*/
|
@@ -761,6 +787,34 @@ push_rows(jpeg_encode_t* ptr, uint8_t* data, int nrow)
|
|
761
787
|
return ret;
|
762
788
|
}
|
763
789
|
|
790
|
+
static void
|
791
|
+
put_exif_tags(jpeg_encode_t* ptr)
|
792
|
+
{
|
793
|
+
uint8_t data[] = {
|
794
|
+
/* Exif header */
|
795
|
+
'E', 'x', 'i', 'f', 0x00, 0x00,
|
796
|
+
'M', 'M',
|
797
|
+
0x00, 0x2a,
|
798
|
+
0x00, 0x00, 0x00, 0x08,
|
799
|
+
0x00, 0x01,
|
800
|
+
|
801
|
+
/* orieatation */
|
802
|
+
0x01, 0x12,
|
803
|
+
0x00, 0x03,
|
804
|
+
0x00, 0x00, 0x00, 0x01,
|
805
|
+
0x00, 0x00,
|
806
|
+
0x00, 0x00,
|
807
|
+
|
808
|
+
/* end mark */
|
809
|
+
0x00, 0x00, 0x00, 0x00,
|
810
|
+
};
|
811
|
+
|
812
|
+
data[24] = (ptr->orientation >> 8) & 0xff;
|
813
|
+
data[25] = (ptr->orientation >> 0) & 0xff;
|
814
|
+
|
815
|
+
jpeg_write_marker(&ptr->cinfo, JPEG_APP1, data, sizeof(data));
|
816
|
+
}
|
817
|
+
|
764
818
|
static VALUE
|
765
819
|
do_encode(jpeg_encode_t* ptr, uint8_t* data)
|
766
820
|
{
|
@@ -772,11 +826,14 @@ do_encode(jpeg_encode_t* ptr, uint8_t* data)
|
|
772
826
|
|
773
827
|
buf = NULL;
|
774
828
|
|
775
|
-
|
776
829
|
jpeg_mem_dest(&ptr->cinfo, &buf, &buf_size);
|
777
830
|
|
778
831
|
jpeg_start_compress(&ptr->cinfo, TRUE);
|
779
832
|
|
833
|
+
if (ptr->orientation != 0) {
|
834
|
+
put_exif_tags(ptr);
|
835
|
+
}
|
836
|
+
|
780
837
|
while (ptr->cinfo.next_scanline < ptr->cinfo.image_height) {
|
781
838
|
nrow = ptr->cinfo.image_height - ptr->cinfo.next_scanline;
|
782
839
|
if (nrow > UNIT_LINES) nrow = UNIT_LINES;
|
@@ -904,7 +961,6 @@ rb_decoder_alloc(VALUE self)
|
|
904
961
|
|
905
962
|
ptr->flags = DEFAULT_FLAGS;
|
906
963
|
ptr->format = FMT_RGB;
|
907
|
-
ptr->orientation = 0;
|
908
964
|
|
909
965
|
ptr->out_color_space = JCS_RGB;
|
910
966
|
|
@@ -924,6 +980,9 @@ rb_decoder_alloc(VALUE self)
|
|
924
980
|
ptr->enable_external_quant = FALSE;
|
925
981
|
ptr->enable_2pass_quant = FALSE;
|
926
982
|
|
983
|
+
ptr->orientation.value = 0;
|
984
|
+
ptr->orientation.buf = Qnil;
|
985
|
+
|
927
986
|
return Data_Wrap_Struct(decoder_klass, 0, rb_decoder_free, ptr);
|
928
987
|
}
|
929
988
|
|
@@ -2116,9 +2175,7 @@ pick_exif_orientation(jpeg_decode_t* ptr)
|
|
2116
2175
|
}
|
2117
2176
|
loop_out:
|
2118
2177
|
|
2119
|
-
|
2120
|
-
ptr->orientation = o9n;
|
2121
|
-
}
|
2178
|
+
ptr->orientation.value = (o9n >= 1 && o9n <= 8)? (o9n - 1): 0;
|
2122
2179
|
}
|
2123
2180
|
|
2124
2181
|
static VALUE
|
@@ -2175,15 +2232,27 @@ create_meta(jpeg_decode_t* ptr)
|
|
2175
2232
|
{
|
2176
2233
|
VALUE ret;
|
2177
2234
|
struct jpeg_decompress_struct* cinfo;
|
2235
|
+
int width;
|
2236
|
+
int height;
|
2178
2237
|
int stride;
|
2179
2238
|
|
2180
2239
|
ret = rb_obj_alloc(meta_klass);
|
2181
2240
|
cinfo = &ptr->cinfo;
|
2241
|
+
|
2242
|
+
if (TEST_FLAG(ptr, F_APPLY_ORIENTATION) && (ptr->orientation.value & 4)) {
|
2243
|
+
width = cinfo->output_height;
|
2244
|
+
height = cinfo->output_width;
|
2245
|
+
} else {
|
2246
|
+
width = cinfo->output_width;
|
2247
|
+
height = cinfo->output_height;
|
2248
|
+
}
|
2249
|
+
|
2182
2250
|
stride = cinfo->output_width * cinfo->output_components;
|
2183
2251
|
|
2184
|
-
rb_ivar_set(ret, id_width, INT2FIX(
|
2252
|
+
rb_ivar_set(ret, id_width, INT2FIX(width));
|
2185
2253
|
rb_ivar_set(ret, id_stride, INT2FIX(stride));
|
2186
|
-
rb_ivar_set(ret, id_height, INT2FIX(
|
2254
|
+
rb_ivar_set(ret, id_height, INT2FIX(height));
|
2255
|
+
|
2187
2256
|
rb_ivar_set(ret, id_orig_cs, get_colorspace_str(cinfo->jpeg_color_space));
|
2188
2257
|
|
2189
2258
|
if (ptr->format == FMT_YVU) {
|
@@ -2198,10 +2267,6 @@ create_meta(jpeg_decode_t* ptr)
|
|
2198
2267
|
rb_ivar_set(ret, id_ncompo, INT2FIX(cinfo->output_components));
|
2199
2268
|
}
|
2200
2269
|
|
2201
|
-
if (TEST_FLAG(ptr, F_APPLY_ORIENTATION)) {
|
2202
|
-
pick_exif_orientation(ptr);
|
2203
|
-
}
|
2204
|
-
|
2205
2270
|
if (TEST_FLAG(ptr, F_PARSE_EXIF)) {
|
2206
2271
|
rb_ivar_set(ret, id_exif_tags, create_exif_tags_hash(ptr));
|
2207
2272
|
rb_define_singleton_method(ret, "exif_tags", rb_meta_exif_tags, 0);
|
@@ -2375,9 +2440,406 @@ swap_cbcr(uint8_t* p, size_t size)
|
|
2375
2440
|
}
|
2376
2441
|
}
|
2377
2442
|
|
2443
|
+
static void
|
2444
|
+
do_transpose8(uint8_t* img, int wd, int ht, void* dst)
|
2445
|
+
{
|
2446
|
+
int x;
|
2447
|
+
int y;
|
2448
|
+
|
2449
|
+
uint8_t* sp;
|
2450
|
+
uint8_t* dp;
|
2451
|
+
|
2452
|
+
sp = (uint8_t*)img;
|
2453
|
+
|
2454
|
+
for (y = 0; y < ht; y++) {
|
2455
|
+
dp = (uint8_t*)dst + y;
|
2456
|
+
|
2457
|
+
for (x = 0; x < wd; x++) {
|
2458
|
+
*dp = *sp;
|
2459
|
+
|
2460
|
+
sp++;
|
2461
|
+
dp += ht;
|
2462
|
+
}
|
2463
|
+
}
|
2464
|
+
}
|
2465
|
+
|
2466
|
+
static void
|
2467
|
+
do_transpose16(void* img, int wd, int ht, void* dst)
|
2468
|
+
{
|
2469
|
+
int x;
|
2470
|
+
int y;
|
2471
|
+
|
2472
|
+
uint16_t* sp;
|
2473
|
+
uint16_t* dp;
|
2474
|
+
|
2475
|
+
sp = (uint16_t*)img;
|
2476
|
+
|
2477
|
+
for (y = 0; y < ht; y++) {
|
2478
|
+
dp = (uint16_t*)dst + y;
|
2479
|
+
|
2480
|
+
for (x = 0; x < wd; x++) {
|
2481
|
+
*dp = *sp;
|
2482
|
+
|
2483
|
+
sp++;
|
2484
|
+
dp += ht;
|
2485
|
+
}
|
2486
|
+
}
|
2487
|
+
}
|
2488
|
+
|
2489
|
+
static void
|
2490
|
+
do_transpose24(void* img, int wd, int ht, void* dst)
|
2491
|
+
{
|
2492
|
+
int x;
|
2493
|
+
int y;
|
2494
|
+
int st;
|
2495
|
+
|
2496
|
+
uint8_t* sp;
|
2497
|
+
uint8_t* dp;
|
2498
|
+
|
2499
|
+
sp = (uint8_t*)img;
|
2500
|
+
st = ht * 3;
|
2501
|
+
|
2502
|
+
for (y = 0; y < ht; y++) {
|
2503
|
+
dp = (uint8_t*)dst + (y * 3);
|
2504
|
+
|
2505
|
+
for (x = 0; x < wd; x++) {
|
2506
|
+
dp[0] = sp[0];
|
2507
|
+
dp[1] = sp[1];
|
2508
|
+
dp[2] = sp[2];
|
2509
|
+
|
2510
|
+
sp += 3;
|
2511
|
+
dp += st;
|
2512
|
+
}
|
2513
|
+
}
|
2514
|
+
}
|
2515
|
+
|
2516
|
+
static void
|
2517
|
+
do_transpose32(void* img, int wd, int ht, void* dst)
|
2518
|
+
{
|
2519
|
+
int x;
|
2520
|
+
int y;
|
2521
|
+
|
2522
|
+
uint32_t* sp;
|
2523
|
+
uint32_t* dp;
|
2524
|
+
|
2525
|
+
sp = (uint32_t*)img;
|
2526
|
+
|
2527
|
+
for (y = 0; y < ht; y++) {
|
2528
|
+
dp = (uint32_t*)dst + y;
|
2529
|
+
|
2530
|
+
for (x = 0; x < wd; x++) {
|
2531
|
+
*dp = *sp;
|
2532
|
+
|
2533
|
+
sp++;
|
2534
|
+
dp += ht;
|
2535
|
+
}
|
2536
|
+
}
|
2537
|
+
}
|
2538
|
+
|
2539
|
+
static void
|
2540
|
+
do_transpose(void* img, int wd, int ht, int nc, void* dst)
|
2541
|
+
{
|
2542
|
+
switch (nc) {
|
2543
|
+
case 1:
|
2544
|
+
do_transpose8(img, wd, ht, dst);
|
2545
|
+
break;
|
2546
|
+
|
2547
|
+
case 2:
|
2548
|
+
do_transpose16(img, wd, ht, dst);
|
2549
|
+
break;
|
2550
|
+
|
2551
|
+
case 3:
|
2552
|
+
do_transpose24(img, wd, ht, dst);
|
2553
|
+
break;
|
2554
|
+
|
2555
|
+
case 4:
|
2556
|
+
do_transpose32(img, wd, ht, dst);
|
2557
|
+
break;
|
2558
|
+
}
|
2559
|
+
}
|
2560
|
+
|
2561
|
+
static void
|
2562
|
+
do_upside_down8(void* img, int wd, int ht)
|
2563
|
+
{
|
2564
|
+
uint8_t* sp;
|
2565
|
+
uint8_t* dp;
|
2566
|
+
|
2567
|
+
sp = (uint8_t*)img;
|
2568
|
+
dp = (uint8_t*)img + ((wd * ht) - 1);
|
2569
|
+
|
2570
|
+
while (sp < dp) {
|
2571
|
+
SWAP(*sp, *dp, uint8_t);
|
2572
|
+
|
2573
|
+
sp++;
|
2574
|
+
dp--;
|
2575
|
+
}
|
2576
|
+
}
|
2577
|
+
|
2578
|
+
static void
|
2579
|
+
do_upside_down16(void* img, int wd, int ht)
|
2580
|
+
{
|
2581
|
+
uint16_t* sp;
|
2582
|
+
uint16_t* dp;
|
2583
|
+
|
2584
|
+
sp = (uint16_t*)img;
|
2585
|
+
dp = (uint16_t*)img + ((wd * ht) - 1);
|
2586
|
+
|
2587
|
+
while (sp < dp) {
|
2588
|
+
SWAP(*sp, *dp, uint8_t);
|
2589
|
+
|
2590
|
+
sp++;
|
2591
|
+
dp--;
|
2592
|
+
}
|
2593
|
+
}
|
2594
|
+
|
2595
|
+
static void
|
2596
|
+
do_upside_down24(void* img, int wd, int ht)
|
2597
|
+
{
|
2598
|
+
uint8_t* sp;
|
2599
|
+
uint8_t* dp;
|
2600
|
+
|
2601
|
+
sp = (uint8_t*)img;
|
2602
|
+
dp = (uint8_t*)img + ((wd * ht * 3) - 3);
|
2603
|
+
|
2604
|
+
while (sp < dp) {
|
2605
|
+
SWAP(sp[0], dp[0], uint8_t);
|
2606
|
+
SWAP(sp[1], dp[1], uint8_t);
|
2607
|
+
SWAP(sp[2], dp[2], uint8_t);
|
2608
|
+
|
2609
|
+
sp += 3;
|
2610
|
+
dp -= 3;
|
2611
|
+
}
|
2612
|
+
}
|
2613
|
+
|
2614
|
+
static void
|
2615
|
+
do_upside_down32(void* img, int wd, int ht)
|
2616
|
+
{
|
2617
|
+
uint32_t* sp;
|
2618
|
+
uint32_t* dp;
|
2619
|
+
|
2620
|
+
sp = (uint32_t*)img;
|
2621
|
+
dp = (uint32_t*)img + ((wd * ht) - 1);
|
2622
|
+
|
2623
|
+
ht /= 2;
|
2624
|
+
|
2625
|
+
while (sp < dp) {
|
2626
|
+
SWAP(*sp, *dp, uint32_t);
|
2627
|
+
|
2628
|
+
sp++;
|
2629
|
+
dp--;
|
2630
|
+
}
|
2631
|
+
}
|
2632
|
+
|
2633
|
+
static void
|
2634
|
+
do_upside_down(void* img, int wd, int ht, int nc)
|
2635
|
+
{
|
2636
|
+
switch (nc) {
|
2637
|
+
case 1:
|
2638
|
+
do_upside_down8(img, wd, ht);
|
2639
|
+
break;
|
2640
|
+
|
2641
|
+
case 2:
|
2642
|
+
do_upside_down16(img, wd, ht);
|
2643
|
+
break;
|
2644
|
+
|
2645
|
+
case 3:
|
2646
|
+
do_upside_down24(img, wd, ht);
|
2647
|
+
break;
|
2648
|
+
|
2649
|
+
case 4:
|
2650
|
+
do_upside_down32(img, wd, ht);
|
2651
|
+
break;
|
2652
|
+
}
|
2653
|
+
}
|
2654
|
+
|
2655
|
+
static void
|
2656
|
+
do_flip_horizon8(void* img, int wd, int ht)
|
2657
|
+
{
|
2658
|
+
int y;
|
2659
|
+
int st;
|
2660
|
+
|
2661
|
+
uint8_t* sp;
|
2662
|
+
uint8_t* dp;
|
2663
|
+
|
2664
|
+
st = wd;
|
2665
|
+
wd /= 2;
|
2666
|
+
|
2667
|
+
sp = (uint8_t*)img;
|
2668
|
+
dp = (uint8_t*)img + (st - 1);
|
2669
|
+
|
2670
|
+
for (y = 0; y < ht; y++) {
|
2671
|
+
while (sp < dp) {
|
2672
|
+
SWAP(*sp, *dp, uint8_t);
|
2673
|
+
|
2674
|
+
sp++;
|
2675
|
+
dp--;
|
2676
|
+
}
|
2677
|
+
|
2678
|
+
sp = sp - wd + st;
|
2679
|
+
dp = sp + (st - 1);
|
2680
|
+
}
|
2681
|
+
}
|
2682
|
+
|
2683
|
+
static void
|
2684
|
+
do_flip_horizon16(void* img, int wd, int ht)
|
2685
|
+
{
|
2686
|
+
int y;
|
2687
|
+
int st;
|
2688
|
+
|
2689
|
+
uint16_t* sp;
|
2690
|
+
uint16_t* dp;
|
2691
|
+
|
2692
|
+
st = wd;
|
2693
|
+
wd /= 2;
|
2694
|
+
|
2695
|
+
sp = (uint16_t*)img;
|
2696
|
+
dp = (uint16_t*)img + (st - 1);
|
2697
|
+
|
2698
|
+
for (y = 0; y < ht; y++) {
|
2699
|
+
while (sp < dp) {
|
2700
|
+
SWAP(*sp, *dp, uint16_t);
|
2701
|
+
|
2702
|
+
sp++;
|
2703
|
+
dp--;
|
2704
|
+
}
|
2705
|
+
|
2706
|
+
sp = sp - wd + st;
|
2707
|
+
dp = sp + (st - 1);
|
2708
|
+
}
|
2709
|
+
}
|
2710
|
+
|
2711
|
+
static void
|
2712
|
+
do_flip_horizon24(void* img, int wd, int ht)
|
2713
|
+
{
|
2714
|
+
int y;
|
2715
|
+
int st;
|
2716
|
+
|
2717
|
+
uint8_t* sp;
|
2718
|
+
uint8_t* dp;
|
2719
|
+
|
2720
|
+
st = wd * 3;
|
2721
|
+
wd /= 2;
|
2722
|
+
|
2723
|
+
sp = (uint8_t*)img;
|
2724
|
+
dp = (uint8_t*)img + (st - 3);
|
2725
|
+
|
2726
|
+
for (y = 0; y < ht; y++) {
|
2727
|
+
while (sp < dp) {
|
2728
|
+
SWAP(sp[0], dp[0], uint8_t);
|
2729
|
+
SWAP(sp[1], dp[1], uint8_t);
|
2730
|
+
SWAP(sp[2], dp[2], uint8_t);
|
2731
|
+
|
2732
|
+
sp += 3;
|
2733
|
+
dp -= 3;
|
2734
|
+
}
|
2735
|
+
|
2736
|
+
sp = (sp - (wd * 3)) + st;
|
2737
|
+
dp = sp + (st - 3);
|
2738
|
+
}
|
2739
|
+
}
|
2740
|
+
|
2741
|
+
static void
|
2742
|
+
do_flip_horizon32(void* img, int wd, int ht)
|
2743
|
+
{
|
2744
|
+
int y;
|
2745
|
+
int st;
|
2746
|
+
|
2747
|
+
uint32_t* sp;
|
2748
|
+
uint32_t* dp;
|
2749
|
+
|
2750
|
+
st = wd;
|
2751
|
+
wd /= 2;
|
2752
|
+
|
2753
|
+
sp = (uint32_t*)img;
|
2754
|
+
dp = (uint32_t*)img + (st - 1);
|
2755
|
+
|
2756
|
+
for (y = 0; y < ht; y++) {
|
2757
|
+
while (sp < dp) {
|
2758
|
+
SWAP(*sp, *dp, uint32_t);
|
2759
|
+
|
2760
|
+
sp++;
|
2761
|
+
dp--;
|
2762
|
+
}
|
2763
|
+
|
2764
|
+
sp = sp - wd + st;
|
2765
|
+
dp = sp + (st - 1);
|
2766
|
+
}
|
2767
|
+
}
|
2768
|
+
|
2769
|
+
static void
|
2770
|
+
do_flip_horizon(void* img, int wd, int ht, int nc)
|
2771
|
+
{
|
2772
|
+
switch (nc) {
|
2773
|
+
case 1:
|
2774
|
+
do_flip_horizon8(img, wd, ht);
|
2775
|
+
break;
|
2776
|
+
|
2777
|
+
case 2:
|
2778
|
+
do_flip_horizon16(img, wd, ht);
|
2779
|
+
break;
|
2780
|
+
|
2781
|
+
case 3:
|
2782
|
+
do_flip_horizon24(img, wd, ht);
|
2783
|
+
break;
|
2784
|
+
|
2785
|
+
case 4:
|
2786
|
+
do_flip_horizon32(img, wd, ht);
|
2787
|
+
break;
|
2788
|
+
}
|
2789
|
+
}
|
2790
|
+
|
2791
|
+
static VALUE
|
2792
|
+
shift_orientation_buffer(jpeg_decode_t* ptr, VALUE img)
|
2793
|
+
{
|
2794
|
+
VALUE ret;
|
2795
|
+
int len;
|
2796
|
+
|
2797
|
+
ret = ptr->orientation.buf;
|
2798
|
+
len = RSTRING_LEN(img);
|
2799
|
+
|
2800
|
+
if (ret == Qnil || RSTRING_LEN(ret) != len) {
|
2801
|
+
ret = rb_str_buf_new(len);
|
2802
|
+
rb_str_set_len(ret, len);
|
2803
|
+
}
|
2804
|
+
|
2805
|
+
ptr->orientation.buf = img;
|
2806
|
+
|
2807
|
+
return ret;
|
2808
|
+
}
|
2809
|
+
|
2378
2810
|
static VALUE
|
2379
2811
|
apply_orientation(jpeg_decode_t* ptr, VALUE img)
|
2380
2812
|
{
|
2813
|
+
struct jpeg_decompress_struct* cinfo;
|
2814
|
+
int wd;
|
2815
|
+
int ht;
|
2816
|
+
int nc;
|
2817
|
+
VALUE tmp;
|
2818
|
+
|
2819
|
+
cinfo = &ptr->cinfo;
|
2820
|
+
wd = cinfo->output_width;
|
2821
|
+
ht = cinfo->output_height;
|
2822
|
+
nc = cinfo->output_components;
|
2823
|
+
|
2824
|
+
if (ptr->orientation.value & 4) {
|
2825
|
+
/* 転置は交換アルゴリズムでは実装できないので新規バッファを
|
2826
|
+
用意する */
|
2827
|
+
tmp = img;
|
2828
|
+
img = shift_orientation_buffer(ptr, tmp);
|
2829
|
+
SWAP(wd, ht, int);
|
2830
|
+
|
2831
|
+
do_transpose(RSTRING_PTR(tmp), ht, wd, nc, RSTRING_PTR(img));
|
2832
|
+
}
|
2833
|
+
|
2834
|
+
if (ptr->orientation.value & 2) {
|
2835
|
+
do_upside_down(RSTRING_PTR(img), wd, ht, nc);
|
2836
|
+
}
|
2837
|
+
|
2838
|
+
if (ptr->orientation.value & 1) {
|
2839
|
+
do_flip_horizon(RSTRING_PTR(img), wd, ht, nc);
|
2840
|
+
}
|
2841
|
+
|
2842
|
+
return img;
|
2381
2843
|
}
|
2382
2844
|
|
2383
2845
|
static VALUE
|
@@ -2475,12 +2937,13 @@ do_decode(jpeg_decode_t* ptr, uint8_t* jpg, size_t jpg_sz)
|
|
2475
2937
|
|
2476
2938
|
if (ptr->format == FMT_YVU) swap_cbcr(raw, raw_sz);
|
2477
2939
|
|
2478
|
-
if (TEST_FLAG(ptr, F_NEED_META)) add_meta(ret, ptr);
|
2479
|
-
|
2480
2940
|
if (TEST_FLAG(ptr, F_APPLY_ORIENTATION)) {
|
2941
|
+
pick_exif_orientation(ptr);
|
2481
2942
|
ret = apply_orientation(ptr, ret);
|
2482
2943
|
}
|
2483
2944
|
|
2945
|
+
if (TEST_FLAG(ptr, F_NEED_META)) add_meta(ret, ptr);
|
2946
|
+
|
2484
2947
|
jpeg_finish_decompress(cinfo);
|
2485
2948
|
jpeg_destroy_decompress(&ptr->cinfo);
|
2486
2949
|
}
|
data/lib/jpeg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libjpeg-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Kuwagata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|