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.
 
 
 
 
 
 

73 lines
1.9 KiB

  1. /*
  2. * libpipi Pathetic image processing interface 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. * mean.c: Mean computation function
  16. */
  17. #include "config.h"
  18. #include "pipi.h"
  19. #include "pipi_internals.h"
  20. pipi_image_t *pipi_mean(pipi_image_t *img1, pipi_image_t *img2)
  21. {
  22. pipi_image_t *dst;
  23. pipi_pixels_t *img1p, *img2p, *dstp;
  24. float *img1data, *img2data, *dstdata;
  25. int x, y, w, h;
  26. if(img1->w != img2->w || img1->h != img2->h)
  27. return NULL;
  28. w = img1->w;
  29. h = img1->h;
  30. dst = pipi_new(w, h);
  31. dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
  32. dstdata = (float *)dstp->pixels;
  33. img1p = pipi_getpixels(img1, PIPI_PIXELS_RGBA_F);
  34. img1data = (float *)img1p->pixels;
  35. img2p = pipi_getpixels(img2, PIPI_PIXELS_RGBA_F);
  36. img2data = (float *)img2p->pixels;
  37. for(y = 0; y < h; y++)
  38. {
  39. for(x = 0; x < w; x++)
  40. {
  41. float p, q;
  42. p = img1data[4 * (y * w + x)];
  43. q = img2data[4 * (y * w + x)];
  44. dstdata[4 * (y * w + x)] = (p + q) * 0.5;
  45. p = img1data[4 * (y * w + x) + 1];
  46. q = img2data[4 * (y * w + x) + 1];
  47. dstdata[4 * (y * w + x) + 1] = (p + q) * 0.5;
  48. p = img1data[4 * (y * w + x) + 2];
  49. q = img2data[4 * (y * w + x) + 2];
  50. dstdata[4 * (y * w + x) + 2] = (p + q) * 0.5;
  51. p = img1data[4 * (y * w + x) + 3];
  52. q = img2data[4 * (y * w + x) + 3];
  53. dstdata[4 * (y * w + x) + 3] = (p + q) * 0.5;
  54. }
  55. }
  56. return dst;
  57. }