bool LLImageDimensionsInfo::getImageDimensionsPng() { const S32 PNG_MAGIC_SIZE = 8; // Make sure the file is long enough. if (!checkFileLength(PNG_MAGIC_SIZE + 8 + sizeof(S32) * 2 /* width, height */)) { LL_WARNS() << "Premature end of file" << LL_ENDL; return false; } // Read PNG signature. const U8 png_magic[PNG_MAGIC_SIZE] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; U8 signature[PNG_MAGIC_SIZE]; mInfile.read((void*)signature, PNG_MAGIC_SIZE); // Make sure it's a PNG file. if (memcmp(signature, png_magic, PNG_MAGIC_SIZE) != 0) { LL_WARNS() << "Not a PNG" << LL_ENDL; return false; } // Read image dimensions. mInfile.seek(APR_CUR, 8 /* chunk length + chunk type */); mWidth = read_s32(); mHeight = read_s32(); return true; }
bool LLImageDimensionsInfo::getImageDimensionsBmp() { // Make sure the file is long enough. const S32 DATA_LEN = 26; // BMP header (14) + DIB header size (4) + width (4) + height (4) if (!checkFileLength(DATA_LEN)) { LL_WARNS() << "Premature end of file" << LL_ENDL; return false; } // Read BMP signature. U8 signature[2]; mInfile.read((void*)signature, sizeof(signature)/sizeof(signature[0])); // Make sure this is actually a BMP file. // We only support Windows bitmaps (BM), according to LLImageBMP::updateData(). if (signature[0] != 'B' || signature[1] != 'M') { LL_WARNS() << "Not a BMP" << LL_ENDL; return false; } // Read image dimensions. mInfile.seek(APR_CUR, 16); mWidth = read_reverse_s32(); mHeight = read_reverse_s32(); return true; }
bool LLImageDimensionsInfo::getImageDimensionsTga() { const S32 TGA_FILE_HEADER_SIZE = 12; // Make sure the file is long enough. if (!checkFileLength(TGA_FILE_HEADER_SIZE + 1 /* width */ + 1 /* height */)) { llwarns << "Premature end of file" << llendl; return false; } mInfile.seek(APR_CUR,TGA_FILE_HEADER_SIZE); mWidth = read_short(); mHeight = read_short(); // KL for testing purposes. llinfos << "Tga header reads width: " << mWidth << " and height: " << mHeight << llendl; return true; }
bool LLImageDimensionsInfo::getImageDimensionsTga() { const S32 TGA_FILE_HEADER_SIZE = 12; // Make sure the file is long enough. if (!checkFileLength(TGA_FILE_HEADER_SIZE + 1 /* width */ + 1 /* height */)) { LL_WARNS() << "Premature end of file" << LL_ENDL; return false; } // *TODO: Detect non-TGA files somehow. mInfile.seek(APR_CUR,TGA_FILE_HEADER_SIZE); mWidth = read_byte() | read_byte() << 8; mHeight = read_byte() | read_byte() << 8; return true; }