void filterOnlyImages(strings& files) { strings out; // O(N) for (size_t u = 0; u < files.size(); u++) { if (isSupportedImageType(files[u])) { out.push_back(files[u]); } } files = out; }
void TGA::readHeader(Common::SeekableReadStream &tga, ImageType &imageType, byte &pixelDepth, byte &imageDesc) { tga.seek(0); // TGAs have an optional "id" string in the header uint32 idLength = tga.readByte(); // Number of colors in the color map / palette if (tga.readByte() != 0) throw Common::Exception("Unsupported feature: Color map"); // Image type. 2 == unmapped RGB, 3 == Grayscale imageType = (ImageType)tga.readByte(); if (!isSupportedImageType(imageType)) throw Common::Exception("Unsupported image type: %d", imageType); // Color map specifications + X + Y tga.skip(5 + 2 + 2); _mipMaps.push_back(new MipMap); // Image dimensions _mipMaps[0]->width = tga.readUint16LE(); _mipMaps[0]->height = tga.readUint16LE(); // Bits per pixel pixelDepth = tga.readByte(); if (imageType == kImageTypeTrueColor || imageType == kImageTypeRLETrueColor) { if (pixelDepth == 24) { _format = kPixelFormatB8G8R8; } else if (pixelDepth == 16 || pixelDepth == 32) { _format = kPixelFormatB8G8R8A8; } else if (pixelDepth == 8) { imageType = kImageTypeBW; _format = kPixelFormatB8G8R8A8; } else throw Common::Exception("Unsupported pixel depth: %d, %d", imageType, pixelDepth); } else if (imageType == kImageTypeBW) { if (pixelDepth != 8) throw Common::Exception("Unsupported pixel depth: %d, %d", imageType, pixelDepth); _format = kPixelFormatB8G8R8A8; } // Image descriptor imageDesc = tga.readByte(); // Skip the id string tga.skip(idLength); }