Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

mean.c 1.9 KiB

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