Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_merge(pipi_image_t *img1, pipi_image_t *img2, double t)
  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. if(t < 0.0)
  30. t = 0.0;
  31. else if(t > 1.0)
  32. t = 1.0;
  33. w = img1->w;
  34. h = img1->h;
  35. dst = pipi_new(w, h);
  36. dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
  37. dstdata = (float *)dstp->pixels;
  38. img1p = pipi_get_pixels(img1, PIPI_PIXELS_RGBA_F32);
  39. img1data = (float *)img1p->pixels;
  40. img2p = pipi_get_pixels(img2, PIPI_PIXELS_RGBA_F32);
  41. img2data = (float *)img2p->pixels;
  42. for(y = 0; y < h; y++)
  43. {
  44. for(x = 0; x < w; x++)
  45. {
  46. float p, q;
  47. double t1 = t * img2data[4 * (y * w + x) + 3];
  48. double t2 = 1.0 - t1;
  49. p = img1data[4 * (y * w + x)];
  50. q = img2data[4 * (y * w + x)];
  51. dstdata[4 * (y * w + x)] = t2 * p + t1 * q;
  52. p = img1data[4 * (y * w + x) + 1];
  53. q = img2data[4 * (y * w + x) + 1];
  54. dstdata[4 * (y * w + x) + 1] = t2 * p + t1 * q;
  55. p = img1data[4 * (y * w + x) + 2];
  56. q = img2data[4 * (y * w + x) + 2];
  57. dstdata[4 * (y * w + x) + 2] = t2 * p + t1 * q;
  58. p = img1data[4 * (y * w + x) + 3];
  59. q = img2data[4 * (y * w + x) + 3];
  60. dstdata[4 * (y * w + x) + 3] = t2 * p + t1 * q;
  61. }
  62. }
  63. return dst;
  64. }
  65. pipi_image_t *pipi_mean(pipi_image_t *img1, pipi_image_t *img2)
  66. {
  67. return pipi_merge(img1, img2, 0.5);
  68. }