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

67 行
1.5 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. * screen.c: halftoning screen 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_bayer(int w, int h)
  25. {
  26. pipi_image_t *ret;
  27. pipi_pixels_t *pix;
  28. float *data;
  29. int i, j, n;
  30. if(w <= 0 || h <= 0)
  31. return NULL;
  32. for(n = 1; n < w || n < h; n *= 2)
  33. ;
  34. ret = pipi_new(w, h);
  35. pix = pipi_getpixels(ret, PIPI_PIXELS_Y_F);
  36. data = (float *)pix->pixels;
  37. for(j = 0; j < h; j++)
  38. for(i = 0; i < w; i++)
  39. {
  40. int k, l, x = 0;
  41. for(k = 1, l = n * n / 4; k < n; k *= 2, l /= 4)
  42. {
  43. if((i & k) && (j & k))
  44. x += l;
  45. else if(i & k)
  46. x += 3 * l;
  47. else if(j & k)
  48. x += 2 * l;
  49. }
  50. data[j * w + i] = (double)(x + 1) / (n * n + 1);
  51. }
  52. return ret;
  53. }