Tried some different color error functions

This commit is contained in:
alpine9000
2016-03-08 21:27:09 +11:00
parent e33422dfc7
commit c3f9cc4bde
4 changed files with 29 additions and 7 deletions
+17 -1
View File
@@ -1,12 +1,28 @@
#include "imagecon.h"
int
color_delta(amiga_color_t c1, amiga_color_t c2)
{
int dr = abs((c1.r)-(c2.r));
int dg = abs((c1.g)-(c2.g));
int db = abs((c1.b)-(c2.b));
return sqrt((dr*dr)+(dg*dg)+(db*db));
enum {
DISTANCE,
WEIGHTED,
SIMPLE
} errorFunc = WEIGHTED;
switch (errorFunc) {
case SIMPLE:
return dr+dg+db;
case DISTANCE:
return sqrt((dr*dr)+(dg*dg)+(db*db));
case WEIGHTED:
default:
return dr*3+dg*4+db*2;
}
}
+6 -4
View File
@@ -20,7 +20,8 @@ dither_getHamColor(imagecon_image_t* ic, amiga_color_t color, amiga_color_t last
float
_gamma(float x)
{
return x * 0.55;
return x * 0.55;
// return x;
}
static void
@@ -48,9 +49,10 @@ dither_image(imagecon_image_t* ic, amiga_color_t (*selector)(imagecon_image_t*,
amiga_color_t new = selector(ic, color_ditheredToAmiga(old), last);
dither_color_t error;
error.r = old.r - new.r;
error.g = old.g - new.g;
error.b = old.b - new.b;
float gamma = 1.0;
error.r = old.r - (new.r*gamma);
error.g = old.g - (new.g*gamma);
error.b = old.b - (new.b*gamma);
color_setDitheredPixel(ic, x, y, color_amigaToDithered(new));
last = new;
+6 -2
View File
@@ -70,7 +70,8 @@ generateQuantizedImage(imagecon_image_t* ic, int usePalette)
}
liq_attr *attr = liq_attr_create();
liq_image *image = liq_image_create_rgba_rows(attr, (void**)ic->rowPointers, ic->width, ic->height, 0);
// TODO: What to do with gamma here ?
liq_image *image = liq_image_create_rgba_rows(attr, (void**)ic->rowPointers, ic->width, ic->height, /* gamma */0.0);
if (usePalette) {
for (int i = 0; i < ic->numColors; i++) {
@@ -83,12 +84,15 @@ generateQuantizedImage(imagecon_image_t* ic, int usePalette)
}
}
liq_set_max_colors(attr, config.maxColors);
// no liq_set_quality(attr, 0, 100);
//liq_set_min_posterization(attr, 4);
liq_set_speed(attr, 1);
liq_result *res = liq_quantize_image(attr, image);
// liq_set_dithering_level(res, 1.0);
//liq_set_output_gamma(res, 0.1);
//liq_set_dithering_level(res, 0);
liq_write_remapped_image(res, image, ic->amigaImage, ic->width*ic->height);
const liq_palette *pal = liq_get_palette(res);
Binary file not shown.