OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 ASSERT_TRUE(size.height() == ySize.height()); | 95 ASSERT_TRUE(size.height() == ySize.height()); |
96 ASSERT_TRUE(uSize.width() == vSize.width()); | 96 ASSERT_TRUE(uSize.width() == vSize.width()); |
97 ASSERT_TRUE(uSize.height() == vSize.height()); | 97 ASSERT_TRUE(uSize.height() == vSize.height()); |
98 | 98 |
99 *outputYWidth = ySize.width(); | 99 *outputYWidth = ySize.width(); |
100 *outputYHeight = ySize.height(); | 100 *outputYHeight = ySize.height(); |
101 *outputUVWidth = uSize.width(); | 101 *outputUVWidth = uSize.width(); |
102 *outputUVHeight = uSize.height(); | 102 *outputUVHeight = uSize.height(); |
103 } | 103 } |
104 | 104 |
| 105 static inline void compareDiffHelper(int c, int treshold, int &counter) |
| 106 { |
| 107 if (c > treshold) { |
| 108 ++counter; |
| 109 } |
| 110 } |
| 111 |
| 112 static inline int max(int x, int y) |
| 113 { |
| 114 return x > y ? x : y; |
| 115 } |
| 116 |
| 117 static void comparePixels(const SkBitmap &b1, const SkBitmap &b2, int treshold,
int &countAboveTreshold, int componentTreshold, int &countComponentAboveTreshold
) |
| 118 { |
| 119 countAboveTreshold = 0; |
| 120 countComponentAboveTreshold = 0; |
| 121 for (int i = 0; i < b1.height(); ++i) { |
| 122 for (int j = 0; j < b1.width(); ++j) { |
| 123 SkColor c1 = b1.getColor(i, j); |
| 124 SkColor c2 = b2.getColor(i, j); |
| 125 unsigned a = abs((int)((c1 >> 24) & 0xFF) - (int)((c2 >> 24) & 0xFF)
); |
| 126 unsigned r = abs((int)((c1 >> 16) & 0xFF) - (int)((c2 >> 16) & 0xFF)
); |
| 127 unsigned g = abs((int)((c1 >> 8) & 0xFF) - (int)((c2 >> 8) & 0xFF)); |
| 128 unsigned b = abs((int)(c1 & 0xFF) - (int)(c2 & 0xFF)); |
| 129 |
| 130 int diff = a + r + g + b; |
| 131 int c = max(max(a, r), max(g, b)); |
| 132 compareDiffHelper(c, componentTreshold, countComponentAboveTreshold)
; |
| 133 compareDiffHelper(diff, treshold, countAboveTreshold); |
| 134 } |
| 135 } |
| 136 } |
| 137 |
| 138 static bool isNull(const SkBitmap& b) |
| 139 { |
| 140 for (int i = 0; i < b.height(); ++i) { |
| 141 for (int j = 0; j < b.width(); ++j) { |
| 142 if (b.getColor(i, j) != 0) |
| 143 return false; |
| 144 } |
| 145 } |
| 146 return true; |
| 147 } |
| 148 |
| 149 static void testRGB565Quality(const char* imageFilePath) |
| 150 { |
| 151 RefPtr<SharedBuffer> data = readFile(imageFilePath); |
| 152 ASSERT_TRUE(data); |
| 153 |
| 154 OwnPtr<ImageDecoder> decoder = createDecoder(); |
| 155 decoder->setData(data.get(), true); |
| 156 |
| 157 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
| 158 ASSERT_TRUE(frame); |
| 159 |
| 160 OwnPtr<ImageDecoder> decoder565 = createDecoder(); |
| 161 decoder565->setData(data.get(), true); |
| 162 ASSERT_TRUE(decoder565->activateDecodeAndScale(ImageFrame::RGB565)); |
| 163 ImageFrame* frame565 = decoder565->frameBufferAtIndex(0); |
| 164 ASSERT_TRUE(frame565); |
| 165 |
| 166 EXPECT_EQ(frame->getSkBitmap().width(), frame565->getSkBitmap().width()); |
| 167 EXPECT_EQ(frame->getSkBitmap().height(), frame565->getSkBitmap().height()); |
| 168 EXPECT_EQ(frame565->getSkBitmap().colorType(), kRGB_565_SkColorType); |
| 169 frame->getSkBitmap().lockPixels(); |
| 170 frame565->getSkBitmap().lockPixels(); |
| 171 ASSERT_FALSE(isNull(frame565->getSkBitmap())); |
| 172 #if USE(QCMSLIB) |
| 173 int diffTreshold = 15; |
| 174 int componentDiffTreshold = 7; |
| 175 float allowedDiff = 0.003f; |
| 176 float allowedComponentsDiff = 0.005f; |
| 177 #else |
| 178 int diffTreshold = 30; |
| 179 int componentDiffTreshold = 15; |
| 180 float allowedDiff = 0.027f; |
| 181 float allowedComponentsDiff = 0.022f; |
| 182 #endif |
| 183 int countAboveTreshold, countComponentAboveTreshold; |
| 184 comparePixels(frame->getSkBitmap(), frame565->getSkBitmap(), diffTreshold, c
ountAboveTreshold, componentDiffTreshold, countComponentAboveTreshold); |
| 185 frame->getSkBitmap().unlockPixels(); |
| 186 frame565->getSkBitmap().unlockPixels(); |
| 187 // not real quality marker here, just a number to track regression |
| 188 EXPECT_GE(allowedDiff, (float) countAboveTreshold / (float) (frame->getSkBit
map().width() * frame->getSkBitmap().height())) |
| 189 << "Value measured and added when implementing this - once you hit this
regressing, just check if all OK and update the value."; |
| 190 EXPECT_GE(allowedComponentsDiff, (float) countComponentAboveTreshold / (floa
t) (frame->getSkBitmap().width() * frame->getSkBitmap().height())) |
| 191 << "Value measured and added when implementing this - once you hit this
regressing, just check if all OK and update the value."; |
| 192 } |
| 193 |
105 // Tests failure on a too big image. | 194 // Tests failure on a too big image. |
106 TEST(JPEGImageDecoderTest, tooBig) | 195 TEST(JPEGImageDecoderTest, tooBig) |
107 { | 196 { |
108 OwnPtr<ImageDecoder> decoder = createDecoder(100); | 197 OwnPtr<ImageDecoder> decoder = createDecoder(100); |
109 EXPECT_FALSE(decoder->setSize(10000, 10000)); | 198 EXPECT_FALSE(decoder->setSize(10000, 10000)); |
110 EXPECT_TRUE(decoder->failed()); | 199 EXPECT_TRUE(decoder->failed()); |
111 } | 200 } |
112 | 201 |
113 // Tests that JPEG decoder can downsample image whose width and height are multi
ple of 8, | 202 // Tests that JPEG decoder can downsample image whose width and height are multi
ple of 8, |
114 // to ensure we compute the correct decodedSize and pass correct parameters to l
ibjpeg to | 203 // to ensure we compute the correct decodedSize and pass correct parameters to l
ibjpeg to |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // segments into the contiguous buffer. If JPEGImageDecoder was pointing to | 366 // segments into the contiguous buffer. If JPEGImageDecoder was pointing to |
278 // data in a segment, its pointer would no longer be valid. | 367 // data in a segment, its pointer would no longer be valid. |
279 segmentedData->data(); | 368 segmentedData->data(); |
280 | 369 |
281 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 370 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
282 ASSERT_FALSE(decoder->failed()); | 371 ASSERT_FALSE(decoder->failed()); |
283 EXPECT_EQ(frame->status(), ImageFrame::FrameComplete); | 372 EXPECT_EQ(frame->status(), ImageFrame::FrameComplete); |
284 EXPECT_EQ(hashBitmap(frame->bitmap()), hash); | 373 EXPECT_EQ(hashBitmap(frame->bitmap()), hash); |
285 } | 374 } |
286 | 375 |
| 376 TEST(JPEGImageDecoderTest, rgb565AndQuality) |
| 377 { |
| 378 testRGB565Quality("/LayoutTests/fast/images/resources/cmyk-jpeg.jpg"); |
| 379 testRGB565Quality("/LayoutTests/fast/images/resources/ycbcr-with-no-color-pr
ofile.jpg"); |
| 380 testRGB565Quality("/LayoutTests/fast/images/resources/red-at-12-oclock-with-
color-profile.jpg"); |
| 381 } |
| 382 |
287 } // namespace blink | 383 } // namespace blink |
OLD | NEW |