| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 case kN32_SkColorType: | 79 case kN32_SkColorType: |
| 80 case kRGB_565_SkColorType: | 80 case kRGB_565_SkColorType: |
| 81 case kGray_8_SkColorType: | 81 case kGray_8_SkColorType: |
| 82 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op
ts.fZeroInitialized, | 82 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op
ts.fZeroInitialized, |
| 83 this->getInfo()); | 83 this->getInfo()); |
| 84 default: | 84 default: |
| 85 return nullptr; | 85 return nullptr; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { | 89 bool SkWbmpCodec::readRow(uint8_t* row) { |
| 90 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { | 90 return this->stream()->read(row, fSrcRowBytes) == fSrcRowBytes; |
| 91 return kIncompleteInput; | |
| 92 } | |
| 93 return kSuccess; | |
| 94 } | 91 } |
| 95 | 92 |
| 96 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) | 93 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) |
| 97 : INHERITED(info, stream) | 94 : INHERITED(info, stream) |
| 98 , fSrcRowBytes(get_src_row_bytes(this->getInfo().width())) | 95 , fSrcRowBytes(get_src_row_bytes(this->getInfo().width())) |
| 99 , fColorTable(nullptr) | 96 , fColorTable(nullptr) |
| 100 , fSwizzler(nullptr) | 97 , fSwizzler(nullptr) |
| 101 {} | 98 {} |
| 102 | 99 |
| 103 SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const { | 100 SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const { |
| 104 return kWBMP_SkEncodedFormat; | 101 return kWBMP_SkEncodedFormat; |
| 105 } | 102 } |
| 106 | 103 |
| 107 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, | 104 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, |
| 108 void* dst, | 105 void* dst, |
| 109 size_t rowBytes, | 106 size_t rowBytes, |
| 110 const Options& options, | 107 const Options& options, |
| 111 SkPMColor ctable[], | 108 SkPMColor ctable[], |
| 112 int* ctableCount) { | 109 int* ctableCount, |
| 110 int* rowsDecoded) { |
| 113 if (options.fSubset) { | 111 if (options.fSubset) { |
| 114 // Subsets are not supported. | 112 // Subsets are not supported. |
| 115 return kUnimplemented; | 113 return kUnimplemented; |
| 116 } | 114 } |
| 117 if (info.dimensions() != this->getInfo().dimensions()) { | 115 if (info.dimensions() != this->getInfo().dimensions()) { |
| 118 return kInvalidScale; | 116 return kInvalidScale; |
| 119 } | 117 } |
| 120 | 118 |
| 121 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { | 119 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { |
| 122 return kInvalidConversion; | 120 return kInvalidConversion; |
| 123 } | 121 } |
| 124 | 122 |
| 125 // Prepare a color table if necessary | 123 // Prepare a color table if necessary |
| 126 setup_color_table(info.colorType(), ctable, ctableCount); | 124 setup_color_table(info.colorType(), ctable, ctableCount); |
| 127 | 125 |
| 128 | 126 |
| 129 // Initialize the swizzler | 127 // Initialize the swizzler |
| 130 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op
tions)); | 128 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op
tions)); |
| 131 if (nullptr == swizzler.get()) { | 129 if (nullptr == swizzler.get()) { |
| 132 return kInvalidConversion; | 130 return kInvalidConversion; |
| 133 } | 131 } |
| 134 | 132 |
| 135 // Perform the decode | 133 // Perform the decode |
| 136 SkISize size = info.dimensions(); | 134 SkISize size = info.dimensions(); |
| 137 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); | 135 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); |
| 138 void* dstRow = dst; | 136 void* dstRow = dst; |
| 139 for (int y = 0; y < size.height(); ++y) { | 137 for (int y = 0; y < size.height(); ++y) { |
| 140 Result rowResult = this->readRow(src.get()); | 138 if (!this->readRow(src.get())) { |
| 141 if (kSuccess != rowResult) { | 139 *rowsDecoded = y; |
| 142 return rowResult; | 140 return kIncompleteInput; |
| 143 } | 141 } |
| 144 swizzler->swizzle(dstRow, src.get()); | 142 swizzler->swizzle(dstRow, src.get()); |
| 145 dstRow = SkTAddOffset<void>(dstRow, rowBytes); | 143 dstRow = SkTAddOffset<void>(dstRow, rowBytes); |
| 146 } | 144 } |
| 147 return kSuccess; | 145 return kSuccess; |
| 148 } | 146 } |
| 149 | 147 |
| 150 bool SkWbmpCodec::IsWbmp(SkStream* stream) { | 148 bool SkWbmpCodec::IsWbmp(SkStream* stream) { |
| 151 return read_header(stream, nullptr); | 149 return read_header(stream, nullptr); |
| 152 } | 150 } |
| 153 | 151 |
| 154 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { | 152 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { |
| 155 SkAutoTDelete<SkStream> streamDeleter(stream); | 153 SkAutoTDelete<SkStream> streamDeleter(stream); |
| 156 SkISize size; | 154 SkISize size; |
| 157 if (!read_header(stream, &size)) { | 155 if (!read_header(stream, &size)) { |
| 158 return nullptr; | 156 return nullptr; |
| 159 } | 157 } |
| 160 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), | 158 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), |
| 161 kGray_8_SkColorType, kOpaque_SkAlphaType); | 159 kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 162 return new SkWbmpCodec(info, streamDeleter.detach()); | 160 return new SkWbmpCodec(info, streamDeleter.detach()); |
| 163 } | 161 } |
| 164 | 162 |
| 165 SkCodec::Result SkWbmpCodec::onGetScanlines(void* dst, int count, size_t dstRowB
ytes) { | 163 int SkWbmpCodec::onGetScanlines(void* dst, int count, size_t dstRowBytes) { |
| 166 void* dstRow = dst; | 164 void* dstRow = dst; |
| 167 for (int y = 0; y < count; ++y) { | 165 for (int y = 0; y < count; ++y) { |
| 168 Result rowResult = this->readRow(fSrcBuffer.get()); | 166 if (!this->readRow(fSrcBuffer.get())) { |
| 169 if (kSuccess != rowResult) { | 167 return y; |
| 170 return rowResult; | |
| 171 } | 168 } |
| 172 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); | 169 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); |
| 173 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); | 170 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); |
| 174 } | 171 } |
| 175 return kSuccess; | 172 return count; |
| 176 } | 173 } |
| 177 | 174 |
| 178 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, | 175 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
| 179 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun
t) { | 176 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun
t) { |
| 180 if (options.fSubset) { | 177 if (options.fSubset) { |
| 181 // Subsets are not supported. | 178 // Subsets are not supported. |
| 182 return kUnimplemented; | 179 return kUnimplemented; |
| 183 } | 180 } |
| 184 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | 181 if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
| 185 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI
nfo)) { | 182 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI
nfo)) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 203 fSwizzler.reset(this->initializeSwizzler(dstInfo, | 200 fSwizzler.reset(this->initializeSwizzler(dstInfo, |
| 204 get_color_ptr(fColorTable.get()), options)); | 201 get_color_ptr(fColorTable.get()), options)); |
| 205 if (nullptr == fSwizzler.get()) { | 202 if (nullptr == fSwizzler.get()) { |
| 206 return kInvalidConversion; | 203 return kInvalidConversion; |
| 207 } | 204 } |
| 208 | 205 |
| 209 fSrcBuffer.reset(fSrcRowBytes); | 206 fSrcBuffer.reset(fSrcRowBytes); |
| 210 | 207 |
| 211 return kSuccess; | 208 return kSuccess; |
| 212 } | 209 } |
| 213 | |
| OLD | NEW |