| 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 "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 59 } |
| 60 if (!read_mbf(stream, &height) || height > 0xFFFF || !height) { | 60 if (!read_mbf(stream, &height) || height > 0xFFFF || !height) { |
| 61 return false; | 61 return false; |
| 62 } | 62 } |
| 63 if (size) { | 63 if (size) { |
| 64 *size = SkISize::Make(SkToS32(width), SkToS32(height)); | 64 *size = SkISize::Make(SkToS32(width), SkToS32(height)); |
| 65 } | 65 } |
| 66 return true; | 66 return true; |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool SkWbmpCodec::handleRewind() { | 69 bool SkWbmpCodec::onRewind() { |
| 70 SkCodec::RewindState rewindState = this->rewindIfNeeded(); | 70 return read_header(this->stream(), NULL); |
| 71 if (rewindState == kCouldNotRewind_RewindState) { | |
| 72 return false; | |
| 73 } else if (rewindState == kRewound_RewindState) { | |
| 74 if (!read_header(this->stream(), NULL)) { | |
| 75 return false; | |
| 76 } | |
| 77 } | |
| 78 return true; | |
| 79 } | 71 } |
| 80 | 72 |
| 81 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, | 73 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, |
| 82 const SkPMColor* ctable, const Options& opts) { | 74 const SkPMColor* ctable, const Options& opts) { |
| 83 // TODO (msarett): Reenable support for 565 if it is desired | 75 // TODO (msarett): Reenable support for 565 if it is desired |
| 84 // skbug.com/3683 | 76 // skbug.com/3683 |
| 85 | 77 |
| 86 // Create the swizzler based on the desired color type | 78 // Create the swizzler based on the desired color type |
| 87 switch (info.colorType()) { | 79 switch (info.colorType()) { |
| 88 case kIndex_8_SkColorType: | 80 case kIndex_8_SkColorType: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 110 SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const { | 102 SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const { |
| 111 return kWBMP_SkEncodedFormat; | 103 return kWBMP_SkEncodedFormat; |
| 112 } | 104 } |
| 113 | 105 |
| 114 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, | 106 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, |
| 115 void* dst, | 107 void* dst, |
| 116 size_t rowBytes, | 108 size_t rowBytes, |
| 117 const Options& options, | 109 const Options& options, |
| 118 SkPMColor ctable[], | 110 SkPMColor ctable[], |
| 119 int* ctableCount) { | 111 int* ctableCount) { |
| 120 if (!this->handleRewind()) { | 112 if (!this->rewindIfNeeded()) { |
| 121 return kCouldNotRewind; | 113 return kCouldNotRewind; |
| 122 } | 114 } |
| 123 if (options.fSubset) { | 115 if (options.fSubset) { |
| 124 // Subsets are not supported. | 116 // Subsets are not supported. |
| 125 return kUnimplemented; | 117 return kUnimplemented; |
| 126 } | 118 } |
| 127 if (info.dimensions() != this->getInfo().dimensions()) { | 119 if (info.dimensions() != this->getInfo().dimensions()) { |
| 128 return kInvalidScale; | 120 return kInvalidScale; |
| 129 } | 121 } |
| 130 | 122 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 182 } |
| 191 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); | 183 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); |
| 192 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); | 184 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); |
| 193 } | 185 } |
| 194 return SkCodec::kSuccess; | 186 return SkCodec::kSuccess; |
| 195 } | 187 } |
| 196 | 188 |
| 197 SkCodec::Result onStart(const SkImageInfo& dstInfo, | 189 SkCodec::Result onStart(const SkImageInfo& dstInfo, |
| 198 const SkCodec::Options& options, SkPMColor inputColorTable[], | 190 const SkCodec::Options& options, SkPMColor inputColorTable[], |
| 199 int* inputColorCount) { | 191 int* inputColorCount) { |
| 200 if (!fCodec->handleRewind()) { | 192 if (!fCodec->rewindIfNeeded()) { |
| 201 return SkCodec::kCouldNotRewind; | 193 return SkCodec::kCouldNotRewind; |
| 202 } | 194 } |
| 203 if (options.fSubset) { | 195 if (options.fSubset) { |
| 204 // Subsets are not supported. | 196 // Subsets are not supported. |
| 205 return SkCodec::kUnimplemented; | 197 return SkCodec::kUnimplemented; |
| 206 } | 198 } |
| 207 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | 199 if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
| 208 return SkCodec::kInvalidScale; | 200 return SkCodec::kInvalidScale; |
| 209 } | 201 } |
| 210 | 202 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 238 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { | 230 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { |
| 239 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( | 231 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( |
| 240 SkWbmpCodec::NewFromStream(stream))); | 232 SkWbmpCodec::NewFromStream(stream))); |
| 241 if (!codec) { | 233 if (!codec) { |
| 242 return NULL; | 234 return NULL; |
| 243 } | 235 } |
| 244 | 236 |
| 245 // Return the new scanline decoder | 237 // Return the new scanline decoder |
| 246 return SkNEW_ARGS(SkWbmpScanlineDecoder, (codec.detach())); | 238 return SkNEW_ARGS(SkWbmpScanlineDecoder, (codec.detach())); |
| 247 } | 239 } |
| OLD | NEW |