25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

noise.c 1.4 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. * noise.c: noise rendering functions
  16. */
  17. #include "config.h"
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "pipi.h"
  22. #include "pipi_internals.h"
  23. pipi_image_t *pipi_render_random(int w, int h)
  24. {
  25. pipi_image_t *ret;
  26. pipi_pixels_t *pix;
  27. float *data;
  28. unsigned int ctx = 1;
  29. int x, y, t;
  30. ret = pipi_new(w, h);
  31. pix = pipi_getpixels(ret, PIPI_PIXELS_RGBA_F);
  32. data = (float *)pix->pixels;
  33. for(y = 0; y < h; y++)
  34. for(x = 0; x < w; x++)
  35. {
  36. for(t = 0; t < 3; t++)
  37. {
  38. long hi, lo;
  39. hi = ctx / 12773L;
  40. lo = ctx % 12773L;
  41. ctx = 16807L * lo - 2836L * hi;
  42. if(ctx <= 0)
  43. ctx += 0x7fffffffL;
  44. data[4 * (y * w + x) + t]
  45. = (double)((ctx % 65536) / 65535.);
  46. }
  47. data[4 * (y * w + x) + 3] = 1.0;
  48. }
  49. return ret;
  50. }