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.
 
 
 
 
 
 

72 line
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. * pixels.c: pixel-level image manipulation
  16. */
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include "config.h"
  21. #include "common.h"
  22. #include "pipi_internals.h"
  23. #include "pipi.h"
  24. int pipi_getgray(pipi_image_t const *img, int x, int y, int *g)
  25. {
  26. if(x < 0 || y < 0 || x >= img->width || y >= img->height)
  27. {
  28. *g = 255;
  29. return -1;
  30. }
  31. *g = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 1];
  32. return 0;
  33. }
  34. int pipi_getpixel(pipi_image_t const *img,
  35. int x, int y, int *r, int *g, int *b)
  36. {
  37. if(x < 0 || y < 0 || x >= img->width || y >= img->height)
  38. {
  39. *r = 255;
  40. *g = 255;
  41. *b = 255;
  42. return -1;
  43. }
  44. *b = (unsigned char)img->pixels[y * img->pitch + x * img->channels];
  45. *g = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 1];
  46. *r = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 2];
  47. return 0;
  48. }
  49. int pipi_setpixel(pipi_image_t *img, int x, int y, int r, int g, int b)
  50. {
  51. if(x < 0 || y < 0 || x >= img->width || y >= img->height)
  52. return -1;
  53. img->pixels[y * img->pitch + x * img->channels] = b;
  54. img->pixels[y * img->pitch + x * img->channels + 1] = g;
  55. img->pixels[y * img->pitch + x * img->channels + 2] = r;
  56. return 0;
  57. }