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.
 
 
 
 
 
 

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