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

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

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" 31 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h"
32 32
33 #include "platform/SharedBuffer.h" 33 #include "platform/SharedBuffer.h"
34 #include "platform/image-decoders/ImageAnimation.h" 34 #include "platform/image-decoders/ImageAnimation.h"
35 #include "platform/image-decoders/ImageDecoderTestHelpers.h" 35 #include "platform/image-decoders/ImageDecoderTestHelpers.h"
36 #include "public/platform/WebData.h" 36 #include "public/platform/WebData.h"
37 #include "public/platform/WebSize.h" 37 #include "public/platform/WebSize.h"
38 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
39 #include "wtf/OwnPtr.h" 39 #include "wtf/PtrUtil.h"
40 #include "wtf/PassOwnPtr.h"
41 #include "wtf/typed_arrays/ArrayBuffer.h" 40 #include "wtf/typed_arrays/ArrayBuffer.h"
41 #include <memory>
42 42
43 namespace blink { 43 namespace blink {
44 44
45 static const size_t LargeEnoughSize = 1000 * 1000; 45 static const size_t LargeEnoughSize = 1000 * 1000;
46 46
47 namespace { 47 namespace {
48 48
49 PassOwnPtr<ImageDecoder> createDecoder(size_t maxDecodedBytes) 49 std::unique_ptr<ImageDecoder> createDecoder(size_t maxDecodedBytes)
50 { 50 {
51 return adoptPtr(new JPEGImageDecoder(ImageDecoder::AlphaNotPremultiplied, Im ageDecoder::GammaAndColorProfileApplied, maxDecodedBytes)); 51 return wrapUnique(new JPEGImageDecoder(ImageDecoder::AlphaNotPremultiplied, ImageDecoder::GammaAndColorProfileApplied, maxDecodedBytes));
52 } 52 }
53 53
54 PassOwnPtr<ImageDecoder> createDecoder() 54 std::unique_ptr<ImageDecoder> createDecoder()
55 { 55 {
56 return createDecoder(ImageDecoder::noDecodedImageByteLimit); 56 return createDecoder(ImageDecoder::noDecodedImageByteLimit);
57 } 57 }
58 58
59 } // anonymous namespace 59 } // anonymous namespace
60 60
61 void downsample(size_t maxDecodedBytes, unsigned* outputWidth, unsigned* outputH eight, const char* imageFilePath) 61 void downsample(size_t maxDecodedBytes, unsigned* outputWidth, unsigned* outputH eight, const char* imageFilePath)
62 { 62 {
63 RefPtr<SharedBuffer> data = readFile(imageFilePath); 63 RefPtr<SharedBuffer> data = readFile(imageFilePath);
64 ASSERT_TRUE(data); 64 ASSERT_TRUE(data);
65 65
66 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); 66 std::unique_ptr<ImageDecoder> decoder = createDecoder(maxDecodedBytes);
67 decoder->setData(data.get(), true); 67 decoder->setData(data.get(), true);
68 68
69 ImageFrame* frame = decoder->frameBufferAtIndex(0); 69 ImageFrame* frame = decoder->frameBufferAtIndex(0);
70 ASSERT_TRUE(frame); 70 ASSERT_TRUE(frame);
71 *outputWidth = frame->bitmap().width(); 71 *outputWidth = frame->bitmap().width();
72 *outputHeight = frame->bitmap().height(); 72 *outputHeight = frame->bitmap().height();
73 EXPECT_EQ(IntSize(*outputWidth, *outputHeight), decoder->decodedSize()); 73 EXPECT_EQ(IntSize(*outputWidth, *outputHeight), decoder->decodedSize());
74 } 74 }
75 75
76 void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe ight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePa th) 76 void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe ight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePa th)
77 { 77 {
78 RefPtr<SharedBuffer> data = readFile(imageFilePath); 78 RefPtr<SharedBuffer> data = readFile(imageFilePath);
79 ASSERT_TRUE(data); 79 ASSERT_TRUE(data);
80 80
81 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); 81 std::unique_ptr<ImageDecoder> decoder = createDecoder(maxDecodedBytes);
82 decoder->setData(data.get(), true); 82 decoder->setData(data.get(), true);
83 83
84 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. 84 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding.
85 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes()); 85 std::unique_ptr<ImagePlanes> dummyImagePlanes = wrapUnique(new ImagePlanes() );
86 decoder->setImagePlanes(std::move(dummyImagePlanes)); 86 decoder->setImagePlanes(std::move(dummyImagePlanes));
87 87
88 bool sizeIsAvailable = decoder->isSizeAvailable(); 88 bool sizeIsAvailable = decoder->isSizeAvailable();
89 ASSERT_TRUE(sizeIsAvailable); 89 ASSERT_TRUE(sizeIsAvailable);
90 90
91 IntSize size = decoder->decodedSize(); 91 IntSize size = decoder->decodedSize();
92 IntSize ySize = decoder->decodedYUVSize(0); 92 IntSize ySize = decoder->decodedYUVSize(0);
93 IntSize uSize = decoder->decodedYUVSize(1); 93 IntSize uSize = decoder->decodedYUVSize(1);
94 IntSize vSize = decoder->decodedYUVSize(2); 94 IntSize vSize = decoder->decodedYUVSize(2);
95 95
(...skipping 11 matching lines...) Expand all
107 rowBytes[0] = decoder->decodedYUVWidthBytes(0); 107 rowBytes[0] = decoder->decodedYUVWidthBytes(0);
108 rowBytes[1] = decoder->decodedYUVWidthBytes(1); 108 rowBytes[1] = decoder->decodedYUVWidthBytes(1);
109 rowBytes[2] = decoder->decodedYUVWidthBytes(2); 109 rowBytes[2] = decoder->decodedYUVWidthBytes(2);
110 110
111 RefPtr<ArrayBuffer> buffer(ArrayBuffer::create(rowBytes[0] * ySize.height() + rowBytes[1] * uSize.height() + rowBytes[2] * vSize.height(), 1)); 111 RefPtr<ArrayBuffer> buffer(ArrayBuffer::create(rowBytes[0] * ySize.height() + rowBytes[1] * uSize.height() + rowBytes[2] * vSize.height(), 1));
112 void* planes[3]; 112 void* planes[3];
113 planes[0] = buffer->data(); 113 planes[0] = buffer->data();
114 planes[1] = ((char*) planes[0]) + rowBytes[0] * ySize.height(); 114 planes[1] = ((char*) planes[0]) + rowBytes[0] * ySize.height();
115 planes[2] = ((char*) planes[1]) + rowBytes[1] * uSize.height(); 115 planes[2] = ((char*) planes[1]) + rowBytes[1] * uSize.height();
116 116
117 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes) ); 117 std::unique_ptr<ImagePlanes> imagePlanes = wrapUnique(new ImagePlanes(planes , rowBytes));
118 decoder->setImagePlanes(std::move(imagePlanes)); 118 decoder->setImagePlanes(std::move(imagePlanes));
119 119
120 ASSERT_TRUE(decoder->decodeToYUV()); 120 ASSERT_TRUE(decoder->decodeToYUV());
121 } 121 }
122 122
123 // Tests failure on a too big image. 123 // Tests failure on a too big image.
124 TEST(JPEGImageDecoderTest, tooBig) 124 TEST(JPEGImageDecoderTest, tooBig)
125 { 125 {
126 OwnPtr<ImageDecoder> decoder = createDecoder(100); 126 std::unique_ptr<ImageDecoder> decoder = createDecoder(100);
127 EXPECT_FALSE(decoder->setSize(10000, 10000)); 127 EXPECT_FALSE(decoder->setSize(10000, 10000));
128 EXPECT_TRUE(decoder->failed()); 128 EXPECT_TRUE(decoder->failed());
129 } 129 }
130 130
131 // Tests that JPEG decoder can downsample image whose width and height are multi ple of 8, 131 // Tests that JPEG decoder can downsample image whose width and height are multi ple of 8,
132 // to ensure we compute the correct decodedSize and pass correct parameters to l ibjpeg to 132 // to ensure we compute the correct decodedSize and pass correct parameters to l ibjpeg to
133 // output image with the expected size. 133 // output image with the expected size.
134 TEST(JPEGImageDecoderTest, downsampleImageSizeMultipleOf8) 134 TEST(JPEGImageDecoderTest, downsampleImageSizeMultipleOf8)
135 { 135 {
136 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256 136 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 EXPECT_EQ(439u, outputYWidth); 240 EXPECT_EQ(439u, outputYWidth);
241 EXPECT_EQ(154u, outputYHeight); 241 EXPECT_EQ(154u, outputYHeight);
242 EXPECT_EQ(220u, outputUVWidth); 242 EXPECT_EQ(220u, outputUVWidth);
243 EXPECT_EQ(77u, outputUVHeight); 243 EXPECT_EQ(77u, outputUVHeight);
244 244
245 // Make sure we revert to RGBA decoding when we're about to downscale, 245 // Make sure we revert to RGBA decoding when we're about to downscale,
246 // which can occur on memory-constrained android devices. 246 // which can occur on memory-constrained android devices.
247 RefPtr<SharedBuffer> data = readFile(jpegFile); 247 RefPtr<SharedBuffer> data = readFile(jpegFile);
248 ASSERT_TRUE(data); 248 ASSERT_TRUE(data);
249 249
250 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); 250 std::unique_ptr<ImageDecoder> decoder = createDecoder(230 * 230 * 4);
251 decoder->setData(data.get(), true); 251 decoder->setData(data.get(), true);
252 252
253 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); 253 std::unique_ptr<ImagePlanes> imagePlanes = wrapUnique(new ImagePlanes());
254 decoder->setImagePlanes(std::move(imagePlanes)); 254 decoder->setImagePlanes(std::move(imagePlanes));
255 ASSERT_TRUE(decoder->isSizeAvailable()); 255 ASSERT_TRUE(decoder->isSizeAvailable());
256 ASSERT_FALSE(decoder->canDecodeToYUV()); 256 ASSERT_FALSE(decoder->canDecodeToYUV());
257 } 257 }
258 258
259 TEST(JPEGImageDecoderTest, byteByByteBaselineJPEGWithColorProfileAndRestartMarke rs) 259 TEST(JPEGImageDecoderTest, byteByByteBaselineJPEGWithColorProfileAndRestartMarke rs)
260 { 260 {
261 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/sma ll-square-with-colorspin-profile.jpg", 1u, cAnimationNone); 261 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/sma ll-square-with-colorspin-profile.jpg", 1u, cAnimationNone);
262 } 262 }
263 263
(...skipping 11 matching lines...) Expand all
275 // not break JPEG decoding at a critical point: in between a call to decode the 275 // not break JPEG decoding at a critical point: in between a call to decode the
276 // size (when JPEGImageDecoder stops while it may still have input data to 276 // size (when JPEGImageDecoder stops while it may still have input data to
277 // read) and a call to do a full decode. 277 // read) and a call to do a full decode.
278 TEST(JPEGImageDecoderTest, mergeBuffer) 278 TEST(JPEGImageDecoderTest, mergeBuffer)
279 { 279 {
280 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; 280 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg";
281 testMergeBuffer(&createDecoder, jpegFile); 281 testMergeBuffer(&createDecoder, jpegFile);
282 } 282 }
283 283
284 } // namespace blink 284 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698