Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

87 righe
2.2 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 <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. }