| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkBmpMaskCodec.h" | 8 #include "SkBmpMaskCodec.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } | 51 } |
| 52 | 52 |
| 53 int rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts); | 53 int rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts); |
| 54 if (rows != dstInfo.height()) { | 54 if (rows != dstInfo.height()) { |
| 55 *rowsDecoded = rows; | 55 *rowsDecoded = rows; |
| 56 return kIncompleteInput; | 56 return kIncompleteInput; |
| 57 } | 57 } |
| 58 return kSuccess; | 58 return kSuccess; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Option
s& options) { | |
| 62 // Create the swizzler | |
| 63 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(dstInfo, this->getInf
o(), fMasks, | |
| 64 this->bitsPerPixel(), options)); | |
| 65 | |
| 66 if (nullptr == fMaskSwizzler.get()) { | |
| 67 return false; | |
| 68 } | |
| 69 | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo, | 61 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo, |
| 74 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { | 62 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { |
| 75 // Initialize a the mask swizzler | 63 // Initialize the mask swizzler |
| 76 if (!this->initializeSwizzler(dstInfo, options)) { | 64 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(dstInfo, this->getInf
o(), fMasks, |
| 77 SkCodecPrintf("Error: cannot initialize swizzler.\n"); | 65 this->bitsPerPixel(), options)); |
| 78 return SkCodec::kInvalidConversion; | 66 SkASSERT(fMaskSwizzler); |
| 79 } | |
| 80 | 67 |
| 81 return SkCodec::kSuccess; | 68 return SkCodec::kSuccess; |
| 82 } | 69 } |
| 83 | 70 |
| 84 /* | 71 /* |
| 85 * Performs the decoding | 72 * Performs the decoding |
| 86 */ | 73 */ |
| 87 int SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo, | 74 int SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo, |
| 88 void* dst, size_t dstRowBytes, | 75 void* dst, size_t dstRowBytes, |
| 89 const Options& opts) { | 76 const Options& opts) { |
| 90 // Iterate over rows of the image | 77 // Iterate over rows of the image |
| 91 uint8_t* srcRow = fSrcBuffer.get(); | 78 uint8_t* srcRow = fSrcBuffer.get(); |
| 92 const int height = dstInfo.height(); | 79 const int height = dstInfo.height(); |
| 93 for (int y = 0; y < height; y++) { | 80 for (int y = 0; y < height; y++) { |
| 94 // Read a row of the input | 81 // Read a row of the input |
| 95 if (this->stream()->read(srcRow, fSrcRowBytes) != fSrcRowBytes) { | 82 if (this->stream()->read(srcRow, fSrcRowBytes) != fSrcRowBytes) { |
| 96 SkCodecPrintf("Warning: incomplete input stream.\n"); | 83 SkCodecPrintf("Warning: incomplete input stream.\n"); |
| 97 return y; | 84 return y; |
| 98 } | 85 } |
| 99 | 86 |
| 100 // Decode the row in destination format | 87 // Decode the row in destination format |
| 101 uint32_t row = this->getDstRow(y, height); | 88 uint32_t row = this->getDstRow(y, height); |
| 102 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); | 89 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); |
| 103 fMaskSwizzler->swizzle(dstRow, srcRow); | 90 fMaskSwizzler->swizzle(dstRow, srcRow); |
| 104 } | 91 } |
| 105 | 92 |
| 106 // Finished decoding the entire image | 93 // Finished decoding the entire image |
| 107 return height; | 94 return height; |
| 108 } | 95 } |
| OLD | NEW |