currently only used by gif.c, but maybe we'll support producing
8-bit (or bigger indexed) png files at some point
*/
-#include "image.h"
+#include "imager.h"
static void makemap_addi(i_quantize *, i_img **imgs, int count);
static void makemap_mediancut(i_quantize *, i_img **imgs, int count);
+static void makemap_mono(i_quantize *);
static
void
handle multiple colour maps.
*/
+/*
+=item i_quant_makemap(quant, imgs, count)
+
+=category Image quantization
+
+Analyzes the I<count> images in I<imgs> according to the rules in
+I<quant> to build a color map (optimal or not depending on
+quant->make_colors).
+
+=cut
+*/
+
void
-quant_makemap(i_quantize *quant, i_img **imgs, int count) {
+i_quant_makemap(i_quantize *quant, i_img **imgs, int count) {
if (quant->translate == pt_giflib) {
/* giflib does it's own color table generation */
makemap_mediancut(quant, imgs, count);
break;
+ case mc_mono:
+ makemap_mono(quant);
+ break;
+
case mc_addi:
default:
makemap_addi(quant, imgs, count);
}
}
-#ifdef HAVE_LIBGIF
-static void translate_giflib(i_quantize *, i_img *, i_palidx *);
-#endif
static void translate_closest(i_quantize *, i_img *, i_palidx *);
static void translate_errdiff(i_quantize *, i_img *, i_palidx *);
static void translate_addi(i_quantize *, i_img *, i_palidx *);
-/* Quantize the image given the palette in quant.
+/*
+=item i_quant_translate(quant, img)
+
+=category Image quantization
+
+Quantize the image given the palette in quant.
+
+On success returns a pointer to a memory block of img->xsize *
+img->ysize i_palidx entries.
+
+On failure returns NULL.
+
+You should call myfree() on the returned block when you're done with
+it.
- The giflib quantizer ignores the palette.
+This function will fail if the supplied palette contains no colors.
+
+=cut
*/
-i_palidx *quant_translate(i_quantize *quant, i_img *img) {
+i_palidx *
+i_quant_translate(i_quantize *quant, i_img *img) {
i_palidx *result;
int bytes;
return rand()/(RAND_MAX+1.0);
}
+#ifdef NOTEF
static
int
eucl_d(cvec* cv,i_color *cl) { return PWR2(cv->r-cl->channel[0])+PWR2(cv->g-cl->channel[1])+PWR2(cv->b-cl->channel[2]); }
+#endif
static
int
color_count = 1;
while (color_count < quant->mc_size) {
- int max_index, max_ch; /* index/channel with biggest spread */
+ /* initialized to avoid compiler warnings */
+ int max_index = 0, max_ch = 0; /* index/channel with biggest spread */
int max_size;
medcut_partition *workpart;
int cum_total;
i_mempool_destroy(&mp);
}
+static void
+makemap_mono(i_quantize *quant) {
+ quant->mc_colors[0].rgba.r = 0;
+ quant->mc_colors[0].rgba.g = 0;
+ quant->mc_colors[0].rgba.b = 0;
+ quant->mc_colors[0].rgba.a = 255;
+ quant->mc_colors[1].rgba.r = 255;
+ quant->mc_colors[1].rgba.g = 255;
+ quant->mc_colors[1].rgba.b = 255;
+ quant->mc_colors[1].rgba.a = 255;
+ quant->mc_count = 2;
+}
+
#define pboxjump 32
/* Define one of the following 4 symbols to choose a colour search method
welcome.
*/
static void hbsetup(i_quantize *quant, hashbox *hb) {
- long *dists, mind, maxd, cd;
+ long *dists, mind, maxd;
int cr, cb, cg, hbnum, i;
i_color cenc;
#ifdef HB_SORT
#endif
static void translate_addi(i_quantize *quant, i_img *img, i_palidx *out) {
- int x, y, i, k, bst_idx;
+ int x, y, i, k, bst_idx = 0;
i_color val;
int pixdev = quant->perturb;
CF_VARS;
int errw;
int difftotal;
int x, y, dx, dy;
- int minr, maxr, ming, maxg, minb, maxb, cr, cg, cb;
- i_color find;
- int bst_idx;
+ int bst_idx = 0;
CF_VARS;
if ((quant->errdiff & ed_mask) == ed_custom) {
static void transparent_errdiff(i_quantize *, i_palidx *, i_img *, i_palidx);
static void transparent_ordered(i_quantize *, i_palidx *, i_img *, i_palidx);
-void quant_transparent(i_quantize *quant, i_palidx *data, i_img *img,
+/*
+=item i_quant_transparent(quant, data, img, trans_index)
+
+=category Image quantization
+
+Dither the alpha channel on I<img> into the palette indexes in
+I<data>. Pixels to be transparent are replaced with I<trans_pixel>.
+
+The method used depends on the tr_* members of quant.
+
+=cut
+*/
+
+void
+i_quant_transparent(i_quantize *quant, i_palidx *data, i_img *img,
i_palidx trans_index)
{
switch (quant->transp) {