Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

59 řádky
1.4 KiB

  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. pipi_image_t *pipi_dither_ordered(pipi_image_t *img, pipi_image_t *kernel)
  22. {
  23. pipi_image_t *dst;
  24. pipi_pixels_t *dstp, *kernelp;
  25. float *dstdata, *kerneldata;
  26. int x, y, w, h, kw, kh;
  27. w = img->w;
  28. h = img->h;
  29. kw = kernel->w;
  30. kh = kernel->h;
  31. dst = pipi_copy(img);
  32. dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
  33. dstdata = (float *)dstp->pixels;
  34. kernelp = pipi_getpixels(kernel, PIPI_PIXELS_Y_F);
  35. kerneldata = (float *)kernelp->pixels;
  36. for(y = 0; y < h; y++)
  37. {
  38. for(x = 0; x < w; x++)
  39. {
  40. float p, q;
  41. p = dstdata[y * w + x];
  42. q = p > kerneldata[(y % kh) * kw + (x % kw)] ? 1. : 0.;
  43. dstdata[y * w + x] = q;
  44. }
  45. }
  46. return dst;
  47. }