You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 regels
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. * test.c: my repository of test functions
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "pipi.h"
  22. #include "pipi_internals.h"
  23. void pipi_test(pipi_image_t *img)
  24. {
  25. int x, y;
  26. for(y = 0; y < img->height; y++)
  27. {
  28. for(x = 0; x < img->width; x++)
  29. {
  30. double r = 0, g = 0, b = 0;
  31. pipi_getpixel(img, x, y, &r, &g, &b);
  32. if(r + g + b == 0)
  33. r = g = b = 1. / 3;
  34. else if(r + g + b < 1.)
  35. {
  36. double d = (1. - r - g - b) / 3;
  37. r += d; g += d; b += d;
  38. }
  39. else if(2. - r + g - b < 1.)
  40. {
  41. double d = (-1. + r - g + b) / 3;
  42. r -= d; g += d; b -= d;
  43. }
  44. else if(2. + r - g - b < 1.)
  45. {
  46. double d = (-1. - r + g + b) / 3;
  47. r += d; g -= d; b -= d;
  48. }
  49. pipi_setpixel(img, x, y, r, g, b);
  50. }
  51. }
  52. }