Skip to content

Commit aa10d12

Browse files
committed
FEAT: image codecs are now included only when requested using compilation defines
To enable these codecs one must use these defines: USE_PNG_CODEC USE_BMP_CODEC USE_JPG_CODEC USE_GIF_CODEC
1 parent a7b0562 commit aa10d12

File tree

6 files changed

+82
-21
lines changed

6 files changed

+82
-21
lines changed

src/core/b-init.c

+8
Original file line numberDiff line numberDiff line change
@@ -721,10 +721,18 @@ extern const REBYTE Str_Banner[];
721721
{
722722
Register_Codec((REBYTE*)"text", Codec_Text);
723723
Register_Codec((REBYTE*)"markup", Codec_Markup);
724+
#ifdef USE_BMP_CODEC
724725
Init_BMP_Codec();
726+
#endif
727+
#ifdef USE_GIF_CODEC
725728
Init_GIF_Codec();
729+
#endif
730+
#ifdef USE_PNG_CODEC
726731
Init_PNG_Codec();
732+
#endif
733+
#ifdef USE_JPG_CODEC
727734
Init_JPEG_Codec();
735+
#endif
728736
}
729737

730738

src/core/u-bmp.c

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef USE_BMP_CODEC
12
/***********************************************************************
23
**
34
** REBOL [R3] Language Interpreter and Run-time Environment
@@ -26,6 +27,14 @@
2627
** This is an optional part of R3. This file can be replaced by
2728
** library function calls into an updated implementation.
2829
**
30+
***********************************************************************
31+
** Base-code:
32+
33+
if find system/codecs 'bmp [
34+
system/codecs/bmp/suffixes: [%.bmp]
35+
append append system/options/file-types system/codecs/bmp/suffixes 'bmp
36+
]
37+
2938
***********************************************************************/
3039

3140
#include "sys-core.h"
@@ -616,3 +625,5 @@ void Unmap_Bytes(void *srcp, REBYTE **dstp, char *map) {
616625
{
617626
Register_Codec("bmp", Codec_BMP_Image);
618627
}
628+
629+
#endif //USE_BMP_CODEC

src/core/u-gif.c

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef USE_GIF_CODEC
12
/***********************************************************************
23
**
34
** REBOL [R3] Language Interpreter and Run-time Environment
@@ -26,6 +27,14 @@
2627
** This is an optional part of R3. This file can be replaced by
2728
** library function calls into an updated implementation.
2829
**
30+
***********************************************************************
31+
** Base-code:
32+
33+
if find system/codecs 'gif [
34+
system/codecs/gif/suffixes: [%.gif]
35+
append append system/options/file-types system/codecs/gif/suffixes 'gif
36+
]
37+
2938
***********************************************************************/
3039

3140
#include "sys-core.h"
@@ -345,3 +354,5 @@ void Chrom_Key_Alpha(REBVAL *v,REBCNT col,REBINT blitmode) {
345354
{
346355
Register_Codec("gif", Codec_GIF_Image);
347356
}
357+
358+
#endif //USE_GIF_CODEC

src/core/u-jpg.c

+38-16
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
1+
#ifdef USE_JPG_CODEC
2+
/***********************************************************************
3+
**
4+
** jdatasrc.c
5+
**
6+
** Copyright (C) 1994-1996, Thomas G. Lane.
7+
** This file is part of the Independent JPEG Group's software.
8+
** For conditions of distribution and use, see the accompanying README file.
9+
**
10+
** This file contains decompression data source routines for the case of
11+
** reading JPEG data from a file (or any stdio stream). While these routines
12+
** are sufficient for most applications, some will want to use a different
13+
** source manager.
14+
** IMPORTANT: we assume that fread() will correctly transcribe an array of
15+
** JOCTETs from 8-bit-wide elements on external storage. If char is wider
16+
** than 8 bits on your machine, you may need to do some tweaking.
17+
**
18+
************************************************************************
19+
**
20+
** Module: u-jpg.c
21+
** Summary: JPEG image format conversion
22+
** Section: utility
23+
** Notes:
24+
** This is an optional part of R3. This file can be replaced by
25+
** library function calls into an updated implementation.
26+
**
27+
***********************************************************************
28+
** Base-code:
29+
30+
if find system/codecs 'jpeg [
31+
system/codecs/jpeg/suffixes: [%.jpg %.jpeg]
32+
append append system/options/file-types system/codecs/jpeg/suffixes 'jpeg
33+
]
34+
35+
***********************************************************************/
36+
137
#define JPEG_INTERNALS
238
#define NO_GETENV
339
#include "reb-config.h"
440
#include "reb-c.h"
541
#include <setjmp.h>
642
#include "sys-jpg.h"
743

8-
/*
9-
* jdatasrc.c
10-
*
11-
* Copyright (C) 1994-1996, Thomas G. Lane.
12-
* This file is part of the Independent JPEG Group's software.
13-
* For conditions of distribution and use, see the accompanying README file.
14-
*
15-
* This file contains decompression data source routines for the case of
16-
* reading JPEG data from a file (or any stdio stream). While these routines
17-
* are sufficient for most applications, some will want to use a different
18-
* source manager.
19-
* IMPORTANT: we assume that fread() will correctly transcribe an array of
20-
* JOCTETs from 8-bit-wide elements on external storage. If char is wider
21-
* than 8 bits on your machine, you may need to do some tweaking.
22-
*/
23-
2444
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
2545
//#include "jinclude.h"
2646
//#include "jpeglib.h"
@@ -10827,3 +10847,5 @@ extern void Register_Codec(char *name, codo dispatcher);
1082710847
{
1082810848
Register_Codec("jpeg", Codec_JPEG_Image);
1082910849
}
10850+
10851+
#endif //USE_JPG_CODEC

src/core/u-png.c

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef USE_PNG_CODEC
12
/***********************************************************************
23
**
34
** REBOL [R3] Language Interpreter and Run-time Environment
@@ -26,6 +27,14 @@
2627
** This is an optional part of R3. This file can be replaced by
2728
** library function calls into an updated implementation.
2829
**
30+
***********************************************************************
31+
** Base-code:
32+
33+
if find system/codecs 'png [
34+
system/codecs/png/suffixes: [%.png]
35+
append append system/options/file-types system/codecs/png/suffixes 'png
36+
]
37+
2938
***********************************************************************/
3039

3140
#include "sys-core.h"
@@ -859,3 +868,5 @@ static void emitchunk(unsigned char **cpp,char *type,char *data,int length) {
859868
{
860869
Register_Codec("png", Codec_PNG_Image);
861870
}
871+
872+
#endif //USE_PNG_CODEC

src/mezz/base-defs.r

+3-5
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@ foreach [codec handler] system/codecs [
5757
suffixes: select [
5858
text [%.txt]
5959
markup [%.html %.htm %.xml %.xsl %.wml %.sgml %.asp %.php %.cgi]
60-
bmp [%.bmp]
61-
gif [%.gif]
62-
jpeg [%.jpg %.jpeg]
63-
png [%.png]
6460
] codec
6561
]
6662
; Media-types block format: [.abc .def type ...]
67-
append append system/options/file-types codec/suffixes codec/name
63+
if codec/suffixes [ ;append to file-types only if there is any suffix
64+
append append system/options/file-types codec/suffixes codec/name
65+
]
6866
]
6967
]
7068

0 commit comments

Comments
 (0)