25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

merge.c 2.2 KiB

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