Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

72 lignes
1.8 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. pipi_pixels_t *pixels;
  26. float *data;
  27. int x, y;
  28. pixels = pipi_getpixels(img, PIPI_PIXELS_RGBA_F);
  29. data = (float *)pixels->pixels;
  30. for(y = 0; y < img->h; y++)
  31. {
  32. for(x = 0; x < img->w; x++)
  33. {
  34. double r = 0, g = 0, b = 0;
  35. r = data[(y * img->w + x) * 4];
  36. g = data[(y * img->w + x) * 4 + 1];
  37. b = data[(y * img->w + x) * 4 + 2];
  38. if(r + g + b == 0)
  39. r = g = b = 1. / 3;
  40. else if(r + g + b < 1.)
  41. {
  42. double d = (1. - r - g - b) / 3;
  43. r += d; g += d; b += d;
  44. }
  45. else if(2. - r + g - b < 1.)
  46. {
  47. double d = (-1. + r - g + b) / 3;
  48. r -= d; g += d; b -= d;
  49. }
  50. else if(2. + r - g - b < 1.)
  51. {
  52. double d = (-1. - r + g + b) / 3;
  53. r += d; g -= d; b -= d;
  54. }
  55. data[(y * img->w + x) * 4] = r;
  56. data[(y * img->w + x) * 4 + 1] = g;
  57. data[(y * img->w + x) * 4 + 2] = b;
  58. }
  59. }
  60. }