|
|
@@ -20,22 +20,33 @@ |
|
|
|
#include "common.h" |
|
|
|
|
|
|
|
#include <stdlib.h> |
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
#include "pipi.h" |
|
|
|
#include "pipi_internals.h" |
|
|
|
|
|
|
|
pipi_image_t *pipi_dither_ordered(pipi_image_t *img, pipi_image_t *kernel) |
|
|
|
{ |
|
|
|
return pipi_dither_ordered_ext(img, kernel, 0.0); |
|
|
|
} |
|
|
|
|
|
|
|
pipi_image_t *pipi_dither_ordered_ext(pipi_image_t *img, pipi_image_t *kernel, |
|
|
|
double angle) |
|
|
|
{ |
|
|
|
double sint, cost; |
|
|
|
pipi_image_t *dst; |
|
|
|
pipi_pixels_t *dstp, *kernelp; |
|
|
|
float *dstdata, *kerneldata; |
|
|
|
int x, y, w, h, kw, kh; |
|
|
|
int x, y, w, h, kx, ky, kw, kh; |
|
|
|
|
|
|
|
w = img->w; |
|
|
|
h = img->h; |
|
|
|
kw = kernel->w; |
|
|
|
kh = kernel->h; |
|
|
|
|
|
|
|
cost = cos(angle * (M_PI / 180)); |
|
|
|
sint = sin(angle * (M_PI / 180)); |
|
|
|
|
|
|
|
dst = pipi_copy(img); |
|
|
|
dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F); |
|
|
|
dstdata = (float *)dstp->pixels; |
|
|
@@ -49,8 +60,11 @@ pipi_image_t *pipi_dither_ordered(pipi_image_t *img, pipi_image_t *kernel) |
|
|
|
{ |
|
|
|
float p, q; |
|
|
|
|
|
|
|
kx = (int)(cost * x - sint * y + 2 * w * h) % kw; |
|
|
|
ky = (int)(cost * y + sint * x + 2 * w * h) % kh; |
|
|
|
|
|
|
|
p = dstdata[y * w + x]; |
|
|
|
q = p > kerneldata[(y % kh) * kw + (x % kw)] ? 1. : 0.; |
|
|
|
q = p > kerneldata[ky * kw + kx] ? 1. : 0.; |
|
|
|
dstdata[y * w + x] = q; |
|
|
|
} |
|
|
|
} |
|
|
|