Parcourir la source

* atkinson.c: implement Atkinson dithering.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2751 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam il y a 16 ans
Parent
révision
b40fc1b330
4 fichiers modifiés avec 81 ajouts et 0 suppressions
  1. +1
    -0
      pipi/Makefile.am
  2. +4
    -0
      pipi/context.c
  3. +75
    -0
      pipi/dither/atkinson.c
  4. +1
    -0
      pipi/pipi.h

+ 1
- 0
pipi/Makefile.am Voir le fichier

@@ -65,6 +65,7 @@ quantize_sources = \
dither_sources = \
dither/floydsteinberg.c \
dither/jajuni.c \
dither/atkinson.c \
dither/ordered.c \
dither/ostromoukhov.c \
dither/dbs.c \


+ 4
- 0
pipi/context.c Voir le fichier

@@ -92,6 +92,10 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...)
dst = pipi_dither_jajuni(src, 0);
else if(!strcmp(method, "sjajuni"))
dst = pipi_dither_jajuni(src, 1);
else if(!strcmp(method, "atkinson"))
dst = pipi_dither_atkinson(src, 0);
else if(!strcmp(method, "satkinson"))
dst = pipi_dither_atkinson(src, 1);
else if(!strcmp(method, "ost"))
dst = pipi_dither_ostromoukhov(src, 0);
else if(!strcmp(method, "sost"))


+ 75
- 0
pipi/dither/atkinson.c Voir le fichier

@@ -0,0 +1,75 @@
/*
* 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.
*/

/*
* atkinson.c: Atkinson dithering functions
*/

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

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

pipi_image_t *pipi_dither_atkinson(pipi_image_t *img, pipi_scan_t scan)
{
pipi_image_t *dst;
pipi_pixels_t *dstp;
float *dstdata;
int x, y, w, h;

w = img->w;
h = img->h;

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

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) / 8.;
if(x < w - 1)
dstdata[y * w + x2 + s] += e;
if(x < w - 2)
dstdata[y * w + x2 + s + s] += e;
if(y < h - 1)
{
if(x > 0)
dstdata[(y + 1) * w + x2 - s] += e;
dstdata[(y + 1) * w + x2] += e;
if(x < w - 1)
dstdata[(y + 1) * w + x2 + s] += e;
}
if(y < h - 2)
{
dstdata[(y + 2) * w + x2] += e;
}
}
}

return dst;
}


+ 1
- 0
pipi/pipi.h Voir le fichier

@@ -145,6 +145,7 @@ extern pipi_image_t *pipi_reduce(pipi_image_t *, int, double const *);

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);
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_ostromoukhov(pipi_image_t *, pipi_scan_t);


Chargement…
Annuler
Enregistrer