//========= Copyright ?1996-2002, Valve LLC, All rights reserved. ============ // // Purpose: // // $NoKeywords: $ //============================================================================= #include #include using namespace vgui; BitmapTGA::BitmapTGA(InputStream* is,bool invertAlpha) : Bitmap() { loadTGA(is,invertAlpha); } bool BitmapTGA::loadTGA(InputStream* is,bool invertAlpha) { if(is==null) { return false; } DataInputStream dis(is); bool success=false; uchar id_length=dis.readUChar(success); if(!success) { return false; } uchar colormap_type=dis.readUChar(success); if(!success) { return false; } uchar image_type=dis.readUChar(success); if(!success) { return false; } ushort colormap_index=dis.readUShort(success); if(!success) { return false; } ushort colormap_length=dis.readUShort(success); if(!success) { return false; } uchar colormap_size=dis.readUChar(success); if(!success) { return false; } ushort x_origin=dis.readUShort(success); if(!success) { return false; } ushort y_origin=dis.readUShort(success); if(!success) { return false; } int wide=dis.readUShort(success); if(!success) { return false; } int tall=dis.readUShort(success); if(!success) { return false; } uchar pixel_size=dis.readUChar(success); if(!success) { return false; } uchar attributes=dis.readUChar(success); if(!success) { return false; } if (image_type!=2 && image_type!=10) { return false; } if (colormap_type !=0 || (pixel_size!=32 && pixel_size!=24)) { return false; } setSize(wide,tall); if(_rgba==null) { return false; } if (id_length != 0) dis.seekRelative(id_length,success); // skip TARGA image comment int column, row; uchar* ptr; if (image_type==2) { // Uncompressed, RGB images for(row=tall-1; row>=0; row--) { ptr = _rgba + row*wide*4; for(column=0; column=0; row--) { ptr = _rgba + row*wide*4; for(column=0; column0) row--; else goto breakOut; ptr = _rgba + row*wide*4; } } } else { // non run-length packet for(j=0;j0) row--; else goto breakOut; ptr = _rgba + row*wide*4; } } } } breakOut:; } } return true; }