]> git.imager.perl.org - imager.git/blobdiff - quant.c
modify the Freetype2 font code to pick it's own encoding rather than
[imager.git] / quant.c
diff --git a/quant.c b/quant.c
index e257b8f53d75c1d7a7e1b0a92760e97e7709d2ea..b80c0538e7460d0b366b44c2607f06d8d1345e5f 100644 (file)
--- a/quant.c
+++ b/quant.c
@@ -27,7 +27,6 @@ setcol(i_color *cl,unsigned char r,unsigned char g,unsigned char b,unsigned char
 
 void
 quant_makemap(i_quantize *quant, i_img **imgs, int count) {
-       i_color temp;
 #ifdef HAVE_LIBGIF
   /* giflib does it's own color table generation */
   if (quant->translate == pt_giflib) 
@@ -69,9 +68,9 @@ static void translate_addi(i_quantize *, i_img *, i_palidx *);
 */
 i_palidx *quant_translate(i_quantize *quant, i_img *img) {
   i_palidx *result;
-       mm_log((1, "quant_translate(quant %p, img %p)\n", quant, img));
+  mm_log((1, "quant_translate(quant %p, img %p)\n", quant, img));
 
-       result = mymalloc(img->xsize * img->ysize);
+  result = mymalloc(img->xsize * img->ysize);
 
   switch (quant->translate) {
 #ifdef HAVE_LIBGIF
@@ -83,17 +82,17 @@ i_palidx *quant_translate(i_quantize *quant, i_img *img) {
   case pt_closest:
     translate_closest(quant, img, result);
     break;
-
+    
   case pt_errdiff:
     translate_errdiff(quant, img, result);
     break;
-
+    
   case pt_perturb:
   default:
     translate_addi(quant, img, result);
     break;
   }
-
+  
   return result;
 }
 
@@ -119,7 +118,7 @@ static void translate_giflib(i_quantize *quant, i_img *img, i_palidx *out) {
   
   i_color col;
 
-       mm_log((1,"i_writegif(quant %p, img %p, out %p)\n", quant, img, out));
+  mm_log((1,"translate_giflib(quant %p, img %p, out %p)\n", quant, img, out));
   
   /*if (!(im->channels==1 || im->channels==3)) { fprintf(stderr,"Unable to write gif, improper colorspace.\n"); exit(3); }*/
   
@@ -155,14 +154,14 @@ static void translate_giflib(i_quantize *quant, i_img *img, i_palidx *out) {
       }
       if ((GreenBuffer = (GifByteType *) mymalloc((unsigned int) Size)) == NULL) {
         m_fatal(0,"Failed to allocate memory required, aborted.");
-        free(RedBuffer);
+        myfree(RedBuffer);
         return;
       }
     
       if ((BlueBuffer  = (GifByteType *) mymalloc((unsigned int) Size)) == NULL) {
         m_fatal(0,"Failed to allocate memory required, aborted.");
-        free(RedBuffer);
-        free(GreenBuffer);
+        myfree(RedBuffer);
+        myfree(GreenBuffer);
         return;
       }
     
@@ -198,8 +197,8 @@ static void translate_giflib(i_quantize *quant, i_img *img, i_palidx *out) {
     }
   }
 
-  free(RedBuffer);
-  if (img->channels == 3) { free(GreenBuffer); free(BlueBuffer); }
+  myfree(RedBuffer);
+  if (img->channels == 3) { myfree(GreenBuffer); myfree(BlueBuffer); }
 
   /* copy over the color map */
   for (i = 0; i < ColorMapSize; ++i) {
@@ -377,9 +376,10 @@ makemap_addi(i_quantize *quant, i_img **imgs, int count) {
   int cnum, i, x, y, bst_idx=0, ld, cd, iter, currhb, img_num;
   i_color val;
   float dlt, accerr;
-  hashbox hb[512];
+  hashbox *hb;
 
   clr = (cvec *)mymalloc(sizeof(cvec) * quant->mc_size);
+  hb = mymalloc(sizeof(hashbox) * 512);
   for (i=0; i < quant->mc_count; ++i) {
     clr[i].r = quant->mc_colors[i].rgb.r;
     clr[i].g = quant->mc_colors[i].rgb.g;
@@ -493,6 +493,7 @@ makemap_addi(i_quantize *quant, i_img **imgs, int count) {
 #endif
 
   /* don't want to keep this */
+  myfree(hb);
   myfree(clr);
 }
 
@@ -543,7 +544,7 @@ makemap_addi(i_quantize *quant, i_img **imgs, int count) {
 #define HB_SORT
 
 /* assume i is available */
-#define CF_VARS hashbox hb[512]; \
+#define CF_VARS hashbox *hb = mymalloc(sizeof(hashbox) * 512); \
                int currhb;  \
                long ld, cd
 
@@ -627,7 +628,7 @@ static void hbsetup(i_quantize *quant, hashbox *hb) {
 #endif
       } 
     } 
-  } 
+  }
 #ifdef HB_SORT
   myfree(indices); 
 #endif
@@ -643,7 +644,7 @@ static void hbsetup(i_quantize *quant, hashbox *hb) {
     if (cd < ld) { ld = cd; bst_idx = hb[currhb].vec[i]; } \
   }
 
-#define CF_CLEANUP
+#define CF_CLEANUP myfree(hb)
   
 #endif
 
@@ -1036,6 +1037,7 @@ translate_errdiff(i_quantize *quant, i_img *img, i_palidx *out) {
     memset(err+(maph-1)*errw, 0, sizeof(*err)*errw);
   }
   CF_CLEANUP;
+  myfree(err);
 }
 /* Prescan finds the boxes in the image that have the highest number of colors 
    and that result is used as the initial value for the vectores */