C
verdammt ...
ich hab beides mal probiert, aber keines von beiden baut mir die beiden Bytes zu den Zahlen zusammen, die ich erwartet hätte (die Abmessungen des TGA-Bildes)
Ich poste mal meinen Code hier, da ich irgendwie nicht weiterkomme.
GLubyte * LadeTGA(const char* dateiname)
{
char IDlength;
char ColorMapType;
char ImageType;
char * ColorMapSpec = new char[5];
short int tgaX0;
short int tgaY0;
short int tgaBreite;
short int tgaHoehe;
char * ImageSpecification = new char[10];
GLubyte bitsPerPixel;
GLubyte ImageDescriptor;
GLubyte * image = NULL;
int imageSize;
ifstream target(dateiname, ios_base::binary);
target.seekg(ios_base::beg);
target.read(&IDlength, 1);
target.read(&ColorMapType, 1);
target.read(&ImageType, 1);
target.read(ColorMapSpec, 5);
target.read(reinterpret_cast<char*>(&tgaX0), 2); std::cout<<tgaX0<<std::endl;
target.read(reinterpret_cast<char*>(&tgaY0), 2); std::cout<<tgaY0<<std::endl;
target.read(reinterpret_cast<char*>(&tgaBreite), 2); std::cout<<tgaBreite<<std::endl;
target.read(reinterpret_cast<char*>(&tgaHoehe), 2); std::cout<<tgaHoehe<<std::endl;
target.read(&ImageDescriptor, 1);
/* target.read(ImageSpecification, 10);
std::cout<<ImageSpecification[5]<<" "<<ImageSpecification[6]<<std::endl;
tgaBreite = (ImageSpecification[5]<<8) & ImageSpecification[6];
std::cout<<ImageSpecification[7]<<" "<<ImageSpecification[8]<<std::endl;
tgaHoehe = (ImageSpecification[7]<<8) & ImageSpecification[8];
ImageDescriptor = ImageSpecification[9]; */
// Auswertung zu TrueColor
// Color Map Type Image Type
if (ColorMapType == 0 && ImageType == 2)
{
target.ignore(IDlength);
imageSize = tgaBreite*tgaHoehe;
image = new GLubyte[imageSize*((int)bitsPerPixel/8)];
target.read((char*)image, imageSize);
return image;
}
// Auswertung zu Pseudo- oder DirectColor
return NULL;
}
bei der reinterpret_cast-Sache ist es so, das Breite und Höhe beides als 4 angegeben wird, und bei der anderen Sache ist es beidesmal 0. Alle anderen TGA-Header-Größen werden offenbar richtig ausgegeben. Dabei hat das Bild, was die Funktion in meinem Programm lädt 1024x1024 Pixel ...