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.

rgb.c 3.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. * rgb.c: RGB combining function
  16. */
  17. #include "config.h"
  18. #include "pipi.h"
  19. #include "pipi_internals.h"
  20. pipi_image_t *pipi_rgb(pipi_image_t *i1, pipi_image_t *i2, pipi_image_t *i3)
  21. {
  22. pipi_image_t *dst;
  23. pipi_pixels_t *i1p, *i2p, *i3p, *dstp;
  24. float *i1data, *i2data, *i3data, *dstdata;
  25. int x, y, w, h;
  26. if(i1->w != i2->w || i1->h != i2->h || i1->w != i3->w || i1->h != i3->h)
  27. return NULL;
  28. w = i1->w;
  29. h = i1->h;
  30. dst = pipi_new(w, h);
  31. dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
  32. dstdata = (float *)dstp->pixels;
  33. i1p = pipi_getpixels(i1, PIPI_PIXELS_Y_F);
  34. i1data = (float *)i1p->pixels;
  35. i2p = pipi_getpixels(i2, PIPI_PIXELS_Y_F);
  36. i2data = (float *)i2p->pixels;
  37. i3p = pipi_getpixels(i3, PIPI_PIXELS_Y_F);
  38. i3data = (float *)i3p->pixels;
  39. for(y = 0; y < h; y++)
  40. {
  41. for(x = 0; x < w; x++)
  42. {
  43. dstdata[4 * (y * w + x)] = i1data[y * w + x];
  44. dstdata[4 * (y * w + x) + 1] = i2data[y * w + x];
  45. dstdata[4 * (y * w + x) + 2] = i3data[y * w + x];
  46. dstdata[4 * (y * w + x) + 3] = 1.0;
  47. }
  48. }
  49. return dst;
  50. }
  51. pipi_image_t *pipi_red(pipi_image_t *src)
  52. {
  53. pipi_image_t *dst;
  54. pipi_pixels_t *srcp, *dstp;
  55. float *srcdata, *dstdata;
  56. int x, y, w, h;
  57. w = src->w;
  58. h = src->h;
  59. dst = pipi_new(w, h);
  60. dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
  61. dstdata = (float *)dstp->pixels;
  62. srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
  63. srcdata = (float *)srcp->pixels;
  64. for(y = 0; y < h; y++)
  65. for(x = 0; x < w; x++)
  66. dstdata[y * w + x] = srcdata[4 * (y * w + x)];
  67. return dst;
  68. }
  69. pipi_image_t *pipi_green(pipi_image_t *src)
  70. {
  71. pipi_image_t *dst;
  72. pipi_pixels_t *srcp, *dstp;
  73. float *srcdata, *dstdata;
  74. int x, y, w, h;
  75. w = src->w;
  76. h = src->h;
  77. dst = pipi_new(w, h);
  78. dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
  79. dstdata = (float *)dstp->pixels;
  80. srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
  81. srcdata = (float *)srcp->pixels;
  82. for(y = 0; y < h; y++)
  83. for(x = 0; x < w; x++)
  84. dstdata[y * w + x] = srcdata[4 * (y * w + x) + 1];
  85. return dst;
  86. }
  87. pipi_image_t *pipi_blue(pipi_image_t *src)
  88. {
  89. pipi_image_t *dst;
  90. pipi_pixels_t *srcp, *dstp;
  91. float *srcdata, *dstdata;
  92. int x, y, w, h;
  93. w = src->w;
  94. h = src->h;
  95. dst = pipi_new(w, h);
  96. dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
  97. dstdata = (float *)dstp->pixels;
  98. srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
  99. srcdata = (float *)srcp->pixels;
  100. for(y = 0; y < h; y++)
  101. for(x = 0; x < w; x++)
  102. dstdata[y * w + x] = srcdata[4 * (y * w + x) + 2];
  103. return dst;
  104. }