Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp

Issue 1403393004: JPEGImageDecoder RGB565 and downsample support and related Skia imagegenerator changes Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 void testRGB565Quality(const char* imageFilePath)
139 {
140 RefPtr<SharedBuffer> data = readFile(imageFilePath);
141 ASSERT_TRUE(data);
142
143 OwnPtr<ImageDecoder> decoder = createDecoder();
144 decoder->setData(data.get(), true);
145
146 ImageFrame* frame = decoder->frameBufferAtIndex(0);
147 ASSERT_TRUE(frame);
148
149 OwnPtr<ImageDecoder> decoder565 = createDecoder();
150 decoder565->setData(data.get(), true);
151 ASSERT_TRUE(decoder565->setDecodeRGB565Enabled(true));
152 ImageFrame* frame565 = decoder565->frameBufferAtIndex(0);
153 ASSERT_TRUE(frame565);
154
155 EXPECT_EQ(frame->getSkBitmap().width(), frame565->getSkBitmap().width());
156 EXPECT_EQ(frame->getSkBitmap().height(), frame565->getSkBitmap().height());
157 EXPECT_EQ(frame565->getSkBitmap().colorType(), kRGB_565_SkColorType);
158 frame->getSkBitmap().lockPixels();
159 frame565->getSkBitmap().lockPixels();
160 #if USE(QCMSLIB)
161 int diffTreshold = 15;
162 int componentDiffTreshold = 7;
163 float allowedDiff = 0.003f;
164 float allowedComponentsDiff = 0.005f;
165 #else
166 int diffTreshold = 30;
167 int componentDiffTreshold = 15;
168 float allowedDiff = 0.027f;
169 float allowedComponentsDiff = 0.022f;
170 #endif
171 int countAboveTreshold, countComponentAboveTreshold;
172 comparePixels(frame->getSkBitmap(), frame565->getSkBitmap(), diffTreshold, c ountAboveTreshold, componentDiffTreshold, countComponentAboveTreshold);
173 frame->getSkBitmap().unlockPixels();
174 frame565->getSkBitmap().unlockPixels();
175 // not real quality marker here, just a number to track regression
176 EXPECT_GE(allowedDiff, (float) countAboveTreshold / (float) (frame->getSkBit map().width() * frame->getSkBitmap().height()))
177 << "Value measured and added when implementing this - once you hit this regressing, just check if all OK and update the value.";
178 EXPECT_GE(allowedComponentsDiff, (float) countComponentAboveTreshold / (floa t) (frame->getSkBitmap().width() * frame->getSkBitmap().height()))
179 << "Value measured and added when implementing this - once you hit this regressing, just check if all OK and update the value.";
180 }
181
105 // Tests failure on a too big image. 182 // Tests failure on a too big image.
106 TEST(JPEGImageDecoderTest, tooBig) 183 TEST(JPEGImageDecoderTest, tooBig)
107 { 184 {
108 OwnPtr<ImageDecoder> decoder = createDecoder(100); 185 OwnPtr<ImageDecoder> decoder = createDecoder(100);
109 EXPECT_FALSE(decoder->setSize(10000, 10000)); 186 EXPECT_FALSE(decoder->setSize(10000, 10000));
110 EXPECT_TRUE(decoder->failed()); 187 EXPECT_TRUE(decoder->failed());
111 } 188 }
112 189
113 // Tests that JPEG decoder can downsample image whose width and height are multi ple of 8, 190 // 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 191 // 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
277 // segments into the contiguous buffer. If JPEGImageDecoder was pointing to 354 // segments into the contiguous buffer. If JPEGImageDecoder was pointing to
278 // data in a segment, its pointer would no longer be valid. 355 // data in a segment, its pointer would no longer be valid.
279 segmentedData->data(); 356 segmentedData->data();
280 357
281 ImageFrame* frame = decoder->frameBufferAtIndex(0); 358 ImageFrame* frame = decoder->frameBufferAtIndex(0);
282 ASSERT_FALSE(decoder->failed()); 359 ASSERT_FALSE(decoder->failed());
283 EXPECT_EQ(frame->status(), ImageFrame::FrameComplete); 360 EXPECT_EQ(frame->status(), ImageFrame::FrameComplete);
284 EXPECT_EQ(hashBitmap(frame->bitmap()), hash); 361 EXPECT_EQ(hashBitmap(frame->bitmap()), hash);
285 } 362 }
286 363
364 TEST(JPEGImageDecoderTest, rgb565AndQuality)
365 {
366 testRGB565Quality("/LayoutTests/fast/images/resources/cmyk-jpeg.jpg");
367 testRGB565Quality("/LayoutTests/fast/images/resources/ycbcr-with-no-color-pr ofile.jpg");
368 testRGB565Quality("/LayoutTests/fast/images/resources/red-at-12-oclock-with- color-profile.jpg");
369 }
370
287 } // namespace blink 371 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698