25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 lines
1.4 KiB

  1. /*
  2. * libpipi Pathetic image processing interface 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. * random.c: random dithering functions
  16. */
  17. #include "config.h"
  18. #include "pipi.h"
  19. #include "pipi_internals.h"
  20. pipi_image_t *pipi_dither_random(pipi_image_t *img)
  21. {
  22. pipi_image_t *dst;
  23. pipi_pixels_t *dstp;
  24. float *dstdata;
  25. unsigned int ctx = 1;
  26. int x, y, w, h;
  27. w = img->w;
  28. h = img->h;
  29. dst = pipi_copy(img);
  30. dstp = pipi_get_pixels(dst, PIPI_PIXELS_Y_F32);
  31. dstdata = (float *)dstp->pixels;
  32. for(y = 0; y < h; y++)
  33. {
  34. for(x = 0; x < w; x++)
  35. {
  36. long hi, lo;
  37. float p, q;
  38. hi = ctx / 12773L;
  39. lo = ctx % 12773L;
  40. ctx = 16807L * lo - 2836L * hi;
  41. if(ctx <= 0)
  42. ctx += 0x7fffffffL;
  43. p = dstdata[y * w + x];
  44. q = p > (double)((ctx % 65536) / 65535.) ? 1. : 0.;
  45. dstdata[y * w + x] = q;
  46. }
  47. }
  48. return dst;
  49. }