@@ -99,10 +99,6 @@ typedef struct _VipsForeignSaveCgif {
99
99
int * palette ;
100
100
int n_colours ;
101
101
102
- /* The palette as RGB (not RGBA).
103
- */
104
- VipsPel palette_rgb [256 * 3 ];
105
-
106
102
/* The current frame coming from libvips, and the y position
107
103
* in the input image.
108
104
*/
@@ -192,11 +188,11 @@ vips__cgif_write( void *client, const uint8_t *buffer, const size_t length )
192
188
*/
193
189
static void
194
190
vips_foreign_save_cgif_set_transparent ( VipsForeignSaveCgif * cgif ,
195
- VipsPel * old , VipsPel * new , VipsPel * index , int n_pels , int trans )
191
+ VipsPel * old , VipsPel * new , VipsPel * index , size_t n_pels , int trans )
196
192
{
197
193
int sq_maxerror = cgif -> interframe_maxerror * cgif -> interframe_maxerror ;
198
194
199
- int i ;
195
+ size_t i ;
200
196
201
197
for ( i = 0 ; i < n_pels ; i ++ ) {
202
198
/* Alpha must match
@@ -325,8 +321,6 @@ vips_foreign_save_cgif_pick_quantiser( VipsForeignSaveCgif *cgif,
325
321
#endif /*DEBUG_VERBOSE*/
326
322
327
323
cgif -> quantisation_result = this_result ;
328
- vips_foreign_save_cgif_get_rgb_palette ( cgif ,
329
- this_result , cgif -> palette_rgb );
330
324
cgif -> n_palettes_generated += 1 ;
331
325
332
326
* result = this_result ;
@@ -423,18 +417,19 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif )
423
417
*/
424
418
VipsPel * frame_bytes =
425
419
VIPS_REGION_ADDR ( cgif -> frame , 0 , frame_rect -> top );
426
- int n_pels = frame_rect -> height * frame_rect -> width ;
420
+ size_t n_pels = ( size_t ) frame_rect -> height * frame_rect -> width ;
427
421
428
422
gboolean has_transparency ;
429
423
gboolean has_alpha_constraint ;
430
424
VipsPel * restrict p ;
431
- int i ;
425
+ size_t i ;
432
426
VipsQuantiseImage * image ;
433
427
gboolean use_local ;
434
428
VipsQuantiseResult * quantisation_result ;
435
429
const VipsQuantisePalette * lp ;
436
430
CGIF_FrameConfig frame_config = { 0 };
437
431
int n_colours ;
432
+ VipsPel palette_rgb [256 * 3 ];
438
433
439
434
#ifdef DEBUG_VERBOSE
440
435
printf ( "vips_foreign_save_cgif_write_frame: %d\n" , page_index );
@@ -493,11 +488,13 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif )
493
488
return ( -1 );
494
489
}
495
490
491
+ lp = vips__quantise_get_palette ( quantisation_result );
496
492
/* If there's a transparent pixel, it's always first.
497
493
*/
498
- lp = vips__quantise_get_palette ( quantisation_result );
499
494
has_transparency = lp -> entries [0 ].a == 0 ;
500
495
n_colours = lp -> count ;
496
+ vips_foreign_save_cgif_get_rgb_palette ( cgif ,
497
+ quantisation_result , palette_rgb );
501
498
502
499
/* Dither frame into @index.
503
500
*/
@@ -527,7 +524,7 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif )
527
524
528
525
cgif -> cgif_config .width = frame_rect -> width ;
529
526
cgif -> cgif_config .height = frame_rect -> height ;
530
- cgif -> cgif_config .pGlobalPalette = cgif -> palette_rgb ;
527
+ cgif -> cgif_config .pGlobalPalette = palette_rgb ;
531
528
cgif -> cgif_config .numGlobalPaletteEntries = n_colours ;
532
529
cgif -> cgif_config .pWriteFn = vips__cgif_write ;
533
530
cgif -> cgif_config .pContext = (void * ) cgif -> target ;
@@ -576,10 +573,8 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif )
576
573
/* Attach a local palette, if we need one.
577
574
*/
578
575
if ( use_local ) {
579
- vips_foreign_save_cgif_get_rgb_palette ( cgif ,
580
- quantisation_result , cgif -> palette_rgb );
581
576
frame_config .attrFlags |= CGIF_FRAME_ATTR_USE_LOCAL_TABLE ;
582
- frame_config .pLocalPalette = cgif -> palette_rgb ;
577
+ frame_config .pLocalPalette = palette_rgb ;
583
578
frame_config .numLocalPaletteEntries = n_colours ;
584
579
}
585
580
@@ -719,12 +714,13 @@ vips_foreign_save_cgif_build( VipsObject *object )
719
714
720
715
/* The previous RGBA frame (for spotting pixels which haven't changed).
721
716
*/
722
- cgif -> previous_frame =
723
- g_malloc0 ( 4 * frame_rect .width * frame_rect .height );
717
+ cgif -> previous_frame = g_malloc0 ( ( size_t ) 4 *
718
+ frame_rect .width * frame_rect .height );
724
719
725
720
/* The frame index buffer.
726
721
*/
727
- cgif -> index = g_malloc0 ( frame_rect .width * frame_rect .height );
722
+ cgif -> index = g_malloc0 ( (size_t ) frame_rect .width *
723
+ frame_rect .height );
728
724
729
725
/* Set up libimagequant.
730
726
*/
@@ -781,9 +777,6 @@ vips_foreign_save_cgif_build( VipsObject *object )
781
777
}
782
778
783
779
VIPS_FREEF ( vips__quantise_image_destroy , image );
784
-
785
- vips_foreign_save_cgif_get_rgb_palette ( cgif ,
786
- cgif -> quantisation_result , cgif -> palette_rgb );
787
780
}
788
781
789
782
if ( vips_sink_disc ( cgif -> in ,
0 commit comments