source: libpipi/trunk/pipi/dither/ordered.c @ 2696

Last change on this file since 2696 was 2696, checked in by Sam Hocevar, 14 years ago
  • pipi_dither_ordered() now takes two arguments; any image can be used as the ordered dithering matrix. To get the old behaviour, use:

pipi image.png pipi:bayer8 --dither ordered out.png

File size: 1.4 KB
Line 
1/*
2 *  libpipi       Proper image processing implementation library
3 *  Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id$
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 * ordered.c: Bayer ordered dithering functions
17 */
18
19#include "config.h"
20#include "common.h"
21
22#include "pipi.h"
23#include "pipi_internals.h"
24
25pipi_image_t *pipi_dither_ordered(pipi_image_t *img, pipi_image_t *kernel)
26{
27    pipi_image_t *dst;
28    pipi_pixels_t *dstp, *kernelp;
29    float *dstdata, *kerneldata;
30    int x, y, w, h, kw, kh;
31
32    w = img->w;
33    h = img->h;
34    kw = kernel->w;
35    kh = kernel->h;
36
37    dst = pipi_copy(img);
38    dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
39    dstdata = (float *)dstp->pixels;
40
41    kernelp = pipi_getpixels(kernel, PIPI_PIXELS_Y_F);
42    kerneldata = (float *)kernelp->pixels;
43
44    for(y = 0; y < h; y++)
45    {
46        for(x = 0; x < w; x++)
47        {
48            float p, q;
49
50            p = dstdata[y * w + x];
51            q = p > kerneldata[(y % kh) * kw + (x % kw)] ? 1. : 0.;
52            dstdata[y * w + x] = q;
53        }
54    }
55
56    return dst;
57}
58
Note: See TracBrowser for help on using the repository browser.