| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, encodedData); | 56 if (nullptr == encodedData.get()) { |
| 57 ERRORF(reporter, "failed to encode the bitmap to KTX"); |
| 58 return; |
| 59 } |
| 60 |
| 57 | 61 |
| 58 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encodedData)); | 62 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encodedData)); |
| 59 REPORTER_ASSERT(reporter, stream); | 63 REPORTER_ASSERT(reporter, stream); |
| 60 | 64 |
| 61 SkBitmap decodedBitmap; | 65 SkBitmap decodedBitmap; |
| 62 bool imageDecodeSuccess = SkImageDecoder::DecodeStream(stream, &decodedBitma
p); | 66 bool imageDecodeSuccess = SkImageDecoder::DecodeStream(stream, &decodedBitma
p); |
| 63 REPORTER_ASSERT(reporter, imageDecodeSuccess); | 67 if (!imageDecodeSuccess) { |
| 68 ERRORF(reporter, "failed to decode the KTX stream"); |
| 69 return; |
| 70 } |
| 64 | 71 |
| 65 REPORTER_ASSERT(reporter, decodedBitmap.colorType() == bm8888.colorType()); | 72 REPORTER_ASSERT(reporter, decodedBitmap.colorType() == bm8888.colorType()); |
| 66 REPORTER_ASSERT(reporter, decodedBitmap.alphaType() == bm8888.alphaType()); | 73 REPORTER_ASSERT(reporter, decodedBitmap.alphaType() == bm8888.alphaType()); |
| 67 REPORTER_ASSERT(reporter, decodedBitmap.width() == bm8888.width()); | 74 REPORTER_ASSERT(reporter, decodedBitmap.width() == bm8888.width()); |
| 68 REPORTER_ASSERT(reporter, decodedBitmap.height() == bm8888.height()); | 75 REPORTER_ASSERT(reporter, decodedBitmap.height() == bm8888.height()); |
| 69 REPORTER_ASSERT(reporter, !(decodedBitmap.empty())); | 76 REPORTER_ASSERT(reporter, !(decodedBitmap.empty())); |
| 70 | 77 |
| 71 uint8_t *decodedPixels = reinterpret_cast<uint8_t*>(decodedBitmap.getPixels(
)); | 78 uint8_t *decodedPixels = reinterpret_cast<uint8_t*>(decodedBitmap.getPixels(
)); |
| 72 REPORTER_ASSERT(reporter, decodedPixels); | 79 REPORTER_ASSERT(reporter, decodedPixels); |
| 73 REPORTER_ASSERT(reporter, decodedBitmap.getSize() == bm8888.getSize()); | 80 REPORTER_ASSERT(reporter, decodedBitmap.getSize() == bm8888.getSize()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 0xFF, 0xFF, 0xFF, 0x80, // Pixel 1 | 112 0xFF, 0xFF, 0xFF, 0x80, // Pixel 1 |
| 106 0xFF, 0xFF, 0xFF, 0x80, // Pixel 2 | 113 0xFF, 0xFF, 0xFF, 0x80, // Pixel 2 |
| 107 0xFF, 0xFF, 0xFF, 0x80, // Pixel 3 | 114 0xFF, 0xFF, 0xFF, 0x80, // Pixel 3 |
| 108 0xFF, 0xFF, 0xFF, 0x80};// Pixel 4 | 115 0xFF, 0xFF, 0xFF, 0x80};// Pixel 4 |
| 109 | 116 |
| 110 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(kHalfWhiteKTX, sizeo
f(kHalfWhiteKTX))); | 117 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(kHalfWhiteKTX, sizeo
f(kHalfWhiteKTX))); |
| 111 REPORTER_ASSERT(reporter, stream); | 118 REPORTER_ASSERT(reporter, stream); |
| 112 | 119 |
| 113 SkBitmap decodedBitmap; | 120 SkBitmap decodedBitmap; |
| 114 bool imageDecodeSuccess = SkImageDecoder::DecodeStream(stream, &decodedBitma
p); | 121 bool imageDecodeSuccess = SkImageDecoder::DecodeStream(stream, &decodedBitma
p); |
| 115 REPORTER_ASSERT(reporter, imageDecodeSuccess); | 122 if (!imageDecodeSuccess) { |
| 123 ERRORF(reporter, "failed to decode the KTX stream"); |
| 124 return; |
| 125 } |
| 116 | 126 |
| 117 REPORTER_ASSERT(reporter, decodedBitmap.colorType() == kN32_SkColorType); | 127 REPORTER_ASSERT(reporter, decodedBitmap.colorType() == kN32_SkColorType); |
| 118 REPORTER_ASSERT(reporter, decodedBitmap.alphaType() == kPremul_SkAlphaType); | 128 REPORTER_ASSERT(reporter, decodedBitmap.alphaType() == kPremul_SkAlphaType); |
| 119 REPORTER_ASSERT(reporter, decodedBitmap.width() == 2); | 129 REPORTER_ASSERT(reporter, decodedBitmap.width() == 2); |
| 120 REPORTER_ASSERT(reporter, decodedBitmap.height() == 2); | 130 REPORTER_ASSERT(reporter, decodedBitmap.height() == 2); |
| 121 REPORTER_ASSERT(reporter, !(decodedBitmap.empty())); | 131 REPORTER_ASSERT(reporter, !(decodedBitmap.empty())); |
| 122 | 132 |
| 123 uint8_t *decodedPixels = reinterpret_cast<uint8_t*>(decodedBitmap.getPixels(
)); | 133 uint8_t *decodedPixels = reinterpret_cast<uint8_t*>(decodedBitmap.getPixels(
)); |
| 124 REPORTER_ASSERT(reporter, decodedPixels); | 134 REPORTER_ASSERT(reporter, decodedPixels); |
| 125 | 135 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 144 // Load PKM file into a bitmap | 154 // Load PKM file into a bitmap |
| 145 SkBitmap etcBitmap; | 155 SkBitmap etcBitmap; |
| 146 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(pkmFilename.c_str())); | 156 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(pkmFilename.c_str())); |
| 147 if (nullptr == fileData) { | 157 if (nullptr == fileData) { |
| 148 SkDebugf("KtxReexportPKM: can't load test file %s\n", pkmFilename.c_str(
)); | 158 SkDebugf("KtxReexportPKM: can't load test file %s\n", pkmFilename.c_str(
)); |
| 149 return; | 159 return; |
| 150 } | 160 } |
| 151 | 161 |
| 152 bool installDiscardablePixelRefSuccess = | 162 bool installDiscardablePixelRefSuccess = |
| 153 SkDEPRECATED_InstallDiscardablePixelRef(fileData, &etcBitmap); | 163 SkDEPRECATED_InstallDiscardablePixelRef(fileData, &etcBitmap); |
| 154 REPORTER_ASSERT(reporter, installDiscardablePixelRefSuccess); | 164 if (!installDiscardablePixelRefSuccess) { |
| 165 ERRORF(reporter, "failed to create discardable pixelRef from KTX file"); |
| 166 return; |
| 167 } |
| 155 | 168 |
| 156 // Write the bitmap out to a KTX file. | 169 // Write the bitmap out to a KTX file. |
| 157 SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::k
KTX_Type, 0); | 170 SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::k
KTX_Type, 0); |
| 158 SkAutoDataUnref newKtxData(ktxDataPtr); | 171 SkAutoDataUnref newKtxData(ktxDataPtr); |
| 159 REPORTER_ASSERT(reporter, ktxDataPtr); | 172 REPORTER_ASSERT(reporter, ktxDataPtr); |
| 160 | 173 |
| 161 // See is this data is identical to data in existing ktx file. | 174 // See is this data is identical to data in existing ktx file. |
| 162 SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); | 175 SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); |
| 163 SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); | 176 SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); |
| 164 REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); | 177 REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); |
| 165 } | 178 } |
| OLD | NEW |