Chromium Code Reviews| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 if (!conversion_possible(dstInfo, this->getInfo())) { | 45 if (!conversion_possible(dstInfo, this->getInfo())) { |
| 46 SkCodecPrintf("Error: cannot convert input type to output type.\n"); | 46 SkCodecPrintf("Error: cannot convert input type to output type.\n"); |
| 47 return kInvalidConversion; | 47 return kInvalidConversion; |
| 48 } | 48 } |
| 49 | 49 |
| 50 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol orCount); | 50 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol orCount); |
| 51 if (kSuccess != result) { | 51 if (kSuccess != result) { |
| 52 return result; | 52 return result; |
| 53 } | 53 } |
| 54 | 54 |
| 55 return this->decodeRows(dstInfo, dst, dstRowBytes, opts); | 55 uint32_t rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts); |
| 56 if (rows != dstInfo.height()) { | |
| 57 this->setIncompleteScanlines(dstInfo.height() - rows); | |
| 58 return kIncompleteInput; | |
| 59 } | |
| 60 return kSuccess; | |
| 56 } | 61 } |
| 57 | 62 |
| 58 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) { | 63 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) { |
| 59 // Create the swizzler | 64 // Create the swizzler |
| 60 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler( | 65 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler( |
| 61 dstInfo, this->getInfo(), fMasks, this->bitsPerPixel())); | 66 dstInfo, this->getInfo(), fMasks, this->bitsPerPixel())); |
| 62 | 67 |
| 63 if (nullptr == fMaskSwizzler.get()) { | 68 if (nullptr == fMaskSwizzler.get()) { |
| 64 return false; | 69 return false; |
| 65 } | 70 } |
| 66 | 71 |
| 67 return true; | 72 return true; |
| 68 } | 73 } |
| 69 | 74 |
| 70 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo, | 75 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo, |
| 71 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) { | 76 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) { |
| 72 // Initialize a the mask swizzler | 77 // Initialize a the mask swizzler |
| 73 if (!this->initializeSwizzler(dstInfo)) { | 78 if (!this->initializeSwizzler(dstInfo)) { |
| 74 SkCodecPrintf("Error: cannot initialize swizzler.\n"); | 79 SkCodecPrintf("Error: cannot initialize swizzler.\n"); |
| 75 return SkCodec::kInvalidConversion; | 80 return SkCodec::kInvalidConversion; |
| 76 } | 81 } |
| 77 | 82 |
| 78 return SkCodec::kSuccess; | 83 return SkCodec::kSuccess; |
| 79 } | 84 } |
| 80 | 85 |
| 81 /* | 86 /* |
| 82 * Performs the decoding | 87 * Performs the decoding |
| 83 */ | 88 */ |
| 84 SkCodec::Result SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo, | 89 uint32_t SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo, |
| 85 void* dst, size_t dstRowBytes, | 90 void* dst, size_t dstRowBytes, |
| 86 const Options& opts) { | 91 const Options& opts) { |
| 87 // Iterate over rows of the image | 92 // Iterate over rows of the image |
| 88 uint8_t* srcRow = fSrcBuffer.get(); | 93 uint8_t* srcRow = fSrcBuffer.get(); |
| 89 const int height = dstInfo.height(); | 94 const int height = dstInfo.height(); |
| 90 for (int y = 0; y < height; y++) { | 95 for (int y = 0; y < height; y++) { |
| 91 // Read a row of the input | 96 // Read a row of the input |
| 92 if (this->stream()->read(srcRow, fSrcRowBytes) != fSrcRowBytes) { | 97 if (this->stream()->read(srcRow, fSrcRowBytes) != fSrcRowBytes) { |
| 93 SkCodecPrintf("Warning: incomplete input stream.\n"); | 98 SkCodecPrintf("Warning: incomplete input stream.\n"); |
| 94 // Fill the destination image on failure | 99 return y; |
|
scroggo
2015/09/22 18:02:48
It seems like we could have called Fill here, righ
msarett
2015/09/23 13:22:40
Yes. It was my intention to make getPixels() take
| |
| 95 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y); | |
| 96 uint32_t fillColor = get_fill_color_or_index(dstInfo.alphaType()); | |
| 97 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, height - y, | |
| 98 fillColor, nullptr, opts.fZeroInitialized); | |
| 99 return kIncompleteInput; | |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Decode the row in destination format | 102 // Decode the row in destination format |
| 103 uint32_t row = this->getDstRow(y, height); | 103 uint32_t row = this->getDstRow(y, height); |
| 104 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); | 104 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); |
| 105 fMaskSwizzler->swizzle(dstRow, srcRow); | 105 fMaskSwizzler->swizzle(dstRow, srcRow); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Finished decoding the entire image | 108 // Finished decoding the entire image |
| 109 return kSuccess; | 109 return height; |
| 110 } | 110 } |
| OLD | NEW |