#include "stdafx.h" #include #include #include #include #include "KTGA_IO.h" #include #include //============================================================================= bool TGAReadImage (KStream* stream, int* width, int* height, int* bitDepth, BYTE** pixels) { //===================// // Read TARGA header // //===================// int nHeaderSize = sizeof(TGAHeaderInfo); TGAHeaderInfo TGAHeader; if (stream->Read((&TGAHeader), nHeaderSize) != nHeaderSize) { _oprint( "ERROR! Bad Targa header!\n" ); return false; } (*width) = TGAHeader.imwidth; (*height) = TGAHeader.imheight; (*bitDepth) = TGAHeader.imdepth; int numTexels = (*width) * (*height) * ((*bitDepth)/8); //============================// // Allocate memory for texels // //============================// (*pixels) = new BYTE [numTexels]; if ((*pixels) == NULL) { _oprint( "ERROR allocating memory for pixels\n"); return false; } //=========================// // Read texels into memory // //=========================// if (stream->Read( (*pixels), sizeof(BYTE)*numTexels) != (unsigned)numTexels) { _oprint( "ERROR! Couldn't read texels!\n"); return false; } return true; }