#include <bitmap.h>
Inheritance diagram for NLMISC::CBitmap:
Nevrax France
Definition at line 87 of file bitmap.h.
[NOHEADER] | |
CRGBA | getDXTC1Texel (sint x, sint y, uint32 numMipMap) const |
CRGBA | getDXTC3Texel (sint x, sint y, uint32 numMipMap) const |
CRGBA | getDXTC5Texel (sint x, sint y, uint32 numMipMap) const |
CRGBA | getDXTCColorFromBlock (const uint8 *block, sint x, sint y) |
Public Types | |
enum | TType { RGBA = 0, Luminance, Alpha, AlphaLuminance, DXTC1, DXTC1Alpha, DXTC3, DXTC5, DsDt, ModeCount, DonTKnow = 0xffffffff } |
Public Member Functions | |
void | blend (CBitmap &Bm0, CBitmap &Bm1, uint16 factor, bool inputBitmapIsMutable=false) |
bool | blit (const CBitmap *src, sint32 x, sint32 y) |
void | buildMipMaps () |
CBitmap () | |
bool | convertToType (TType type) |
void | flipH () |
void | flipV () |
CRGBAF | getColor (float x, float y) const |
virtual uint32 | getHeight (uint32 numMipMap=0) const |
uint32 | getMipMapCount () const |
CRGBA | getPixelColor (sint x, sint y, uint32 numMipMap=0) const |
TType | getPixelFormat () const |
uint32 | getSize (uint32 numMipMap=0) const |
virtual uint32 | getWidth (uint32 numMipMap=0) const |
bool | isGrayscaleAsAlpha () const |
uint8 | load (NLMISC::IStream &f, uint mipMapSkip=0) |
void | loadGrayscaleAsAlpha (bool loadAsAlpha) |
void | makeDummy () |
void | releaseMipMaps () |
void | resample (sint32 nNewWidth, sint32 nNewHeight) |
void | reset (TType type=RGBA) |
void | resize (sint32 nNewWidth, sint32 nNewHeight, TType newType=DonTKnow, bool resetTo0=true) |
void | resizeMipMap (uint32 numMipMap, sint32 nNewWidth, sint32 nNewHeight, bool resetTo0=true) |
void | rot90CCW () |
void | rot90CW () |
void | rotateCCW () |
void | setMipMapCount (uint32 mmc) |
bool | writeJPG (NLMISC::IStream &f, uint8 quality=80) |
bool | writeTGA (NLMISC::IStream &f, uint32 d, bool upsideDown=false) |
virtual | ~CBitmap () |
Static Public Member Functions | |
void | loadSize (const std::string &path, uint32 &retWidth, uint32 &retHeight) |
void | loadSize (NLMISC::IStream &f, uint32 &width, uint32 &height) |
Data Fields | |
enum NLMISC::CBitmap::TType | PixelFormat |
Static Public Attributes | |
const uint32 | bitPerPixels [ModeCount] |
const uint32 | DXTC1HEADER = NL_MAKEFOURCC('D','X', 'T', '1') |
const uint32 | DXTC3HEADER = NL_MAKEFOURCC('D','X', 'T', '3') |
const uint32 | DXTC5HEADER = NL_MAKEFOURCC('D','X', 'T', '5') |
Protected Attributes | |
CObjectVector< uint8 > | _Data [MAX_MIPMAP] |
uint32 | _Height |
bool | _LoadGrayscaleAsAlpha |
uint8 | _MipMapCount |
uint32 | _Width |
Private Member Functions | |
uint32 | blend (uint32 &n0, uint32 &n1, uint32 coef0) |
bool | decompressDXT1 (bool alpha) |
bool | decompressDXT3 () |
bool | decompressDXT5 () |
float | getColorInterp (float x, float y, float xy00, float xy01, float xy10, float xy11) const |
CRGBA | getRGBAPixel (sint x, sint y, uint32 numMipMap) const |
uint8 | readDDS (NLMISC::IStream &f, uint mipMapSkip) |
uint8 | readTGA (NLMISC::IStream &f) |
void | resamplePicture32 (const NLMISC::CRGBA *pSrc, NLMISC::CRGBA *pDest, sint32 nSrcWidth, sint32 nSrcHeight, sint32 nDestWidth, sint32 nDestHeight) |
bool | alphaLuminanceToAlpha () |
bool | alphaLuminanceToLuminance () |
bool | alphaLuminanceToRGBA () |
bool | alphaToAlphaLuminance () |
bool | alphaToLuminance () |
bool | alphaToRGBA () |
bool | convertToAlpha () |
bool | convertToAlphaLuminance () |
bool | convertToDXTC5 () |
bool | convertToLuminance () |
bool | convertToRGBA () |
bool | luminanceToAlpha () |
bool | luminanceToAlphaLuminance () |
bool | luminanceToRGBA () |
bool | rgbaToAlpha () |
bool | rgbaToAlphaLuminance () |
bool | rgbaToLuminance () |
Static Private Member Functions | |
void | uncompress (uint16 color, NLMISC::CRGBA &) |
|
Definition at line 234 of file bitmap.h.
00235 { 00236 RGBA=0, 00237 Luminance, 00238 Alpha, 00239 AlphaLuminance, 00240 DXTC1, 00241 DXTC1Alpha, 00242 DXTC3, 00243 DXTC5, 00244 DsDt, 00245 ModeCount, 00246 DonTKnow=0xffffffff 00247 } PixelFormat; |
|
Definition at line 254 of file bitmap.h. References _LoadGrayscaleAsAlpha, _MipMapCount, PixelFormat, and RGBA.
00255 { 00256 _MipMapCount = 1; 00257 _Width = 0; 00258 _Height = 0; 00259 PixelFormat = RGBA; 00260 _LoadGrayscaleAsAlpha = true; 00261 } |
|
Definition at line 263 of file bitmap.h.
00263 { } |
|
Definition at line 762 of file bitmap.cpp. References _MipMapCount, NLMISC::contReset(), PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToAlpha().
00763 { 00764 uint32 i; 00765 00766 if(_Width*_Height == 0) return false; 00767 00768 for(uint8 m= 0; m<_MipMapCount; m++) 00769 { 00770 CObjectVector<uint8> dataTmp; 00771 dataTmp.resize(_Data[m].size()/2); 00772 uint dstId= 0; 00773 00774 for(i=0; i<_Data[m].size(); i+=2) 00775 { 00776 dataTmp[dstId++]= _Data[m][i+1]; 00777 } 00778 NLMISC::contReset(_Data[m]); 00779 _Data[m].resize(0); 00780 _Data[m] = dataTmp; 00781 } 00782 PixelFormat = Alpha; 00783 return true; 00784 } |
|
Definition at line 677 of file bitmap.cpp. References _MipMapCount, NLMISC::contReset(), PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToLuminance().
00678 { 00679 uint32 i; 00680 00681 if(_Width*_Height == 0) return false; 00682 00683 for(uint8 m= 0; m<_MipMapCount; m++) 00684 { 00685 CObjectVector<uint8> dataTmp; 00686 dataTmp.resize(_Data[m].size()/2); 00687 uint dstId= 0; 00688 00689 for(i=0; i<_Data[m].size(); i+=2) 00690 { 00691 dataTmp[dstId++]= 0; 00692 dataTmp[dstId++]= 0; 00693 dataTmp[dstId++]= 0; 00694 dataTmp[dstId++]= _Data[m][i]; 00695 } 00696 NLMISC::contReset(_Data[m]); 00697 _Data[m].resize(0); 00698 _Data[m] = dataTmp; 00699 } 00700 PixelFormat = Luminance; 00701 return true; 00702 } |
|
Definition at line 519 of file bitmap.cpp. References _MipMapCount, PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), RGBA, NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToRGBA().
00520 { 00521 uint32 i; 00522 00523 if(_Width*_Height == 0) return false; 00524 00525 for(uint8 m= 0; m<_MipMapCount; m++) 00526 { 00527 CObjectVector<uint8> dataTmp; 00528 dataTmp.resize(_Data[m].size()*2); 00529 uint dstId= 0; 00530 00531 for(i=0; i<_Data[m].size(); i+=2) 00532 { 00533 dataTmp[dstId++]= _Data[m][i]; 00534 dataTmp[dstId++]= _Data[m][i]; 00535 dataTmp[dstId++]= _Data[m][i]; 00536 dataTmp[dstId++]= _Data[m][i+1]; 00537 } 00538 _Data[m] = dataTmp; 00539 } 00540 PixelFormat = RGBA; 00541 return true; 00542 } |
|
Definition at line 607 of file bitmap.cpp. References _MipMapCount, PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToAlphaLuminance().
00608 { 00609 uint32 i; 00610 00611 if(_Width*_Height == 0) return false; 00612 00613 for(uint8 m= 0; m<_MipMapCount; m++) 00614 { 00615 CObjectVector<uint8> dataTmp; 00616 dataTmp.resize(_Data[m].size()*2); 00617 uint dstId= 0; 00618 00619 for(i=0; i<_Data[m].size(); i++) 00620 { 00621 dataTmp[dstId++]= 0; 00622 dataTmp[dstId++]= _Data[m][i]; 00623 } 00624 _Data[m] = dataTmp; 00625 } 00626 PixelFormat = AlphaLuminance; 00627 return true; 00628 } |
|
Definition at line 664 of file bitmap.cpp. References PixelFormat. Referenced by convertToLuminance().
00665 { 00666 if(_Width*_Height == 0) return false; 00667 00668 PixelFormat = Luminance; 00669 return true; 00670 } |
|
Definition at line 490 of file bitmap.cpp. References _MipMapCount, PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), RGBA, NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToRGBA().
00491 { 00492 uint32 i; 00493 00494 if(_Width*_Height == 0) return false; 00495 00496 for(uint8 m= 0; m<_MipMapCount; m++) 00497 { 00498 CObjectVector<uint8> dataTmp; 00499 dataTmp.resize(_Data[m].size()*4); 00500 uint dstId= 0; 00501 00502 for(i=0; i<_Data[m].size(); i++) 00503 { 00504 dataTmp[dstId++]= 255; 00505 dataTmp[dstId++]= 255; 00506 dataTmp[dstId++]= 255; 00507 dataTmp[dstId++]= _Data[m][i]; 00508 } 00509 _Data[m] = dataTmp; 00510 } 00511 PixelFormat = RGBA; 00512 return true; 00513 } |
|
Set this bitmap as the result of the blend bewteen 2 bitmap REQUIRE : - Bm0 and Bm1 should have the same size.
Definition at line 2817 of file bitmap.cpp. References _Data, _Height, _Width, convertToRGBA(), nlassert, PixelFormat, resize(), RGBA, uint, uint16, uint64, and uint8.
02818 { 02819 nlassert(factor <= 256); 02820 02821 nlassert(Bm0._Width != 0 && Bm0._Height != 0 02822 && Bm1._Width != 0 && Bm1._Height != 0); 02823 02824 nlassert(Bm0._Width == Bm1._Width); // the bitmap should have the same size 02825 nlassert(Bm0._Height == Bm1._Height); 02826 02827 const CBitmap *nBm0, *nBm1; // pointer to the bitmap that is used for blending, or to a copy is a conversion wa required 02828 02829 CBitmap cp0, cp1; // these bitmap are copies of Bm1 and Bm0 if a conversion was needed 02830 02831 if (Bm0.PixelFormat != RGBA) 02832 { 02833 if (inputBitmapIsMutable) 02834 { 02835 Bm0.convertToRGBA(); 02836 nBm0 = &Bm0; 02837 } 02838 else 02839 { 02840 cp0 = Bm0; 02841 cp0.convertToRGBA(); 02842 nBm0 = &cp0; 02843 } 02844 } 02845 else 02846 { 02847 nBm0 = &Bm0; 02848 } 02849 02850 02851 if (Bm1.PixelFormat != RGBA) 02852 { 02853 if (inputBitmapIsMutable) 02854 { 02855 Bm1.convertToRGBA(); 02856 nBm1 = &Bm1; 02857 } 02858 else 02859 { 02860 cp1 = Bm1; 02861 cp1.convertToRGBA(); 02862 nBm1 = &cp1; 02863 } 02864 } 02865 else 02866 { 02867 nBm1 = &Bm1; 02868 } 02869 02870 this->resize(Bm0._Width, Bm0._Height, RGBA); 02871 02872 uint numPix = _Width * _Height; // 4 component per pixels 02873 02874 02875 const uint8 *src0 = &(nBm0->_Data[0][0]); 02876 const uint8 *src1 = &(nBm1->_Data[0][0]); 02877 uint8 *dest = &(this->_Data[0][0]); 02878 02879 02880 #ifdef NL_OS_WINDOWS 02881 if (CSystemInfo::hasMMX()) 02882 { 02883 // On a P4 2GHz, with a 256x256 texture, I got the following results : 02884 // without mmx : 5.2 ms 02885 // with mmx : 1.7 ms 02886 // I'm sure this can be further optimized.. 02887 02888 uint numPixLeft = numPix & 1; // process 2 pixels at once, so special case for odd number 02889 numPix = numPix & ~1; 02890 // do fast blend with mmx 02891 uint64 blendFactor0; 02892 uint64 blendFactor1; 02893 uint16 *bf0 = (uint16 *) &blendFactor0; 02894 uint16 *bf1 = (uint16 *) &blendFactor1; 02895 bf0[0] = bf0[1] = bf0[2] = bf0[3] = factor; 02896 bf1[0] = bf1[1] = bf1[2] = bf1[3] = 256 - factor; 02897 __asm 02898 { 02899 mov esi, src0 02900 mov eax, src1 02901 mov edi, dest 02902 mov ebx, -8 02903 mov ecx, numPix 02904 shr ecx, 1 // process pixels 2 by 2 02905 movq mm1, blendFactor0 02906 movq mm0, blendFactor1 02907 02908 myLoop: 02909 pxor mm6, mm6 02910 lea ebx, [ebx + 8] // points next location 02911 pxor mm7, mm7 02912 movq mm2, [esi + ebx] 02913 movq mm3, [eax + ebx] 02914 // do blend 02915 punpckhbw mm7, mm2 // mm7 contains src0 color 0 in high bytes 02916 punpckhbw mm6, mm3 // mm6 contains src1 color 0 in high bytes 02917 psrl mm7, 1 02918 pxor mm4, mm4 // mm4 = 0 02919 psrl mm6, 1 02920 pmulhw mm7, mm0 // src0 = src0 * blendFactor 02921 pxor mm5, mm5 // mm5 = 0 02922 pmulhw mm6, mm1 // src1 = src1 * (1 - blendfactor) 02923 punpcklbw mm4, mm2 // mm4 contains src0 color 1 in high bytes 02924 paddusw mm6, mm7 // mm6 = src0[0] blended with src1[0] 02925 psrl mm4, 1 02926 punpcklbw mm5, mm3 // mm4 contains src1 color 1 in high bytes 02927 psll mm6, 1 02928 psrl mm5, 1 02929 pmulhw mm4, mm0 // src0 = src0 * blendFactor 02930 pmulhw mm5, mm1 // src1 = src1 * (1 - blendfactor) 02931 paddusw mm4, mm5 // mm6 = src0[1] blended with src1[1] 02932 psll mm4, 1 02933 // pack result 02934 packuswb mm4, mm6 02935 dec ecx 02936 movq [edi + ebx], mm4 // store result 02937 jne myLoop 02938 emms 02939 } 02940 if (numPixLeft) 02941 { 02942 // case of odd number of pixels 02943 src0 += 4 * numPix; 02944 src1 += 4 * numPix; 02945 dest += 4 * numPix; 02946 uint blendFact = (uint) factor; 02947 uint invblendFact = 256 - blendFact; 02948 *dest = (uint8) (((blendFact * *src1) + (invblendFact * *src0)) >> 8); 02949 *(dest + 1) = (uint8) (((blendFact * *(src1 + 1)) + (invblendFact * *(src0 + 1))) >> 8); 02950 *(dest + 2) = (uint8) (((blendFact * *(src1 + 2)) + (invblendFact * *(src0 + 2))) >> 8); 02951 *(dest + 3) = (uint8) (((blendFact * *(src1 + 3)) + (invblendFact * *(src0 + 3))) >> 8); 02952 } 02953 } 02954 else 02955 #endif //#ifdef NL_OS_WINDOWS 02956 { 02957 uint8 *endPix = dest + (numPix << 2); 02958 // no mmx version 02959 uint blendFact = (uint) factor; 02960 uint invblendFact = 256 - blendFact; 02961 do 02962 { 02964 *dest = (uint8) (((blendFact * *src1) + (invblendFact * *src0)) >> 8); 02965 *(dest + 1) = (uint8) (((blendFact * *(src1 + 1)) + (invblendFact * *(src0 + 1))) >> 8); 02966 *(dest + 2) = (uint8) (((blendFact * *(src1 + 2)) + (invblendFact * *(src0 + 2))) >> 8); 02967 *(dest + 3) = (uint8) (((blendFact * *(src1 + 3)) + (invblendFact * *(src0 + 3))) >> 8); 02968 02969 src0 = src0 + 4; 02970 src1 = src1 + 4; 02971 dest = dest + 4; 02972 } 02973 while (dest != endPix); 02974 } 02975 } |
|
blend 2 integers between 0 and 255 .
Definition at line 1338 of file bitmap.cpp. References uint32. Referenced by decompressDXT5(), and NL3D::CTextureBlend::doGenerate().
01339 { 01340 int a0 = coef0; 01341 int a1 = 256-a0; 01342 return ((n0*a0 + n1*a1) >>8); 01343 } |
|
Perform a simple blit from the source to this bitmap at the (x, y) pos The dimension of the original bitmap are preserved For now, this texture and the source must have the same format With DXTC format, the dest coordinates must be a multiple of 4 mipmap are not rebuild when present
Definition at line 2332 of file bitmap.cpp. References bitPerPixels, DonTKnow, height, nlassert, PixelFormat, sint, sint32, src, uint, uint8, width, x, and y. Referenced by NL3D::CTextureGrouped::doGenerate(), and NL3D::CCoarseMeshBuild::expand().
02333 { 02334 02335 nlassert(this->PixelFormat == src->PixelFormat); 02336 if (this->PixelFormat != src->PixelFormat) 02337 { 02338 return false; 02339 } 02340 02341 02342 // check for dxtc use 02343 02344 const bool useDXTC = PixelFormat == DXTC1 || PixelFormat == DXTC1Alpha || PixelFormat == DXTC3 || PixelFormat == DXTC5; 02345 02346 // number of bits for a 4x4 pix block 02347 const uint dxtcNumBits = PixelFormat == DXTC1 || PixelFormat == DXTC1Alpha ? 64 : 128; 02348 02349 02350 if (useDXTC) 02351 { 02352 // blit pos must be multiple of 4 02353 02354 nlassert(! (x & 3 || y & 3) ); 02355 if (x & 3 || y & 3) return false; 02356 02357 } 02358 02359 nlassert(PixelFormat != DonTKnow); 02360 02361 // the width to copy 02362 sint width = src->_Width; 02363 // the height to copy 02364 sint height = src->_Height; 02365 02366 uint destStartX, destStartY; 02367 uint srcStartX, srcStartY; 02368 02369 02370 // clip against left 02371 if (x < 0) 02372 { 02373 width += x; 02374 if (width <= 0) return true; 02375 destStartX = 0; 02376 srcStartX = -x; 02377 } 02378 else 02379 { 02380 destStartX = x; 02381 srcStartX = 0; 02382 } 02383 02384 // clip against top 02385 if (y < 0) 02386 { 02387 height += y; 02388 if (height <= 0) return true; 02389 srcStartY = -y; 02390 destStartY = 0; 02391 } 02392 else 02393 { 02394 destStartY = y; 02395 srcStartY = 0; 02396 } 02397 02398 // clip against right 02399 if ((destStartX + width - 1) >= _Width) 02400 { 02401 width = _Width - destStartX; 02402 if (width <= 0) return true; 02403 } 02404 02405 // clip against bottom 02406 if ((destStartY + height - 1) >= _Height) 02407 { 02408 height = _Height - destStartY; 02409 if (width <= 0) return true; 02410 } 02411 02412 02413 // divide all distance by 4 when using DXTC 02414 if (useDXTC) 02415 { 02416 destStartX >>= 2; 02417 destStartY >>= 2; 02418 srcStartX >>= 2; 02419 srcStartY >>= 2; 02420 width >>= 2; 02421 height >>= 2; 02422 } 02423 02424 02425 // bytes per pixs is for either one pixel or 16 (a 4x4 block in DXTC) 02426 const uint bytePerPixs = ( useDXTC ? dxtcNumBits : bitPerPixels[PixelFormat] ) >> 3 /* divide by 8 to get the number of bytes */; 02427 02428 02429 const uint destRealWidth = useDXTC ? (_Width >> 2) : _Width; 02430 const uint srcRealWidth = useDXTC ? (src->_Width >> 2) : src->_Width; 02431 02432 02433 // size to go to the next line in the destination 02434 const uint destStride = destRealWidth * bytePerPixs; 02435 02436 // size to go to the next line in the source 02437 const uint srcStride = srcRealWidth * bytePerPixs; 02438 02439 // length in bytes of a line to copy 02440 const uint lineLength = width * bytePerPixs; 02441 02442 02443 uint8 *destPos = &(_Data[0][0]) + destStride * destStartY + bytePerPixs * destStartX; 02444 const uint8 *srcPos = &(src->_Data[0][0]) + srcStride * srcStartY + bytePerPixs * srcStartX; 02445 02446 // copy each hline 02447 for (sint k = 0; k < height; ++k) 02448 { 02449 ::memcpy(destPos, srcPos, lineLength); 02450 destPos += destStride; 02451 srcPos += srcStride; 02452 } 02453 02454 02455 return true; 02456 } |
|
Build the mipmaps of the bitmap if they don't exist. Work only in RGBA mode...
Definition at line 1422 of file bitmap.cpp. References _MipMapCount, NLMISC::CRGBA::A, NLMISC::CRGBA::B, NLMISC::CRGBA::G, NLMISC::isPowerOf2(), PixelFormat, NLMISC::CRGBA::R, NLMISC::CObjectVector< uint8 >::resize(), RGBA, sint, uint32, and w. Referenced by NL3D::CHLSColorTexture::addMask(), NL3D::CTextureMem::doGenerate(), flipH(), flipV(), resample(), rot90CCW(), rot90CW(), and NL3D::CDriverGL::setupTextureEx().
01423 { 01424 uint32 i,j; 01425 01426 if(PixelFormat!=RGBA) return; 01427 if(_MipMapCount!=1) return; 01428 if(!NLMISC::isPowerOf2(_Width)) return; 01429 if(!NLMISC::isPowerOf2(_Height)) return; 01430 01431 uint32 w = _Width; 01432 uint32 h = _Height; 01433 01434 while(w>1 || h>1) 01435 { 01436 uint32 precw = w; 01437 uint32 prech = h; 01438 w = (w+1)/2; 01439 h = (h+1)/2; 01440 uint32 mulw= precw/w; 01441 uint32 mulh= prech/h; 01442 01443 _Data[_MipMapCount].resize(w*h*4); 01444 01445 01446 NLMISC::CRGBA *pRgba = (NLMISC::CRGBA*)&_Data[_MipMapCount][0]; 01447 NLMISC::CRGBA *pRgbaPrev = (NLMISC::CRGBA*)&_Data[_MipMapCount-1][0]; 01448 for(i=0; i<h; i++) 01449 { 01450 sint i0= mulh*i; 01451 sint i1= mulh*i+1; 01452 if(mulh==1) 01453 i1=i0; 01454 i0*=precw; 01455 i1*=precw; 01456 for(j=0; j<w; j++) 01457 { 01458 sint j0= mulw*j; 01459 sint j1= mulw*j+1; 01460 if(mulh==1) 01461 j1=j0; 01462 CRGBA &c0= pRgbaPrev[i0+j0]; 01463 CRGBA &c1= pRgbaPrev[i0+j1]; 01464 CRGBA &c2= pRgbaPrev[i1+j0]; 01465 CRGBA &c3= pRgbaPrev[i1+j1]; 01466 pRgba[i*w + j].R = (c0.R + 01467 c1.R + 01468 c2.R + 01469 c3.R + 2 ) /4; 01470 pRgba[i*w + j].G = (c0.G + 01471 c1.G + 01472 c2.G + 01473 c3.G + 2 ) /4; 01474 pRgba[i*w + j].B = (c0.B + 01475 c1.B + 01476 c2.B + 01477 c3.B + 2 ) /4; 01478 pRgba[i*w + j].A = (c0.A + 01479 c1.A + 01480 c2.A + 01481 c3.A + 2 ) /4; 01482 } 01483 } 01484 01485 _MipMapCount++; 01486 } 01487 } |
|
Definition at line 821 of file bitmap.cpp. References alphaLuminanceToAlpha(), luminanceToAlpha(), PixelFormat, RGBA, and rgbaToAlpha(). Referenced by convertToType().
00822 { 00823 switch(PixelFormat) 00824 { 00825 case RGBA : 00826 return rgbaToAlpha(); 00827 break; 00828 00829 case Luminance : 00830 return luminanceToAlpha(); 00831 break; 00832 00833 case Alpha : 00834 return true; 00835 break; 00836 00837 case AlphaLuminance : 00838 return alphaLuminanceToAlpha(); 00839 break; 00840 00841 default: 00842 break; 00843 } 00844 return false; 00845 } |
|
Definition at line 852 of file bitmap.cpp. References alphaToAlphaLuminance(), luminanceToAlphaLuminance(), PixelFormat, RGBA, and rgbaToAlphaLuminance(). Referenced by convertToType().
00853 { 00854 switch(PixelFormat) 00855 { 00856 case RGBA : 00857 return rgbaToAlphaLuminance(); 00858 break; 00859 00860 case Luminance : 00861 return luminanceToAlphaLuminance(); 00862 break; 00863 00864 case Alpha : 00865 return alphaToAlphaLuminance(); 00866 break; 00867 00868 case AlphaLuminance : 00869 return true; 00870 break; 00871 00872 default: 00873 break; 00874 } 00875 return false; 00876 } |
|
Change bitmap format about DXTC1 to DXTC5 : Does nothing if the format is not DXTC1 about alpha encoding : alpha0 == alpha1 code(x,y) == 7 for every (x,y) about luminance to alpha and alpha to luminance : the buffer keeps unchanged Definition at line 415 of file bitmap.cpp. Referenced by convertToType().
00416 { 00417 /* Yoyo: RGB encoding for DXTC1 and DXTC5/3 are actually different!! 00418 DXTC3/5 don't rely on sign of color0>color1 to setup special encoding (ie use a special compression for Black) 00419 Since this can arise if the src is DXTC1 , we can't simply compress it into DXTC5 without doing a 00420 heavy compression... 00421 (the inverse is false: DXTC5 to DXTC1 is possible, with maybe swap color0/color1 and bits). 00422 */ 00423 00424 return false; 00425 00426 /* uint32 i,j; 00427 00428 if(PixelFormat!=DXTC1) return false; 00429 00430 for(uint8 m= 0; m<_MipMapCount; m++) 00431 { 00432 CObjectVector<uint8> dataTmp; 00433 dataTmp.resize(2*_Data[m].size()); 00434 uint dstId= 0; 00435 00436 for(i=0; i<_Data[m].size(); i+=8) 00437 { 00438 //64 bits alpha 00439 for(j=0; j<8; j++) 00440 { 00441 dataTmp[dstId++]= 255; 00442 } 00443 00444 //64 bits RGB 00445 for(j=0; j<8; j++) 00446 { 00447 dataTmp[dstId++]= _Data[m][i+j]; 00448 } 00449 } 00450 _Data[m] = dataTmp; 00451 } 00452 PixelFormat = DXTC5; 00453 return true; 00454 */ 00455 } |
|
Definition at line 790 of file bitmap.cpp. References alphaLuminanceToLuminance(), alphaToLuminance(), PixelFormat, RGBA, and rgbaToLuminance(). Referenced by convertToType().
00791 { 00792 switch(PixelFormat) 00793 { 00794 case RGBA : 00795 return rgbaToLuminance(); 00796 break; 00797 00798 case Luminance : 00799 return true; 00800 break; 00801 00802 case Alpha : 00803 return alphaToLuminance(); 00804 break; 00805 00806 case AlphaLuminance : 00807 return alphaLuminanceToLuminance(); 00808 break; 00809 00810 default: 00811 break; 00812 } 00813 return false; 00814 } |
|
Definition at line 882 of file bitmap.cpp. References alphaLuminanceToRGBA(), alphaToRGBA(), decompressDXT1(), decompressDXT3(), decompressDXT5(), luminanceToRGBA(), PixelFormat, and RGBA. Referenced by blend(), and convertToType().
00883 { 00884 switch(PixelFormat) 00885 { 00886 case DXTC1 : 00887 return decompressDXT1(false); 00888 break; 00889 00890 case DXTC1Alpha : 00891 return decompressDXT1(true); 00892 break; 00893 00894 case DXTC3 : 00895 return decompressDXT3(); 00896 break; 00897 00898 case DXTC5 : 00899 return decompressDXT5(); 00900 break; 00901 00902 case Luminance : 00903 return luminanceToRGBA(); 00904 break; 00905 00906 case Alpha : 00907 return alphaToRGBA(); 00908 break; 00909 00910 case AlphaLuminance : 00911 return alphaLuminanceToRGBA(); 00912 break; 00913 case RGBA: 00914 return true; 00915 break; 00916 default: 00917 break; 00918 } 00919 return false; 00920 } |
|
Convert bitmap to another type conversion to rgba always work. No-op if already rgba.
Definition at line 926 of file bitmap.cpp. References convertToAlpha(), convertToAlphaLuminance(), convertToDXTC5(), convertToLuminance(), convertToRGBA(), PixelFormat, RGBA, and type. Referenced by NL3D::CHLSColorTexture::addMask(), NL3D::CLodCharacterTmpBitmap::build(), NL3D::CCoarseMeshBuild::buildBitmap(), NL3D::CTextureFile::buildBitmapFromFile(), NL3D::CHeightMap::buildFromBitmap(), NL3D::CAsyncTextureManager::CTextureEntry::createCoarseBitmap(), NL3D::CZoneLighter::getTexture(), NL3D::CTileBank::getTileNoiseMap(), and NL3D::CDriverGL::setupTextureEx().
00927 { 00928 if(PixelFormat==type) return true; 00929 00930 switch(type) 00931 { 00932 case RGBA : 00933 return convertToRGBA(); 00934 break; 00935 00936 case DXTC5 : 00937 return convertToDXTC5(); 00938 break; 00939 00940 case Luminance : 00941 return convertToLuminance(); 00942 break; 00943 00944 case Alpha : 00945 return convertToAlpha(); 00946 break; 00947 00948 case AlphaLuminance : 00949 return convertToAlphaLuminance(); 00950 break; 00951 00952 default: 00953 break; 00954 } 00955 00956 return false; 00957 } |
|
Decompress bitmap compressed with S3TC DXT1 algorithm.
Definition at line 965 of file bitmap.cpp. References _MipMapCount, NLMISC::CRGBA::A, alpha, NLMISC::CRGBA::blendFromui(), height, NLMISC::MAX_MIPMAP, PixelFormat, NLMISC::CRGBA::R, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), RGBA, NLMISC::CRGBA::set(), NLMISC::CObjectVector< uint8 >::size(), NLMISC::CObjectVector< T, EnableObjectBehavior >::size(), src, uint, uint16, uint32, uint8, uncompress(), width, x, and y. Referenced by convertToRGBA().
00966 { 00967 uint32 i,j,k; 00968 NLMISC::CRGBA c[4]; 00969 CObjectVector<uint8> dataTmp[MAX_MIPMAP]; 00970 00971 uint32 width= _Width; 00972 uint32 height= _Height; 00973 00974 for(uint8 m= 0; m<_MipMapCount; m++) 00975 { 00976 uint32 wtmp, htmp; 00977 if(width<4) 00978 wtmp = 4; 00979 else 00980 wtmp = width; 00981 if(height < 4) 00982 htmp = 4; 00983 else 00984 htmp = height; 00985 uint32 mipMapSz = wtmp*htmp*4; 00986 dataTmp[m].resize(mipMapSz); 00987 if(dataTmp[m].size()<mipMapSz) 00988 { 00989 throw EAllocationFailure(); 00990 } 00991 uint32 wBlockCount= wtmp/4; 00992 00993 00994 00995 for(i=0; i < _Data[m].size(); i+=8) 00996 { 00997 uint16 color0; 00998 uint16 color1; 00999 uint32 bits; 01000 memcpy(&color0,&_Data[m][i],2); 01001 memcpy(&color1,&_Data[m][i+2],2); 01002 memcpy(&bits,&_Data[m][i+4],4); 01003 01004 uncompress(color0,c[0]); 01005 uncompress(color1,c[1]); 01006 01007 if (alpha) 01008 { 01009 c[0].A= 0; 01010 c[1].A= 0; 01011 c[2].A= 0; 01012 c[3].A= 0; 01013 } 01014 else 01015 { 01016 c[0].A= 255; 01017 c[1].A= 255; 01018 c[2].A= 255; 01019 c[3].A= 255; 01020 } 01021 01022 if(color0>color1) 01023 { 01024 c[2].blendFromui(c[0],c[1],85); 01025 if(alpha) c[2].A= 255; 01026 01027 c[3].blendFromui(c[0],c[1],171); 01028 if(alpha) c[3].A= 255; 01029 } 01030 else 01031 { 01032 c[2].blendFromui(c[0],c[1],128); 01033 if(alpha) c[2].A= 255; 01034 01035 c[3].set(0,0,0,0); 01036 } 01037 01038 // computing the 16 RGBA of the block 01039 01040 uint32 blockNum= i/8; //(64 bits) 01041 // <previous blocks in above lines> * 4 (rows) * _Width (columns) + 4pix*4rgba*<same line previous blocks> 01042 uint32 pixelsCount= 4*(blockNum/wBlockCount)*wtmp*4 + 4*4*(blockNum%wBlockCount); 01043 for(j=0; j<4; j++) 01044 { 01045 for(k=0; k<4; k++) 01046 { 01047 dataTmp[m][pixelsCount + j*wtmp*4 + 4*k]= c[bits&3].R; 01048 dataTmp[m][pixelsCount + j*wtmp*4 + 4*k+1]= c[bits&3].G; 01049 dataTmp[m][pixelsCount + j*wtmp*4 + 4*k+2]= c[bits&3].B; 01050 dataTmp[m][pixelsCount + j*wtmp*4 + 4*k+3]= c[bits&3].A; 01051 bits>>=2; 01052 } 01053 } 01054 } 01055 01056 // Copy result into the mipmap level. 01057 if(wtmp==width && htmp==height) 01058 { 01059 // For mipmaps level >4 pixels. 01060 _Data[m]= dataTmp[m]; 01061 } 01062 else 01063 { 01064 // For last mipmaps, level <4 pixels. 01065 _Data[m].resize(width*height*4); 01066 CRGBA *src= (CRGBA*)&dataTmp[m][0]; 01067 CRGBA *dst= (CRGBA*)&_Data[m][0]; 01068 uint x,y; 01069 for(y=0;y<height;y++) 01070 { 01071 for(x=0;x<width;x++) 01072 dst[y*width+x]= src[y*wtmp+x]; 01073 } 01074 } 01075 01076 // Next mipmap size. 01077 width = (width+1)/2; 01078 height = (height+1)/2; 01079 } 01080 PixelFormat = RGBA; 01081 return true; 01082 } |
|
Decompress bitmap compressed with S3TC DXT3 algorithm.
Definition at line 1090 of file bitmap.cpp. References _MipMapCount, alpha, NLMISC::CRGBA::blendFromui(), height, NLMISC::MAX_MIPMAP, PixelFormat, NLMISC::CRGBA::R, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), RGBA, NLMISC::CObjectVector< uint8 >::size(), NLMISC::CObjectVector< T, EnableObjectBehavior >::size(), src, uint, uint16, uint32, uint64, uint8, uncompress(), width, x, and y. Referenced by convertToRGBA().
01091 { 01092 uint32 i,j,k; 01093 NLMISC::CRGBA c[4]; 01094 CObjectVector<uint8> dataTmp[MAX_MIPMAP]; 01095 01096 uint32 width= _Width; 01097 uint32 height= _Height; 01098 01099 for(uint8 m= 0; m<_MipMapCount; m++) 01100 { 01101 uint32 wtmp, htmp; 01102 if(width<4) 01103 wtmp = 4; 01104 else 01105 wtmp = width; 01106 if(height < 4) 01107 htmp = 4; 01108 else 01109 htmp = height; 01110 uint32 mipMapSz = wtmp*htmp*4; 01111 dataTmp[m].resize(mipMapSz); 01112 if(dataTmp[m].size()<mipMapSz) 01113 { 01114 throw EAllocationFailure(); 01115 } 01116 uint32 wBlockCount= wtmp/4; 01117 01118 01119 for(i=0; i < _Data[m].size(); i+=16) 01120 { 01121 uint8 alpha[16]; 01122 uint64 alphatmp; 01123 memcpy(&alphatmp,&_Data[m][i],8); 01124 01125 for(j=0; j<16; j++) 01126 { 01127 uint8 a= (uint8)(alphatmp&15); 01128 // expand to 0-255. 01129 alpha[j]= a+(a<<4); 01130 alphatmp>>=4; 01131 } 01132 01133 01134 uint16 color0; 01135 uint16 color1; 01136 uint32 bits; 01137 memcpy(&color0,&_Data[m][i+8],2); 01138 memcpy(&color1,&_Data[m][i+10],2); 01139 memcpy(&bits,&_Data[m][i+12],4); 01140 01141 uncompress(color0,c[0]); 01142 uncompress(color1,c[1]); 01143 01144 // ignore color0>color1 for DXT3 and DXT5. 01145 c[2].blendFromui(c[0],c[1],85); 01146 c[3].blendFromui(c[0],c[1],171); 01147 01148 // computing the 16 RGBA of the block 01149 01150 uint32 blockNum= i/16; //(128 bits) 01151 // <previous blocks in above lines> * 4 (rows) * wtmp (columns) + 4pix*4rgba*<same line previous blocks> 01152 uint32 pixelsCount= 4*(blockNum/wBlockCount)*wtmp*4 + 4*4*(blockNum%wBlockCount); 01153 for(j=0; j<4; j++) 01154 { 01155 for(k=0; k<4; k++) 01156 { 01157 dataTmp[m][pixelsCount + j*wtmp*4 + 4*k]= c[bits&3].R; 01158 dataTmp[m][pixelsCount + j*wtmp*4 + 4*k+1]= c[bits&3].G; 01159 dataTmp[m][pixelsCount + j*wtmp*4 + 4*k+2]= c[bits&3].B; 01160 dataTmp[m][pixelsCount + j*wtmp*4 + 4*k+3]= alpha[4*j+k]; 01161 bits>>=2; 01162 } 01163 } 01164 } 01165 01166 // Copy result into the mipmap level. 01167 if(wtmp==width && htmp==height) 01168 { 01169 // For mipmaps level >4 pixels. 01170 _Data[m]= dataTmp[m]; 01171 } 01172 else 01173 { 01174 // For last mipmaps, level <4 pixels. 01175 _Data[m].resize(width*height*4); 01176 CRGBA *src= (CRGBA*)&dataTmp[m][0]; 01177 CRGBA *dst= (CRGBA*)&_Data[m][0]; 01178 uint x,y; 01179 for(y=0;y<height;y++) 01180 { 01181 for(x=0;x<width;x++) 01182 dst[y*width+x]= src[y*wtmp+x]; 01183 } 01184 } 01185 01186 // Next mipmap size. 01187 width = (width+1)/2; 01188 height = (height+1)/2; 01189 } 01190 PixelFormat = RGBA; 01191 return true; 01192 } |
|
Decompress bitmap compressed with S3TC DXT3 algorithm.
Definition at line 1200 of file bitmap.cpp. References _MipMapCount, alpha, blend(), NLMISC::CRGBA::blendFromui(), height, NLMISC::MAX_MIPMAP, PixelFormat, NLMISC::CRGBA::R, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), RGBA, NLMISC::CObjectVector< uint8 >::size(), NLMISC::CObjectVector< T, EnableObjectBehavior >::size(), src, uint, uint16, uint32, uint64, uint8, uncompress(), width, x, and y. Referenced by convertToRGBA().
01201 { 01202 uint32 i,j,k; 01203 NLMISC::CRGBA c[4]; 01204 CObjectVector<uint8> dataTmp[MAX_MIPMAP]; 01205 01206 uint32 width= _Width; 01207 uint32 height= _Height; 01208 01209 for(uint8 m= 0; m<_MipMapCount; m++) 01210 { 01211 uint32 wtmp, htmp; 01212 if(width<4) 01213 wtmp = 4; 01214 else 01215 wtmp = width; 01216 if(height < 4) 01217 htmp = 4; 01218 else 01219 htmp = height; 01220 uint32 mipMapSz = wtmp*htmp*4; 01221 dataTmp[m].resize(mipMapSz); 01222 if(dataTmp[m].size()<mipMapSz) 01223 { 01224 throw EAllocationFailure(); 01225 } 01226 uint32 wBlockCount= wtmp/4; 01227 01228 01229 01230 for(i=0; i < _Data[m].size(); i+=16) 01231 { 01232 uint64 bitsAlpha; 01233 memcpy(&bitsAlpha,&_Data[m][i],8); 01234 bitsAlpha>>= 16; 01235 01236 uint32 alpha[8]; 01237 alpha[0]= _Data[m][i+0]; 01238 alpha[1]= _Data[m][i+1]; 01239 01240 if(alpha[0]>alpha[1]) 01241 { 01242 alpha[2]= blend(alpha[0], alpha[1], 219); 01243 alpha[3]= blend(alpha[0], alpha[1], 183); 01244 alpha[4]= blend(alpha[0], alpha[1], 146); 01245 alpha[5]= blend(alpha[0], alpha[1], 110); 01246 alpha[6]= blend(alpha[0], alpha[1], 73); 01247 alpha[7]= blend(alpha[0], alpha[1], 37); 01248 } 01249 else 01250 { 01251 alpha[2]= blend(alpha[0], alpha[1], 204); 01252 alpha[3]= blend(alpha[0], alpha[1], 154); 01253 alpha[4]= blend(alpha[0], alpha[1], 102); 01254 alpha[5]= blend(alpha[0], alpha[1], 51); 01255 alpha[6]= 0; 01256 alpha[7]= 255; 01257 } 01258 01259 uint8 codeAlpha[16]; 01260 for(j=0; j<16; j++) 01261 { 01262 codeAlpha[j] = (uint8)bitsAlpha & 7; 01263 bitsAlpha>>=3; 01264 } 01265 01266 01267 uint16 color0; 01268 uint16 color1; 01269 uint32 bits; 01270 memcpy(&color0,&_Data[m][i+8],2); 01271 memcpy(&color1,&_Data[m][i+10],2); 01272 memcpy(&bits,&_Data[m][i+12],4); 01273 01274 uncompress(color0,c[0]); 01275 uncompress(color1,c[1]); 01276 01277 // ignore color0>color1 for DXT3 and DXT5. 01278 c[2].blendFromui(c[0],c[1],85); 01279 c[3].blendFromui(c[0],c[1],171); 01280 01281 // computing the 16 RGBA of the block 01282 01283 uint32 blockNum= i/16; //(128 bits) 01284 01285 // <previous blocks in above lines> * 4 (rows) * wtmp (columns) + 4pix*<same line previous blocks> 01286 uint32 pixelsCount= (blockNum/wBlockCount)*wtmp*4 + 4*(blockNum%wBlockCount); 01287 // *sizeof(RGBA) 01288 pixelsCount*=4; 01289 for(j=0; j<4; j++) 01290 { 01291 for(k=0; k<4; k++) 01292 { 01293 dataTmp[m][pixelsCount + (j*wtmp+k)*4 +0]= c[bits&3].R; 01294 dataTmp[m][pixelsCount + (j*wtmp+k)*4 +1]= c[bits&3].G; 01295 dataTmp[m][pixelsCount + (j*wtmp+k)*4 +2]= c[bits&3].B; 01296 dataTmp[m][pixelsCount + (j*wtmp+k)*4 +3]= (uint8) alpha[codeAlpha[4*j+k]]; 01297 bits>>=2; 01298 } 01299 } 01300 01301 } 01302 01303 // Copy result into the mipmap level. 01304 if(wtmp==width && htmp==height) 01305 { 01306 // For mipmaps level >4 pixels. 01307 _Data[m]= dataTmp[m]; 01308 } 01309 else 01310 { 01311 // For last mipmaps, level <4 pixels. 01312 _Data[m].resize(width*height*4); 01313 CRGBA *src= (CRGBA*)&dataTmp[m][0]; 01314 CRGBA *dst= (CRGBA*)&_Data[m][0]; 01315 uint x,y; 01316 for(y=0;y<height;y++) 01317 { 01318 for(x=0;x<width;x++) 01319 dst[y*width+x]= src[y*wtmp+x]; 01320 } 01321 } 01322 01323 // Next mipmap size. 01324 width = (width+1)/2; 01325 height = (height+1)/2; 01326 } 01327 PixelFormat = RGBA; 01328 return true; 01329 01330 } |
|
Horizontal flip (all the columns are flipped) Definition at line 2682 of file bitmap.cpp. References _MipMapCount, buildMipMaps(), getHeight(), getWidth(), PixelFormat, releaseMipMaps(), RGBA, and sint32.
02683 { 02684 if (PixelFormat != RGBA) 02685 return; 02686 02687 sint32 nWidth = getWidth(0); 02688 sint32 nHeight = getHeight(0); 02689 sint32 i, j; 02690 NLMISC::CRGBA *pBitmap = (NLMISC::CRGBA*)&_Data[0][0]; 02691 bool needRebuild = false; 02692 CRGBA temp; 02693 02694 if(_MipMapCount>1) 02695 needRebuild = true; 02696 releaseMipMaps(); 02697 02698 for( i = 0; i < nHeight; ++i ) 02699 for( j = 0; j < nWidth/2; ++j ) 02700 { 02701 temp = pBitmap[i*nWidth+j]; 02702 pBitmap[i*nWidth+j] = pBitmap[i*nWidth+nWidth-j-1]; 02703 pBitmap[i*nWidth+nWidth-j-1] = temp; 02704 } 02705 02706 // Rebuilding mipmaps 02707 if(needRebuild) 02708 { 02709 buildMipMaps(); 02710 } 02711 } |
|
Vertical flip (all the rows are flipped) Definition at line 2714 of file bitmap.cpp. References _MipMapCount, buildMipMaps(), getHeight(), getWidth(), PixelFormat, releaseMipMaps(), RGBA, and sint32.
02715 { 02716 if (PixelFormat != RGBA) 02717 return; 02718 02719 sint32 nWidth = getWidth(0); 02720 sint32 nHeight = getHeight(0); 02721 sint32 i, j; 02722 NLMISC::CRGBA *pBitmap = (NLMISC::CRGBA*)&_Data[0][0]; 02723 bool needRebuild = false; 02724 CRGBA temp; 02725 02726 if(_MipMapCount>1) 02727 needRebuild = true; 02728 releaseMipMaps(); 02729 02730 for( j = 0; j < nHeight/2; ++j ) 02731 for( i = 0; i < nWidth; ++i ) 02732 { 02733 temp = pBitmap[j*nWidth+i]; 02734 pBitmap[j*nWidth+i] = pBitmap[(nHeight-j-1)*nWidth+i]; 02735 pBitmap[(nHeight-j-1)*nWidth+i] = temp; 02736 } 02737 02738 // Rebuilding mipmaps 02739 if(needRebuild) 02740 { 02741 buildMipMaps(); 02742 } 02743 } |
|
Get the color in the bitmap given a pixel size The mipmaps must be built. If not just return the bilinear at the given point. The input x and y must be clamped between 0 and 1 Definition at line 2470 of file bitmap.cpp. References NLMISC::CRGBAF::A, NLMISC::CRGBAF::B, NLMISC::CRGBAF::G, getColorInterp(), getHeight(), getPixelColor(), getPixels(), getWidth(), nlassert, PixelFormat, NLMISC::CRGBAF::R, RGBA, sint32, uint32, x, and y.
02471 { 02472 if (x < 0.0f) x = 0.0f; 02473 if (x > 1.0f) x = 1.0f; 02474 if (y < 0.0f) y = 0.0f; 02475 if (y > 1.0f) y = 1.0f; 02476 02477 sint32 nWidth = getWidth(0); 02478 sint32 nHeight = getHeight(0); 02479 02480 if (nWidth == 0 || nHeight == 0) return CRGBAF(0, 0, 0, 0); 02481 02482 const CObjectVector<uint8> &rBitmap = getPixels(0); 02483 sint32 nX[4], nY[4]; 02484 02485 x *= nWidth-1; 02486 y *= nHeight-1; 02487 02488 // Integer part of (x,y) 02489 //nX[0] = ((sint32)floor(x-0.5f)); 02490 //nY[0] = ((sint32)floor(y-0.5f)); 02491 nX[0] = ((sint32)floor(x)); 02492 nY[0] = ((sint32)floor(y)); 02493 02494 nX[1] = (nX[0] < (nWidth-1) ? nX[0]+1 : nX[0]); 02495 nY[1] = nY[0]; 02496 02497 nX[2] = nX[0]; 02498 nY[2] = (nY[0] < (nHeight-1) ? nY[0]+1 : nY[0]); 02499 02500 nX[3] = nX[1]; 02501 nY[3] = nY[2]; 02502 02503 uint32 i; 02504 02505 for (i = 0; i < 4; ++i) 02506 { 02507 nlassert (nX[i] >= 0); 02508 nlassert (nY[i] >= 0 ); 02509 nlassert (nX[i] < nWidth); 02510 nlassert (nY[i] < nHeight); 02511 } 02512 02513 // Decimal part of (x,y) 02514 x = x - (float)nX[0]; 02515 y = y - (float)nY[0]; 02516 02517 switch (this->PixelFormat) 02518 { 02519 case RGBA: 02520 case DXTC1: 02521 case DXTC1Alpha: 02522 case DXTC3: 02523 case DXTC5: 02524 { 02525 CRGBAF finalVal; 02526 CRGBA val[4]; 02527 02528 if (this->PixelFormat == RGBA) 02529 { 02530 for (i = 0; i < 4; ++i) 02531 { 02532 val[i] = CRGBA (rBitmap[(nX[i]+nY[i]*nWidth)*4+0], 02533 rBitmap[(nX[i]+nY[i]*nWidth)*4+1], 02534 rBitmap[(nX[i]+nY[i]*nWidth)*4+2], 02535 rBitmap[(nX[i]+nY[i]*nWidth)*4+3]); 02536 } 02537 } 02538 else 02539 { 02540 // slower version : get from DXT 02541 for (i = 0; i < 4; ++i) 02542 { 02543 val[i] = getPixelColor(nX[i], nY[i]); 02544 } 02545 } 02546 02547 finalVal.R = getColorInterp (x, y, val[0].R, val[1].R, val[2].R, val[3].R); 02548 finalVal.G = getColorInterp (x, y, val[0].G, val[1].G, val[2].G, val[3].G); 02549 finalVal.B = getColorInterp (x, y, val[0].B, val[1].B, val[2].B, val[3].B); 02550 finalVal.A = getColorInterp (x, y, val[0].A, val[1].A, val[2].A, val[3].A); 02551 finalVal /= 255.f; 02552 02553 return finalVal; 02554 } 02555 break; 02556 case Alpha: 02557 case Luminance: 02558 { 02559 02560 float finalVal; 02561 float val[4]; 02562 02563 for (i = 0; i < 4; ++i) 02564 val[i] = rBitmap[(nX[i]+nY[i]*nWidth)]; 02565 02566 finalVal = getColorInterp (x, y, val[0], val[1], val[2], val[3]); 02567 finalVal /= 255.f; 02568 02569 if (this->PixelFormat == Alpha) 02570 return CRGBAF (1.f, 1.f, 1.f, finalVal); 02571 else // Luminance 02572 return CRGBAF (finalVal, finalVal, finalVal, 1.f); 02573 } 02574 break; 02575 default: break; 02576 } 02577 02578 return CRGBAF (0.0f, 0.0f, 0.0f, 0.0f); 02579 } |
|
Quadratic interpolator
Definition at line 2459 of file bitmap.cpp. References NLMISC::clamp(), res, x, and y. Referenced by getColor().
|
|
Definition at line 3048 of file bitmap.cpp. References getDXTCColorFromBlock(), getHeight(), getPixels(), getWidth(), sint, uint, uint32, uint8, w, x, and y. Referenced by getPixelColor().
03049 { 03050 uint w = getWidth(numMipMap); 03051 uint h = getHeight(numMipMap); 03052 if (w == 0 || h == 0 || (uint) x >= w || (uint) y >= h) return CRGBA::Black; // include negative cases 03053 uint numRowBlocks = std::max((w + 3) >> 2, 1u); 03054 const uint8 *pix = &getPixels(numMipMap)[0]; 03055 const uint8 *block = pix + ((y >> 2) * (numRowBlocks << 3) + ((x >> 2) << 3)); 03056 return getDXTCColorFromBlock(block, x, y); 03057 } |
|
Definition at line 3061 of file bitmap.cpp. References NLMISC::CRGBA::A, getDXTCColorFromBlock(), getHeight(), getPixels(), getWidth(), sint, uint, uint32, uint8, w, x, and y. Referenced by getPixelColor().
03062 { 03063 uint w = getWidth(numMipMap); 03064 uint h = getHeight(numMipMap); 03065 if (w == 0 || h == 0 || (uint) x >= w || (uint) y >= h) return CRGBA::Black; // include negative cases 03066 uint numRowBlocks = std::max((w + 3) >> 2, 1u); 03067 const uint8 *pix = &getPixels(numMipMap)[0]; 03068 const uint8 *block = pix + ((y >> 2) * (numRowBlocks << 4) + ((x >> 2) << 4)); 03069 CRGBA result = getDXTCColorFromBlock(block + 8, x, y); 03070 // get alpha part 03071 uint8 alphaByte = block[((y & 3) << 1) + ((x & 2) >> 1)]; 03072 result.A = (x & 1) ? (alphaByte & 0xf0) : (alphaByte << 4); 03073 return result; 03074 } |
|
Definition at line 3077 of file bitmap.cpp. References NLMISC::CRGBA::A, getDXTCColorFromBlock(), getHeight(), getPixels(), getWidth(), sint, uint, uint32, uint8, w, x, and y. Referenced by getPixelColor().
03078 { 03079 uint w = getWidth(numMipMap); 03080 uint h = getHeight(numMipMap); 03081 if (w == 0 || h == 0 || (uint) x >= w || (uint) y >= h) return CRGBA::Black; // include negative cases 03082 uint numRowBlocks = std::max((w + 3) >> 2, 1u); 03083 const uint8 *pix = &getPixels(numMipMap)[0]; 03084 const uint8 *block = pix + ((y >> 2) * (numRowBlocks << 4) + ((x >> 2) << 4)); 03085 CRGBA result = getDXTCColorFromBlock(block + 8, x, y); 03086 // get alpha part 03087 uint8 alpha0 = block[0]; 03088 uint8 alpha1 = block[1]; 03089 03090 uint alphaIndex; 03091 uint tripletIndex = (x & 3) + ((y & 3) << 2); 03092 if (tripletIndex < 8) 03093 { 03094 alphaIndex = (((uint32 &) block[2]) >> (tripletIndex * 3)) & 7; 03095 } 03096 else 03097 { 03098 alphaIndex = (((uint32 &) block[5]) >> ((tripletIndex - 8) * 3)) & 7; // we can read a dword there because there are color datas following he alpha datas 03099 } 03100 03101 if (alpha0 > alpha1) 03102 { 03103 switch (alphaIndex) 03104 { 03105 case 0: result.A = alpha0; break; 03106 case 1: result.A = alpha1; break; 03107 case 2: result.A = (uint8) ((6 * (uint) alpha0 + (uint) alpha1) / 7); break; 03108 case 3: result.A = (uint8) ((5 * (uint) alpha0 + 2 * (uint) alpha1) / 7); break; 03109 case 4: result.A = (uint8) ((4 * (uint) alpha0 + 3 * (uint) alpha1) / 7); break; 03110 case 5: result.A = (uint8) ((3 * (uint) alpha0 + 4 * (uint) alpha1) / 7); break; 03111 case 6: result.A = (uint8) ((2 * (uint) alpha0 + 5 * (uint) alpha1) / 7); break; 03112 case 7: result.A = (uint8) (((uint) alpha0 + (uint) 6 * alpha1) / 7); break; 03113 } 03114 } 03115 else 03116 { 03117 switch (alphaIndex) 03118 { 03119 case 0: result.A = alpha0; break; 03120 case 1: result.A = alpha1; break; 03121 case 2: result.A = (uint8) ((4 * (uint) alpha0 + (uint) alpha1) / 5); break; 03122 case 3: result.A = (uint8) ((3 * (uint) alpha0 + 2 * (uint) alpha1) / 5); break; 03123 case 4: result.A = (uint8) ((2 * (uint) alpha0 + 3 * (uint) alpha1) / 5); break; 03124 case 5: result.A = (uint8) (((uint) alpha0 + 4 * (uint) alpha1) / 5); break; 03125 case 6: result.A = 0; break; 03126 case 7: result.A = 255; break; 03127 } 03128 } 03129 return result; 03130 } |
|
Definition at line 2990 of file bitmap.cpp. References NLMISC::CRGBA::A, NLMISC::CRGBA::blendFromui(), NLMISC::CRGBA::set(), sint, uint, uint16, uint8, uncompress(), x, and y. Referenced by getDXTC1Texel(), getDXTC3Texel(), and getDXTC5Texel().
02991 { 02992 uint16 col0; 02993 uint16 col1; 02994 memcpy(&col0, block, sizeof(uint16)); 02995 memcpy(&col1, block + 2, sizeof(uint16)); 02996 uint colIndex = (block[4 + (y & 3)] >> ((x & 3) << 1)) & 3; 02997 CRGBA result, c0, c1; 02998 if (col0 > col1) 02999 { 03000 switch(colIndex) 03001 { 03002 case 0: 03003 uncompress(col0, result); 03004 break; 03005 case 1: 03006 uncompress(col1, result); 03007 break; 03008 case 2: 03009 uncompress(col0, c0); 03010 uncompress(col1, c1); 03011 result.blendFromui(c0, c1, 85); 03012 break; 03013 case 3: 03014 uncompress(col0, c0); 03015 uncompress(col1, c1); 03016 result.blendFromui(c0, c1, 171); 03017 break; 03018 } 03019 result.A = 255; 03020 } 03021 else 03022 { 03023 switch(colIndex) 03024 { 03025 case 0: 03026 uncompress(col0, result); 03027 result.A = 255; 03028 break; 03029 case 1: 03030 uncompress(col1, result); 03031 result.A = 255; 03032 break; 03033 case 2: 03034 uncompress(col0, c0); 03035 uncompress(col1, c1); 03036 result.blendFromui(c0, c1, 128); 03037 result.A = 255; 03038 break; 03039 case 3: 03040 result.set(0, 0, 0, 0); 03041 break; 03042 } 03043 } 03044 return result; 03045 } |
|
Return the image height, or a mipmap height.
Definition at line 1388 of file bitmap.cpp. Referenced by NL3D::CHLSColorTexture::addMask(), NL3D::CLodCharacterTmpBitmap::build(), NL3D::CCoarseMeshBuild::buildBitmap(), NL3D::CTextureFile::buildBitmapFromFile(), NL3D::CFontManager::computeString(), NL3D::CFastHLSModifier::convertDDSBitmap(), draw2dLine(), NL3D::CCoarseMeshBuild::expand(), NL3D::CDriverGL::fillBuffer(), flipH(), flipV(), NL3D::CPatchDLMContext::generate(), getColor(), getDXTC1Texel(), getDXTC3Texel(), getDXTC5Texel(), getRGBAPixel(), getSize(), NL3D::GetTextureSize(), NL3D::CTileBank::getTileNoiseMap(), NL3D::CZoneLighter::lightWater(), NL3D::CShapeBank::processWSUploadTexture(), RenderTriangle(), rot90CCW(), rot90CW(), NL3D::CHLSColorTexture::setBitmap(), NL3D::CDriverGL::setupTextureEx(), NL3D::CDriverGL::uploadTexture(), and NL3D::CAsyncTextureManager::uploadTexturePart().
|
|
Return the number of mipmaps. Level0 is a mipmap...
Definition at line 369 of file bitmap.h. References _MipMapCount, and uint32. Referenced by NL3D::CHLSColorTexture::addMask(), NL3D::CShapeBank::processWSUploadTexture(), NL3D::CHLSColorTexture::setBitmap(), NL3D::CDriverGL::setupTextureEx(), NL3D::CDriverGL::uploadTexture(), NL3D::CAsyncTextureManager::uploadTexturePart(), and NL3D::CAsyncTextureManager::validDXTCMipMap().
00370 { 00371 return _MipMapCount; 00372 } |
|
Get the pixel at the given coorrdinate. Works in RGBA and DXTC modes. Outside of the bitmap it returns Black (or if mipmap is not found) Definition at line 3134 of file bitmap.cpp. References getDXTC1Texel(), getDXTC3Texel(), getDXTC5Texel(), getRGBAPixel(), nlstop, PixelFormat, RGBA, sint, uint32, x, and y. Referenced by getColor().
03135 { 03136 03137 switch (PixelFormat) 03138 { 03139 case RGBA: 03140 return getRGBAPixel(x, y, numMipMap); 03141 case DXTC1: 03142 case DXTC1Alpha: 03143 return getDXTC1Texel(x, y, numMipMap); 03144 case DXTC3: 03145 return getDXTC3Texel(x, y, numMipMap); 03146 case DXTC5: 03147 return getDXTC5Texel(x, y, numMipMap); 03148 default: 03149 nlstop; 03150 break; 03151 } 03152 return CRGBA::Black; 03153 } |
|
Return the format of pixels stored at the present time in the object buffer.
Definition at line 335 of file bitmap.h. References PixelFormat. Referenced by NL3D::CFastHLSModifier::convertDDSBitmap(), NL3D::CFastHLSModifier::convertRGBABitmap(), NL3D::CTextureGrouped::doGenerate(), NL3D::CDriverGL::fillBuffer(), NL3D::getGlSrcTextureFormat(), NL3D::CDriverGL::getGlTextureFormat(), NL3D::CShapeBank::processWSUploadTexture(), NL3D::CTextureFar::rebuildPatch(), NL3D::CHLSColorTexture::setBitmap(), NL3D::CDriverGL::setupTextureEx(), NL3D::CAsyncTextureManager::update(), NL3D::CDriverGL::uploadTexture(), NL3D::CAsyncTextureManager::uploadTexturePart(), and NL3D::CAsyncTextureManager::validDXTCMipMap().
00336 { 00337 return PixelFormat; 00338 } |
|
Definition at line 313 of file bitmap.h. References uint32.
00314 { 00315 //nlassert (numMipMap<=_MipMapCount); 00316 return _Data[numMipMap]; 00317 } |
|
|
Definition at line 2980 of file bitmap.cpp. References getHeight(), getPixels(), getWidth(), sint, uint, uint32, uint8, w, x, and y. Referenced by getPixelColor().
02981 { 02982 uint w = getWidth(numMipMap); 02983 uint h = getHeight(numMipMap); 02984 if (w == 0 || (uint) x >= w || (uint) y >= h) return CRGBA::Black; // include negative cases 02985 const uint8 *pix = &getPixels(numMipMap)[(x + y * w) << 2]; 02986 return CRGBA(pix[0], pix[1], pix[2], pix[3]); 02987 } |
|
Return the size (in pixels) of the image: <=> getHeight()*getWidth().
Definition at line 1412 of file bitmap.cpp. References getHeight(), getWidth(), and uint32. Referenced by NL3D::CShapeBank::processWSUploadTexture(), NL3D::CDriverGL::setupTextureEx(), NL3D::CAsyncTextureManager::update(), and NL3D::CAsyncTextureManager::uploadTexturePart().
|
|
|
Tell if the bitmap loads grayscale bitmap as alpha or luminance format.
Definition at line 483 of file bitmap.h. References _LoadGrayscaleAsAlpha.
00484 { 00485 return _LoadGrayscaleAsAlpha; 00486 } |
|
Read a bitmap(TGA or DDS) from an IStream. Bitmap supported are DDS (DXTC1, DXTC1 with Alpha, DXTC3, DXTC5, and uncompressed TGA (24 and 32 bits).
Definition at line 109 of file bitmap.cpp. References NLMISC::IStream::begin, NLMISC::DDS, depth, height, NLMISC::IStream::isReading(), nlassert, readDDS(), readTGA(), NLMISC::IStream::seek(), NLMISC::IStream::serial(), uint, uint16, uint32, uint8, and width. Referenced by NL3D::CTextureFile::buildBitmapFromFile(), and NL3D::CTextureMem::doGenerate().
00110 { 00111 nlassert(f.isReading()); 00112 00113 // testing if DDS 00114 uint32 fileType = 0;; 00115 f.serial(fileType); 00116 if(fileType == DDS) 00117 { 00118 #ifdef NEL_ALL_BITMAP_WHITE 00119 uint8 result = readDDS(f, mipMapSkip); 00120 MakeWhite (*this); 00121 return result; 00122 #else // NEL_ALL_BITMAP_WHITE 00123 return readDDS(f, mipMapSkip); 00124 #endif // NEL_ALL_BITMAP_WHITE 00125 } 00126 // assuming it's TGA 00127 else 00128 { 00129 NLMISC::IStream::TSeekOrigin origin= f.begin; 00130 if(!f.seek (0, origin)) 00131 { 00132 throw ESeekFailed(); 00133 } 00134 00135 // Reading header, 00136 // To make sure that the bitmap is TGA, we check imageType and imageDepth. 00137 uint8 lengthID; 00138 uint8 cMapType; 00139 uint8 imageType; 00140 uint16 tgaOrigin; 00141 uint16 length; 00142 uint8 depth; 00143 uint16 xOrg; 00144 uint16 yOrg; 00145 uint16 width; 00146 uint16 height; 00147 uint8 imageDepth; 00148 uint8 desc; 00149 00150 f.serial(lengthID); 00151 f.serial(cMapType); 00152 f.serial(imageType); 00153 if(imageType!=2 && imageType!=3 && imageType!=10 && imageType!=11) return 0; 00154 f.serial(tgaOrigin); 00155 f.serial(length); 00156 f.serial(depth); 00157 f.serial(xOrg); 00158 f.serial(yOrg); 00159 f.serial(width); 00160 f.serial(height); 00161 f.serial(imageDepth); 00162 if(imageDepth!=8 && imageDepth!=16 && imageDepth!=24 && imageDepth!=32) return 0; 00163 f.serial(desc); 00164 00165 if(!f.seek (0, origin)) 00166 { 00167 throw ESeekFailed(); 00168 } 00169 #ifdef NEL_ALL_BITMAP_WHITE 00170 uint8 result = readTGA(f); 00171 MakeWhite (*this); 00172 return result; 00173 #else // NEL_ALL_BITMAP_WHITE 00174 return readTGA(f); 00175 #endif // NEL_ALL_BITMAP_WHITE 00176 00177 } 00178 } |
|
Tell the bitmap to load grayscale bitmap as alpha or luminance format.
Definition at line 472 of file bitmap.h. References _LoadGrayscaleAsAlpha. Referenced by NL3D::CTextureFile::buildBitmapFromFile(), and NL3D::CTileBank::getTileNoiseMap().
00473 { 00474 _LoadGrayscaleAsAlpha=loadAsAlpha; 00475 } |
|
same than other loadSize(), but with a pathName.
Definition at line 2671 of file bitmap.cpp. References loadSize(), NLMISC::CIFile::open(), and uint32.
|
|
Determinate the bitmap size from a bitmap(TGA or DDS) from an IStream. load just header of the file. Bitmap supported are DDS (DXTC1, DXTC1 with Alpha, DXTC3, DXTC5, and uncompressed TGA (24 and 32 bits). NB: at the end, f is seeked to begin.
Definition at line 2582 of file bitmap.cpp. References NLMISC::DDS, DDSD_LINEARSIZE, depth, height, NLMISC::IStream::isReading(), nlassert, NLMISC::IStream::seek(), NLMISC::IStream::serial(), size, uint, uint16, uint32, uint8, and width. Referenced by loadSize().
02583 { 02584 retWidth= 0; 02585 retHeight= 0; 02586 02587 02588 nlassert(f.isReading()); 02589 02590 // testing if DDS 02591 uint32 fileType = 0; 02592 f.serial(fileType); 02593 if(fileType == DDS) 02594 { 02595 // read entire DDS header. 02596 uint32 size = 0; 02597 f.serial(size); // size in Bytes of header(without "DDS") 02598 uint32 * _DDSSurfaceDesc = new uint32[size]; 02599 std::auto_ptr<uint32> _DDSSurfaceDescAuto(_DDSSurfaceDesc); 02600 _DDSSurfaceDesc[0]= size; 02601 02602 for(uint i= 0; i<size/4 - 1; i++) 02603 { 02604 f.serial(_DDSSurfaceDesc[i+1]); 02605 } 02606 02607 // flags determines which members of the header structure contain valid data 02608 uint32 flags = _DDSSurfaceDesc[1]; 02609 02610 //verify if file have linearsize set 02611 if(!(flags & DDSD_LINEARSIZE)) 02612 { 02613 throw EDDSBadHeader(); 02614 } 02615 02616 //-------------- extracting and testing useful info 02617 retHeight = _DDSSurfaceDesc[2]; 02618 retWidth = _DDSSurfaceDesc[3]; 02619 } 02620 // assuming it's TGA 02621 else 02622 { 02623 if(!f.seek (0, NLMISC::IStream::begin)) 02624 { 02625 throw ESeekFailed(); 02626 } 02627 02628 // Reading header, 02629 // To make sure that the bitmap is TGA, we check imageType and imageDepth. 02630 uint8 lengthID; 02631 uint8 cMapType; 02632 uint8 imageType; 02633 uint16 tgaOrigin; 02634 uint16 length; 02635 uint8 depth; 02636 uint16 xOrg; 02637 uint16 yOrg; 02638 uint16 width; 02639 uint16 height; 02640 uint8 imageDepth; 02641 uint8 desc; 02642 02643 f.serial(lengthID); 02644 f.serial(cMapType); 02645 f.serial(imageType); 02646 if(imageType!=2 && imageType!=3 && imageType!=10 && imageType!=11) return; 02647 f.serial(tgaOrigin); 02648 f.serial(length); 02649 f.serial(depth); 02650 f.serial(xOrg); 02651 f.serial(yOrg); 02652 f.serial(width); 02653 f.serial(height); 02654 f.serial(imageDepth); 02655 if(imageDepth!=8 && imageDepth!=24 && imageDepth!=32) return; 02656 f.serial(desc); 02657 02658 // Ok, we have width and height. 02659 retWidth= width; 02660 retHeight= height; 02661 } 02662 02663 // reset stream. 02664 if(!f.seek (0, NLMISC::IStream::begin)) 02665 { 02666 throw ESeekFailed(); 02667 } 02668 } |
|
Definition at line 736 of file bitmap.cpp. References _MipMapCount, PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToAlpha().
00737 { 00738 uint32 i; 00739 00740 if(_Width*_Height == 0) return false; 00741 00742 for(uint8 m= 0; m<_MipMapCount; m++) 00743 { 00744 CObjectVector<uint8> dataTmp; 00745 dataTmp.resize(_Data[m].size()); 00746 uint dstId= 0; 00747 00748 for(i=0; i<_Data[m].size(); i++) 00749 { 00750 dataTmp[dstId++]= _Data[m][i]; 00751 } 00752 _Data[m] = dataTmp; 00753 } 00754 PixelFormat = Alpha; 00755 return true; 00756 } |
|
Definition at line 579 of file bitmap.cpp. References _MipMapCount, PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToAlphaLuminance().
00580 { 00581 uint32 i; 00582 00583 if(_Width*_Height == 0) return false; 00584 00585 for(uint8 m= 0; m<_MipMapCount; m++) 00586 { 00587 CObjectVector<uint8> dataTmp; 00588 dataTmp.resize(_Data[m].size()*2); 00589 uint dstId= 0; 00590 00591 for(i=0; i<_Data[m].size(); i++) 00592 { 00593 dataTmp[dstId++]= _Data[m][i]; 00594 dataTmp[dstId++]= 255; 00595 } 00596 _Data[m] = dataTmp; 00597 } 00598 PixelFormat = AlphaLuminance; 00599 return true; 00600 } |
|
Definition at line 462 of file bitmap.cpp. References _MipMapCount, PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), RGBA, NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToRGBA().
00463 { 00464 uint32 i; 00465 00466 if(_Width*_Height == 0) return false; 00467 00468 for(uint8 m= 0; m<_MipMapCount; m++) 00469 { 00470 CObjectVector<uint8> dataTmp; 00471 dataTmp.resize(_Data[m].size()*4); 00472 uint dstId= 0; 00473 00474 for(i=0; i<_Data[m].size(); i++) 00475 { 00476 dataTmp[dstId++]= _Data[m][i]; 00477 dataTmp[dstId++]= _Data[m][i]; 00478 dataTmp[dstId++]= _Data[m][i]; 00479 dataTmp[dstId++]= 255; 00480 } 00481 _Data[m] = dataTmp; 00482 } 00483 PixelFormat = RGBA; 00484 return true; 00485 } |
|
Make a dummy "?" texture. Usefull for file not found. Mode is rgba. Definition at line 184 of file bitmap.cpp. References _MipMapCount, NLMISC::CObjectVector< uint8 >::getPtr(), PixelFormat, NLMISC::CObjectVector< uint8 >::resize(), RGBA, NLMISC::CRGBA::set(), sint, and uint8. Referenced by NL3D::CTextureFile::buildBitmapFromFile(), NL3D::CreateDummyMesh(), NL3D::CTextureMultiFile::doGenerate(), NL3D::CTextureMem::doGenerate(), NL3D::CTextureGrouped::doGenerate(), NL3D::CTextureEmboss::doGenerate(), NL3D::CTextureBump::doGenerate(), and NL3D::CTextureBlend::doGenerate().
00185 { 00186 static const uint8 bitmap[1024]= { 00187 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 00188 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0, 00189 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00190 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00191 0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0, 00192 0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0, 00193 0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0, 00194 0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0, 00195 0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0, 00196 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00197 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00198 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00199 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00200 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00201 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00202 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 00203 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 00204 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0, 00205 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00206 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00207 0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0, 00208 0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0, 00209 0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0, 00210 0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0, 00211 0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0, 00212 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00213 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00214 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00215 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00216 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00217 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 00218 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 00219 }; 00220 00221 PixelFormat = RGBA; 00222 _MipMapCount = 1; 00223 _Width= 32; 00224 _Height= 32; 00225 _Data[0].resize(_Width*_Height*sizeof(NLMISC::CRGBA)); 00226 NLMISC::CRGBA *pix= (NLMISC::CRGBA*)(_Data[0].getPtr()); 00227 00228 for(sint i=0;i<(sint)(_Width*_Height);i++) 00229 { 00230 if(bitmap[i]) 00231 pix[i].set(255,255,255,255); 00232 else 00233 pix[i].set(0x80,0x80,0x80,0x40); 00234 } 00235 00236 } |
|
Read a DDS from an IStream. The bitmap is readen as a set of bytes and stocked compressed. Width and Height are multiple of 4.
Definition at line 244 of file bitmap.cpp. References _MipMapCount, DDSD_LINEARSIZE, DXTC1HEADER, DXTC3HEADER, DXTC5HEADER, NLMISC::getPowerOf2(), min, PixelFormat, NLMISC::CObjectVector< uint8 >::resize(), NLMISC::IStream::seek(), NLMISC::IStream::serial(), NLMISC::IStream::serialBuffer(), NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, uint8, and w. Referenced by load().
00245 { 00246 //------------------ Reading Header ------------------------ 00247 00248 //-------------- reading entire header 00249 00250 uint32 size = 0; 00251 f.serial(size); // size in Bytes of header(without "DDS") 00252 uint32 * _DDSSurfaceDesc = new uint32[size]; 00253 std::auto_ptr<uint32> _DDSSurfaceDescAuto(_DDSSurfaceDesc); 00254 _DDSSurfaceDesc[0]= size; 00255 00256 #ifdef NL_LITTLE_ENDIAN 00257 f.serialBuffer((uint8*)(_DDSSurfaceDesc+1), size-4); 00258 #else 00259 for(uint i= 0; i<size/4 - 1; i++) 00260 { 00261 f.serial(_DDSSurfaceDesc[i+1]); 00262 } 00263 #endif 00264 00265 // flags determines which members of the header structure contain valid data 00266 uint32 flags = _DDSSurfaceDesc[1]; 00267 00268 //verify if file have linearsize set 00269 if(!(flags & DDSD_LINEARSIZE)) 00270 { 00271 throw EDDSBadHeader(); 00272 } 00273 00274 //-------------- extracting and testing useful info 00275 00276 _Height = _DDSSurfaceDesc[2]; 00277 _Width = _DDSSurfaceDesc[3]; 00278 _MipMapCount= (uint8) _DDSSurfaceDesc[6]; 00279 // If no mipmap. 00280 if(_MipMapCount==0) 00281 _MipMapCount=1; 00282 switch (_DDSSurfaceDesc[20]) 00283 { 00284 case DXTC1HEADER: 00285 PixelFormat=DXTC1; 00286 break; 00287 case DXTC3HEADER: 00288 PixelFormat=DXTC3; 00289 break; 00290 case DXTC5HEADER: 00291 PixelFormat=DXTC5; 00292 break; 00293 } 00294 00295 flags = _DDSSurfaceDesc[19]; //PixelFormat flags 00296 00297 if(PixelFormat==DXTC1 && _DDSSurfaceDesc[21]>0) //AlphaBitDepth 00298 { 00299 PixelFormat = DXTC1Alpha; 00300 } 00301 00302 if(PixelFormat!= DXTC1 && PixelFormat!= DXTC1Alpha && PixelFormat!= DXTC3 && PixelFormat!= DXTC5) 00303 { 00304 throw EDDSBadHeader(); 00305 } 00306 00307 // compute the min power of 2 between width and height 00308 uint minSizeLevel= min(_Width, _Height); 00309 minSizeLevel= getPowerOf2(minSizeLevel); 00310 00311 //------------- manage mipMapSkip 00312 if(_MipMapCount>1 && mipMapSkip>0 && minSizeLevel>2) 00313 { 00314 // Keep at least the level where width and height are at leat 4. 00315 mipMapSkip= min(mipMapSkip, minSizeLevel-2); 00316 // skip any mipmap 00317 uint seekSize= 0; 00318 while(mipMapSkip>0) 00319 { 00320 uint32 mipMapSz; 00321 if(PixelFormat==DXTC1 || PixelFormat==DXTC1Alpha) 00322 mipMapSz = _Width*_Height/2; 00323 else 00324 mipMapSz = _Width*_Height; 00325 00326 // add to how many to skip 00327 seekSize+= mipMapSz; 00328 00329 // Size of final bitmap is reduced. 00330 _Width>>=1; 00331 _Height>>=1; 00332 _MipMapCount--; 00333 mipMapSkip--; 00334 } 00335 // skip data in file 00336 if(seekSize>0) 00337 { 00338 if(!f.seek(seekSize, IStream::current)) 00339 { 00340 throw ESeekFailed(); 00341 } 00342 } 00343 00344 } 00345 00346 //------------- preload all the mipmaps (one serialBuffer() is faster) 00347 uint32 w = _Width; 00348 uint32 h = _Height; 00349 uint32 totalSize= 0; 00350 00351 uint8 m; 00352 for(m= 0; m<_MipMapCount; m++) 00353 { 00354 uint32 wtmp, htmp; 00355 if(w<4) 00356 wtmp = 4; 00357 else 00358 wtmp = w; 00359 if(h < 4) 00360 htmp = 4; 00361 else 00362 htmp = h; 00363 00364 uint32 mipMapSz; 00365 if(PixelFormat==DXTC1 || PixelFormat==DXTC1Alpha) 00366 mipMapSz = wtmp*htmp/2; 00367 else 00368 mipMapSz = wtmp*htmp; 00369 00370 00371 _Data[m].resize(mipMapSz); 00372 totalSize+= mipMapSz; 00373 00374 w = (w+1)/2; 00375 h = (h+1)/2; 00376 } 00377 00378 // Read all the data in one block. 00379 vector<uint8> pixData; 00380 pixData.resize(totalSize); 00381 f.serialBuffer(&(*pixData.begin()), totalSize); 00382 00383 00384 //------------- reading mipmap levels from pixData 00385 00386 uint32 pixIndex= 0; 00387 00388 for(m= 0; m<_MipMapCount; m++) 00389 { 00390 uint32 mipMapSz= _Data[m].size(); 00391 memcpy(_Data[m].getPtr(), &(pixData[pixIndex]), mipMapSz); 00392 pixIndex+= mipMapSz; 00393 } 00394 00395 //------------- End 00396 00397 switch(PixelFormat) 00398 { 00399 case DXTC1 : return 24; 00400 case DXTC1Alpha : return 32; 00401 case DXTC3 : return 32; 00402 case DXTC5 : return 32; 00403 default : break; 00404 } 00405 00406 return 0; 00407 } |
|
Read a TGA from an IStream. TGA pictures can be in 24 or 32 bits, RLE or uncompressed
Definition at line 1800 of file bitmap.cpp. References _LoadGrayscaleAsAlpha, _MipMapCount, NLMISC::IStream::begin, depth, NLMISC::IStream::end, NLMISC::IStream::getPos(), height, imageSize, NLMISC::IStream::isReading(), nlinfo, PixelFormat, r, NLMISC::CObjectVector< uint8 >::resize(), RGBA, NLMISC::IStream::seek(), NLMISC::IStream::serial(), NLMISC::IStream::serialBuffer(), sint32, size, uint, uint16, uint32, uint8, width, x, and y. Referenced by load().
01801 { 01802 if(!f.isReading()) return 0; 01803 01804 uint32 size; 01805 uint32 x,y; 01806 sint32 slsize; 01807 uint8 *scanline; 01808 uint8 r,g,b; 01809 sint32 i,j,k; 01810 01811 // TGA file header fields 01812 uint8 lengthID; 01813 uint8 cMapType; 01814 uint8 imageType; 01815 uint16 origin; 01816 uint16 length; 01817 uint8 depth; 01818 uint16 xOrg; 01819 uint16 yOrg; 01820 uint16 width; 01821 uint16 height; 01822 uint8 imageDepth; 01823 uint8 desc; 01824 01825 // Image/Color map data 01826 uint8 *imageID; 01827 01828 01829 01830 // Determining whether file is in Original or New TGA format 01831 01832 bool newTgaFormat; 01833 uint32 extAreaOffset; 01834 uint32 devDirectoryOffset; 01835 char signature[16]; 01836 01837 f.seek (0, f.end); 01838 newTgaFormat = false; 01839 if (f.getPos() >= 26) 01840 { 01841 f.seek (-26, f.end); 01842 f.serial(extAreaOffset); 01843 f.serial(devDirectoryOffset); 01844 for(i=0; i<16; i++) 01845 { 01846 f.serial(signature[i]); 01847 } 01848 if(strncmp(signature,"TRUEVISION-XFILE",16)==0) 01849 newTgaFormat = true; 01850 } 01851 01852 01853 01854 // Reading TGA file header 01855 f.seek (0, f.begin); 01856 01857 f.serial(lengthID); 01858 f.serial(cMapType); 01859 f.serial(imageType); 01860 f.serial(origin); 01861 f.serial(length); 01862 f.serial(depth); 01863 f.serial(xOrg); 01864 f.serial(yOrg); 01865 f.serial(width); 01866 f.serial(height); 01867 f.serial(imageDepth); 01868 f.serial(desc); 01869 01870 if(cMapType!=0) 01871 { 01872 nlinfo("readTga : color-map not supported"); 01873 } 01874 01875 if(lengthID>0) 01876 { 01877 imageID = new uint8[lengthID]; 01878 for(i=0; i<lengthID; i++) 01879 f.serial(imageID[i]); 01880 } 01881 01882 01883 01884 // Reading TGA image data 01885 01886 _Width = width; 01887 _Height = height; 01888 size = _Width * _Height * (imageDepth/8); 01889 01890 switch(imageType) 01891 { 01892 // Uncompressed RGB or RGBA 01893 case 2: 01894 { 01895 _Data[0].resize(_Width*_Height*4); 01896 uint8 upSideDown = ((desc & (1 << 5))==0); 01897 slsize = _Width * imageDepth / 8; 01898 01899 scanline = new uint8[slsize]; 01900 if(!scanline) 01901 { 01902 throw EAllocationFailure(); 01903 } 01904 01905 for(y=0; y<_Height;y++) 01906 { 01907 // Serial buffer: more efficient way to load. 01908 f.serialBuffer (scanline, slsize); 01909 01910 if(imageDepth==24 || imageDepth==32) 01911 { 01912 sint32 mult = 3; 01913 if(imageDepth==16) 01914 { 01915 mult = 2; 01916 } 01917 if(imageDepth==32) 01918 { 01919 mult = 4; 01920 } 01921 if(imageDepth!=16) 01922 { 01923 for(x=0; x<_Width; x++) 01924 { 01925 // RGB(A) 01926 r = scanline[x*mult+0]; 01927 g = scanline[x*mult+1]; 01928 b = scanline[x*mult+2]; 01929 // Switching to BGR(A) 01930 scanline[x*mult+0] = b; 01931 scanline[x*mult+1] = g; 01932 scanline[x*mult+2] = r; 01933 } 01934 } 01935 } 01936 01937 k=0; 01938 for(i=0; i<width; i++) 01939 { 01940 if(upSideDown) 01941 { 01942 if(imageDepth==16) 01943 { 01944 uint16 toto = (uint16)scanline[k++]; 01945 toto |= scanline[k++]<<8; 01946 uint _r = toto>>10; 01947 uint _g = (toto>>5)&0x1f; 01948 uint _b = toto&0x1f; 01949 _Data[0][(height-y-1)*width*4 + 4*i] = (_r<<3) | (_r>>2); 01950 _Data[0][(height-y-1)*width*4 + 4*i + 1] = (_g<<3) | (_g>>2); 01951 _Data[0][(height-y-1)*width*4 + 4*i + 2] = (_b<<3) | (_b>>2); 01952 _Data[0][(height-y-1)*width*4 + 4*i + 3] = 255; 01953 } 01954 else 01955 { 01956 _Data[0][(height-y-1)*width*4 + 4*i] = scanline[k++]; 01957 _Data[0][(height-y-1)*width*4 + 4*i + 1] = scanline[k++]; 01958 _Data[0][(height-y-1)*width*4 + 4*i + 2] = scanline[k++]; 01959 if(imageDepth==32) 01960 _Data[0][(height-y-1)*width*4 + 4*i + 3] = scanline[k++]; 01961 else 01962 _Data[0][(height-y-1)*width*4 + 4*i + 3] = 255; 01963 } 01964 } 01965 else 01966 { 01967 if(imageDepth==16) 01968 { 01969 uint16 toto = (uint16)scanline[k++]; 01970 toto |= scanline[k++]<<8; 01971 int _r = toto>>10; 01972 int _g = toto&(0x3e0)>>5; 01973 int _b = toto&0x1f; 01974 _Data[0][y*width*4 + 4*i] = (_r<<3) | (_r>>2); 01975 _Data[0][y*width*4 + 4*i + 1] = (_g<<3) | (_g>>2); 01976 _Data[0][y*width*4 + 4*i + 2] = (_b<<3) | (_b>>2); 01977 _Data[0][y*width*4 + 4*i + 3] = 255; 01978 } 01979 else 01980 { 01981 _Data[0][y*width*4 + 4*i] = scanline[k++]; 01982 _Data[0][y*width*4 + 4*i + 1] = scanline[k++]; 01983 _Data[0][y*width*4 + 4*i + 2] = scanline[k++]; 01984 if(imageDepth==32) 01985 _Data[0][y*width*4 + 4*i + 3] = scanline[k++]; 01986 else 01987 _Data[0][y*width*4 + 4*i + 3] = 255; 01988 } 01989 } 01990 } 01991 } 01992 01993 PixelFormat = RGBA; 01994 delete scanline; 01995 }; 01996 break; 01997 01998 // Uncompressed Grayscale bitmap 01999 case 3: 02000 { 02001 _Data[0].resize(_Width*_Height); 02002 uint8 upSideDown = ((desc & (1 << 5))==0); 02003 slsize = _Width; 02004 02005 scanline = new uint8[slsize]; 02006 if(!scanline) 02007 { 02008 throw EAllocationFailure(); 02009 } 02010 02011 for(y=0; y<_Height;y++) 02012 { 02013 // Serial buffer: more efficient way to load. 02014 f.serialBuffer (scanline, slsize); 02015 02016 k=0; 02017 for(i=0; i<width; i++) 02018 { 02019 if(upSideDown) 02020 _Data[0][(height-y-1)*width + i] = scanline[k++]; 02021 else 02022 _Data[0][y*width + i] = scanline[k++]; 02023 } 02024 } 02025 02026 PixelFormat = _LoadGrayscaleAsAlpha?Alpha:Luminance; 02027 delete scanline; 02028 }; 02029 break; 02030 02031 // Compressed RGB or RGBA 02032 case 10: 02033 { 02034 uint8 packet; 02035 uint8 pixel[4]; 02036 uint32 imageSize = width*height; 02037 uint32 readSize = 0; 02038 _Data[0].resize(_Width*_Height*4); 02039 uint dstId= 0; 02040 02041 while(readSize < imageSize) 02042 { 02043 f.serial(packet); 02044 if((packet & 0x80) > 0) // packet RLE 02045 { 02046 for(i=0; i<imageDepth/8; i++) 02047 { 02048 f.serial(pixel[i]); 02049 } 02050 for (i=0; i < (packet & 0x7F) + 1; i++) 02051 { 02052 for(j=0; j<imageDepth/8; j++) 02053 { 02054 _Data[0][dstId++]= pixel[j]; 02055 } 02056 if(imageDepth==24) 02057 { 02058 _Data[0][dstId++]= 0; 02059 } 02060 } 02061 } 02062 else // packet Raw 02063 { 02064 for(i=0; i<((packet & 0x7F) + 1); i++) 02065 { 02066 for(j=0; j<imageDepth/8; j++) 02067 { 02068 f.serial(pixel[j]); 02069 } 02070 if(imageDepth==32) 02071 { 02072 _Data[0][dstId++]= pixel[2]; 02073 _Data[0][dstId++]= pixel[1]; 02074 _Data[0][dstId++]= pixel[0]; 02075 _Data[0][dstId++]= pixel[3]; 02076 } 02077 if(imageDepth==24) 02078 { 02079 _Data[0][dstId++]= pixel[2]; 02080 _Data[0][dstId++]= pixel[1]; 02081 _Data[0][dstId++]= pixel[0]; 02082 _Data[0][dstId++]= 0; 02083 } 02084 } 02085 } 02086 readSize += (packet & 0x7F) + 1; 02087 } 02088 PixelFormat = RGBA; 02089 }; 02090 break; 02091 02092 // Compressed Grayscale bitmap (not tested) 02093 case 11: 02094 { 02095 uint8 packet; 02096 uint8 pixel[4]; 02097 uint32 imageSize = width*height; 02098 uint32 readSize = 0; 02099 _Data[0].resize(_Width*_Height); 02100 uint dstId= 0; 02101 02102 while(readSize < imageSize) 02103 { 02104 f.serial(packet); 02105 if((packet & 0x80) > 0) // packet RLE 02106 { 02107 f.serial(pixel[0]); 02108 for (i=0; i < (packet & 0x7F) + 1; i++) 02109 { 02110 _Data[0][dstId++]= pixel[0]; 02111 } 02112 } 02113 else // packet Raw 02114 { 02115 for(i=0; i<((packet & 0x7F) + 1); i++) 02116 { 02117 f.serial(pixel[0]); 02118 _Data[0][dstId++]= pixel[0]; 02119 } 02120 } 02121 readSize += (packet & 0x7F) + 1; 02122 } 02123 PixelFormat = _LoadGrayscaleAsAlpha?Alpha:Luminance; 02124 }; 02125 break; 02126 02127 default: 02128 return 0; 02129 } 02130 02131 _MipMapCount = 1; 02132 return(imageDepth); 02133 02134 } |
|
Release the mipmaps of the bitmap if they exist. Work for any mode.
Definition at line 1493 of file bitmap.cpp. References _MipMapCount, NLMISC::contReset(), NLMISC::MAX_MIPMAP, and sint. Referenced by NL3D::CAsyncTextureManager::CTextureEntry::createCoarseBitmap(), NL3D::CTextureEmboss::doGenerate(), NL3D::CTextureBump::doGenerate(), flipH(), flipV(), resample(), resize(), rot90CCW(), rot90CW(), and NL3D::CDriverGL::setupTextureEx().
01494 { 01495 if(_MipMapCount<=1) return; 01496 01497 _MipMapCount=1; 01498 for(sint i=1;i<MAX_MIPMAP;i++) 01499 { 01500 NLMISC::contReset(_Data[i]); 01501 } 01502 } |
|
Resample the bitmap. If mipmaps exist they are deleted, then rebuilt after resampling.
Definition at line 1508 of file bitmap.cpp. References _MipMapCount, buildMipMaps(), NLMISC::contReset(), nlassert, PixelFormat, releaseMipMaps(), resamplePicture32(), NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), RGBA, and sint32. Referenced by NL3D::CCoarseMeshBuild::buildBitmap(), and NL3D::CDriverGL::setupTextureEx().
01509 { 01510 nlassert(PixelFormat == RGBA); 01511 bool needRebuild = false; 01512 01513 // Deleting mipmaps 01514 if(_MipMapCount>1) 01515 needRebuild = true; 01516 releaseMipMaps(); 01517 01518 if(nNewWidth==0 || nNewHeight==0) 01519 { 01520 _Width = _Height = 0; 01521 return; 01522 } 01523 01524 CObjectVector<uint8> pDestui; 01525 pDestui.resize(nNewWidth*nNewHeight*4); 01526 NLMISC::CRGBA *pDestRgba = (NLMISC::CRGBA*)&pDestui[0]; 01527 01528 resamplePicture32 ((NLMISC::CRGBA*)&_Data[0][0], pDestRgba, _Width, _Height, nNewWidth, nNewHeight); 01529 NLMISC::contReset(_Data[0]); // free memory 01530 _Data[0] = pDestui; 01531 _Width= nNewWidth; 01532 _Height= nNewHeight; 01533 01534 // Rebuilding mipmaps 01535 if(needRebuild) 01536 { 01537 buildMipMaps(); 01538 } 01539 } |
|
The resample function
Definition at line 1618 of file bitmap.cpp. References nlassert, and sint32. Referenced by resample().
01621 { 01622 if ((nSrcWidth<=0)||(nSrcHeight<=0)||(nDestHeight<=0)||(nDestHeight<=0)) 01623 return; 01624 bool bXMag=(nDestWidth>=nSrcWidth); 01625 bool bYMag=(nDestHeight>=nSrcHeight); 01626 bool bXEq=(nDestWidth==nSrcWidth); 01627 bool bYEq=(nDestHeight==nSrcHeight); 01628 std::vector<NLMISC::CRGBAF> pIterm (nDestWidth*nSrcHeight); 01629 01630 if (bXMag) 01631 { 01632 float fXdelta=(float)(nSrcWidth)/(float)(nDestWidth); 01633 NLMISC::CRGBAF *pItermPtr=&*pIterm.begin(); 01634 sint32 nY; 01635 for (nY=0; nY<nSrcHeight; nY++) 01636 { 01637 const NLMISC::CRGBA *pSrcLine=pSrc; 01638 float fX=0.f; 01639 sint32 nX; 01640 for (nX=0; nX<nDestWidth; nX++) 01641 { 01642 float fVirgule=fX-(float)floor(fX); 01643 nlassert (fVirgule>=0.f); 01644 NLMISC::CRGBAF vColor; 01645 if (fVirgule>=0.5f) 01646 { 01647 if (fX<(float)(nSrcWidth-1)) 01648 { 01649 NLMISC::CRGBAF vColor1 (pSrcLine[(sint32)floor(fX)]); 01650 NLMISC::CRGBAF vColor2 (pSrcLine[(sint32)floor(fX)+1]); 01651 vColor=vColor1*(1.5f-fVirgule)+vColor2*(fVirgule-0.5f); 01652 } 01653 else 01654 vColor=NLMISC::CRGBAF (pSrcLine[(sint32)floor(fX)]); 01655 } 01656 else 01657 { 01658 if (fX>=1.f) 01659 { 01660 NLMISC::CRGBAF vColor1 (pSrcLine[(sint32)floor(fX)]); 01661 NLMISC::CRGBAF vColor2 (pSrcLine[(sint32)floor(fX)-1]); 01662 vColor=vColor1*(0.5f+fVirgule)+vColor2*(0.5f-fVirgule); 01663 } 01664 else 01665 vColor=NLMISC::CRGBAF (pSrcLine[(sint32)floor(fX)]); 01666 } 01667 *(pItermPtr++)=vColor; 01668 fX+=fXdelta; 01669 } 01670 pSrc+=nSrcWidth; 01671 } 01672 } 01673 else if (bXEq) 01674 { 01675 NLMISC::CRGBAF *pItermPtr=&*pIterm.begin(); 01676 for (sint32 nY=0; nY<nSrcHeight; nY++) 01677 { 01678 const NLMISC::CRGBA *pSrcLine=pSrc; 01679 sint32 nX; 01680 for (nX=0; nX<nDestWidth; nX++) 01681 *(pItermPtr++)=NLMISC::CRGBAF (pSrcLine[nX]); 01682 pSrc+=nSrcWidth; 01683 } 01684 } 01685 else 01686 { 01687 double fXdelta=(double)(nSrcWidth)/(double)(nDestWidth); 01688 nlassert (fXdelta>1.f); 01689 NLMISC::CRGBAF *pItermPtr=&*pIterm.begin(); 01690 sint32 nY; 01691 for (nY=0; nY<nSrcHeight; nY++) 01692 { 01693 const NLMISC::CRGBA *pSrcLine=pSrc; 01694 double fX=0.f; 01695 sint32 nX; 01696 for (nX=0; nX<nDestWidth; nX++) 01697 { 01698 NLMISC::CRGBAF vColor (0.f, 0.f, 0.f, 0.f); 01699 double fFinal=fX+fXdelta; 01700 while (fX<fFinal) 01701 { 01702 double fNext=(double)floor (fX)+1.f; 01703 if (fNext>fFinal) 01704 fNext=fFinal; 01705 vColor+=((float)(fNext-fX))*NLMISC::CRGBAF (pSrcLine[(sint32)floor(fX)]); 01706 fX=fNext; 01707 } 01708 nlassert (fX==fFinal); 01709 vColor/=(float)fXdelta; 01710 *(pItermPtr++)=vColor; 01711 } 01712 pSrc+=nSrcWidth; 01713 } 01714 } 01715 01716 if (bYMag) 01717 { 01718 double fYdelta=(double)(nSrcHeight)/(double)(nDestHeight); 01719 sint32 nX; 01720 for (nX=0; nX<nDestWidth; nX++) 01721 { 01722 double fY=0.f; 01723 sint32 nY; 01724 for (nY=0; nY<nDestHeight; nY++) 01725 { 01726 double fVirgule=fY-(double)floor(fY); 01727 nlassert (fVirgule>=0.f); 01728 NLMISC::CRGBAF vColor; 01729 if (fVirgule>=0.5f) 01730 { 01731 if (fY<(double)(nSrcHeight-1)) 01732 { 01733 NLMISC::CRGBAF vColor1=pIterm[((sint32)floor(fY))*nDestWidth+nX]; 01734 NLMISC::CRGBAF vColor2=pIterm[(((sint32)floor(fY))+1)*nDestWidth+nX]; 01735 vColor=vColor1*(1.5f-(float)fVirgule)+vColor2*((float)fVirgule-0.5f); 01736 } 01737 else 01738 vColor=pIterm[((sint32)floor(fY))*nDestWidth+nX]; 01739 } 01740 else 01741 { 01742 if (fY>=1.f) 01743 { 01744 NLMISC::CRGBAF vColor1=pIterm[((sint32)floor(fY))*nDestWidth+nX]; 01745 NLMISC::CRGBAF vColor2=pIterm[(((sint32)floor(fY))-1)*nDestWidth+nX]; 01746 vColor=vColor1*(0.5f+(float)fVirgule)+vColor2*(0.5f-(float)fVirgule); 01747 } 01748 else 01749 vColor=pIterm[((sint32)floor(fY))*nDestWidth+nX]; 01750 } 01751 pDest[nX+nY*nDestWidth]=vColor; 01752 fY+=fYdelta; 01753 } 01754 } 01755 } 01756 else if (bYEq) 01757 { 01758 for (sint32 nX=0; nX<nDestWidth; nX++) 01759 { 01760 sint32 nY; 01761 for (nY=0; nY<nDestHeight; nY++) 01762 { 01763 pDest[nX+nY*nDestWidth]=pIterm[nY*nDestWidth+nX]; 01764 } 01765 } 01766 } 01767 else 01768 { 01769 double fYdelta=(double)(nSrcHeight)/(double)(nDestHeight); 01770 nlassert (fYdelta>1.f); 01771 sint32 nX; 01772 for (nX=0; nX<nDestWidth; nX++) 01773 { 01774 double fY=0.f; 01775 sint32 nY; 01776 for (nY=0; nY<nDestHeight; nY++) 01777 { 01778 NLMISC::CRGBAF vColor (0.f, 0.f, 0.f, 0.f); 01779 double fFinal=fY+fYdelta; 01780 while ((fY<fFinal)&&((sint32)fY!=nSrcHeight)) 01781 { 01782 double fNext=(double)floor (fY)+1.f; 01783 if (fNext>fFinal) 01784 fNext=fFinal; 01785 vColor+=((float)(fNext-fY))*pIterm[((sint32)floor(fY))*nDestWidth+nX]; 01786 fY=fNext; 01787 } 01788 vColor/=(float)fYdelta; 01789 pDest[nX+nY*nDestWidth]=vColor; 01790 } 01791 } 01792 } 01793 } |
|
Reset the buffer. Mipmaps are deleted and bitmap is not valid anymore.
Definition at line 1599 of file bitmap.cpp. References _MipMapCount, NLMISC::contReset(), PixelFormat, NLMISC::CObjectVector< uint8 >::resize(), type, and uint. Referenced by NL3D::CHLSColorTexture::buildColorVersion(), NL3D::CDriverGL::getBufferPart(), and NL3D::ITexture::release().
01600 { 01601 for(uint i=0; i<_MipMapCount; i++) 01602 { 01603 NLMISC::contReset(_Data[i]); 01604 _Data[i].resize(0); 01605 } 01606 _Width = _Height = 0; 01607 _MipMapCount= 1; 01608 01609 // Change pixel format 01610 PixelFormat=type; 01611 } |
|
Resize the bitmap. If mipmaps exist they are deleted and not rebuilt. This is not a crop. Pixels are lost after resize.
Definition at line 1545 of file bitmap.cpp. References DonTKnow, PixelFormat, releaseMipMaps(), resizeMipMap(), and sint32. Referenced by blend(), NL3D::CHLSColorTexture::buildColorVersion(), NL3D::CTextureFont::CTextureFont(), NL3D::CTextureMem::doGenerate(), NL3D::CTextureGrouped::doGenerate(), NL3D::CTextureCross::doGenerate(), NL3D::CTextureFont::dumpTextureFont(), NL3D::CCoarseMeshBuild::expand(), and NL3D::CDriverGL::getBufferPart().
01546 { 01547 // Deleting mipmaps 01548 releaseMipMaps(); 01549 01550 // Change type of bitmap ? 01551 if (newType!=DonTKnow) 01552 PixelFormat=newType; 01553 01554 _Width = nNewWidth; 01555 _Height = nNewHeight; 01556 01557 // resize the level 0 only. 01558 resizeMipMap(0, nNewWidth, nNewHeight, resetTo0); 01559 } |
|
ADVANCED USE Resize a single mipmap level. resize() should have been called before. This is not a crop. Pixels are lost after resize. No validity check is made. It is the user responsabitility fo setup correct mipmap size.
Definition at line 1565 of file bitmap.cpp. References bitPerPixels, NLMISC::contReset(), NLMISC::CObjectVector< uint8 >::fill(), NLMISC::MAX_MIPMAP, nlassert, PixelFormat, NLMISC::CObjectVector< uint8 >::resize(), sint32, and uint32. Referenced by NL3D::CHLSColorTexture::buildColorVersion(), and resize().
01566 { 01567 nlassert(numMipMap<MAX_MIPMAP); 01568 01569 // free memory 01570 NLMISC::contReset(_Data[numMipMap]); 01571 01572 // DXTC compressed?? 01573 //bool isDXTC= PixelFormat==DXTC1 || PixelFormat==DXTC1Alpha || PixelFormat==DXTC3 || PixelFormat==DXTC5; 01574 // if yes, must round up width and height to 4, for allocation 01575 nNewWidth= 4*((nNewWidth+3)/4); 01576 nNewHeight= 4*((nNewHeight+3)/4); 01577 01578 // resize the buffer 01579 _Data[numMipMap].resize (((uint32)(nNewWidth*nNewHeight)*bitPerPixels[PixelFormat])/8); 01580 01581 // Fill 0? 01582 if( resetTo0 ) 01583 _Data[numMipMap].fill(0); 01584 } |
|
Definition at line 708 of file bitmap.cpp. References _MipMapCount, NLMISC::contReset(), PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToAlpha().
00709 { 00710 uint32 i; 00711 00712 if(_Width*_Height == 0) return false; 00713 00714 for(uint8 m= 0; m<_MipMapCount; m++) 00715 { 00716 CObjectVector<uint8> dataTmp; 00717 dataTmp.resize(_Data[m].size()/4); 00718 uint dstId= 0; 00719 00720 for(i=0; i<_Data[m].size(); i+=4) 00721 { 00722 dataTmp[dstId++]= _Data[m][i+3]; 00723 } 00724 NLMISC::contReset(_Data[m]); 00725 _Data[m].resize(0); 00726 _Data[m] = dataTmp; 00727 } 00728 PixelFormat = Alpha; 00729 return true; 00730 } |
|
Definition at line 550 of file bitmap.cpp. References _MipMapCount, NLMISC::contReset(), PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToAlphaLuminance().
00551 { 00552 uint32 i; 00553 00554 if(_Width*_Height == 0) return false; 00555 00556 for(uint8 m= 0; m<_MipMapCount; m++) 00557 { 00558 CObjectVector<uint8> dataTmp; 00559 dataTmp.resize(_Data[m].size()/2); 00560 uint dstId= 0; 00561 00562 for(i=0; i<_Data[m].size(); i+=4) 00563 { 00564 dataTmp[dstId++]= (_Data[m][i]*77 + _Data[m][i+1]*150 + _Data[m][i+2]*28)/255; 00565 dataTmp[dstId++]= _Data[m][i+3]; 00566 } 00567 NLMISC::contReset(_Data[m]); 00568 _Data[m].resize(0); 00569 _Data[m] = dataTmp; 00570 } 00571 PixelFormat = AlphaLuminance; 00572 return true; 00573 } |
|
Definition at line 635 of file bitmap.cpp. References _MipMapCount, NLMISC::contReset(), PixelFormat, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), NLMISC::CObjectVector< uint8 >::size(), size, uint, uint32, and uint8. Referenced by convertToLuminance().
00636 { 00637 uint32 i; 00638 00639 if(_Width*_Height == 0) return false; 00640 00641 for(uint8 m= 0; m<_MipMapCount; m++) 00642 { 00643 CObjectVector<uint8> dataTmp; 00644 dataTmp.resize(_Data[m].size()/4); 00645 uint dstId= 0; 00646 00647 for(i=0; i<_Data[m].size(); i+=4) 00648 { 00649 dataTmp[dstId++]= (_Data[m][i]*77 + _Data[m][i+1]*150 + _Data[m][i+2]*28)/255; 00650 } 00651 NLMISC::contReset(_Data[m]); 00652 _Data[m].resize(0); 00653 _Data[m] = dataTmp; 00654 } 00655 PixelFormat = Luminance; 00656 return true; 00657 } |
|
Rotation of the bitmap of 90 degree in counter clockwise Definition at line 2781 of file bitmap.cpp. References _MipMapCount, buildMipMaps(), NLMISC::contReset(), getHeight(), getWidth(), PixelFormat, releaseMipMaps(), NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), RGBA, sint32, and uint32.
02782 { 02783 if (PixelFormat != RGBA) 02784 return; 02785 sint32 nWidth = getWidth(0); 02786 sint32 nHeight = getHeight(0); 02787 sint32 i, j; 02788 NLMISC::CRGBA *pSrcRgba = (NLMISC::CRGBA*)&_Data[0][0]; 02789 bool needRebuild = false; 02790 02791 if(_MipMapCount>1) 02792 needRebuild = true; 02793 releaseMipMaps(); 02794 02795 CObjectVector<uint8> pDestui; 02796 pDestui.resize(nWidth*nHeight*4); 02797 NLMISC::CRGBA *pDestRgba = (NLMISC::CRGBA*)&pDestui[0]; 02798 02799 for( j = 0; j < nHeight; ++j ) 02800 for( i = 0; i < nWidth; ++i ) 02801 pDestRgba[j+i*nHeight] = pSrcRgba[nWidth-1-i+j*nWidth]; 02802 02803 uint32 nTemp = _Width; 02804 _Width = _Height; 02805 _Height = nTemp; 02806 02807 NLMISC::contReset(_Data[0]); // free memory 02808 _Data[0] = pDestui; 02809 // Rebuilding mipmaps 02810 if(needRebuild) 02811 { 02812 buildMipMaps(); 02813 } 02814 } |
|
Rotation of the bitmap of 90 degree in clockwise Definition at line 2746 of file bitmap.cpp. References _MipMapCount, buildMipMaps(), NLMISC::contReset(), getHeight(), getWidth(), PixelFormat, releaseMipMaps(), NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), RGBA, sint32, and uint32.
02747 { 02748 if (PixelFormat != RGBA) 02749 return; 02750 sint32 nWidth = getWidth(0); 02751 sint32 nHeight = getHeight(0); 02752 sint32 i, j; 02753 NLMISC::CRGBA *pSrcRgba = (NLMISC::CRGBA*)&_Data[0][0]; 02754 bool needRebuild = false; 02755 02756 if(_MipMapCount>1) 02757 needRebuild = true; 02758 releaseMipMaps(); 02759 02760 CObjectVector<uint8> pDestui; 02761 pDestui.resize(nWidth*nHeight*4); 02762 NLMISC::CRGBA *pDestRgba = (NLMISC::CRGBA*)&pDestui[0]; 02763 02764 for( j = 0; j < nHeight; ++j ) 02765 for( i = 0; i < nWidth; ++i ) 02766 pDestRgba[j+i*nHeight] = pSrcRgba[i+(nHeight-1-j)*nWidth]; 02767 02768 uint32 nTemp = _Width; 02769 _Width = _Height; 02770 _Height = nTemp; 02771 02772 NLMISC::contReset(_Data[0]); // free memory 02773 _Data[0] = pDestui; 02774 // Rebuilding mipmaps 02775 if(needRebuild) 02776 { 02777 buildMipMaps(); 02778 } 02779 } |
|
Rotate a bitmap in CCW mode.
Definition at line 2306 of file bitmap.cpp. References PixelFormat, RGBA, NLMISC::rotateCCW(), uint16, and uint32.
02307 { 02308 // Copy the array 02309 CObjectVector<uint8> copy=_Data[0]; 02310 02311 switch (PixelFormat) 02312 { 02313 case RGBA: 02314 NLMISC::rotateCCW ((uint32*)&(_Data[0][0]), (uint32*)&(copy[0]), _Width, _Height); 02315 break; 02316 case Luminance: 02317 case Alpha: 02318 NLMISC::rotateCCW (&_Data[0][0], ©[0], _Width, _Height); 02319 break; 02320 case AlphaLuminance: 02321 NLMISC::rotateCCW ((uint16*)&(_Data[0][0]), (uint16*)&(copy[0]), _Width, _Height);; 02322 break; 02323 default: break; 02324 } 02325 02326 uint32 tmp=_Width; 02327 _Width=_Height; 02328 _Height=tmp; 02329 _Data[0]=copy; 02330 } |
|
ADVANCED USE To use in conjunction with resizeMipMap. Setup the correct total number of mipmap No validity check is made. It is the user responsabitility fo setup correct mipmap count. Definition at line 1590 of file bitmap.cpp. References _MipMapCount, uint32, and uint8. Referenced by NL3D::CHLSColorTexture::buildColorVersion().
01591 { 01592 _MipMapCount= uint8(mmc); 01593 } |
|
Extracting RGBA infos from a 16bits word. (used by S3TC decompression)
Definition at line 1350 of file bitmap.cpp. Referenced by decompressDXT1(), decompressDXT3(), decompressDXT5(), and getDXTCColorFromBlock().
|
|
Write a JPG from the object pixels buffer. If the current pixel format is not rgba then the method does nothing If the pixel format is Alpha then we save in 8 bpp
Definition at line 620 of file bitmap.h. References nlwarning, and uint8.
00621 { 00622 nlwarning ("You must put #define USE_JPEG before all include in the file where you call writeJPG() if you want jpeg support"); 00623 return false; 00624 } |
|
Write a TGA (24 or 32 bits) from the object pixels buffer. If the current pixel format is not rgba then the method does nothing If the pixel format is Alpha then we save in 8 bpp
Definition at line 2139 of file bitmap.cpp. References depth, height, NLMISC::IStream::isReading(), PixelFormat, r, RGBA, NLMISC::IStream::serial(), sint32, uint16, uint32, uint8, width, x, and y. Referenced by NL3D::CTextureFont::dumpTextureFont(), NL3D::CZoneLighter::lightWater(), and NL3D::CNELU::screenshot().
02140 { 02141 if(f.isReading()) return false; 02142 if(d!=24 && d!=32 && d!=16 && d!=8) return false; 02143 if ((PixelFormat != RGBA)&&(PixelFormat != Alpha)&&(PixelFormat != Luminance)) return false; 02144 if ((PixelFormat == Alpha) && (d != 8)) return false; 02145 if ((PixelFormat == Luminance) && (d != 8)) return false; 02146 02147 sint32 i,j,x,y; 02148 uint8 * scanline; 02149 uint8 r,g,b,a; 02150 02151 uint8 lengthID = 0; 02152 uint8 cMapType = 0; 02153 uint8 imageType = 2; 02154 uint16 origin = 0; 02155 uint16 length = 0; 02156 uint8 depth = 0; 02157 uint16 xOrg = 0; 02158 uint16 yOrg = 0; 02159 uint16 width = (uint16)_Width; 02160 uint16 height = (uint16)_Height; 02161 uint8 imageDepth = (uint8)d; 02162 uint8 desc = 0; 02163 if (upsideDown) 02164 desc |= 1<<5; 02165 02166 if ((PixelFormat == Alpha) || (PixelFormat == Luminance)) 02167 imageType = 3; // Uncompressed grayscale 02168 02169 f.serial(lengthID); 02170 f.serial(cMapType); 02171 f.serial(imageType); 02172 f.serial(origin); 02173 f.serial(length); 02174 f.serial(depth); 02175 f.serial(xOrg); 02176 f.serial(yOrg); 02177 f.serial(width); 02178 f.serial(height); 02179 f.serial(imageDepth); 02180 f.serial(desc); 02181 02182 if ((PixelFormat == Alpha)||(PixelFormat == Luminance)) 02183 scanline = new uint8[width]; 02184 else 02185 scanline = new uint8[width*4]; 02186 if(!scanline) 02187 { 02188 throw EAllocationFailure(); 02189 } 02190 02191 for(y=0; y<(sint32)height; y++) 02192 { 02193 02194 uint32 k=0; 02195 if (PixelFormat == Alpha) 02196 { 02197 for(i=0; i<width; ++i) // Alpha 02198 { 02199 scanline[k++] = _Data[0][(height-y-1)*width + i]; 02200 } 02201 } 02202 else if (PixelFormat == Luminance) 02203 { 02204 for(i=0; i<width; ++i) // Luminance 02205 { 02206 scanline[k++] = _Data[0][(height-y-1)*width + i]; 02207 } 02208 } 02209 else 02210 { 02211 for(i=0; i<width*4; i+=4) // 4:RGBA 02212 { 02213 if(d==16) 02214 { 02215 for(j=0; j<(sint32)4; j++) 02216 { 02217 scanline[k++] = _Data[0][(height-y-1)*width*4 + i + j]; 02218 } 02219 } 02220 else 02221 { 02222 for(j=0; j<(sint32)d/8; j++) 02223 { 02224 scanline[k++] = _Data[0][(height-y-1)*width*4 + i + j]; 02225 } 02226 } 02227 } 02228 } 02229 02230 if(d==16) 02231 { 02232 for(x=0; x<(sint32)width; x++) 02233 { 02234 r = scanline[x*4+0]; 02235 g = scanline[x*4+1]; 02236 b = scanline[x*4+2]; 02237 int rr = r >>3; 02238 int gg = g >>3; 02239 int bb = b >>3; 02240 uint16 c16 = (rr<<10) | (gg<<5) | bb; 02241 scanline[x*2+0] = c16&0xff; 02242 scanline[x*2+1] = c16>>8; 02243 } 02244 } 02245 if(d==24) 02246 { 02247 for(x=0; x<(sint32)width; x++) 02248 { 02249 r = scanline[x*3+0]; 02250 g = scanline[x*3+1]; 02251 b = scanline[x*3+2]; 02252 scanline[x*3+0] = b; 02253 scanline[x*3+1] = g; 02254 scanline[x*3+2] = r; 02255 } 02256 } 02257 if(d==32) 02258 { 02259 for(x=0; x<(sint32)width; x++) 02260 { 02261 r = scanline[x*4+0]; 02262 g = scanline[x*4+1]; 02263 b = scanline[x*4+2]; 02264 a= scanline[x*4+3]; 02265 scanline[x*4+0] = b; 02266 scanline[x*4+1] = g; 02267 scanline[x*4+2] = r; 02268 scanline[x*4+3] = a; 02269 } 02270 } 02271 02272 int finaleSize=width*d/8; 02273 for(i=0; i<finaleSize; i++) 02274 { 02275 f.serial(scanline[i]); 02276 } 02277 } 02278 delete scanline; 02279 return true; 02280 } |
|
Reimplemented in NL3D::CTextureMem. Definition at line 90 of file bitmap.h. Referenced by blend(). |
|
Definition at line 96 of file bitmap.h. Referenced by blend(). |
|
Definition at line 94 of file bitmap.h. Referenced by CBitmap(), isGrayscaleAsAlpha(), loadGrayscaleAsAlpha(), and readTGA(). |
|
Definition at line 93 of file bitmap.h. Referenced by alphaLuminanceToAlpha(), alphaLuminanceToLuminance(), alphaLuminanceToRGBA(), alphaToAlphaLuminance(), alphaToRGBA(), buildMipMaps(), CBitmap(), decompressDXT1(), decompressDXT3(), decompressDXT5(), flipH(), flipV(), getMipMapCount(), luminanceToAlpha(), luminanceToAlphaLuminance(), luminanceToRGBA(), makeDummy(), readDDS(), readTGA(), releaseMipMaps(), resample(), reset(), rgbaToAlpha(), rgbaToAlphaLuminance(), rgbaToLuminance(), rot90CCW(), rot90CW(), and setMipMapCount(). |
|
Definition at line 95 of file bitmap.h. Referenced by blend(). |
|
Initial value: { 32, 8, 8, 16, 4, 4, 8, 8, 16 } Definition at line 70 of file bitmap.cpp. Referenced by blit(), and resizeMipMap(). |
|
Definition at line 83 of file bitmap.cpp. Referenced by readDDS(). |
|
Definition at line 84 of file bitmap.cpp. Referenced by readDDS(). |
|
Definition at line 85 of file bitmap.cpp. Referenced by readDDS(). |
|
Referenced by alphaLuminanceToAlpha(), alphaLuminanceToLuminance(), alphaLuminanceToRGBA(), alphaToAlphaLuminance(), alphaToLuminance(), alphaToRGBA(), blend(), blit(), NL3D::CTextureFile::buildBitmapFromFile(), buildMipMaps(), CBitmap(), convertToAlpha(), convertToAlphaLuminance(), convertToLuminance(), convertToRGBA(), convertToType(), decompressDXT1(), decompressDXT3(), decompressDXT5(), flipH(), flipV(), getColor(), getPixelColor(), getPixelFormat(), luminanceToAlpha(), luminanceToAlphaLuminance(), luminanceToRGBA(), makeDummy(), readDDS(), readTGA(), resample(), reset(), resize(), resizeMipMap(), rgbaToAlpha(), rgbaToAlphaLuminance(), rgbaToLuminance(), rot90CCW(), rot90CW(), rotateCCW(), NL3D::sameDXTCFormat(), and writeTGA(). |