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 "csextern.h" 00029 00030 #include "cstypes.h" 00031 #include "rgbpixel.h" 00032 00081 #ifdef CS_RGBCOLOR_SANE 00082 // sizeof(csRGBcolor) == 3 00083 00084 inline const uint8* csPackRGBcolorToRGB (const csRGBcolor* pixels, 00085 int /*numPixels*/) 00086 { 00087 return (const uint8*)pixels; 00088 } 00089 00090 inline void csDiscardPackedRGB (const uint8* /*rgb*/) {} 00091 00092 inline const csRGBcolor* csUnpackRGBtoRGBcolor (const uint8* rgb, 00093 int /*numPixels*/) 00094 { 00095 return (const csRGBcolor*)rgb; 00096 } 00097 00098 inline void csDiscardUnpackedRGBcolor (const csRGBcolor* /*pixels*/) {} 00099 00100 #else 00101 // sizeof(csRGBcolor) != 3 00102 00103 inline uint8* csPackRGBcolorToRGB (const csRGBcolor* pixels, 00104 int numPixels) 00105 { 00106 uint8* buf = new uint8[numPixels * 3]; 00107 uint8* bufptr = buf; 00108 while (numPixels--) 00109 { 00110 *bufptr++ = pixels->red; 00111 *bufptr++ = pixels->green; 00112 *bufptr++ = pixels->blue; 00113 pixels++; 00114 } 00115 return buf; 00116 } 00117 00118 inline void csDiscardPackedRGB (const uint8* rgb) 00119 { 00120 delete[] rgb; 00121 } 00122 00123 inline const csRGBcolor* csUnpackRGBtoRGBcolor (const uint8* rgb, 00124 int numPixels) 00125 { 00126 csRGBcolor* buf = new csRGBcolor[numPixels]; 00127 csRGBcolor* bufptr = buf; 00128 while (numPixels--) 00129 { 00130 bufptr->red = *rgb++; 00131 bufptr->green = *rgb++; 00132 bufptr->blue = *rgb++; 00133 bufptr++; 00134 } 00135 return buf; 00136 } 00137 00138 inline void csDiscardUnpackedRGBcolor (const csRGBcolor* pixels) 00139 { 00140 delete[] pixels; 00141 } 00142 00143 #endif // CS_RGBCOLOR_SANE 00144 00185 #ifdef CS_RGBPIXEL_SANE 00186 // sizeof(csRGBpixel) == 4 00187 00188 inline const uint8* csPackRGBpixelToRGBA (const csRGBpixel* pixels, 00189 int /*numPixels*/) 00190 { 00191 return (uint8*)pixels; 00192 } 00193 00194 inline void csDiscardPackedRGBA (const uint8* /*rgba*/) {} 00195 00196 inline const csRGBpixel* csUnpackRGBAtoRGBpixel (const uint8* rgba, 00197 int /*numPixels*/) 00198 { 00199 return (csRGBpixel*)rgba; 00200 } 00201 00202 inline csRGBpixel* csCopyUnpackRGBAtoRGBpixel (const uint8* rgba, 00203 int numPixels) 00204 { 00205 csRGBpixel* buf = new csRGBpixel[numPixels]; 00206 memcpy ((void*)buf, (const void*)rgba, numPixels* sizeof(csRGBpixel)); 00207 return buf; 00208 } 00209 00210 inline void csDiscardUnpackedRGBpixel (const csRGBpixel* /*pixels*/) {} 00211 00212 #else 00213 // sizeof(csRGBpixel) != 4 00214 00215 inline const uint8* csPackRGBpixelToRGBA (const csRGBpixel* pixels, 00216 int numPixels) 00217 { 00218 uint8* buf = new uint8[numPixels * 4]; 00219 uint8* bufptr = buf; 00220 while (numPixels--) 00221 { 00222 *bufptr++ = pixels->red; 00223 *bufptr++ = pixels->green; 00224 *bufptr++ = pixels->blue; 00225 *bufptr++ = pixels->alpha; 00226 pixels++; 00227 } 00228 return buf; 00229 } 00230 00231 inline void csDiscardPackedRGBA (const uint8* rgba) 00232 { 00233 delete[] rgba; 00234 } 00235 00236 inline const csRGBpixel* csUnpackRGBAtoRGBpixel (const uint8* rgba, 00237 int numPixels) 00238 { 00239 csRGBpixel* buf = new csRGBpixel[numPixels]; 00240 csRGBpixel* bufptr = buf; 00241 while (numPixels--) 00242 { 00243 bufptr->red = *rgba++; 00244 bufptr->green = *rgba++; 00245 bufptr->blue = *rgba++; 00246 bufptr->alpha = *rgba++; 00247 bufptr++; 00248 } 00249 return buf; 00250 } 00251 00252 inline csRGBpixel* csCopyUnpackRGBAtoRGBpixel (const uint8* rgba, 00253 int numPixels) 00254 { 00255 return (csRGBpixel*)csUnpackRGBAtoRGBpixel (rgba, numPixels); 00256 } 00257 00258 inline void csDiscardUnpackedRGBpixel (const csRGBpixel* pixels) 00259 { 00260 delete[] pixels; 00261 } 00262 00263 #endif // CS_RGBPIXEL_SANE 00264 00274 inline uint8* csPackRGBpixelToRGB (const csRGBpixel* pixels, 00275 int numPixels) 00276 { 00277 uint8* buf = new uint8[numPixels * 3]; 00278 uint8* bufptr = buf; 00279 while (numPixels--) 00280 { 00281 *bufptr++ = pixels->red; 00282 *bufptr++ = pixels->green; 00283 *bufptr++ = pixels->blue; 00284 pixels++; 00285 } 00286 return buf; 00287 } 00288 00298 inline csRGBcolor* csUnpackRGBAtoRGBcolor (const uint8* rgba, 00299 int numPixels) 00300 { 00301 csRGBcolor* buf = new csRGBcolor[numPixels]; 00302 csRGBcolor* bufptr = buf; 00303 while (numPixels--) 00304 { 00305 bufptr->red = *rgba++; 00306 bufptr->green = *rgba++; 00307 bufptr->blue = *rgba++; 00308 rgba++; 00309 bufptr++; 00310 } 00311 return buf; 00312 } 00313 00318 #endif // __CSGFX_PACKRGB_H__
Generated for Crystal Space by doxygen 1.2.18