You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

122 lines
3.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. * minmax.c: min and max computation functions
  16. */
  17. #include "config.h"
  18. #include "pipi.h"
  19. #include "pipi_internals.h"
  20. pipi_image_t *pipi_min(pipi_image_t *img1, pipi_image_t *img2)
  21. {
  22. pipi_image_t *dst;
  23. pipi_pixels_t *img1p, *img2p, *dstp;
  24. float *img1data, *img2data, *dstdata;
  25. int x, y, w, h;
  26. if(img1->w != img2->w || img1->h != img2->h)
  27. return NULL;
  28. w = img1->w;
  29. h = img1->h;
  30. dst = pipi_new(w, h);
  31. dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
  32. dstdata = (float *)dstp->pixels;
  33. img1p = pipi_getpixels(img1, PIPI_PIXELS_RGBA_F);
  34. img1data = (float *)img1p->pixels;
  35. img2p = pipi_getpixels(img2, PIPI_PIXELS_RGBA_F);
  36. img2data = (float *)img2p->pixels;
  37. for(y = 0; y < h; y++)
  38. {
  39. for(x = 0; x < w; x++)
  40. {
  41. float p, q;
  42. p = img1data[4 * (y * w + x)];
  43. q = img2data[4 * (y * w + x)];
  44. dstdata[4 * (y * w + x)] = p < q ? p : q;
  45. p = img1data[4 * (y * w + x) + 1];
  46. q = img2data[4 * (y * w + x) + 1];
  47. dstdata[4 * (y * w + x) + 1] = p < q ? p : q;
  48. p = img1data[4 * (y * w + x) + 2];
  49. q = img2data[4 * (y * w + x) + 2];
  50. dstdata[4 * (y * w + x) + 2] = p < q ? p : q;
  51. p = img1data[4 * (y * w + x) + 3];
  52. q = img2data[4 * (y * w + x) + 3];
  53. dstdata[4 * (y * w + x) + 3] = p < q ? p : q;
  54. }
  55. }
  56. return dst;
  57. }
  58. pipi_image_t *pipi_max(pipi_image_t *img1, pipi_image_t *img2)
  59. {
  60. pipi_image_t *dst;
  61. pipi_pixels_t *img1p, *img2p, *dstp;
  62. float *img1data, *img2data, *dstdata;
  63. int x, y, w, h;
  64. if(img1->w != img2->w || img1->h != img2->h)
  65. return NULL;
  66. w = img1->w;
  67. h = img1->h;
  68. dst = pipi_new(w, h);
  69. dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
  70. dstdata = (float *)dstp->pixels;
  71. img1p = pipi_getpixels(img1, PIPI_PIXELS_RGBA_F);
  72. img1data = (float *)img1p->pixels;
  73. img2p = pipi_getpixels(img2, PIPI_PIXELS_RGBA_F);
  74. img2data = (float *)img2p->pixels;
  75. for(y = 0; y < h; y++)
  76. {
  77. for(x = 0; x < w; x++)
  78. {
  79. float p, q;
  80. p = img1data[4 * (y * w + x)];
  81. q = img2data[4 * (y * w + x)];
  82. dstdata[4 * (y * w + x)] = p > q ? p : q;
  83. p = img1data[4 * (y * w + x) + 1];
  84. q = img2data[4 * (y * w + x) + 1];
  85. dstdata[4 * (y * w + x) + 1] = p > q ? p : q;
  86. p = img1data[4 * (y * w + x) + 2];
  87. q = img2data[4 * (y * w + x) + 2];
  88. dstdata[4 * (y * w + x) + 2] = p > q ? p : q;
  89. p = img1data[4 * (y * w + x) + 3];
  90. q = img2data[4 * (y * w + x) + 3];
  91. dstdata[4 * (y * w + x) + 3] = p > q ? p : q;
  92. }
  93. }
  94. return dst;
  95. }