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

Side by Side Diff: tests/CodexTest.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 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
« no previous file with comments | « tests/ClipStackTest.cpp ('k') | tests/ColorFilterTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
(...skipping 28 matching lines...) Expand all
39 static void compare_to_good_digest(skiatest::Reporter* r, const SkMD5::Digest& g oodDigest, 39 static void compare_to_good_digest(skiatest::Reporter* r, const SkMD5::Digest& g oodDigest,
40 const SkBitmap& bm) { 40 const SkBitmap& bm) {
41 SkMD5::Digest digest; 41 SkMD5::Digest digest;
42 md5(bm, &digest); 42 md5(bm, &digest);
43 REPORTER_ASSERT(r, digest == goodDigest); 43 REPORTER_ASSERT(r, digest == goodDigest);
44 } 44 }
45 45
46 /** 46 /**
47 * Test decoding an SkCodec to a particular SkImageInfo. 47 * Test decoding an SkCodec to a particular SkImageInfo.
48 * 48 *
49 * Calling getPixels(info) should return expectedResult, and if goodDigest is n on NULL, 49 * Calling getPixels(info) should return expectedResult, and if goodDigest is n on nullptr,
50 * the resulting decode should match. 50 * the resulting decode should match.
51 */ 51 */
52 static void test_info(skiatest::Reporter* r, SkCodec* codec, const SkImageInfo& info, 52 static void test_info(skiatest::Reporter* r, SkCodec* codec, const SkImageInfo& info,
53 SkCodec::Result expectedResult, const SkMD5::Digest* goodD igest) { 53 SkCodec::Result expectedResult, const SkMD5::Digest* goodD igest) {
54 SkBitmap bm; 54 SkBitmap bm;
55 bm.allocPixels(info); 55 bm.allocPixels(info);
56 SkAutoLockPixels autoLockPixels(bm); 56 SkAutoLockPixels autoLockPixels(bm);
57 57
58 SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes( )); 58 SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes( ));
59 REPORTER_ASSERT(r, result == expectedResult); 59 REPORTER_ASSERT(r, result == expectedResult);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // on the color type (ex: building a color table for kIndex8). DM is where we test 97 // on the color type (ex: building a color table for kIndex8). DM is where we test
98 // decodes to all possible destination color types. 98 // decodes to all possible destination color types.
99 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); 99 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
100 REPORTER_ASSERT(r, info.dimensions() == size); 100 REPORTER_ASSERT(r, info.dimensions() == size);
101 101
102 { 102 {
103 // Test decoding to 565 103 // Test decoding to 565
104 SkImageInfo info565 = info.makeColorType(kRGB_565_SkColorType); 104 SkImageInfo info565 = info.makeColorType(kRGB_565_SkColorType);
105 SkCodec::Result expected = (supports565 && info.alphaType() == kOpaque_S kAlphaType) ? 105 SkCodec::Result expected = (supports565 && info.alphaType() == kOpaque_S kAlphaType) ?
106 SkCodec::kSuccess : SkCodec::kInvalidConversion; 106 SkCodec::kSuccess : SkCodec::kInvalidConversion;
107 test_info(r, codec, info565, expected, NULL); 107 test_info(r, codec, info565, expected, nullptr);
108 } 108 }
109 109
110 SkBitmap bm; 110 SkBitmap bm;
111 bm.allocPixels(info); 111 bm.allocPixels(info);
112 SkAutoLockPixels autoLockPixels(bm); 112 SkAutoLockPixels autoLockPixels(bm);
113 SkCodec::Result result = 113 SkCodec::Result result =
114 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); 114 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), nullptr, nullptr, nullptr);
115 REPORTER_ASSERT(r, result == SkCodec::kSuccess); 115 REPORTER_ASSERT(r, result == SkCodec::kSuccess);
116 116
117 SkMD5::Digest digest; 117 SkMD5::Digest digest;
118 md5(bm, &digest); 118 md5(bm, &digest);
119 119
120 // verify that re-decoding gives the same result. 120 // verify that re-decoding gives the same result.
121 test_info(r, codec, info, SkCodec::kSuccess, &digest); 121 test_info(r, codec, info, SkCodec::kSuccess, &digest);
122 122
123 { 123 {
124 // Check alpha type conversions 124 // Check alpha type conversions
125 if (info.alphaType() == kOpaque_SkAlphaType) { 125 if (info.alphaType() == kOpaque_SkAlphaType) {
126 test_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType), 126 test_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType),
127 SkCodec::kInvalidConversion, NULL); 127 SkCodec::kInvalidConversion, nullptr);
128 test_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType), 128 test_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType),
129 SkCodec::kInvalidConversion, NULL); 129 SkCodec::kInvalidConversion, nullptr);
130 } else { 130 } else {
131 // Decoding to opaque should fail 131 // Decoding to opaque should fail
132 test_info(r, codec, info.makeAlphaType(kOpaque_SkAlphaType), 132 test_info(r, codec, info.makeAlphaType(kOpaque_SkAlphaType),
133 SkCodec::kInvalidConversion, NULL); 133 SkCodec::kInvalidConversion, nullptr);
134 SkAlphaType otherAt = info.alphaType(); 134 SkAlphaType otherAt = info.alphaType();
135 if (kPremul_SkAlphaType == otherAt) { 135 if (kPremul_SkAlphaType == otherAt) {
136 otherAt = kUnpremul_SkAlphaType; 136 otherAt = kUnpremul_SkAlphaType;
137 } else { 137 } else {
138 otherAt = kPremul_SkAlphaType; 138 otherAt = kPremul_SkAlphaType;
139 } 139 }
140 // The other non-opaque alpha type should always succeed, but not ma tch. 140 // The other non-opaque alpha type should always succeed, but not ma tch.
141 test_info(r, codec, info.makeAlphaType(otherAt), SkCodec::kSuccess, NULL); 141 test_info(r, codec, info.makeAlphaType(otherAt), SkCodec::kSuccess, nullptr);
142 } 142 }
143 } 143 }
144 144
145 // Scanline decoding follows. 145 // Scanline decoding follows.
146 146
147 stream.reset(resource(path)); 147 stream.reset(resource(path));
148 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( 148 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(
149 SkScanlineDecoder::NewFromStream(stream.detach())); 149 SkScanlineDecoder::NewFromStream(stream.detach()));
150 if (supportsScanlineDecoding) { 150 if (supportsScanlineDecoding) {
151 bm.eraseColor(SK_ColorYELLOW); 151 bm.eraseColor(SK_ColorYELLOW);
(...skipping 26 matching lines...) Expand all
178 for (int i = 0; i < 5; i++) { 178 for (int i = 0; i < 5; i++) {
179 subset = generate_random_subset(&rand, size.width(), size.height()); 179 subset = generate_random_subset(&rand, size.width(), size.height());
180 SkASSERT(!subset.isEmpty()); 180 SkASSERT(!subset.isEmpty());
181 const bool supported = codec->getValidSubset(&subset); 181 const bool supported = codec->getValidSubset(&subset);
182 REPORTER_ASSERT(r, supported == supportsSubsetDecoding); 182 REPORTER_ASSERT(r, supported == supportsSubsetDecoding);
183 183
184 SkImageInfo subsetInfo = info.makeWH(subset.width(), subset.height()); 184 SkImageInfo subsetInfo = info.makeWH(subset.width(), subset.height());
185 SkBitmap bm; 185 SkBitmap bm;
186 bm.allocPixels(subsetInfo); 186 bm.allocPixels(subsetInfo);
187 const SkCodec::Result result = codec->getPixels(bm.info(), bm.getPixels( ), bm.rowBytes(), 187 const SkCodec::Result result = codec->getPixels(bm.info(), bm.getPixels( ), bm.rowBytes(),
188 &opts, NULL, NULL); 188 &opts, nullptr, nullptr) ;
189 189
190 if (supportsSubsetDecoding) { 190 if (supportsSubsetDecoding) {
191 REPORTER_ASSERT(r, result == SkCodec::kSuccess); 191 REPORTER_ASSERT(r, result == SkCodec::kSuccess);
192 // Webp is the only codec that supports subsets, and it will have mo dified the subset 192 // Webp is the only codec that supports subsets, and it will have mo dified the subset
193 // to have even left/top. 193 // to have even left/top.
194 REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTo p)); 194 REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTo p));
195 } else { 195 } else {
196 // No subsets will work. 196 // No subsets will work.
197 REPORTER_ASSERT(r, result == SkCodec::kUnimplemented); 197 REPORTER_ASSERT(r, result == SkCodec::kUnimplemented);
198 } 198 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 SkImageInfo scaledInfo = codec->getInfo() 295 SkImageInfo scaledInfo = codec->getInfo()
296 .makeWH(scaledDims.width(), scaledDims.height()) 296 .makeWH(scaledDims.width(), scaledDims.height())
297 .makeColorType(kN32_SkColorType); 297 .makeColorType(kN32_SkColorType);
298 298
299 // Set up for the decode 299 // Set up for the decode
300 size_t rowBytes = scaledDims.width() * sizeof(SkPMColor); 300 size_t rowBytes = scaledDims.width() * sizeof(SkPMColor);
301 size_t totalBytes = scaledInfo.getSafeSize(rowBytes); 301 size_t totalBytes = scaledInfo.getSafeSize(rowBytes);
302 SkAutoTMalloc<SkPMColor> pixels(totalBytes); 302 SkAutoTMalloc<SkPMColor> pixels(totalBytes);
303 303
304 SkCodec::Result result = 304 SkCodec::Result result =
305 codec->getPixels(scaledInfo, pixels.get(), rowBytes, NULL, NULL, NULL); 305 codec->getPixels(scaledInfo, pixels.get(), rowBytes, nullptr, nu llptr, nullptr);
306 REPORTER_ASSERT(r, SkCodec::kSuccess == result); 306 REPORTER_ASSERT(r, SkCodec::kSuccess == result);
307 } 307 }
308 } 308 }
309 309
310 // Ensure that onGetScaledDimensions returns valid image dimensions to use for d ecodes 310 // Ensure that onGetScaledDimensions returns valid image dimensions to use for d ecodes
311 DEF_TEST(Codec_Dimensions, r) { 311 DEF_TEST(Codec_Dimensions, r) {
312 // JPG 312 // JPG
313 test_dimensions(r, "CMYK.jpg"); 313 test_dimensions(r, "CMYK.jpg");
314 test_dimensions(r, "color_wheel.jpg"); 314 test_dimensions(r, "color_wheel.jpg");
315 test_dimensions(r, "grayscale.jpg"); 315 test_dimensions(r, "grayscale.jpg");
(...skipping 16 matching lines...) Expand all
332 332
333 } 333 }
334 334
335 static void test_invalid(skiatest::Reporter* r, const char path[]) { 335 static void test_invalid(skiatest::Reporter* r, const char path[]) {
336 SkAutoTDelete<SkStream> stream(resource(path)); 336 SkAutoTDelete<SkStream> stream(resource(path));
337 if (!stream) { 337 if (!stream) {
338 SkDebugf("Missing resource '%s'\n", path); 338 SkDebugf("Missing resource '%s'\n", path);
339 return; 339 return;
340 } 340 }
341 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); 341 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
342 REPORTER_ASSERT(r, NULL == codec); 342 REPORTER_ASSERT(r, nullptr == codec);
343 } 343 }
344 344
345 DEF_TEST(Codec_Empty, r) { 345 DEF_TEST(Codec_Empty, r) {
346 // Test images that should not be able to create a codec 346 // Test images that should not be able to create a codec
347 test_invalid(r, "empty_images/zero-dims.gif"); 347 test_invalid(r, "empty_images/zero-dims.gif");
348 test_invalid(r, "empty_images/zero-embedded.ico"); 348 test_invalid(r, "empty_images/zero-embedded.ico");
349 test_invalid(r, "empty_images/zero-width.bmp"); 349 test_invalid(r, "empty_images/zero-width.bmp");
350 test_invalid(r, "empty_images/zero-height.bmp"); 350 test_invalid(r, "empty_images/zero-height.bmp");
351 test_invalid(r, "empty_images/zero-width.jpg"); 351 test_invalid(r, "empty_images/zero-width.jpg");
352 test_invalid(r, "empty_images/zero-height.jpg"); 352 test_invalid(r, "empty_images/zero-height.jpg");
(...skipping 11 matching lines...) Expand all
364 SkDebugf("Missing resource '%s'\n", path); 364 SkDebugf("Missing resource '%s'\n", path);
365 return; 365 return;
366 } 366 }
367 SkAutoTDelete<SkScanlineDecoder> decoder(SkScanlineDecoder::NewFromStream( 367 SkAutoTDelete<SkScanlineDecoder> decoder(SkScanlineDecoder::NewFromStream(
368 stream.detach())); 368 stream.detach()));
369 369
370 // This should return kSuccess because kIndex8 is supported. 370 // This should return kSuccess because kIndex8 is supported.
371 SkPMColor colorStorage[256]; 371 SkPMColor colorStorage[256];
372 int colorCount; 372 int colorCount;
373 SkCodec::Result result = decoder->start( 373 SkCodec::Result result = decoder->start(
374 decoder->getInfo().makeColorType(kIndex_8_SkColorType), NULL, colorStora ge, &colorCount); 374 decoder->getInfo().makeColorType(kIndex_8_SkColorType), nullptr, colorSt orage, &colorCount);
375 REPORTER_ASSERT(r, SkCodec::kSuccess == result); 375 REPORTER_ASSERT(r, SkCodec::kSuccess == result);
376 // The rest of the test is uninteresting if kIndex8 is not supported 376 // The rest of the test is uninteresting if kIndex8 is not supported
377 if (SkCodec::kSuccess != result) { 377 if (SkCodec::kSuccess != result) {
378 return; 378 return;
379 } 379 }
380 380
381 // This should return kInvalidParameters because, in kIndex_8 mode, we must pass in a valid 381 // This should return kInvalidParameters because, in kIndex_8 mode, we must pass in a valid
382 // colorPtr and a valid colorCountPtr. 382 // colorPtr and a valid colorCountPtr.
383 result = decoder->start( 383 result = decoder->start(
384 decoder->getInfo().makeColorType(kIndex_8_SkColorType), NULL, NULL, NULL ); 384 decoder->getInfo().makeColorType(kIndex_8_SkColorType), nullptr, nullptr , nullptr);
385 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); 385 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
386 result = decoder->start( 386 result = decoder->start(
387 decoder->getInfo().makeColorType(kIndex_8_SkColorType)); 387 decoder->getInfo().makeColorType(kIndex_8_SkColorType));
388 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); 388 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
389 } 389 }
390 390
391 DEF_TEST(Codec_Params, r) { 391 DEF_TEST(Codec_Params, r) {
392 test_invalid_parameters(r, "index8.png"); 392 test_invalid_parameters(r, "index8.png");
393 test_invalid_parameters(r, "mandrill.wbmp"); 393 test_invalid_parameters(r, "mandrill.wbmp");
394 } 394 }
OLDNEW
« no previous file with comments | « tests/ClipStackTest.cpp ('k') | tests/ColorFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698