Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

134 lignes
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. * 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. }