| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 uint8_t *row = decodedPixels; | 136 uint8_t *row = decodedPixels; |
| 137 for (int j = 0; j < decodedBitmap.height(); ++j) { | 137 for (int j = 0; j < decodedBitmap.height(); ++j) { |
| 138 for (int i = 0; i < decodedBitmap.width(); ++i) { | 138 for (int i = 0; i < decodedBitmap.width(); ++i) { |
| 139 SkPMColor pixel = *(reinterpret_cast<SkPMColor*>(row + i*sizeof(SkPM
Color))); | 139 SkPMColor pixel = *(reinterpret_cast<SkPMColor*>(row + i*sizeof(SkPM
Color))); |
| 140 REPORTER_ASSERT(reporter, SkPreMultiplyARGB(0x80, 0xFF, 0xFF, 0xFF)
== pixel); | 140 REPORTER_ASSERT(reporter, SkPreMultiplyARGB(0x80, 0xFF, 0xFF, 0xFF)
== pixel); |
| 141 } | 141 } |
| 142 row += decodedBitmap.rowBytes(); | 142 row += decodedBitmap.rowBytes(); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 // For KtxReexportPKM, below. Defined in SkImageDecoder_ktx.cpp | |
| 147 extern SkImageGenerator* decoder_image_generator(SkData*); | |
| 148 | |
| 149 /** | 146 /** |
| 150 * Finally, make sure that if we get ETC1 data from a PKM file that we can then | 147 * Finally, make sure that if we get ETC1 data from a PKM file that we can then |
| 151 * accurately write it out into a KTX file (i.e. transferring the ETC1 data from | 148 * accurately write it out into a KTX file (i.e. transferring the ETC1 data from |
| 152 * the PKM to the KTX should produce an identical KTX to the one we have on file
) | 149 * the PKM to the KTX should produce an identical KTX to the one we have on file
) |
| 153 */ | 150 */ |
| 154 DEF_TEST(KtxReexportPKM, reporter) { | 151 DEF_TEST(KtxReexportPKM, reporter) { |
| 155 SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); | 152 SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); |
| 156 | 153 |
| 157 // Load PKM file into a bitmap | 154 // Load PKM file into a bitmap |
| 158 SkBitmap etcBitmap; | 155 SkBitmap etcBitmap; |
| 159 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(pkmFilename.c_str())); | 156 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(pkmFilename.c_str())); |
| 160 if (nullptr == fileData) { | 157 if (nullptr == fileData) { |
| 161 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(
)); |
| 162 return; | 159 return; |
| 163 } | 160 } |
| 164 | 161 |
| 165 bool installDiscardablePixelRefSuccess = | 162 bool installDiscardablePixelRefSuccess = |
| 166 SkDEPRECATED_InstallDiscardablePixelRef(decoder_image_generator(fileData
), &etcBitmap); | 163 SkDEPRECATED_InstallDiscardablePixelRef(fileData, &etcBitmap); |
| 167 if (!installDiscardablePixelRefSuccess) { | 164 if (!installDiscardablePixelRefSuccess) { |
| 168 ERRORF(reporter, "failed to create discardable pixelRef from KTX file"); | 165 ERRORF(reporter, "failed to create discardable pixelRef from KTX file"); |
| 169 return; | 166 return; |
| 170 } | 167 } |
| 171 | 168 |
| 172 // Write the bitmap out to a KTX file. | 169 // Write the bitmap out to a KTX file. |
| 173 SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::k
KTX_Type, 0); | 170 SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::k
KTX_Type, 0); |
| 174 SkAutoDataUnref newKtxData(ktxDataPtr); | 171 SkAutoDataUnref newKtxData(ktxDataPtr); |
| 175 REPORTER_ASSERT(reporter, ktxDataPtr); | 172 REPORTER_ASSERT(reporter, ktxDataPtr); |
| 176 | 173 |
| 177 // 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. |
| 178 SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); | 175 SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); |
| 179 SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); | 176 SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); |
| 180 REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); | 177 REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); |
| 181 } | 178 } |
| OLD | NEW |