00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00081
00082 inline const uint8* csPackRGBcolorToRGB (const csRGBcolor* pixels,
00083 int )
00084 {
00085 return (const uint8*)pixels;
00086 }
00087
00088 inline void csDiscardPackedRGB (const uint8* ) {}
00089
00090 inline const csRGBcolor* csUnpackRGBtoRGBcolor (const uint8* rgb,
00091 int )
00092 {
00093 return (const csRGBcolor*)rgb;
00094 }
00095
00096 inline void csDiscardUnpackedRGBcolor (const csRGBcolor* ) {}
00097
00098 #else
00099
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
00185
00186 inline const uint8* csPackRGBpixelToRGBA (const csRGBpixel* pixels,
00187 int )
00188 {
00189 return (uint8*)pixels;
00190 }
00191
00192 inline void csDiscardPackedRGBA (const uint8* ) {}
00193
00194 inline const csRGBpixel* csUnpackRGBAtoRGBpixel (const uint8* rgba,
00195 int )
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* ) {}
00209
00210 #else
00211
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__