bool PalettedRowsAreSolidColor(Decoder* aDecoder, int32_t aStartRow, int32_t aRowCount, uint8_t aColor) { RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef(); IntRect frameRect = currentFrame->GetRect(); IntRect solidColorRect(frameRect.x, aStartRow, frameRect.width, aRowCount); return PalettedRectIsSolidColor(aDecoder, solidColorRect, aColor); }
bool PalettedRectIsSolidColor(Decoder* aDecoder, const IntRect& aRect, uint8_t aColor) { RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef(); uint8_t* imageData; uint32_t imageLength; currentFrame->GetImageData(&imageData, &imageLength); ASSERT_TRUE_OR_RETURN(imageData, false); // Clamp to the frame rect. If any pixels outside the frame rect are included, // we immediately fail, because such pixels don't have any "color" in the // sense this function measures - they're transparent, and that doesn't // necessarily correspond to any color palette index at all. IntRect frameRect = currentFrame->GetRect(); ASSERT_EQ_OR_RETURN(imageLength, uint32_t(frameRect.Area()), false); IntRect rect = aRect.Intersect(frameRect); ASSERT_EQ_OR_RETURN(rect.Area(), aRect.Area(), false); // Translate |rect| by |frameRect.TopLeft()| to reflect the fact that the // frame rect's offset doesn't actually mean anything in terms of the // in-memory representation of the surface. The image data starts at the upper // left corner of the frame rect, in other words. rect -= frameRect.TopLeft(); // Walk through the image data and make sure that the entire rect has the // palette index |aColor|. int32_t rowLength = frameRect.width; for (int32_t row = rect.y; row < rect.YMost(); ++row) { for (int32_t col = rect.x; col < rect.XMost(); ++col) { int32_t i = row * rowLength + col; ASSERT_EQ_OR_RETURN(aColor, imageData[i], false); } } return true; }
bool IsSolidPalettedColor(Decoder* aDecoder, uint8_t aColor) { RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef(); return PalettedRectIsSolidColor(aDecoder, currentFrame->GetRect(), aColor); }