You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IndexedBmpWriter will extend the palette, which will ensure all pixels indices are contained on the palette. However, it should be possible to detect if a pixel index is out of range before the palette is extended.
A first draft of the function is:
void IndexedBmpWriter::VerifyPixelsContainedInPalette(uint16_t bitCount, std::size_t paletteEntryCount, const std::vector<uint8_t>& pixels)
{
// Check if palette is full
// Use explicit size_t type to avoid compiler warnings for signedness or size
if (paletteEntryCount == std::size_t{1} << bitCount) {
return;
}
if (bitCount == 1) {
for (const auto& pixelGroup : pixels) {
if (pixelGroup > 0) {
throw (std::runtime_error("A pixel is outside the range of set palette indices."));
}
}
}
if (bitCount == 4) {
return; //TODO: Support checking 2 bit images
}
for (std::size_t i = 0; i < pixels.size(); ++i) {
if (pixels[i] >= paletteEntryCount) {
throw std::runtime_error("Pixel " + std::to_string(i) + " is outside the range of set palette indices.");
}
}
}
The text was updated successfully, but these errors were encountered:
Brett208
changed the title
Allow verifying indexed pixels contained on palette
Verify indexed pixels contained on palette (if palette is not at capacity)
Oct 8, 2018
IndexedBmpWriter will extend the palette, which will ensure all pixels indices are contained on the palette. However, it should be possible to detect if a pixel index is out of range before the palette is extended.
A first draft of the function is:
The text was updated successfully, but these errors were encountered: