Quellcode durchsuchen

* Add Floyd-Steinberg grayscale dithering.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2637 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam vor 16 Jahren
Ursprung
Commit
1408cff41d
3 geänderte Dateien mit 70 neuen und 0 gelöschten Zeilen
  1. +1
    -0
      pipi/Makefile.am
  2. +68
    -0
      pipi/dither/floydsteinberg.c
  3. +1
    -0
      pipi/pipi.h

+ 1
- 0
pipi/Makefile.am Datei anzeigen

@@ -29,6 +29,7 @@ libpipi_la_SOURCES = \
test.c \
$(codec_sources) \
filter/blur.c \
dither/floydsteinberg.c \
$(NULL)
libpipi_la_CFLAGS = $(codec_cflags)
libpipi_la_LDFLAGS = $(codec_libs) \


+ 68
- 0
pipi/dither/floydsteinberg.c Datei anzeigen

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

/*
* floydsteinberg.c: Floyd-Steinberg dithering functions
*/

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

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

pipi_image_t *pipi_floydsteinberg(pipi_image_t *src)
{
pipi_image_t *dst;
pipi_pixels_t *srcp, *dstp;
float *srcdata, *dstdata;
int x, y, w, h;

w = src->w;
h = src->h;

srcp = pipi_getpixels(src, PIPI_PIXELS_Y_F);
srcdata = (float *)srcp->pixels;

dst = pipi_new(w, h);
dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
dstdata = (float *)dstp->pixels;

for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
float p, q, e;

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

e = p - q;
if(x < w - 1)
srcdata[y * w + x + 1] += e * .4375;
if(y < h - 1)
{
if(x > 0)
srcdata[(y + 1) * w + x - 1] += e * .1875;
srcdata[(y + 1) * w + x] += e * .3125;
if(x < w - 1)
srcdata[(y + 1) * w + x + 1] += e * .0625;
}
}
}

return dst;
}


+ 1
- 0
pipi/pipi.h Datei anzeigen

@@ -67,6 +67,7 @@ extern pipi_image_t *pipi_gaussian_blur(pipi_image_t *, float);
extern pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *,
float, float, float, float);

extern pipi_image_t *pipi_floydsteinberg(pipi_image_t *);
extern void pipi_dither_24to16(pipi_image_t *);

extern void pipi_test(pipi_image_t *);


Laden…
Abbrechen
Speichern