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

Side by Side Diff: tests/KtxTest.cpp

Issue 544233002: "NULL !=" = NULL (Closed) Base URL: https://skia.googlesource.com/skia.git@are
Patch Set: rebase Created 6 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/ImageFilterTest.cpp ('k') | tests/LListTest.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 2014 Google Inc. 2 * Copyright 2014 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 "SkData.h" 10 #include "SkData.h"
(...skipping 13 matching lines...) Expand all
24 */ 24 */
25 DEF_TEST(KtxReadWrite, reporter) { 25 DEF_TEST(KtxReadWrite, reporter) {
26 26
27 // Random number generator with explicit seed for reproducibility 27 // Random number generator with explicit seed for reproducibility
28 SkRandom rand(0x1005cbad); 28 SkRandom rand(0x1005cbad);
29 29
30 SkBitmap bm8888; 30 SkBitmap bm8888;
31 bm8888.allocN32Pixels(128, 128); 31 bm8888.allocN32Pixels(128, 128);
32 32
33 uint8_t *pixels = reinterpret_cast<uint8_t*>(bm8888.getPixels()); 33 uint8_t *pixels = reinterpret_cast<uint8_t*>(bm8888.getPixels());
34 REPORTER_ASSERT(reporter, NULL != pixels); 34 REPORTER_ASSERT(reporter, pixels);
35 35
36 if (NULL == pixels) { 36 if (NULL == pixels) {
37 return; 37 return;
38 } 38 }
39 39
40 uint8_t *row = pixels; 40 uint8_t *row = pixels;
41 for (int y = 0; y < bm8888.height(); ++y) { 41 for (int y = 0; y < bm8888.height(); ++y) {
42 for (int x = 0; x < bm8888.width(); ++x) { 42 for (int x = 0; x < bm8888.width(); ++x) {
43 uint8_t a = rand.nextRangeU(0, 255); 43 uint8_t a = rand.nextRangeU(0, 255);
44 uint8_t r = rand.nextRangeU(0, 255); 44 uint8_t r = rand.nextRangeU(0, 255);
45 uint8_t g = rand.nextRangeU(0, 255); 45 uint8_t g = rand.nextRangeU(0, 255);
46 uint8_t b = rand.nextRangeU(0, 255); 46 uint8_t b = rand.nextRangeU(0, 255);
47 47
48 SkPMColor &pixel = *(reinterpret_cast<SkPMColor*>(row + x*sizeof(SkP MColor))); 48 SkPMColor &pixel = *(reinterpret_cast<SkPMColor*>(row + x*sizeof(SkP MColor)));
49 pixel = SkPreMultiplyARGB(a, r, g, b); 49 pixel = SkPreMultiplyARGB(a, r, g, b);
50 } 50 }
51 row += bm8888.rowBytes(); 51 row += bm8888.rowBytes();
52 } 52 }
53 REPORTER_ASSERT(reporter, !(bm8888.empty())); 53 REPORTER_ASSERT(reporter, !(bm8888.empty()));
54 54
55 SkAutoDataUnref encodedData(SkImageEncoder::EncodeData(bm8888, SkImageEncode r::kKTX_Type, 0)); 55 SkAutoDataUnref encodedData(SkImageEncoder::EncodeData(bm8888, SkImageEncode r::kKTX_Type, 0));
56 REPORTER_ASSERT(reporter, NULL != encodedData); 56 REPORTER_ASSERT(reporter, encodedData);
57 57
58 SkAutoTUnref<SkMemoryStream> stream(SkNEW_ARGS(SkMemoryStream, (encodedData) )); 58 SkAutoTUnref<SkMemoryStream> stream(SkNEW_ARGS(SkMemoryStream, (encodedData) ));
59 REPORTER_ASSERT(reporter, NULL != stream); 59 REPORTER_ASSERT(reporter, stream);
60 60
61 SkBitmap decodedBitmap; 61 SkBitmap decodedBitmap;
62 bool imageDecodeSuccess = SkImageDecoder::DecodeStream(stream, &decodedBitma p); 62 bool imageDecodeSuccess = SkImageDecoder::DecodeStream(stream, &decodedBitma p);
63 REPORTER_ASSERT(reporter, imageDecodeSuccess); 63 REPORTER_ASSERT(reporter, imageDecodeSuccess);
64 64
65 REPORTER_ASSERT(reporter, decodedBitmap.colorType() == bm8888.colorType()); 65 REPORTER_ASSERT(reporter, decodedBitmap.colorType() == bm8888.colorType());
66 REPORTER_ASSERT(reporter, decodedBitmap.alphaType() == bm8888.alphaType()); 66 REPORTER_ASSERT(reporter, decodedBitmap.alphaType() == bm8888.alphaType());
67 REPORTER_ASSERT(reporter, decodedBitmap.width() == bm8888.width()); 67 REPORTER_ASSERT(reporter, decodedBitmap.width() == bm8888.width());
68 REPORTER_ASSERT(reporter, decodedBitmap.height() == bm8888.height()); 68 REPORTER_ASSERT(reporter, decodedBitmap.height() == bm8888.height());
69 REPORTER_ASSERT(reporter, !(decodedBitmap.empty())); 69 REPORTER_ASSERT(reporter, !(decodedBitmap.empty()));
70 70
71 uint8_t *decodedPixels = reinterpret_cast<uint8_t*>(decodedBitmap.getPixels( )); 71 uint8_t *decodedPixels = reinterpret_cast<uint8_t*>(decodedBitmap.getPixels( ));
72 REPORTER_ASSERT(reporter, NULL != decodedPixels); 72 REPORTER_ASSERT(reporter, decodedPixels);
73 REPORTER_ASSERT(reporter, decodedBitmap.getSize() == bm8888.getSize()); 73 REPORTER_ASSERT(reporter, decodedBitmap.getSize() == bm8888.getSize());
74 74
75 if (NULL == decodedPixels) { 75 if (NULL == decodedPixels) {
76 return; 76 return;
77 } 77 }
78 78
79 REPORTER_ASSERT(reporter, memcmp(decodedPixels, pixels, decodedBitmap.getSiz e()) == 0); 79 REPORTER_ASSERT(reporter, memcmp(decodedPixels, pixels, decodedBitmap.getSiz e()) == 0);
80 } 80 }
81 81
82 /** 82 /**
(...skipping 19 matching lines...) Expand all
102 0x01, 0x00, 0x00, 0x00, // uint32_t fNumberOfMipmapLevels; 102 0x01, 0x00, 0x00, 0x00, // uint32_t fNumberOfMipmapLevels;
103 0x00, 0x00, 0x00, 0x00, // uint32_t fBytesOfKeyValueData; 103 0x00, 0x00, 0x00, 0x00, // uint32_t fBytesOfKeyValueData;
104 0x10, 0x00, 0x00, 0x00, // image size: 2x2 image of RGBA = 4 * 4 = 16 by tes 104 0x10, 0x00, 0x00, 0x00, // image size: 2x2 image of RGBA = 4 * 4 = 16 by tes
105 0xFF, 0xFF, 0xFF, 0x80, // Pixel 1 105 0xFF, 0xFF, 0xFF, 0x80, // Pixel 1
106 0xFF, 0xFF, 0xFF, 0x80, // Pixel 2 106 0xFF, 0xFF, 0xFF, 0x80, // Pixel 2
107 0xFF, 0xFF, 0xFF, 0x80, // Pixel 3 107 0xFF, 0xFF, 0xFF, 0x80, // Pixel 3
108 0xFF, 0xFF, 0xFF, 0x80};// Pixel 4 108 0xFF, 0xFF, 0xFF, 0x80};// Pixel 4
109 109
110 SkAutoTUnref<SkMemoryStream> stream( 110 SkAutoTUnref<SkMemoryStream> stream(
111 SkNEW_ARGS(SkMemoryStream, (kHalfWhiteKTX, sizeof(kHalfWhiteKTX)))); 111 SkNEW_ARGS(SkMemoryStream, (kHalfWhiteKTX, sizeof(kHalfWhiteKTX))));
112 REPORTER_ASSERT(reporter, NULL != stream); 112 REPORTER_ASSERT(reporter, stream);
113 113
114 SkBitmap decodedBitmap; 114 SkBitmap decodedBitmap;
115 bool imageDecodeSuccess = SkImageDecoder::DecodeStream(stream, &decodedBitma p); 115 bool imageDecodeSuccess = SkImageDecoder::DecodeStream(stream, &decodedBitma p);
116 REPORTER_ASSERT(reporter, imageDecodeSuccess); 116 REPORTER_ASSERT(reporter, imageDecodeSuccess);
117 117
118 REPORTER_ASSERT(reporter, decodedBitmap.colorType() == kN32_SkColorType); 118 REPORTER_ASSERT(reporter, decodedBitmap.colorType() == kN32_SkColorType);
119 REPORTER_ASSERT(reporter, decodedBitmap.alphaType() == kPremul_SkAlphaType); 119 REPORTER_ASSERT(reporter, decodedBitmap.alphaType() == kPremul_SkAlphaType);
120 REPORTER_ASSERT(reporter, decodedBitmap.width() == 2); 120 REPORTER_ASSERT(reporter, decodedBitmap.width() == 2);
121 REPORTER_ASSERT(reporter, decodedBitmap.height() == 2); 121 REPORTER_ASSERT(reporter, decodedBitmap.height() == 2);
122 REPORTER_ASSERT(reporter, !(decodedBitmap.empty())); 122 REPORTER_ASSERT(reporter, !(decodedBitmap.empty()));
123 123
124 uint8_t *decodedPixels = reinterpret_cast<uint8_t*>(decodedBitmap.getPixels( )); 124 uint8_t *decodedPixels = reinterpret_cast<uint8_t*>(decodedBitmap.getPixels( ));
125 REPORTER_ASSERT(reporter, NULL != decodedPixels); 125 REPORTER_ASSERT(reporter, decodedPixels);
126 126
127 uint8_t *row = decodedPixels; 127 uint8_t *row = decodedPixels;
128 for (int j = 0; j < decodedBitmap.height(); ++j) { 128 for (int j = 0; j < decodedBitmap.height(); ++j) {
129 for (int i = 0; i < decodedBitmap.width(); ++i) { 129 for (int i = 0; i < decodedBitmap.width(); ++i) {
130 SkPMColor pixel = *(reinterpret_cast<SkPMColor*>(row + i*sizeof(SkPM Color))); 130 SkPMColor pixel = *(reinterpret_cast<SkPMColor*>(row + i*sizeof(SkPM Color)));
131 REPORTER_ASSERT(reporter, SkPreMultiplyARGB(0x80, 0xFF, 0xFF, 0xFF) == pixel); 131 REPORTER_ASSERT(reporter, SkPreMultiplyARGB(0x80, 0xFF, 0xFF, 0xFF) == pixel);
132 } 132 }
133 row += decodedBitmap.rowBytes(); 133 row += decodedBitmap.rowBytes();
134 } 134 }
135 } 135 }
136 136
137 /** 137 /**
138 * Finally, make sure that if we get ETC1 data from a PKM file that we can then 138 * Finally, make sure that if we get ETC1 data from a PKM file that we can then
139 * accurately write it out into a KTX file (i.e. transferring the ETC1 data from 139 * accurately write it out into a KTX file (i.e. transferring the ETC1 data from
140 * the PKM to the KTX should produce an identical KTX to the one we have on file ) 140 * the PKM to the KTX should produce an identical KTX to the one we have on file )
141 */ 141 */
142 DEF_TEST(KtxReexportPKM, reporter) { 142 DEF_TEST(KtxReexportPKM, reporter) {
143 SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); 143 SkString pkmFilename = GetResourcePath("mandrill_128.pkm");
144 144
145 // Load PKM file into a bitmap 145 // Load PKM file into a bitmap
146 SkBitmap etcBitmap; 146 SkBitmap etcBitmap;
147 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(pkmFilename.c_str())); 147 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(pkmFilename.c_str()));
148 REPORTER_ASSERT(reporter, NULL != fileData); 148 REPORTER_ASSERT(reporter, fileData);
149 if (NULL == fileData) { 149 if (NULL == fileData) {
150 return; 150 return;
151 } 151 }
152 152
153 bool installDiscardablePixelRefSuccess = 153 bool installDiscardablePixelRefSuccess =
154 SkInstallDiscardablePixelRef( 154 SkInstallDiscardablePixelRef(
155 SkDecodingImageGenerator::Create( 155 SkDecodingImageGenerator::Create(
156 fileData, SkDecodingImageGenerator::Options()), &etcBitmap); 156 fileData, SkDecodingImageGenerator::Options()), &etcBitmap);
157 REPORTER_ASSERT(reporter, installDiscardablePixelRefSuccess); 157 REPORTER_ASSERT(reporter, installDiscardablePixelRefSuccess);
158 158
159 // Write the bitmap out to a KTX file. 159 // Write the bitmap out to a KTX file.
160 SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::k KTX_Type, 0); 160 SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::k KTX_Type, 0);
161 SkAutoDataUnref newKtxData(ktxDataPtr); 161 SkAutoDataUnref newKtxData(ktxDataPtr);
162 REPORTER_ASSERT(reporter, NULL != ktxDataPtr); 162 REPORTER_ASSERT(reporter, ktxDataPtr);
163 163
164 // See is this data is identical to data in existing ktx file. 164 // See is this data is identical to data in existing ktx file.
165 SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); 165 SkString ktxFilename = GetResourcePath("mandrill_128.ktx");
166 SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); 166 SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str()));
167 REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); 167 REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData));
168 } 168 }
OLDNEW
« no previous file with comments | « tests/ImageFilterTest.cpp ('k') | tests/LListTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698