csgfx/packrgb.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 1998-2003 by Jorrit Tyberghein 00003 2003 by Frank Richter 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00025 #ifndef __CSGFX_PACKRGB_H__ 00026 #define __CSGFX_PACKRGB_H__ 00027 00028 #include "cstypes.h" 00029 #include "rgbpixel.h" 00030 00079 #ifdef CS_RGBCOLOR_SANE 00080 // sizeof(csRGBcolor) == 3 00081 00082 inline const uint8* csPackRGBcolorToRGB (const csRGBcolor* pixels, 00083 int /*numPixels*/) 00084 { 00085 return (const uint8*)pixels; 00086 } 00087 00088 inline void csDiscardPackedRGB (const uint8* /*rgb*/) {} 00089 00090 inline const csRGBcolor* csUnpackRGBtoRGBcolor (const uint8* rgb, 00091 int /*numPixels*/) 00092 { 00093 return (const csRGBcolor*)rgb; 00094 } 00095 00096 inline void csDiscardUnpackedRGBcolor (const csRGBcolor* /*pixels*/) {} 00097 00098 #else 00099 // sizeof(csRGBcolor) != 3 00100 00101 inline uint8* csPackRGBcolorToRGB (const csRGBcolor* pixels, 00102 int numPixels) 00103 { 00104 uint8* buf = new uint8[numPixels * 3]; 00105 uint8* bufptr = buf; 00106 while (numPixels--) 00107 { 00108 *bufptr++ = pixels->red; 00109 *bufptr++ = pixels->green; 00110 *bufptr++ = pixels->blue; 00111 pixels++; 00112 } 00113 return buf; 00114 } 00115 00116 inline void csDiscardPackedRGB (const uint8* rgb) 00117 { 00118 delete[] rgb; 00119 } 00120 00121 inline const csRGBcolor* csUnpackRGBtoRGBcolor (const uint8* rgb, 00122 int numPixels) 00123 { 00124 csRGBcolor* buf = new csRGBcolor[numPixels]; 00125 csRGBcolor* bufptr = buf; 00126 while (numPixels--) 00127 { 00128 bufptr->red = *rgb++; 00129 bufptr->green = *rgb++; 00130 bufptr->blue = *rgb++; 00131 bufptr++; 00132 } 00133 return buf; 00134 } 00135 00136 inline void csDiscardUnpackedRGBcolor (const csRGBcolor* pixels) 00137 { 00138 delete[] pixels; 00139 } 00140 00141 #endif // CS_RGBCOLOR_SANE 00142 00183 #ifdef CS_RGBPIXEL_SANE 00184 // sizeof(csRGBpixel) == 4 00185 00186 inline const uint8* csPackRGBpixelToRGBA (const csRGBpixel* pixels, 00187 int /*numPixels*/) 00188 { 00189 return (uint8*)pixels; 00190 } 00191 00192 inline void csDiscardPackedRGBA (const uint8* /*rgba*/) {} 00193 00194 inline const csRGBpixel* csUnpackRGBAtoRGBpixel (const uint8* rgba, 00195 int /*numPixels*/) 00196 { 00197 return (csRGBpixel*)rgba; 00198 } 00199 00200 inline csRGBpixel* csCopyUnpackRGBAtoRGBpixel (const uint8* rgba, 00201 int numPixels) 00202 { 00203 csRGBpixel* buf = new csRGBpixel[numPixels]; 00204 memcpy ((void*)buf, (const void*)rgba, numPixels* sizeof(csRGBpixel)); 00205 return buf; 00206 } 00207 00208 inline void csDiscardUnpackedRGBpixel (const csRGBpixel* /*pixels*/) {} 00209 00210 #else 00211 // sizeof(csRGBpixel) != 4 00212 00213 inline const uint8* csPackRGBpixelToRGBA (const csRGBpixel* pixels, 00214 int numPixels) 00215 { 00216 uint8* buf = new uint8[numPixels * 4]; 00217 uint8* bufptr = buf; 00218 while (numPixels--) 00219 { 00220 *bufptr++ = pixels->red; 00221 *bufptr++ = pixels->green; 00222 *bufptr++ = pixels->blue; 00223 *bufptr++ = pixels->alpha; 00224 pixels++; 00225 } 00226 return buf; 00227 } 00228 00229 inline void csDiscardPackedRGBA (const uint8* rgba) 00230 { 00231 delete[] rgba; 00232 } 00233 00234 inline const csRGBpixel* csUnpackRGBAtoRGBpixel (const uint8* rgba, 00235 int numPixels) 00236 { 00237 csRGBpixel* buf = new csRGBpixel[numPixels]; 00238 csRGBpixel* bufptr = buf; 00239 while (numPixels--) 00240 { 00241 bufptr->red = *rgba++; 00242 bufptr->green = *rgba++; 00243 bufptr->blue = *rgba++; 00244 bufptr->alpha = *rgba++; 00245 bufptr++; 00246 } 00247 return buf; 00248 } 00249 00250 inline csRGBpixel* csCopyUnpackRGBAtoRGBpixel (const uint8* rgba, 00251 int numPixels) 00252 { 00253 return (csRGBpixel*)csUnpackRGBAtoRGBpixel (rgba, numPixels); 00254 } 00255 00256 inline void csDiscardUnpackedRGBpixel (const csRGBpixel* pixels) 00257 { 00258 delete[] pixels; 00259 } 00260 00261 #endif // CS_RGBPIXEL_SANE 00262 00272 inline uint8* csPackRGBpixelToRGB (const csRGBpixel* pixels, 00273 int numPixels) 00274 { 00275 uint8* buf = new uint8[numPixels * 3]; 00276 uint8* bufptr = buf; 00277 while (numPixels--) 00278 { 00279 *bufptr++ = pixels->red; 00280 *bufptr++ = pixels->green; 00281 *bufptr++ = pixels->blue; 00282 pixels++; 00283 } 00284 return buf; 00285 } 00286 00296 inline csRGBcolor* csUnpackRGBAtoRGBcolor (const uint8* rgba, 00297 int numPixels) 00298 { 00299 csRGBcolor* buf = new csRGBcolor[numPixels]; 00300 csRGBcolor* bufptr = buf; 00301 while (numPixels--) 00302 { 00303 bufptr->red = *rgba++; 00304 bufptr->green = *rgba++; 00305 bufptr->blue = *rgba++; 00306 rgba++; 00307 bufptr++; 00308 } 00309 return buf; 00310 } 00311 00316 #endif // __CSGFX_PACKRGB_H__
Generated for Crystal Space by doxygen 1.2.18