You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * ordered.c: Bayer ordered dithering functions
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #include "pipi.h"
  20. #include "pipi_internals.h"
  21. static const int kernel8x8[8 * 8] =
  22. {
  23. 0, 32, 8, 40, 2, 34, 10, 42,
  24. 48, 16, 56, 24, 50, 18, 58, 26,
  25. 12, 44, 4, 36, 14, 46, 6, 38,
  26. 60, 28, 52, 20, 62, 30, 54, 22,
  27. 3, 35, 11, 43, 1, 33, 9, 41,
  28. 51, 19, 59, 27, 49, 17, 57, 25,
  29. 15, 47, 7, 39, 13, 45, 5, 37,
  30. 63, 31, 55, 23, 61, 29, 53, 21,
  31. };
  32. pipi_image_t *pipi_dither_ordered(pipi_image_t *img)
  33. {
  34. pipi_image_t *dst;
  35. pipi_pixels_t *dstp;
  36. float *dstdata;
  37. int x, y, w, h;
  38. w = img->w;
  39. h = img->h;
  40. dst = pipi_copy(img);
  41. dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
  42. dstdata = (float *)dstp->pixels;
  43. for(y = 0; y < h; y++)
  44. {
  45. for(x = 0; x < w; x++)
  46. {
  47. float p, q;
  48. p = dstdata[y * w + x];
  49. q = p > (1. + kernel8x8[(y % 8) * 8 + (x % 8)]) / 65. ? 1. : 0.;
  50. dstdata[y * w + x] = q;
  51. }
  52. }
  53. return dst;
  54. }