Skip to content

Commit 6e33611

Browse files
committed
disable the RGB API by default
1 parent f1272ac commit 6e33611

22 files changed

Lines changed: 128 additions & 38 deletions

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ int cgif_addframe (CGIF* pGIF, CGIF_FrameConfig* pConfig); // adds a frame to
4040
int cgif_close (CGIF* pGIF); // close the created file and free memory
4141

4242
// The user needs only these functions to create a GIF image from RGB data:
43+
// (EXPERIMENTAL: declared in the separate header "cgif_rgb.h")
4344
CGIFrgb* cgif_rgb_newgif (const CGIFrgb_Config* pConfig);
4445
cgif_result cgif_rgb_addframe (CGIFrgb* pGIF, const CGIFrgb_FrameConfig* pConfig);
4546
cgif_result cgif_rgb_close (CGIFrgb* pGIF);
4647
```
4748
49+
**Note:** The RGB API is **experimental** and subject to change. It is **disabled by default** and lives in its own header ```inc/cgif_rgb.h``` (include it via ```#include "cgif_rgb.h"```). To compile it into the library and install the header, configure the build with ```-Dexperimental_rgb=true```. The regular header ```inc/cgif.h``` no longer declares the RGB API.
50+
4851
With our encoder you can create animated or static GIFs, you can or cannot use certain optimizations, and so on. You can switch between all these different options easily using the two attributes ```attrFlags``` and ```genFlags``` in the configurations ```CGIF_Config``` and ```CGIF_FrameConfig``` (or their RGB counterparts). These attributes are of type ```uint32_t``` and bundle yes/no-options with a bit-wise logic. So far only a few of the 32 bits are used leaving space to include further functionalities ensuring backward compatibility. We provide the following flag settings which can be combined by bit-wise or-operations:
4952
```C
5053
CGIF_ATTR_IS_ANIMATED // make an animated GIF (default is non-animated GIF)

examples/cgif_rgb_example.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdio.h>
55

66
#include "cgif.h"
7+
#include "cgif_rgb.h"
78

89
#define WIDTH 200
910
#define HEIGHT 200

examples/cgif_rgb_example_video.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdio.h>
55

66
#include "cgif.h"
7+
#include "cgif_rgb.h"
78

89
#define WIDTH 200
910
#define HEIGHT 200

fuzz/cgif_rgb_create_fuzz_seed.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <cgif.h>
7+
#include <cgif_rgb.h>
78

89
#include <stdio.h>
910
#include <stdint.h>

fuzz/cgif_rgb_fuzzer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <cgif.h>
2+
#include <cgif_rgb.h>
23

34
#include <stddef.h>
45
#include <stdint.h>

fuzz/meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ src_rgb = ['cgif_fuzzer_standalone.c', 'cgif_rgb_fuzzer.c']
4141
exe_rgb = executable(
4242
'cgif_rgb_fuzzer_standalone',
4343
sources : src_rgb,
44-
dependencies : [libcgif_dep],
44+
# use the RGB-enabled internal library so this keeps building regardless of
45+
# the 'experimental_rgb' option
46+
dependencies : [libcgif_rgb_dep],
4547
include_directories : ['../inc'],
4648
)
4749
# test indexed seed corpus with standalone fuzzer and standalone file fuzzer

inc/cgif.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ extern "C" {
2626

2727
#define CGIF_INFINITE_LOOP (0x0000uL) // for animated GIF: 0 specifies infinite loop
2828

29-
#define CGIF_RGB_FRAME_ATTR_INTERLACED (1ul << 0) // encode frame interlaced (default is not interlaced)
30-
#define CGIF_RGB_FRAME_ATTR_NO_DITHERING (1ul << 1) // disable color dithering (default is with dithering)
31-
3229
typedef enum {
3330
CGIF_ERROR = -1, // something unspecified failed
3431
CGIF_OK = 0, // everything OK
@@ -41,17 +38,9 @@ typedef enum {
4138
CGIF_PENDING,
4239
} cgif_result;
4340

44-
typedef enum {
45-
CGIF_CHAN_FMT_RGB = 3, // 3 byte per pixel (red, green, blue)
46-
CGIF_CHAN_FMT_RGBA = 4, // 4 byte per pixel (red, green, blue, alpha)
47-
} cgif_chan_fmt;
48-
4941
typedef struct st_gif CGIF; // struct for the full GIF
5042
typedef struct st_gifconfig CGIF_Config; // global cofinguration parameters of the GIF
5143
typedef struct st_frameconfig CGIF_FrameConfig; // local configuration parameters for a frame
52-
typedef struct st_cgif_rgb_config CGIFrgb_Config;
53-
typedef struct st_cgif_rgb CGIFrgb;
54-
typedef struct st_cgif_rgb_frameconfig CGIFrgb_FrameConfig;
5544

5645
typedef int cgif_write_fn(void* pContext, const uint8_t* pData, const size_t numBytes); // callback function for stream-based output
5746

@@ -60,10 +49,6 @@ CGIF* cgif_newgif (CGIF_Config* pConfig); // creates a new
6049
int cgif_addframe (CGIF* pGIF, CGIF_FrameConfig* pConfig); // adds the next frame to an existing GIF (returns 0 on success)
6150
int cgif_close (CGIF* pGIF); // close file and free allocated memory (returns 0 on success)
6251

63-
CGIFrgb* cgif_rgb_newgif (const CGIFrgb_Config* pConfig);
64-
cgif_result cgif_rgb_addframe (CGIFrgb* pGIF, const CGIFrgb_FrameConfig* pConfig);
65-
cgif_result cgif_rgb_close (CGIFrgb* pGIF);
66-
6752
// CGIF_Config type (parameters passed by user)
6853
// note: must stay AS IS for backward compatibility
6954
struct st_gifconfig {
@@ -91,25 +76,6 @@ struct st_frameconfig {
9176
uint8_t transIndex; // introduced with V0.2.0
9277
};
9378

94-
struct st_cgif_rgb_config {
95-
cgif_write_fn* pWriteFn;
96-
void* pContext;
97-
const char* path;
98-
uint32_t attrFlags;
99-
uint32_t genFlags;
100-
uint16_t numLoops;
101-
uint16_t width;
102-
uint16_t height;
103-
};
104-
105-
struct st_cgif_rgb_frameconfig {
106-
uint8_t* pImageData;
107-
cgif_chan_fmt fmtChan;
108-
uint32_t attrFlags; // TBD
109-
uint32_t genFlags; // TBD
110-
uint16_t delay;
111-
};
112-
11379
#ifdef __cplusplus
11480
}
11581
#endif

inc/cgif_rgb.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef CGIF_RGB_H
2+
#define CGIF_RGB_H
3+
4+
// EXPERIMENTAL: the RGB API is experimental and subject to change.
5+
// It is not part of the stable cgif API and must be enabled explicitly
6+
// via the 'experimental_rgb' build option. The declarations below used to
7+
// live in cgif.h but have been moved out of the regular header.
8+
9+
#include <stdint.h>
10+
11+
#include "cgif.h"
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
// flags to set the RGB frame-attributes
18+
#define CGIF_RGB_FRAME_ATTR_INTERLACED (1ul << 0) // encode frame interlaced (default is not interlaced)
19+
#define CGIF_RGB_FRAME_ATTR_NO_DITHERING (1ul << 1) // disable color dithering (default is with dithering)
20+
21+
typedef enum {
22+
CGIF_CHAN_FMT_RGB = 3, // 3 byte per pixel (red, green, blue)
23+
CGIF_CHAN_FMT_RGBA = 4, // 4 byte per pixel (red, green, blue, alpha)
24+
} cgif_chan_fmt;
25+
26+
typedef struct st_cgif_rgb_config CGIFrgb_Config;
27+
typedef struct st_cgif_rgb CGIFrgb;
28+
typedef struct st_cgif_rgb_frameconfig CGIFrgb_FrameConfig;
29+
30+
// prototypes
31+
CGIFrgb* cgif_rgb_newgif (const CGIFrgb_Config* pConfig);
32+
cgif_result cgif_rgb_addframe (CGIFrgb* pGIF, const CGIFrgb_FrameConfig* pConfig);
33+
cgif_result cgif_rgb_close (CGIFrgb* pGIF);
34+
35+
struct st_cgif_rgb_config {
36+
cgif_write_fn* pWriteFn;
37+
void* pContext;
38+
const char* path;
39+
uint32_t attrFlags;
40+
uint32_t genFlags;
41+
uint16_t numLoops;
42+
uint16_t width;
43+
uint16_t height;
44+
};
45+
46+
struct st_cgif_rgb_frameconfig {
47+
uint8_t* pImageData;
48+
cgif_chan_fmt fmtChan;
49+
uint32_t attrFlags; // TBD
50+
uint32_t genFlags; // TBD
51+
uint16_t delay;
52+
};
53+
54+
#ifdef __cplusplus
55+
}
56+
#endif
57+
58+
#endif // CGIF_RGB_H

meson.build

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ project(
1010
cc = meson.get_compiler('c')
1111
m_dep = cc.find_library('m', required : false)
1212

13-
cgif_sources = ['src/cgif.c', 'src/cgif_raw.c', 'src/cgif_rgb.c']
13+
cgif_sources = ['src/cgif.c', 'src/cgif_raw.c']
14+
cgif_headers = ['inc/cgif.h']
15+
16+
# EXPERIMENTAL: the RGB API is opt-in and disabled by default.
17+
# When enabled it is compiled into the public library and its header installed.
18+
if get_option('experimental_rgb')
19+
cgif_sources += 'src/cgif_rgb.c'
20+
cgif_headers += 'inc/cgif_rgb.h'
21+
endif
22+
1423
lib = library(
1524
'cgif',
1625
cgif_sources,
@@ -21,7 +30,7 @@ lib = library(
2130
install : true,
2231
)
2332

24-
install_headers('inc/cgif.h')
33+
install_headers(cgif_headers)
2534

2635
import('pkgconfig').generate(
2736
lib,
@@ -32,6 +41,19 @@ import('pkgconfig').generate(
3241
libcgif_dep = declare_dependency(link_with : lib)
3342

3443
if get_option('tests') and not meson.is_cross_build()
44+
# Internal (non-installed) library that always includes the experimental RGB
45+
# API so the RGB tests keep building even when 'experimental_rgb' is off.
46+
cgif_rgb_test_lib = static_library(
47+
'cgif_rgb_test',
48+
['src/cgif.c', 'src/cgif_raw.c', 'src/cgif_rgb.c'],
49+
dependencies : m_dep,
50+
include_directories : ['inc/'],
51+
install : false,
52+
)
53+
libcgif_rgb_dep = declare_dependency(
54+
link_with : cgif_rgb_test_lib,
55+
include_directories : ['inc/'],
56+
)
3557
subdir('tests')
3658
if get_option('fuzzer')
3759
subdir('fuzz')

meson_options.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ option(
1919
description : 'build tests',
2020
)
2121

22+
# EXPERIMENTAL: the RGB API is experimental and disabled by default.
23+
# When disabled, the public library does not export the RGB API and the
24+
# cgif_rgb.h header is not installed. The tests always build the RGB API.
25+
option(
26+
'experimental_rgb',
27+
type : 'boolean',
28+
value : false,
29+
description : 'build the experimental RGB API into the library (EXPERIMENTAL, API subject to change)',
30+
)
31+
2232
# for debugging purposes
2333
option(
2434
'install_examples',

0 commit comments

Comments
 (0)