Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/codec/SkScaledCodec.cpp

Issue 1332053002: Fill incomplete images in SkCodec parent class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use aligned memory in swizzler test Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/codec/SkSampler.cpp ('k') | src/codec/SkSwizzler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkScaledCodec.h" 9 #include "SkScaledCodec.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 191 }
192 if (sampleYPtr) { 192 if (sampleYPtr) {
193 *sampleYPtr = sampleY; 193 *sampleYPtr = sampleY;
194 } 194 }
195 } 195 }
196 196
197 // TODO: Implement subsetting in onGetPixels which works when and when not sampl ing 197 // TODO: Implement subsetting in onGetPixels which works when and when not sampl ing
198 198
199 SkCodec::Result SkScaledCodec::onGetPixels(const SkImageInfo& requestedInfo, voi d* dst, 199 SkCodec::Result SkScaledCodec::onGetPixels(const SkImageInfo& requestedInfo, voi d* dst,
200 size_t rowBytes, const Options& optio ns, 200 size_t rowBytes, const Options& optio ns,
201 SkPMColor ctable[], int* ctableCount) { 201 SkPMColor ctable[], int* ctableCount,
202 int* rowsDecoded) {
202 203
203 if (options.fSubset) { 204 if (options.fSubset) {
204 // Subsets are not supported. 205 // Subsets are not supported.
205 return kUnimplemented; 206 return kUnimplemented;
206 } 207 }
207 208
208 if (fCodec->dimensionsSupported(requestedInfo.dimensions())) { 209 if (fCodec->dimensionsSupported(requestedInfo.dimensions())) {
210 // Make sure that the parent class does not fill on an incomplete decode , since
211 // fCodec will take care of filling the uninitialized lines.
212 *rowsDecoded = requestedInfo.height();
209 return fCodec->getPixels(requestedInfo, dst, rowBytes, &options, ctable, ctableCount); 213 return fCodec->getPixels(requestedInfo, dst, rowBytes, &options, ctable, ctableCount);
210 } 214 }
211 215
212 // scaling requested 216 // scaling requested
213 int sampleX; 217 int sampleX;
214 int sampleY; 218 int sampleY;
215 if (!scaling_supported(requestedInfo.dimensions(), fCodec->getInfo().dimensi ons(), 219 if (!scaling_supported(requestedInfo.dimensions(), fCodec->getInfo().dimensi ons(),
216 &sampleX, &sampleY)) { 220 &sampleX, &sampleY)) {
217 // onDimensionsSupported would have returned false, meaning we should ne ver reach here. 221 // onDimensionsSupported would have returned false, meaning we should ne ver reach here.
218 SkASSERT(false); 222 SkASSERT(false);
219 return kInvalidScale; 223 return kInvalidScale;
220 } 224 }
221 225
222 // set first sample pixel in y direction 226 // set first sample pixel in y direction
223 const int Y0 = get_start_coord(sampleY); 227 const int Y0 = get_start_coord(sampleY);
224 228
225 const int dstHeight = requestedInfo.height(); 229 const int dstHeight = requestedInfo.height();
226 const int srcWidth = fCodec->getInfo().width(); 230 const int srcWidth = fCodec->getInfo().width();
227 const int srcHeight = fCodec->getInfo().height(); 231 const int srcHeight = fCodec->getInfo().height();
228 232
229 const SkImageInfo info = requestedInfo.makeWH(srcWidth, srcHeight); 233 const SkImageInfo info = requestedInfo.makeWH(srcWidth, srcHeight);
230 234
231 Result result = fCodec->startScanlineDecode(info, &options, ctable, ctableCo unt); 235 Result result = fCodec->startScanlineDecode(info, &options, ctable, ctableCo unt);
232 236
233 if (kSuccess != result) { 237 if (kSuccess != result) {
234 return result; 238 return result;
235 } 239 }
236 240
237 SkSampler* sampler = fCodec->getSampler(); 241 SkSampler* sampler = fCodec->getSampler(true);
238 if (!sampler) { 242 if (!sampler) {
239 return kUnimplemented; 243 return kUnimplemented;
240 } 244 }
241 245
242 if (sampler->setSampleX(sampleX) != requestedInfo.width()) { 246 if (sampler->setSampleX(sampleX) != requestedInfo.width()) {
243 return kInvalidScale; 247 return kInvalidScale;
244 } 248 }
245 249
246 switch(fCodec->getScanlineOrder()) { 250 switch(fCodec->getScanlineOrder()) {
247 case SkCodec::kTopDown_SkScanlineOrder: { 251 case SkCodec::kTopDown_SkScanlineOrder: {
248 result = fCodec->skipScanlines(Y0); 252 if (!fCodec->skipScanlines(Y0)) {
249 if (kSuccess != result && kIncompleteInput != result) { 253 *rowsDecoded = 0;
250 return result; 254 return kIncompleteInput;
251 } 255 }
252 for (int y = 0; y < dstHeight; y++) { 256 for (int y = 0; y < dstHeight; y++) {
253 result = fCodec->getScanlines(dst, 1, rowBytes); 257 if (1 != fCodec->getScanlines(dst, 1, rowBytes)) {
254 if (kSuccess != result && kIncompleteInput != result) { 258 // The failed call to getScanlines() will take care of
255 return result; 259 // filling the failed row, so we indicate that we have
260 // decoded (y + 1) rows.
261 *rowsDecoded = y + 1;
262 return kIncompleteInput;
256 } 263 }
257 if (y < dstHeight - 1) { 264 if (y < dstHeight - 1) {
258 result = fCodec->skipScanlines(sampleY - 1); 265 if (!fCodec->skipScanlines(sampleY - 1)) {
259 if (kSuccess != result && kIncompleteInput != result) { 266 *rowsDecoded = y + 1;
260 return result; 267 return kIncompleteInput;
261 } 268 }
262 } 269 }
263 dst = SkTAddOffset<void>(dst, rowBytes); 270 dst = SkTAddOffset<void>(dst, rowBytes);
264 } 271 }
265 return result; 272 return kSuccess;
266 } 273 }
267 case SkCodec::kBottomUp_SkScanlineOrder: 274 case SkCodec::kBottomUp_SkScanlineOrder:
268 case SkCodec::kOutOfOrder_SkScanlineOrder: { 275 case SkCodec::kOutOfOrder_SkScanlineOrder: {
269 for (int y = 0; y < srcHeight; y++) { 276 Result result = kSuccess;
277 int y;
278 for (y = 0; y < srcHeight; y++) {
270 int srcY = fCodec->nextScanline(); 279 int srcY = fCodec->nextScanline();
271 if (is_coord_necessary(srcY, sampleY, dstHeight)) { 280 if (is_coord_necessary(srcY, sampleY, dstHeight)) {
272 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co ord(srcY, sampleY)); 281 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co ord(srcY, sampleY));
273 result = fCodec->getScanlines(dstPtr, 1, rowBytes); 282 if (1 != fCodec->getScanlines(dstPtr, 1, rowBytes)) {
274 if (kSuccess != result && kIncompleteInput != result) { 283 result = kIncompleteInput;
275 return result; 284 break;
276 } 285 }
277 } else { 286 } else {
278 result = fCodec->skipScanlines(1); 287 if (!fCodec->skipScanlines(1)) {
279 if (kSuccess != result && kIncompleteInput != result) { 288 result = kIncompleteInput;
280 return result; 289 break;
281 } 290 }
282 } 291 }
283 } 292 }
293
294 // We handle filling uninitialized memory here instead of in the par ent class.
295 // The parent class does not know that we are sampling.
296 if (kIncompleteInput == result) {
297 const uint32_t fillValue = fCodec->getFillValue(requestedInfo.co lorType(),
298 requestedInfo.alphaType());
299 for (; y < srcHeight; y++) {
300 int srcY = fCodec->outputScanline(y);
301 if (is_coord_necessary(srcY, sampleY, dstHeight)) {
302 void* dstRow = SkTAddOffset<void>(dst,
303 rowBytes * get_dst_coord(srcY, sampleY));
304 SkSampler::Fill(requestedInfo.makeWH(requestedInfo.width (), 1), dstRow,
305 rowBytes, fillValue, options.fZeroInitialized);
306 }
307 }
308 *rowsDecoded = dstHeight;
309 }
284 return result; 310 return result;
285 } 311 }
286 case SkCodec::kNone_SkScanlineOrder: { 312 case SkCodec::kNone_SkScanlineOrder: {
287 SkAutoMalloc storage(srcHeight * rowBytes); 313 SkAutoMalloc storage(srcHeight * rowBytes);
288 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); 314 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get());
289 result = fCodec->getScanlines(storagePtr, srcHeight, rowBytes); 315 int scanlines = fCodec->getScanlines(storagePtr, srcHeight, rowBytes );
290 if (kSuccess != result && kIncompleteInput != result) {
291 return result;
292 }
293 storagePtr += Y0 * rowBytes; 316 storagePtr += Y0 * rowBytes;
294 for (int y = 0; y < dstHeight; y++) { 317 scanlines -= Y0;
318 int y = 0;
319 while (y < dstHeight && scanlines > 0) {
295 memcpy(dst, storagePtr, rowBytes); 320 memcpy(dst, storagePtr, rowBytes);
296 storagePtr += sampleY * rowBytes; 321 storagePtr += sampleY * rowBytes;
297 dst = SkTAddOffset<void>(dst, rowBytes); 322 dst = SkTAddOffset<void>(dst, rowBytes);
323 scanlines -= sampleY;
324 y++;
298 } 325 }
299 return result; 326 if (y < dstHeight) {
327 // fCodec has already handled filling uninitialized memory.
328 *rowsDecoded = dstHeight;
329 return kIncompleteInput;
330 }
331 return kSuccess;
300 } 332 }
301 default: 333 default:
302 SkASSERT(false); 334 SkASSERT(false);
303 return kUnimplemented; 335 return kUnimplemented;
304 } 336 }
305 } 337 }
338
339 uint32_t SkScaledCodec::onGetFillValue(SkColorType colorType, SkAlphaType alphaT ype) const {
340 return fCodec->onGetFillValue(colorType, alphaType);
341 }
342
343 SkCodec::SkScanlineOrder SkScaledCodec::onGetScanlineOrder() const {
344 return fCodec->onGetScanlineOrder();
345 }
OLDNEW
« no previous file with comments | « src/codec/SkSampler.cpp ('k') | src/codec/SkSwizzler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698