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 kRGB_565_SkColorType: | 79 case kRGB_565_SkColorType: |
80 case kGray_8_SkColorType: | 80 case kGray_8_SkColorType: |
81 break; | 81 break; |
82 default: | 82 default: |
83 return nullptr; | 83 return nullptr; |
84 } | 84 } |
85 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, | 85 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, |
86 opts.fZeroInitialized); | 86 opts.fZeroInitialized); |
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 | 115 |
118 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { | 116 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { |
119 return kInvalidConversion; | 117 return kInvalidConversion; |
120 } | 118 } |
121 | 119 |
122 // Prepare a color table if necessary | 120 // Prepare a color table if necessary |
123 setup_color_table(info.colorType(), ctable, ctableCount); | 121 setup_color_table(info.colorType(), ctable, ctableCount); |
124 | 122 |
125 // Initialize the swizzler | 123 // Initialize the swizzler |
126 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op
tions)); | 124 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op
tions)); |
127 if (nullptr == swizzler.get()) { | 125 if (nullptr == swizzler.get()) { |
128 return kInvalidConversion; | 126 return kInvalidConversion; |
129 } | 127 } |
130 | 128 |
131 // Perform the decode | 129 // Perform the decode |
132 SkISize size = info.dimensions(); | 130 SkISize size = info.dimensions(); |
133 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); | 131 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); |
134 void* dstRow = dst; | 132 void* dstRow = dst; |
135 for (int y = 0; y < size.height(); ++y) { | 133 for (int y = 0; y < size.height(); ++y) { |
136 Result rowResult = this->readRow(src.get()); | 134 if (!this->readRow(src.get())) { |
137 if (kSuccess != rowResult) { | 135 *rowsDecoded = y; |
138 return rowResult; | 136 return kIncompleteInput; |
139 } | 137 } |
140 swizzler->swizzle(dstRow, src.get()); | 138 swizzler->swizzle(dstRow, src.get()); |
141 dstRow = SkTAddOffset<void>(dstRow, rowBytes); | 139 dstRow = SkTAddOffset<void>(dstRow, rowBytes); |
142 } | 140 } |
143 return kSuccess; | 141 return kSuccess; |
144 } | 142 } |
145 | 143 |
146 bool SkWbmpCodec::IsWbmp(SkStream* stream) { | 144 bool SkWbmpCodec::IsWbmp(SkStream* stream) { |
147 return read_header(stream, nullptr); | 145 return read_header(stream, nullptr); |
148 } | 146 } |
149 | 147 |
150 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { | 148 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { |
151 SkAutoTDelete<SkStream> streamDeleter(stream); | 149 SkAutoTDelete<SkStream> streamDeleter(stream); |
152 SkISize size; | 150 SkISize size; |
153 if (!read_header(stream, &size)) { | 151 if (!read_header(stream, &size)) { |
154 return nullptr; | 152 return nullptr; |
155 } | 153 } |
156 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), | 154 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), |
157 kGray_8_SkColorType, kOpaque_SkAlphaType); | 155 kGray_8_SkColorType, kOpaque_SkAlphaType); |
158 return new SkWbmpCodec(info, streamDeleter.detach()); | 156 return new SkWbmpCodec(info, streamDeleter.detach()); |
159 } | 157 } |
160 | 158 |
161 SkCodec::Result SkWbmpCodec::onGetScanlines(void* dst, int count, size_t dstRowB
ytes) { | 159 int SkWbmpCodec::onGetScanlines(void* dst, int count, size_t dstRowBytes) { |
162 void* dstRow = dst; | 160 void* dstRow = dst; |
163 for (int y = 0; y < count; ++y) { | 161 for (int y = 0; y < count; ++y) { |
164 Result rowResult = this->readRow(fSrcBuffer.get()); | 162 if (!this->readRow(fSrcBuffer.get())) { |
165 if (kSuccess != rowResult) { | 163 return y; |
166 return rowResult; | |
167 } | 164 } |
168 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); | 165 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); |
169 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); | 166 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); |
170 } | 167 } |
171 return kSuccess; | 168 return count; |
172 } | 169 } |
173 | 170 |
174 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, | 171 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
175 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun
t) { | 172 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun
t) { |
176 if (options.fSubset) { | 173 if (options.fSubset) { |
177 // Subsets are not supported. | 174 // Subsets are not supported. |
178 return kUnimplemented; | 175 return kUnimplemented; |
179 } | 176 } |
180 | 177 |
181 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { | 178 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { |
(...skipping 12 matching lines...) Expand all Loading... |
194 fSwizzler.reset(this->initializeSwizzler(dstInfo, | 191 fSwizzler.reset(this->initializeSwizzler(dstInfo, |
195 get_color_ptr(fColorTable.get()), options)); | 192 get_color_ptr(fColorTable.get()), options)); |
196 if (nullptr == fSwizzler.get()) { | 193 if (nullptr == fSwizzler.get()) { |
197 return kInvalidConversion; | 194 return kInvalidConversion; |
198 } | 195 } |
199 | 196 |
200 fSrcBuffer.reset(fSrcRowBytes); | 197 fSrcBuffer.reset(fSrcRowBytes); |
201 | 198 |
202 return kSuccess; | 199 return kSuccess; |
203 } | 200 } |
204 | |
OLD | NEW |