Skip to content

Commit 894708f

Browse files
committed
FEAT: using native system image codecs on macOS
1 parent 1a36060 commit 894708f

10 files changed

+534
-9
lines changed

make/rebol3.nest

+15-2
Original file line numberDiff line numberDiff line change
@@ -332,20 +332,33 @@ include-image-os-codec: [
332332
#if Windows? [
333333
config: INCLUDE_IMAGE_OS_CODEC
334334
host-files: %os/win32/host-image.c
335-
mezz-lib-files: %mezz/codec-image.reb
335+
mezz-lib-files: %mezz/codec-image-win.reb
336+
]
337+
#if MacOS? [
338+
config: INCLUDE_IMAGE_OS_CODEC
339+
host-files: [
340+
%os/osx/host-image.c
341+
%os/osx/sys-codecs.m
342+
%os/osx/sys-utils.c
343+
]
344+
frameworks: [CoreGraphics CoreImage ImageIO Foundation]
345+
mezz-lib-files: %mezz/codec-image-osx.reb
336346
]
337347
]
338348

339349
include-image-codecs: [
340350
#if Windows? [
341351
:include-image-os-codec
342352
]
343-
#if Posix? [
353+
#if Linux? [
344354
:include-native-bmp-codec
345355
:include-native-png-codec
346356
:include-native-jpg-codec
347357
:include-native-gif-codec
348358
]
359+
#if MacOS? [
360+
:include-image-os-codec
361+
]
349362
]
350363

351364
;- native devices:

src/core/n-image.c

