Explorar el Código

* Add pipi_dither_ediff(), a generic error diffusion dithering algorithm

that uses an image as the error diffusion kernel.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2758 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam hace 16 años
padre
commit
90c7527281
Se han modificado 4 ficheros con 95 adiciones y 0 borrados
  1. +1
    -0
      pipi/Makefile.am
  2. +8
    -0
      pipi/context.c
  3. +84
    -0
      pipi/dither/ediff.c
  4. +2
    -0
      pipi/pipi.h

+ 1
- 0
pipi/Makefile.am Ver fichero

@@ -64,6 +64,7 @@ quantize_sources = \
quantize/reduce.c

dither_sources = \
dither/ediff.c \
dither/floydsteinberg.c \
dither/jajuni.c \
dither/atkinson.c \


+ 8
- 0
pipi/context.c Ver fichero

@@ -100,6 +100,14 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...)
dst = pipi_dither_ostromoukhov(src, 0);
else if(!strcmp(method, "sost"))
dst = pipi_dither_ostromoukhov(src, 1);
else if(!strcmp(method, "ediff"))
{
if(ctx->nimages < 2)
return -1;
dst = pipi_dither_ediff(ctx->images[ctx->nimages - 2], src, 0);
pipi_free(ctx->images[ctx->nimages - 2]);
ctx->nimages--;
}
else if(!strcmp(method, "ordered"))
{
if(ctx->nimages < 2)


+ 84
- 0
pipi/dither/ediff.c Ver fichero

@@ -0,0 +1,84 @@
/*
* libpipi Proper image processing implementation library
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* This library is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/

/*
* ed.c: generic error diffusion functions
*/

#include "config.h"
#include "common.h"

#include "pipi.h"
#include "pipi_internals.h"

/* Perform a generic error diffusion dithering. The first non-zero
* element in ker is treated as the current pixel. All other non-zero
* elements are the error diffusion coefficients. */
pipi_image_t *pipi_dither_ediff(pipi_image_t *img, pipi_image_t *ker,
pipi_scan_t scan)
{
pipi_image_t *dst;
pipi_pixels_t *dstp, *kerp;
float *dstdata, *kerdata;
int x, y, w, h, i, j, kx, kw, kh;

w = img->w;
h = img->h;
kw = ker->w;
kh = ker->h;

dst = pipi_copy(img);
dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
dstdata = (float *)dstp->pixels;

kerp = pipi_getpixels(ker, PIPI_PIXELS_Y_F);
kerdata = (float *)kerp->pixels;
for(kx = 0; kx < kw; kx++)
if(kerdata[kx] > 0)
break;

for(y = 0; y < h; y++)
{
int reverse = (y & 1) && (scan == PIPI_SCAN_SERPENTINE);

for(x = 0; x < w; x++)
{
float p, q, e;
int x2 = reverse ? w - 1 - x : x;
int s = reverse ? -1 : 1;

p = dstdata[y * w + x2];
q = p < 0.5 ? 0. : 1.;
dstdata[y * w + x2] = q;

e = (p - q);

for(j = 0; j < kh && y < h - j; j++)
for(i = 0; i < kw; i++)
{
if(j == 0 && i <= kx)
continue;

if(x + i - kx < 0 || x + i - kx >= w)
continue;

dstdata[(y + j) * w + x2 + (i - kx) * s]
+= e * kerdata[j * kw + i];
}
}
}

return dst;
}


+ 2
- 0
pipi/pipi.h Ver fichero

@@ -147,6 +147,8 @@ extern int pipi_flood_fill(pipi_image_t *,

extern pipi_image_t *pipi_reduce(pipi_image_t *, int, double const *);

extern pipi_image_t *pipi_dither_ediff(pipi_image_t *, 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_jajuni(pipi_image_t *, pipi_scan_t);
extern pipi_image_t *pipi_dither_atkinson(pipi_image_t *, pipi_scan_t);


Cargando…
Cancelar
Guardar