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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/webp/WEBPImageDecoderTest.cpp

Issue 2155973002: Save a bitmap copy when advancing to dependent GIF and WebP animation frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +webp. fix test failures. Created 4 years, 3 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 decoder->setData(data.get(), true); 122 decoder->setData(data.get(), true);
123 size_t frameCount = decoder->frameCount(); 123 size_t frameCount = decoder->frameCount();
124 124
125 // ... and then decode frames from 'reallocatedData'. 125 // ... and then decode frames from 'reallocatedData'.
126 RefPtr<SharedBuffer> reallocatedData = data.get()->copy(); 126 RefPtr<SharedBuffer> reallocatedData = data.get()->copy();
127 ASSERT_TRUE(reallocatedData.get()); 127 ASSERT_TRUE(reallocatedData.get());
128 data.clear(); 128 data.clear();
129 decoder->setData(reallocatedData.get(), true); 129 decoder->setData(reallocatedData.get(), true);
130 130
131 for (size_t i = 0; i < frameCount; ++i) { 131 for (size_t i = 0; i < frameCount; ++i) {
132 const ImageFrame* const frame = decoder->frameBufferAtIndex(i); 132 ImageFrame* frame = decoder->frameBufferAtIndex(i);
Peter Kasting 2016/08/26 19:04:05 Why remove the consts here and on similar lines be
aleksandar.stojiljkovic 2016/08/26 21:53:51 To make it consistent with other places (GIFImageD
Peter Kasting 2016/08/27 04:19:58 Don't worry about that kind of consistency, especi
aleksandar.stojiljkovic 2016/08/28 08:58:31 Done, bitmap() const reverted back .
133 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); 133 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
134 } 134 }
135 } 135 }
136 136
137 void testByteByByteSizeAvailable(const char* webpFile, size_t frameOffset, bool hasColorProfile, int expectedRepetitionCount) 137 void testByteByByteSizeAvailable(const char* webpFile, size_t frameOffset, bool hasColorProfile, int expectedRepetitionCount)
138 { 138 {
139 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 139 std::unique_ptr<ImageDecoder> decoder = createDecoder();
140 RefPtr<SharedBuffer> data = readFile(webpFile); 140 RefPtr<SharedBuffer> data = readFile(webpFile);
141 ASSERT_TRUE(data.get()); 141 ASSERT_TRUE(data.get());
142 EXPECT_LT(frameOffset, data->size()); 142 EXPECT_LT(frameOffset, data->size());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 198 }
199 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount()); 199 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount());
200 EXPECT_TRUE(decoder->failed()); 200 EXPECT_TRUE(decoder->failed());
201 } 201 }
202 202
203 uint32_t premultiplyColor(uint32_t c) 203 uint32_t premultiplyColor(uint32_t c)
204 { 204 {
205 return SkPremultiplyARGBInline(SkGetPackedA32(c), SkGetPackedR32(c), SkGetPa ckedG32(c), SkGetPackedB32(c)); 205 return SkPremultiplyARGBInline(SkGetPackedA32(c), SkGetPackedR32(c), SkGetPa ckedG32(c), SkGetPackedB32(c));
206 } 206 }
207 207
208 void verifyFramesMatch(const char* webpFile, const ImageFrame* const a, ImageFra me* const b) 208 void verifyFramesMatch(const char* webpFile, ImageFrame* a, ImageFrame* b)
Peter Kasting 2016/08/26 19:04:05 Why remove the first const here? (The other two a
209 { 209 {
210 const SkBitmap& bitmapA = a->bitmap(); 210 const SkBitmap& bitmapA = a->bitmap();
211 const SkBitmap& bitmapB = b->bitmap(); 211 const SkBitmap& bitmapB = b->bitmap();
212 ASSERT_EQ(bitmapA.width(), bitmapB.width()); 212 ASSERT_EQ(bitmapA.width(), bitmapB.width());
213 ASSERT_EQ(bitmapA.height(), bitmapB.height()); 213 ASSERT_EQ(bitmapA.height(), bitmapB.height());
214 214
215 int maxDifference = 0; 215 int maxDifference = 0;
216 for (int y = 0; y < bitmapA.height(); ++y) { 216 for (int y = 0; y < bitmapA.height(); ++y) {
217 for (int x = 0; x < bitmapA.width(); ++x) { 217 for (int x = 0; x < bitmapA.width(); ++x) {
218 uint32_t colorA = *bitmapA.getAddr32(x, y); 218 uint32_t colorA = *bitmapA.getAddr32(x, y);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 ImageFrame::AlphaBlendSource alphaBlendSource; 290 ImageFrame::AlphaBlendSource alphaBlendSource;
291 unsigned duration; 291 unsigned duration;
292 bool hasAlpha; 292 bool hasAlpha;
293 } frameParameters[] = { 293 } frameParameters[] = {
294 { 0, 0, 11, 29, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFr ame, 1000u, true }, 294 { 0, 0, 11, 29, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFr ame, 1000u, true },
295 { 2, 10, 7, 17, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFr ame, 500u, true }, 295 { 2, 10, 7, 17, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFr ame, 500u, true },
296 { 2, 2, 7, 16, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFra me, 1000u, true }, 296 { 2, 2, 7, 16, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFra me, 1000u, true },
297 }; 297 };
298 298
299 for (size_t i = 0; i < WTF_ARRAY_LENGTH(frameParameters); ++i) { 299 for (size_t i = 0; i < WTF_ARRAY_LENGTH(frameParameters); ++i) {
300 const ImageFrame* const frame = decoder->frameBufferAtIndex(i); 300 ImageFrame* frame = decoder->frameBufferAtIndex(i);
301 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); 301 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
302 EXPECT_EQ(canvasWidth, frame->bitmap().width()); 302 EXPECT_EQ(canvasWidth, frame->bitmap().width());
303 EXPECT_EQ(canvasHeight, frame->bitmap().height()); 303 EXPECT_EQ(canvasHeight, frame->bitmap().height());
304 EXPECT_EQ(frameParameters[i].xOffset, frame->originalFrameRect().x()); 304 EXPECT_EQ(frameParameters[i].xOffset, frame->originalFrameRect().x());
305 EXPECT_EQ(frameParameters[i].yOffset, frame->originalFrameRect().y()); 305 EXPECT_EQ(frameParameters[i].yOffset, frame->originalFrameRect().y());
306 EXPECT_EQ(frameParameters[i].width, frame->originalFrameRect().width()); 306 EXPECT_EQ(frameParameters[i].width, frame->originalFrameRect().width());
307 EXPECT_EQ(frameParameters[i].height, frame->originalFrameRect().height() ); 307 EXPECT_EQ(frameParameters[i].height, frame->originalFrameRect().height() );
308 EXPECT_EQ(frameParameters[i].disposalMethod, frame->getDisposalMethod()) ; 308 EXPECT_EQ(frameParameters[i].disposalMethod, frame->getDisposalMethod()) ;
309 EXPECT_EQ(frameParameters[i].alphaBlendSource, frame->getAlphaBlendSourc e()); 309 EXPECT_EQ(frameParameters[i].alphaBlendSource, frame->getAlphaBlendSourc e());
310 EXPECT_EQ(frameParameters[i].duration, frame->duration()); 310 EXPECT_EQ(frameParameters[i].duration, frame->duration());
(...skipping 22 matching lines...) Expand all
333 unsigned duration; 333 unsigned duration;
334 bool hasAlpha; 334 bool hasAlpha;
335 } frameParameters[] = { 335 } frameParameters[] = {
336 { 4, 10, 33, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::BlendA topPreviousFrame, 1000u, true }, 336 { 4, 10, 33, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::BlendA topPreviousFrame, 1000u, true },
337 { 34, 30, 33, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopPreviousFrame, 1000u, true }, 337 { 34, 30, 33, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopPreviousFrame, 1000u, true },
338 { 62, 50, 32, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopPreviousFrame, 1000u, true }, 338 { 62, 50, 32, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopPreviousFrame, 1000u, true },
339 { 10, 54, 32, 33, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopPreviousFrame, 1000u, true }, 339 { 10, 54, 32, 33, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopPreviousFrame, 1000u, true },
340 }; 340 };
341 341
342 for (size_t i = 0; i < WTF_ARRAY_LENGTH(frameParameters); ++i) { 342 for (size_t i = 0; i < WTF_ARRAY_LENGTH(frameParameters); ++i) {
343 const ImageFrame* const frame = decoder->frameBufferAtIndex(i); 343 ImageFrame* frame = decoder->frameBufferAtIndex(i);
344 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); 344 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
345 EXPECT_EQ(canvasWidth, frame->bitmap().width()); 345 EXPECT_EQ(canvasWidth, frame->bitmap().width());
346 EXPECT_EQ(canvasHeight, frame->bitmap().height()); 346 EXPECT_EQ(canvasHeight, frame->bitmap().height());
347 EXPECT_EQ(frameParameters[i].xOffset, frame->originalFrameRect().x()); 347 EXPECT_EQ(frameParameters[i].xOffset, frame->originalFrameRect().x());
348 EXPECT_EQ(frameParameters[i].yOffset, frame->originalFrameRect().y()); 348 EXPECT_EQ(frameParameters[i].yOffset, frame->originalFrameRect().y());
349 EXPECT_EQ(frameParameters[i].width, frame->originalFrameRect().width()); 349 EXPECT_EQ(frameParameters[i].width, frame->originalFrameRect().width());
350 EXPECT_EQ(frameParameters[i].height, frame->originalFrameRect().height() ); 350 EXPECT_EQ(frameParameters[i].height, frame->originalFrameRect().height() );
351 EXPECT_EQ(frameParameters[i].disposalMethod, frame->getDisposalMethod()) ; 351 EXPECT_EQ(frameParameters[i].disposalMethod, frame->getDisposalMethod()) ;
352 EXPECT_EQ(frameParameters[i].alphaBlendSource, frame->getAlphaBlendSourc e()); 352 EXPECT_EQ(frameParameters[i].alphaBlendSource, frame->getAlphaBlendSourc e());
353 EXPECT_EQ(frameParameters[i].duration, frame->duration()); 353 EXPECT_EQ(frameParameters[i].duration, frame->duration());
(...skipping 22 matching lines...) Expand all
376 unsigned duration; 376 unsigned duration;
377 bool hasAlpha; 377 bool hasAlpha;
378 } frameParameters[] = { 378 } frameParameters[] = {
379 { 4, 10, 33, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::BlendA topBgcolor, 1000u, true }, 379 { 4, 10, 33, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::BlendA topBgcolor, 1000u, true },
380 { 34, 30, 33, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopBgcolor, 1000u, true }, 380 { 34, 30, 33, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopBgcolor, 1000u, true },
381 { 62, 50, 32, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopBgcolor, 1000u, true }, 381 { 62, 50, 32, 32, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopBgcolor, 1000u, true },
382 { 10, 54, 32, 33, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopBgcolor, 1000u, true }, 382 { 10, 54, 32, 33, ImageFrame::DisposeOverwriteBgcolor, ImageFrame::Blend AtopBgcolor, 1000u, true },
383 }; 383 };
384 384
385 for (size_t i = 0; i < WTF_ARRAY_LENGTH(frameParameters); ++i) { 385 for (size_t i = 0; i < WTF_ARRAY_LENGTH(frameParameters); ++i) {
386 const ImageFrame* const frame = decoder->frameBufferAtIndex(i); 386 ImageFrame* frame = decoder->frameBufferAtIndex(i);
387 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); 387 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
388 EXPECT_EQ(canvasWidth, frame->bitmap().width()); 388 EXPECT_EQ(canvasWidth, frame->bitmap().width());
389 EXPECT_EQ(canvasHeight, frame->bitmap().height()); 389 EXPECT_EQ(canvasHeight, frame->bitmap().height());
390 EXPECT_EQ(frameParameters[i].xOffset, frame->originalFrameRect().x()); 390 EXPECT_EQ(frameParameters[i].xOffset, frame->originalFrameRect().x());
391 EXPECT_EQ(frameParameters[i].yOffset, frame->originalFrameRect().y()); 391 EXPECT_EQ(frameParameters[i].yOffset, frame->originalFrameRect().y());
392 EXPECT_EQ(frameParameters[i].width, frame->originalFrameRect().width()); 392 EXPECT_EQ(frameParameters[i].width, frame->originalFrameRect().width());
393 EXPECT_EQ(frameParameters[i].height, frame->originalFrameRect().height() ); 393 EXPECT_EQ(frameParameters[i].height, frame->originalFrameRect().height() );
394 EXPECT_EQ(frameParameters[i].disposalMethod, frame->getDisposalMethod()) ; 394 EXPECT_EQ(frameParameters[i].disposalMethod, frame->getDisposalMethod()) ;
395 EXPECT_EQ(frameParameters[i].alphaBlendSource, frame->getAlphaBlendSourc e()); 395 EXPECT_EQ(frameParameters[i].alphaBlendSource, frame->getAlphaBlendSourc e());
396 EXPECT_EQ(frameParameters[i].duration, frame->duration()); 396 EXPECT_EQ(frameParameters[i].duration, frame->duration());
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 { 681 {
682 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 682 std::unique_ptr<ImageDecoder> decoder = createDecoder();
683 RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/web p-color-profile-lossy.webp"); 683 RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/web p-color-profile-lossy.webp");
684 ASSERT_TRUE(data.get()); 684 ASSERT_TRUE(data.get());
685 decoder->setData(data.get(), true); 685 decoder->setData(data.get(), true);
686 EXPECT_EQ(1u, decoder->frameCount()); 686 EXPECT_EQ(1u, decoder->frameCount());
687 EXPECT_EQ(cAnimationNone, decoder->repetitionCount()); 687 EXPECT_EQ(cAnimationNone, decoder->repetitionCount());
688 } 688 }
689 689
690 } // namespace blink 690 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698