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.
 
 
 
 
 
 

90 satır
2.4 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_blit(pipi_image_t *img1, pipi_image_t *img2, int x, int y)
  22. {
  23. pipi_image_t *dst;
  24. pipi_pixels_t *img1p, *img2p, *dstp;
  25. float *img1data, *img2data, *dstdata;
  26. int dx, dy, w1, h1, w2, h2;
  27. w1 = img1->w;
  28. h1 = img1->h;
  29. w2 = img2->w;
  30. h2 = img2->h;
  31. dst = pipi_copy(img1);
  32. dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
  33. dstdata = (float *)dstp->pixels;
  34. img1p = pipi_get_pixels(img1, PIPI_PIXELS_RGBA_F32);
  35. img1data = (float *)img1p->pixels;
  36. img2p = pipi_get_pixels(img2, PIPI_PIXELS_RGBA_F32);
  37. img2data = (float *)img2p->pixels;
  38. for(dy = 0; dy < h2; dy++)
  39. {
  40. if (y + dy < 0)
  41. continue;
  42. if (y + dy >= h1)
  43. break;
  44. for(dx = 0; dx < w2; dx++)
  45. {
  46. float p, q;
  47. double t1, t2;
  48. if (x + dx < 0)
  49. continue;
  50. if (x + dx >= w1)
  51. break;
  52. t1 = img2data[4 * (dy * w2 + dx) + 3];
  53. t2 = 1.0 - t1;
  54. p = img1data[4 * ((y + dy) * w1 + (x + dx))];
  55. q = img2data[4 * (dy * w2 + dx)];
  56. dstdata[4 * ((y + dy) * w1 + (x + dx))] = t2 * p + t1 * q;
  57. p = img1data[4 * ((y + dy) * w1 + (x + dx)) + 1];
  58. q = img2data[4 * (dy * w2 + dx) + 1];
  59. dstdata[4 * ((y + dy) * w1 + (x + dx)) + 1] = t2 * p + t1 * q;
  60. p = img1data[4 * ((y + dy) * w1 + (x + dx)) + 2];
  61. q = img2data[4 * (dy * w2 + dx) + 2];
  62. dstdata[4 * ((y + dy) * w1 + (x + dx)) + 2] = t2 * p + t1 * q;
  63. p = img1data[4 * ((y + dy) * w1 + (x + dx)) + 3];
  64. q = img2data[4 * (dy * w2 + dx) + 3];
  65. dstdata[4 * ((y + dy) * w1 + (x + dx)) + 3] = t2 * p + t1 * q;
  66. }
  67. }
  68. return dst;
  69. }