]> git.imager.perl.org - imager.git/blobdiff - quant.c
- change the "double-include" protection macro that imio.h uses.
[imager.git] / quant.c
diff --git a/quant.c b/quant.c
index 2c11a5580bc98dec1ceffbdfcbfc924d7d70fe22..2a23b1070624f8a716a525702774589d627da97e 100644 (file)
--- a/quant.c
+++ b/quant.c
@@ -50,7 +50,7 @@ quant_makemap(i_quantize *quant, i_img **imgs, int count) {
       for (r = 0; r < 256; r+=0x33)
        for (g = 0; g < 256; g+=0x33)
          for (b = 0; b < 256; b += 0x33)
-           setcol(quant->mc_colors+i++, r, g, b, 0);
+           setcol(quant->mc_colors+i++, r, g, b, 255);
       quant->mc_count = i;
     }
     break;
@@ -81,6 +81,13 @@ 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));
 
+  /* there must be at least one color in the paletted (though even that
+     isn't very useful */
+  if (quant->mc_count == 0) {
+    i_push_error(0, "no colors available for translation");
+    return NULL;
+  }
+
   result = mymalloc(img->xsize * img->ysize);
 
   switch (quant->translate) {
@@ -403,6 +410,9 @@ makemap_addi(i_quantize *quant, i_img **imgs, int count) {
   i_sample_t *line;
   const int *sample_indices;
 
+  mm_log((1, "makemap_addi(quant %p { mc_count=%d, mc_colors=%p }, imgs %p, count %d)\n", 
+          quant, quant->mc_count, quant->mc_colors, imgs, count));
+         
   i_mempool_init(&mp);
 
   clr = i_mempool_alloc(&mp, sizeof(cvec) * quant->mc_size);
@@ -416,6 +426,10 @@ makemap_addi(i_quantize *quant, i_img **imgs, int count) {
   }
   /* mymalloc doesn't clear memory, so I think we need this */
   for (; i < quant->mc_size; ++i) {
+    /*clr[i].r = clr[i].g = clr[i].b = 0;*/
+    clr[i].dr = 0;
+    clr[i].dg = 0;
+    clr[i].db = 0;
     clr[i].fixed = 0;
     clr[i].mcount = 0;
   }
@@ -538,6 +552,12 @@ makemap_addi(i_quantize *quant, i_img **imgs, int count) {
   quant->mc_count = cnum;
 #endif
 
+#if 0
+  mm_log((1, "makemap_addi returns - quant.mc_count = %d\n", quant->mc_count));
+  for (i = 0; i < quant->mc_count; ++i)
+    mm_log((5, "  map entry %d: (%d, %d, %d)\n", i, clr[i].r, clr[i].g, clr[i].b));
+#endif
+
   i_mempool_destroy(&mp);
 }