| OLD | NEW |
| 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 15 matching lines...) Expand all Loading... |
| 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, pixels); | 34 REPORTER_ASSERT(reporter, pixels); |
| 35 | 35 |
| 36 if (NULL == pixels) { | 36 if (nullptr == 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); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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, 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 (nullptr == 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 /** |
| 83 * Next test is to see whether or not reading an unpremultiplied KTX file accura
tely | 83 * Next test is to see whether or not reading an unpremultiplied KTX file accura
tely |
| 84 * creates a premultiplied buffer... | 84 * creates a premultiplied buffer... |
| 85 */ | 85 */ |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 * Finally, make sure that if we get ETC1 data from a PKM file that we can then | 137 * Finally, make sure that if we get ETC1 data from a PKM file that we can then |
| 138 * accurately write it out into a KTX file (i.e. transferring the ETC1 data from | 138 * accurately write it out into a KTX file (i.e. transferring the ETC1 data from |
| 139 * the PKM to the KTX should produce an identical KTX to the one we have on file
) | 139 * the PKM to the KTX should produce an identical KTX to the one we have on file
) |
| 140 */ | 140 */ |
| 141 DEF_TEST(KtxReexportPKM, reporter) { | 141 DEF_TEST(KtxReexportPKM, reporter) { |
| 142 SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); | 142 SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); |
| 143 | 143 |
| 144 // Load PKM file into a bitmap | 144 // Load PKM file into a bitmap |
| 145 SkBitmap etcBitmap; | 145 SkBitmap etcBitmap; |
| 146 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(pkmFilename.c_str())); | 146 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(pkmFilename.c_str())); |
| 147 if (NULL == fileData) { | 147 if (nullptr == fileData) { |
| 148 SkDebugf("KtxReexportPKM: can't load test file %s\n", pkmFilename.c_str(
)); | 148 SkDebugf("KtxReexportPKM: can't load test file %s\n", pkmFilename.c_str(
)); |
| 149 return; | 149 return; |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool installDiscardablePixelRefSuccess = | 152 bool installDiscardablePixelRefSuccess = |
| 153 SkInstallDiscardablePixelRef(fileData, &etcBitmap); | 153 SkInstallDiscardablePixelRef(fileData, &etcBitmap); |
| 154 REPORTER_ASSERT(reporter, installDiscardablePixelRefSuccess); | 154 REPORTER_ASSERT(reporter, installDiscardablePixelRefSuccess); |
| 155 | 155 |
| 156 // Write the bitmap out to a KTX file. | 156 // Write the bitmap out to a KTX file. |
| 157 SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::k
KTX_Type, 0); | 157 SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::k
KTX_Type, 0); |
| 158 SkAutoDataUnref newKtxData(ktxDataPtr); | 158 SkAutoDataUnref newKtxData(ktxDataPtr); |
| 159 REPORTER_ASSERT(reporter, ktxDataPtr); | 159 REPORTER_ASSERT(reporter, ktxDataPtr); |
| 160 | 160 |
| 161 // See is this data is identical to data in existing ktx file. | 161 // See is this data is identical to data in existing ktx file. |
| 162 SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); | 162 SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); |
| 163 SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); | 163 SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); |
| 164 REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); | 164 REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); |
| 165 } | 165 } |
| OLD | NEW |