| Index: third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
|
| diff --git a/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp b/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
|
| index 514ebcf24035046ee73f3c5be5a4bf4faa782ca8..a4f5de44c6d904c8421b7a142d14925f361e014a 100644
|
| --- a/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
|
| +++ b/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
|
| @@ -102,6 +102,95 @@ void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe
|
| *outputUVHeight = uSize.height();
|
| }
|
|
|
| +static inline void compareDiffHelper(int c, int treshold, int &counter)
|
| +{
|
| + if (c > treshold) {
|
| + ++counter;
|
| + }
|
| +}
|
| +
|
| +static inline int max(int x, int y)
|
| +{
|
| + return x > y ? x : y;
|
| +}
|
| +
|
| +static void comparePixels(const SkBitmap &b1, const SkBitmap &b2, int treshold, int &countAboveTreshold, int componentTreshold, int &countComponentAboveTreshold)
|
| +{
|
| + countAboveTreshold = 0;
|
| + countComponentAboveTreshold = 0;
|
| + for (int i = 0; i < b1.height(); ++i) {
|
| + for (int j = 0; j < b1.width(); ++j) {
|
| + SkColor c1 = b1.getColor(i, j);
|
| + SkColor c2 = b2.getColor(i, j);
|
| + unsigned a = abs((int)((c1 >> 24) & 0xFF) - (int)((c2 >> 24) & 0xFF));
|
| + unsigned r = abs((int)((c1 >> 16) & 0xFF) - (int)((c2 >> 16) & 0xFF));
|
| + unsigned g = abs((int)((c1 >> 8) & 0xFF) - (int)((c2 >> 8) & 0xFF));
|
| + unsigned b = abs((int)(c1 & 0xFF) - (int)(c2 & 0xFF));
|
| +
|
| + int diff = a + r + g + b;
|
| + int c = max(max(a, r), max(g, b));
|
| + compareDiffHelper(c, componentTreshold, countComponentAboveTreshold);
|
| + compareDiffHelper(diff, treshold, countAboveTreshold);
|
| + }
|
| + }
|
| +}
|
| +
|
| +static bool isNull(const SkBitmap& b)
|
| +{
|
| + for (int i = 0; i < b.height(); ++i) {
|
| + for (int j = 0; j < b.width(); ++j) {
|
| + if (b.getColor(i, j) != 0)
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +static void testRGB565Quality(const char* imageFilePath)
|
| +{
|
| + RefPtr<SharedBuffer> data = readFile(imageFilePath);
|
| + ASSERT_TRUE(data);
|
| +
|
| + OwnPtr<ImageDecoder> decoder = createDecoder();
|
| + decoder->setData(data.get(), true);
|
| +
|
| + ImageFrame* frame = decoder->frameBufferAtIndex(0);
|
| + ASSERT_TRUE(frame);
|
| +
|
| + OwnPtr<ImageDecoder> decoder565 = createDecoder();
|
| + decoder565->setData(data.get(), true);
|
| + ASSERT_TRUE(decoder565->activateDecodeAndScale(ImageFrame::RGB565));
|
| + ImageFrame* frame565 = decoder565->frameBufferAtIndex(0);
|
| + ASSERT_TRUE(frame565);
|
| +
|
| + EXPECT_EQ(frame->getSkBitmap().width(), frame565->getSkBitmap().width());
|
| + EXPECT_EQ(frame->getSkBitmap().height(), frame565->getSkBitmap().height());
|
| + EXPECT_EQ(frame565->getSkBitmap().colorType(), kRGB_565_SkColorType);
|
| + frame->getSkBitmap().lockPixels();
|
| + frame565->getSkBitmap().lockPixels();
|
| + ASSERT_FALSE(isNull(frame565->getSkBitmap()));
|
| +#if USE(QCMSLIB)
|
| + int diffTreshold = 15;
|
| + int componentDiffTreshold = 7;
|
| + float allowedDiff = 0.003f;
|
| + float allowedComponentsDiff = 0.005f;
|
| +#else
|
| + int diffTreshold = 30;
|
| + int componentDiffTreshold = 15;
|
| + float allowedDiff = 0.027f;
|
| + float allowedComponentsDiff = 0.022f;
|
| +#endif
|
| + int countAboveTreshold, countComponentAboveTreshold;
|
| + comparePixels(frame->getSkBitmap(), frame565->getSkBitmap(), diffTreshold, countAboveTreshold, componentDiffTreshold, countComponentAboveTreshold);
|
| + frame->getSkBitmap().unlockPixels();
|
| + frame565->getSkBitmap().unlockPixels();
|
| + // not real quality marker here, just a number to track regression
|
| + EXPECT_GE(allowedDiff, (float) countAboveTreshold / (float) (frame->getSkBitmap().width() * frame->getSkBitmap().height()))
|
| + << "Value measured and added when implementing this - once you hit this regressing, just check if all OK and update the value.";
|
| + EXPECT_GE(allowedComponentsDiff, (float) countComponentAboveTreshold / (float) (frame->getSkBitmap().width() * frame->getSkBitmap().height()))
|
| + << "Value measured and added when implementing this - once you hit this regressing, just check if all OK and update the value.";
|
| +}
|
| +
|
| // Tests failure on a too big image.
|
| TEST(JPEGImageDecoderTest, tooBig)
|
| {
|
| @@ -284,4 +373,11 @@ TEST(JPEGImageDecoderTest, mergeBuffer)
|
| EXPECT_EQ(hashBitmap(frame->bitmap()), hash);
|
| }
|
|
|
| +TEST(JPEGImageDecoderTest, rgb565AndQuality)
|
| +{
|
| + testRGB565Quality("/LayoutTests/fast/images/resources/cmyk-jpeg.jpg");
|
| + testRGB565Quality("/LayoutTests/fast/images/resources/ycbcr-with-no-color-profile.jpg");
|
| + testRGB565Quality("/LayoutTests/fast/images/resources/red-at-12-oclock-with-color-profile.jpg");
|
| +}
|
| +
|
| } // namespace blink
|
|
|