Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

rgb.c 3.2 KiB

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