the ordered dithering matrix. To get the old behaviour, use: pipi image.png pipi:bayer8 --dither ordered out.png git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2696 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
@@ -93,7 +93,13 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) | |||||
else if(!strcmp(method, "sost")) | else if(!strcmp(method, "sost")) | ||||
dst = pipi_dither_ostromoukhov(src, 1); | dst = pipi_dither_ostromoukhov(src, 1); | ||||
else if(!strcmp(method, "ordered")) | else if(!strcmp(method, "ordered")) | ||||
dst = pipi_dither_ordered(src); | |||||
{ | |||||
if(ctx->nimages < 2) | |||||
return -1; | |||||
dst = pipi_dither_ordered(ctx->images[ctx->nimages - 2], src); | |||||
pipi_free(ctx->images[ctx->nimages - 2]); | |||||
ctx->nimages--; | |||||
} | |||||
else if(!strcmp(method, "random")) | else if(!strcmp(method, "random")) | ||||
dst = pipi_dither_random(src); | dst = pipi_dither_random(src); | ||||
else if(!strcmp(method, "dbs")) | else if(!strcmp(method, "dbs")) | ||||
@@ -22,32 +22,25 @@ | |||||
#include "pipi.h" | #include "pipi.h" | ||||
#include "pipi_internals.h" | #include "pipi_internals.h" | ||||
static const int kernel8x8[8 * 8] = | |||||
{ | |||||
0, 32, 8, 40, 2, 34, 10, 42, | |||||
48, 16, 56, 24, 50, 18, 58, 26, | |||||
12, 44, 4, 36, 14, 46, 6, 38, | |||||
60, 28, 52, 20, 62, 30, 54, 22, | |||||
3, 35, 11, 43, 1, 33, 9, 41, | |||||
51, 19, 59, 27, 49, 17, 57, 25, | |||||
15, 47, 7, 39, 13, 45, 5, 37, | |||||
63, 31, 55, 23, 61, 29, 53, 21, | |||||
}; | |||||
pipi_image_t *pipi_dither_ordered(pipi_image_t *img) | |||||
pipi_image_t *pipi_dither_ordered(pipi_image_t *img, pipi_image_t *kernel) | |||||
{ | { | ||||
pipi_image_t *dst; | pipi_image_t *dst; | ||||
pipi_pixels_t *dstp; | |||||
float *dstdata; | |||||
int x, y, w, h; | |||||
pipi_pixels_t *dstp, *kernelp; | |||||
float *dstdata, *kerneldata; | |||||
int x, y, w, h, kw, kh; | |||||
w = img->w; | w = img->w; | ||||
h = img->h; | h = img->h; | ||||
kw = kernel->w; | |||||
kh = kernel->h; | |||||
dst = pipi_copy(img); | dst = pipi_copy(img); | ||||
dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F); | dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F); | ||||
dstdata = (float *)dstp->pixels; | dstdata = (float *)dstp->pixels; | ||||
kernelp = pipi_getpixels(kernel, PIPI_PIXELS_Y_F); | |||||
kerneldata = (float *)kernelp->pixels; | |||||
for(y = 0; y < h; y++) | for(y = 0; y < h; y++) | ||||
{ | { | ||||
for(x = 0; x < w; x++) | for(x = 0; x < w; x++) | ||||
@@ -55,7 +48,7 @@ pipi_image_t *pipi_dither_ordered(pipi_image_t *img) | |||||
float p, q; | float p, q; | ||||
p = dstdata[y * w + x]; | p = dstdata[y * w + x]; | ||||
q = p > (1. + kernel8x8[(y % 8) * 8 + (x % 8)]) / 65. ? 1. : 0.; | |||||
q = p > kerneldata[(y % kh) * kw + (x % kw)] ? 1. : 0.; | |||||
dstdata[y * w + x] = q; | dstdata[y * w + x] = q; | ||||
} | } | ||||
} | } | ||||
@@ -97,7 +97,7 @@ extern int pipi_flood_fill(pipi_image_t *, | |||||
int, int, float, float, float, float); | int, int, float, float, float, float); | ||||
extern pipi_image_t *pipi_dither_floydsteinberg(pipi_image_t *, pipi_scan_t); | extern pipi_image_t *pipi_dither_floydsteinberg(pipi_image_t *, pipi_scan_t); | ||||
extern pipi_image_t *pipi_dither_ordered(pipi_image_t *); | |||||
extern pipi_image_t *pipi_dither_ordered(pipi_image_t *, pipi_image_t *); | |||||
extern pipi_image_t *pipi_dither_random(pipi_image_t *); | extern pipi_image_t *pipi_dither_random(pipi_image_t *); | ||||
extern pipi_image_t *pipi_dither_ostromoukhov(pipi_image_t *, pipi_scan_t); | extern pipi_image_t *pipi_dither_ostromoukhov(pipi_image_t *, pipi_scan_t); | ||||
extern pipi_image_t *pipi_dither_dbs(pipi_image_t *); | extern pipi_image_t *pipi_dither_dbs(pipi_image_t *); | ||||