您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

71 行
1.7 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. * stock.c: stock images
  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_load_stock(char const *name)
  25. {
  26. pipi_image_t *ret;
  27. pipi_pixels_t *pix;
  28. float *data;
  29. /* Generate a Bayer dithering pattern. */
  30. if(!strncmp(name, "bayer", 5))
  31. {
  32. int i, j, n = atoi(name + 5);
  33. if(n <= 0 || (n & (n - 1))) /* is n a power of two? */
  34. return NULL;
  35. ret = pipi_new(n, n);
  36. pix = pipi_getpixels(ret, PIPI_PIXELS_Y_F);
  37. data = (float *)pix->pixels;
  38. for(j = 0; j < n; j++)
  39. for(i = 0; i < n; i++)
  40. {
  41. int k, l, x = 0;
  42. for(k = 1, l = n * n / 4; k < n; k *= 2, l /= 4)
  43. {
  44. if((i & k) && (j & k))
  45. x += l;
  46. else if(i & k)
  47. x += 3 * l;
  48. else if(j & k)
  49. x += 2 * l;
  50. }
  51. data[j * n + i] = (double)(x + 1) / (n * n + 1);
  52. }
  53. return ret;
  54. }
  55. return NULL;
  56. }