| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 REPORTER_ASSERT(reporter, encodedData); |
| 57 | 57 |
| 58 SkAutoTUnref<SkMemoryStream> stream(SkNEW_ARGS(SkMemoryStream, (encodedData)
)); | 58 SkAutoTDelete<SkMemoryStream> stream(SkNEW_ARGS(SkMemoryStream, (encodedData
))); |
| 59 REPORTER_ASSERT(reporter, 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()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 0x00, 0x00, 0x00, 0x00, // uint32_t fNumberOfArrayElements; | 100 0x00, 0x00, 0x00, 0x00, // uint32_t fNumberOfArrayElements; |
| 101 0x01, 0x00, 0x00, 0x00, // uint32_t fNumberOfFaces; | 101 0x01, 0x00, 0x00, 0x00, // uint32_t fNumberOfFaces; |
| 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 SkAutoTDelete<SkMemoryStream> stream( |
| 111 SkNEW_ARGS(SkMemoryStream, (kHalfWhiteKTX, sizeof(kHalfWhiteKTX)))); | 111 SkNEW_ARGS(SkMemoryStream, (kHalfWhiteKTX, sizeof(kHalfWhiteKTX)))); |
| 112 REPORTER_ASSERT(reporter, 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); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // Write the bitmap out to a KTX file. | 157 // Write the bitmap out to a KTX file. |
| 158 SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::k
KTX_Type, 0); | 158 SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::k
KTX_Type, 0); |
| 159 SkAutoDataUnref newKtxData(ktxDataPtr); | 159 SkAutoDataUnref newKtxData(ktxDataPtr); |
| 160 REPORTER_ASSERT(reporter, ktxDataPtr); | 160 REPORTER_ASSERT(reporter, ktxDataPtr); |
| 161 | 161 |
| 162 // See is this data is identical to data in existing ktx file. | 162 // See is this data is identical to data in existing ktx file. |
| 163 SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); | 163 SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); |
| 164 SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); | 164 SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); |
| 165 REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); | 165 REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); |
| 166 } | 166 } |
| OLD | NEW |