}
static void translate_closest(i_quantize *, i_img *, i_palidx *);
-static void translate_errdiff(i_quantize *, i_img *, i_palidx *);
+static int translate_errdiff(i_quantize *, i_img *, i_palidx *);
static void translate_addi(i_quantize *, i_img *, i_palidx *);
/*
break;
case pt_errdiff:
- translate_errdiff(quant, img, result);
+ if (!translate_errdiff(quant, img, result)) {
+ myfree(result);
+ return NULL;
+ }
break;
case pt_perturb:
} errdiff_t;
/* perform an error diffusion dither */
-static
-void
+static int
translate_errdiff(i_quantize *quant, i_img *img, i_palidx *out) {
int *map;
int mapw, maph, mapo;
mapo = maps[index].orig;
}
+ difftotal = 0;
+ for (i = 0; i < maph * mapw; ++i) {
+ if (map[i] < 0) {
+ i_push_errorf(0, "errdiff_map values must be non-negative, errdiff[%d] is negative", i);
+ return 0;
+ }
+ difftotal += map[i];
+ }
+
+ if (!difftotal) {
+ i_push_error(0, "error diffusion map must contain some non-zero values");
+ return 0;
+ }
+
errw = img->xsize+mapw;
err = mymalloc(sizeof(*err) * maph * errw);
/*errp = err+mapo;*/
memset(err, 0, sizeof(*err) * maph * errw);
- difftotal = 0;
- for (i = 0; i < maph * mapw; ++i)
- difftotal += map[i];
/*printf("map:\n");
for (dy = 0; dy < maph; ++dy) {
for (dx = 0; dx < mapw; ++dx) {
}
CF_CLEANUP;
myfree(err);
+
+ return 1;
}
/* 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 */