88#include "cgif.h"
99#include "cgif_raw.h"
1010
11- #define WIDTH 2
12- #define HEIGHT 2
11+ /*
12+ * 18x16 = 288 pixels with >255 unique colors to trigger color quantization.
13+ * The first 32 colors are crafted to trigger resize_col_hash_table via the
14+ * collision path (>30 collisions): colors (0,0,0)..(0,0,30) occupy consecutive
15+ * hash slots, then (8,0,21) hashes to the same slot as (0,0,0) causing 31
16+ * collisions.
17+ */
18+ #define WIDTH 18
19+ #define HEIGHT 16
1320
1421/* malloc/realloc failure injection */
1522static int fail_after = 0 ;
@@ -55,17 +62,37 @@ static int writeFn(void* pContext, const uint8_t* pData, const size_t numBytes)
5562 return 0 ;
5663}
5764
65+ static void initImageData (uint8_t * p , int numPixels ) {
66+ int i = 0 ;
67+ // first 31 pixels: (0,0,0)..(0,0,30) -- occupy consecutive hash slots
68+ for (; i < 31 && i < numPixels ; ++ i ) {
69+ p [3 * i + 0 ] = 0 ;
70+ p [3 * i + 1 ] = 0 ;
71+ p [3 * i + 2 ] = i ;
72+ }
73+ // 32nd pixel: (8,0,21) -- hashes to slot 0 (8*65536+21 = 524309 = tableSize),
74+ // causing 31 collisions which triggers resize_col_hash_table
75+ if (i < numPixels ) {
76+ p [3 * i + 0 ] = 8 ;
77+ p [3 * i + 1 ] = 0 ;
78+ p [3 * i + 2 ] = 21 ;
79+ ++ i ;
80+ }
81+ // remaining pixels: unique colors starting from (31,0,0)
82+ for (int c = 31 ; i < numPixels ; ++ i , ++ c ) {
83+ p [3 * i + 0 ] = (c >> 0 ) & 0xFF ;
84+ p [3 * i + 1 ] = (c >> 8 ) & 0xFF ;
85+ p [3 * i + 2 ] = 0 ;
86+ }
87+ }
88+
5889int main (void ) {
5990 CGIFrgb * pGIF ;
6091 CGIFrgb_Config gConfig ;
6192 CGIFrgb_FrameConfig fConfig ;
6293 cgif_result r ;
63- uint8_t aImageData [] = {
64- 0xFF , 0x00 , 0x00 , // red
65- 0x00 , 0xFF , 0x00 , // green
66- 0x00 , 0x00 , 0xFF , // blue
67- 0xFF , 0xFF , 0x00 , // yellow
68- };
94+ uint8_t aImageData [WIDTH * HEIGHT * 3 ];
95+ initImageData (aImageData , WIDTH * HEIGHT );
6996
7097 for (int n = 1 ; ; ++ n ) {
7198 memset (& gConfig , 0 , sizeof (gConfig ));
@@ -76,6 +103,7 @@ int main(void) {
76103
77104 fConfig .pImageData = aImageData ;
78105 fConfig .fmtChan = CGIF_CHAN_FMT_RGB ;
106+ fConfig .attrFlags = CGIF_RGB_FRAME_ATTR_INTERLACED ;
79107
80108 fail_after = n ;
81109 malloc_count = 0 ;
0 commit comments