+18-6
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ typedef struct REBCLR {
374374
// num [integer!] "1-based index of the image to receive"
375375
// /as "Used to define which codec should be used"
376376
// type [word!] "One of: [PNG JPEG JPEGXR BMP DDS GIF TIFF] read only: [DNG ICO HEIF]"
377-
// /scale
378-
// sc [pair! percent!]
377+
//; /scale
378+
//; sc [pair! percent!]
379379
// ]
380380
***********************************************************************/
381381
{
@@ -388,17 +388,16 @@ typedef struct REBCLR {
388388
REBVAL *val_frame = D_ARG(7);
389389
REBOOL ref_as = D_REF(8);
390390
REBVAL *val_type = D_ARG(9);
391-
REBOOL ref_scale = D_REF(10);
392-
REBVAL *val_scale = D_ARG(11);
391+
//REBOOL ref_scale = D_REF(10);
392+
//REBVAL *val_scale = D_ARG(11);
393393

394394
REBCDI codi;
395395
REBSER *ser = NULL;
396396
REBCNT frm = ref_frame ? VAL_INT32(val_frame) - 1 : 0;
397-
REBVAL *ret = D_RET;
398397
REBCNT length;
399398

400399

401-
#if defined(TO_WINDOWS) && defined(INCLUDE_IMAGE_OS_CODEC)
400+
#ifdef INCLUDE_IMAGE_OS_CODEC
402401
CLEARS(&codi);
403402
if (ref_as) {
404403
switch (VAL_WORD_CANON(val_type)) {
@@ -408,6 +407,7 @@ typedef struct REBCLR {
408407
case SYM_JPEGXR:
409408
case SYM_HDP:
410409
case SYM_JXR: codi.type = CODI_IMG_JXR; break;
410+
case SYM_JP2: codi.type = CODI_IMG_JP2; break;
411411
case SYM_BMP: codi.type = CODI_IMG_BMP; break;
412412
case SYM_GIF: codi.type = CODI_IMG_GIF; break;
413413
case SYM_DDS: codi.type = CODI_IMG_DDS; break;
@@ -423,7 +423,11 @@ typedef struct REBCLR {
423423
if (ref_load) {
424424

425425
if (IS_FILE(val_src_file)) {
426+
#ifdef TO_WINDOWS
426427
ser = Value_To_Local_Path(val_src_file, TRUE);
428+
#else
429+
ser = Value_To_OS_Path(val_src_file, TRUE);
430+
#endif
427431
} else {
428432
// raw binary data
429433
codi.data = VAL_BIN(val_src_file);
@@ -434,9 +438,11 @@ typedef struct REBCLR {
434438

435439
if(codi.error) {
436440
switch (codi.error) {
441+
#ifdef TO_WINDOWS
437442
case WINCODEC_ERR_COMPONENTNOTFOUND:
438443
Trap1(RE_NO_CODEC, val_type);
439444
break;
445+
#endif
440446
default:
441447
SET_INTEGER(D_RET, codi.error);
442448
if (IS_BINARY(val_src_file)) {
@@ -459,7 +465,11 @@ typedef struct REBCLR {
459465
codi.h = VAL_IMAGE_HIGH(val_dst_img);
460466

461467
if (IS_FILE(val_dest)) {
468+
#ifdef TO_WINDOWS
462469
ser = Value_To_Local_Path(val_dest, TRUE);
470+
#else
471+
ser = Value_To_OS_Path(val_dest, TRUE);
472+
#endif
463473
} else {
464474
// raw binary data...
465475
// ... predict number of bytes large enough to hold the result
@@ -494,9 +504,11 @@ typedef struct REBCLR {
494504

495505
if(codi.error) {
496506
switch (codi.error) {
507+
#ifdef TO_WINDOWS
497508
case WINCODEC_ERR_COMPONENTNOTFOUND:
498509
Trap1(RE_NO_CODEC, val_type);
499510
break;
511+
#endif
500512
default:
501513
SET_INTEGER(D_RET, codi.error);
502514
if (IS_BINARY(val_dest)) {

src/include/reb-codec.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ enum {
108108
CODI_IMG_JXR, // Windows Digital Photo (JpegXR)
109109
CODI_IMG_HEIF, // High Efficiency Image Format
110110
CODI_IMG_WEBP, //
111+
CODI_IMG_JP2, // JPEG 2000 (JP2)
111112
};
112113

113114
//#ifndef WINCODEC_ERR_COMPONENTNOTFOUND
114115
//#define WINCODEC_ERR_COMPONENTNOTFOUND 0x88982F50
115116
//#endif
116117

117-
#endif
118+
#endif

src/mezz/codec-image-osx.reb

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
REBOL [
2+
title: "REBOL 3 codec for image file formats (OSX version)"
3+
name: 'codec-image
4+
author: "Oldes"
5+
version: 0.1.0
6+
date: 13-Aug-2021
7+
history: [
8+
0.1.0 13-Aug-2021 "Oldes" {Initial version}
9+
]
10+
note: {Add the most common codec at tail (identify is testing the last codec as first)}
11+
]
12+
13+
register-codec [
14+
name: 'tiff
15+
title: "Tagged Image File Format"
16+
suffixes: [%.tif %.tiff]
17+
18+
decode: func [data [binary!]][lib/image/load/as data 'TIFF]
19+
encode: func [data [image! ]][lib/image/save/as none data 'TIFF]
20+
identify: func [data [binary!]][parse data [#{4949} to end]]
21+
]
22+
23+
register-codec [
24+
name: 'gif
25+
title: "Graphics Interchange Format"
26+
suffixes: [%.gif]
27+
28+
decode: func [data [binary!]][lib/image/load/as data 'GIF]
29+
encode: func [data [image! ]][lib/image/save/as none data 'GIF]
30+
identify: func [data [binary!]][parse data [#{4749463839} to end]]
31+
]
32+
33+
register-codec [
34+
name: 'bmp
35+
title: "Portable Bitmap"
36+
suffixes: [%.bmp]
37+
38+
decode: func [data [binary!]][lib/image/load/as data 'BMP]
39+
encode: func [data [image! ]][lib/image/save/as none data 'BMP]
40+
identify: func [data [binary!]][parse data [#{4249} to end]]
41+
]
42+
43+
register-codec [
44+
name: 'jpeg2000
45+
title: "JPEG 2000"
46+
suffixes: [%.jp2 %.j2k %.jpf %.jpm %.jpg2 %.j2c %.jpc %.jpx %.mj2]
47+
48+
decode: func [data [binary!]][lib/image/load/as data 'JP2]
49+
encode: func [data [image! ]][lib/image/save/as none data 'JP2]
50+
identify: func [data [binary!]][parse data [#{0000000C6A5020200D0A870A} to end]]
51+
]
52+
53+
register-codec [
54+
name: 'jpeg
55+
title: "Joint Photographic Experts Group"
56+
suffixes: [%.jpg %.jpeg]
57+
58+
decode: func [data [binary!]][lib/image/load/as data 'JPEG]
59+
encode: func [data [image! ]][lib/image/save/as none data 'JPEG]
60+
identify: func [data [binary!]][parse data [#{FFD8} to end]]
61+
]
62+
63+
register-codec [
64+
name: 'png
65+
title: "Portable Network Graphics"
66+
suffixes: [%.png]
67+
68+
decode: func [data [binary!]][lib/image/load/as data 'PNG]
69+
encode: func [data [image! ]][lib/image/save/as none data 'PNG]
70+
identify: func [data [binary!]][parse data [#{89504E47} to end]]
71+
]
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+

src/mezz/codec-image-win.reb

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
REBOL [
2+
title: "REBOL 3 codec for image file formats (Windows)"
3+
name: 'codec-image
4+
author: "Oldes"
5+
version: 0.2.0
6+
date: 13-Aug-2021
7+
history: [
8+
0.2.0 13-Aug-2021 "Oldes" {Removed ICO codec registration as there is platform independent implementation now}
9+
0.1.0 31-Jul-2019 "Oldes" {Initial version}
10+
]
11+
note: {Add the most common codec at tail (identify is testing the last codec as first)}
12+
]
13+
14+
register-codec [
15+
name: 'dng
16+
title: "Digital Negative"
17+
suffixes: [%.dng]
18+
comment: {Decodes only thumbnail, not RAW data!}
19+
20+
decode: func [data [binary!]][lib/image/load/as data 'DNG]
21+
;encode not available!
22+
identify: func [data [binary!]][none] ; same like TIFF
23+
]
24+
25+
register-codec [
26+
name: 'dds
27+
title: "DirectDraw Surface"
28+
suffixes: [%.dds]
29+
30+
decode: func [data [binary!]][lib/image/load/as data 'DDS]
31+
encode: func [data [image! ]][lib/image/save/as none data 'DDS]
32+
identify: func [data [binary!]][parse data [#{444453} to end]]
33+
]
34+
35+
register-codec [
36+
name: 'tiff
37+
title: "Tagged Image File Format"
38+
suffixes: [%.tif %.tiff]
39+
40+
decode: func [data [binary!]][lib/image/load/as data 'TIFF]
41+
encode: func [data [image! ]][lib/image/save/as none data 'TIFF]
42+
identify: func [data [binary!]][parse data [#{4949} to end]]
43+
]
44+
45+
register-codec [
46+
name: 'gif
47+
title: "Graphics Interchange Format"
48+
suffixes: [%.gif]
49+
50+
decode: func [data [binary!]][lib/image/load/as data 'GIF]
51+
encode: func [data [image! ]][lib/image/save/as none data 'GIF]
52+
identify: func [data [binary!]][parse data [#{4749463839} to end]]
53+
]
54+
55+
register-codec [
56+
name: 'bmp
57+
title: "Portable Bitmap"
58+
suffixes: [%.bmp]
59+
60+
decode: func [data [binary!]][lib/image/load/as data 'BMP]
61+
encode: func [data [image! ]][lib/image/save/as none data 'BMP]
62+
identify: func [data [binary!]][parse data [#{4249} to end]]
63+
]
64+
65+
register-codec [
66+
name: 'jpegxr
67+
title: "JPEG extended range"
68+
suffixes: [%.jxr %.hdp %.wdp]
69+
70+
decode: func [data [binary!]][lib/image/load/as data 'JPEGXR]
71+
encode: func [data [image! ]][lib/image/save/as none data 'JPEGXR]
72+
identify: func [data [binary!]][parse data [#{4949} to end]]
73+
]
74+
75+
register-codec [
76+
name: 'jpeg
77+
title: "Joint Photographic Experts Group"
78+
suffixes: [%.jpg %.jpeg]
79+
80+
decode: func [data [binary!]][lib/image/load/as data 'JPEG]
81+
encode: func [data [image! ]][lib/image/save/as none data 'JPEG]
82+
identify: func [data [binary!]][parse data [#{FFD8} to end]]
83+
]
84+
85+
register-codec [
86+
name: 'png
87+
title: "Portable Network Graphics"
88+
suffixes: [%.png]
89+
90+
decode: func [data [binary!]][lib/image/load/as data 'PNG]
91+
encode: func [data [image! ]][lib/image/save/as none data 'PNG]
92+
identify: func [data [binary!]][parse data [#{89504E47} to end]]
93+
]
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+

0 commit comments

Comments
 (0)