#include "basetype.h"#include "bitmap.h"Go to the source code of this file.
Typedefs | |
| typedef palInfo | palInfo |
Functions | |
| geBoolean | palettizePlane (const geBitmap_Info *SrcInfo, const void *SrcBits, geBitmap_Info *DstInfo, void *DstBits, int SizeX, int SizeY) |
| palInfo * | closestPalInit (uint8 *palette) |
| void | closestPalFree (palInfo *info) |
| int | closestPal (int R, int G, int B, palInfo *pi) |
| void | Palettize_Start (void) |
| void | Palettize_Stop (void) |
|
|
Definition at line 41 of file palettize.h. |
|
||||||||||||||||||||
|
Referenced by geBitmap_UpdateMips_Data(), and paletteOptimize(). |
|
|
Referenced by geBitmap_UpdateMips_Data(), paletteOptimize(), and palettizePlane(). |
|
|
Referenced by geBitmap_UpdateMips_Data(), paletteOptimize(), and palettizePlane(). |
|
|
Definition at line 343 of file palettize.c. References hashNodePool, MemPool_Create(), octNode, octNodePool, and PoolRefs. Referenced by geBitmap_Start().
00344 {
00345 if ( PoolRefs == 0 )
00346 {
00347 // we init with 256 octnodes, then add one for each unique color
00348 octNodePool = MemPool_Create(sizeof(octNode),1024,1024);
00349 assert(octNodePool);
00350 hashNodePool = MemPool_Create(sizeof(hashNode),1024,1024);
00351 assert(hashNodePool);
00352 }
00353 PoolRefs ++;
00354 }
|
|
|
Definition at line 356 of file palettize.c. References hashNodePool, MemPool_Destroy(), octNodePool, and PoolRefs. Referenced by geBitmap_Stop().
00357 {
00358 PoolRefs --;
00359 if ( PoolRefs == 0 )
00360 {
00361 MemPool_Destroy(&octNodePool);
00362 MemPool_Destroy(&hashNodePool);
00363 }
00364 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 68 of file palettize.c. References A, B, closestPalFree(), closestPalInit(), closestPalInlineRGB(), geBitmap_Info::ColorKey, gePixelFormat_Operations::DecomposePixel, DstInfo, geBitmap_Info::Format, G, GE_FALSE, GE_PIXELFORMAT_24BIT_BGR, GE_PIXELFORMAT_24BIT_RGB, GE_PIXELFORMAT_8BIT_PAL, GE_TRUE, geBitmap_Palette_GetData(), geBoolean, gePixelFormat, gePixelFormat_BytesPerPel(), gePixelFormat_ColorGetter, gePixelFormat_Decomposer, gePixelFormat_GetOperations(), gePixelFormat_HasAlpha(), gePixelFormat_IsRaw(), gePixelFormat_PixelGetter, gePixelFormat_Operations::GetColor, gePixelFormat_Operations::GetPixel, geBitmap_Info::HasColorKey, palInfo, pushTSC, R, showPopTSC, SizeX, SizeY, geBitmap_Info::Stride, uint32, uint8, and y. Referenced by BlitData_Palettize().
00071 {
00072 palInfo *palInfo;
00073 int x,y,xtra,bpp;
00074 gePixelFormat Format;
00075 int R,G,B,A;
00076 uint8 palette[768],*pSrc,*pDst;
00077
00078 assert( SrcInfo && SrcBits );
00079 assert( DstInfo && DstBits );
00080
00081 assert( DstInfo->Format == GE_PIXELFORMAT_8BIT_PAL );
00082 assert( gePixelFormat_IsRaw(SrcInfo->Format) );
00083
00084 if ( ! DstInfo->Palette )
00085 return GE_FALSE;
00086
00087 if ( ! geBitmap_Palette_GetData(DstInfo->Palette,palette,GE_PIXELFORMAT_24BIT_RGB,256) )
00088 return GE_FALSE;
00089
00090 #ifdef _TSC
00091 pushTSC();
00092 #endif
00093
00094 // rgbPlane is (planeLen*3) bytes
00095 // palette is 768 bytes
00096
00097 palInfo = closestPalInit(palette);
00098 if ( ! palInfo ) return GE_FALSE;
00099
00100 Format = SrcInfo->Format;
00101 bpp = gePixelFormat_BytesPerPel(Format);
00102 xtra = (SrcInfo->Stride - SizeX) * bpp;
00103 pSrc = (uint8 *)SrcBits;
00104 pDst = DstBits;
00105
00106 if ( DstInfo->HasColorKey )
00107 {
00108 int DstCK;
00109 const gePixelFormat_Operations * ops;
00110 ops = gePixelFormat_GetOperations(Format);
00111 assert(ops);
00112 DstCK = DstInfo->ColorKey;
00113
00114 if ( gePixelFormat_HasAlpha(Format) )
00115 {
00116 gePixelFormat_ColorGetter GetColor;
00117 GetColor = ops->GetColor;
00118 for(y=SizeY;y--;)
00119 {
00120 for(x=SizeX;x--;)
00121 {
00122 GetColor(&pSrc,&R,&G,&B,&A);
00123 if ( A < 128 )
00124 {
00125 *pDst++ = DstCK;
00126 }
00127 else
00128 {
00129 *pDst = closestPalInlineRGB(R,G,B,palInfo);
00130 if ( *pDst == DstCK ) // {} this is really poor color-key avoidance!
00131 *pDst ^= 1;
00132 pDst++;
00133 }
00134 }
00135 pSrc += xtra;
00136 pDst += DstInfo->Stride - SizeX;
00137 }
00138 }
00139 else if ( SrcInfo->HasColorKey )
00140 {
00141 uint32 SrcCK,Pixel;
00142 gePixelFormat_PixelGetter GetPixel;
00143 gePixelFormat_Decomposer DecomposePixel;
00144 DecomposePixel = ops->DecomposePixel;
00145 GetPixel = ops->GetPixel;
00146
00147 SrcCK = SrcInfo->ColorKey;
00148
00149 for(y=SizeY;y--;)
00150 {
00151 for(x=SizeX;x--;)
00152 {
00153 Pixel = GetPixel(&pSrc);
00154 if ( Pixel == SrcCK )
00155 {
00156 *pDst++ = DstCK;
00157 }
00158 else
00159 {
00160 DecomposePixel(Pixel,&R,&G,&B,&A);
00161 *pDst = closestPalInlineRGB(R,G,B,palInfo);
00162 if ( *pDst == DstCK ) // {} this is really poor color-key avoidance!
00163 *pDst ^= 1;
00164 pDst++;
00165 }
00166 }
00167 pSrc += xtra;
00168 pDst += DstInfo->Stride - SizeX;
00169 }
00170 }
00171 else
00172 {
00173 gePixelFormat_ColorGetter GetColor;
00174 GetColor = ops->GetColor;
00175
00176 for(y=SizeY;y--;)
00177 {
00178 for(x=SizeX;x--;)
00179 {
00180 GetColor(&pSrc,&R,&G,&B,&A);
00181 *pDst = closestPalInlineRGB(R,G,B,palInfo);
00182 if ( *pDst == DstCK ) // {} this is really poor color-key avoidance!
00183 *pDst ^= 1;
00184 pDst++;
00185 }
00186 pSrc += xtra;
00187 pDst += DstInfo->Stride - SizeX;
00188 }
00189 }
00190 }
00191 else
00192 {
00193 // dst does not have CK, and can't have alpha in this universe, so ignore src colorkey
00194 #if 0 // these special cases just avoid a functional-call overhead
00195 if ( Format == GE_PIXELFORMAT_24BIT_RGB )
00196 {
00197 for(y=SizeY;y--;)
00198 {
00199 for(x=SizeX;x--;)
00200 {
00201 R = *pSrc++; G = *pSrc++; B = *pSrc++;
00202 *pDst++ = closestPalInlineRGB(R,G,B,palInfo);
00203 }
00204 pSrc += xtra;
00205 pDst += DstInfo->Stride - SizeX;
00206 }
00207 }
00208 else if ( Format == GE_PIXELFORMAT_24BIT_BGR )
00209 {
00210 for(y=SizeY;y--;)
00211 {
00212 for(x=SizeX;x--;)
00213 {
00214 B = *pSrc++; G = *pSrc++; R = *pSrc++;
00215 *pDst++ = closestPalInlineRGB(R,G,B,palInfo);
00216 }
00217 pSrc += xtra;
00218 pDst += DstInfo->Stride - SizeX;
00219 }
00220 }
00221 else
00222 #endif
00223 {
00224 const gePixelFormat_Operations * ops;
00225 gePixelFormat_ColorGetter GetColor;
00226 ops = gePixelFormat_GetOperations(Format);
00227 assert(ops);
00228 GetColor = ops->GetColor;
00229 assert(GetColor);
00230 for(y=SizeY;y--;)
00231 {
00232 for(x=SizeX;x--;)
00233 {
00234 GetColor(&pSrc,&R,&G,&B,&A);
00235 *pDst++ = closestPalInlineRGB(R,G,B,palInfo);
00236 }
00237 pSrc += xtra;
00238 pDst += DstInfo->Stride - SizeX;
00239 }
00240 }
00241 }
00242
00243 #ifdef _TSC
00244 showPopTSC("palettize");
00245 #endif
00246
00247 closestPalFree(palInfo);
00248
00249 return GE_TRUE;
00250 }
|
1.3.2