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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1220733013: SkCodec no longer inherits from SkImageGenerator. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Manually handle the lifetime of fScanlineDecoder. Created 5 years, 5 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 | « bench/subset/SubsetZoomBench.cpp ('k') | include/codec/SkCodec.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 "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "SamplePipeControllers.h" 9 #include "SamplePipeControllers.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 SkBitmap bitmap; 136 SkBitmap bitmap;
137 if (!bitmap.tryAllocPixels(decodeInfo, NULL, colorTable.get())) { 137 if (!bitmap.tryAllocPixels(decodeInfo, NULL, colorTable.get())) {
138 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str( ), 138 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str( ),
139 decodeInfo.width(), decodeInfo.height()); 139 decodeInfo.width(), decodeInfo.height());
140 } 140 }
141 141
142 switch (fMode) { 142 switch (fMode) {
143 case kNormal_Mode: { 143 case kNormal_Mode: {
144 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB ytes(), NULL, 144 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB ytes(), NULL,
145 colorPtr, colorCountPtr)) { 145 colorPtr, colorCountPtr)) {
146 case SkImageGenerator::kSuccess: 146 case SkCodec::kSuccess:
147 // We consider incomplete to be valid, since we should still decode what is 147 // We consider incomplete to be valid, since we should still decode what is
148 // available. 148 // available.
149 case SkImageGenerator::kIncompleteInput: 149 case SkCodec::kIncompleteInput:
150 break; 150 break;
151 case SkImageGenerator::kInvalidConversion: 151 case SkCodec::kInvalidConversion:
152 return Error::Nonfatal("Incompatible colortype conversion"); 152 return Error::Nonfatal("Incompatible colortype conversion");
153 default: 153 default:
154 // Everything else is considered a failure. 154 // Everything else is considered a failure.
155 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); 155 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( ));
156 } 156 }
157 canvas->drawBitmap(bitmap, 0, 0); 157 canvas->drawBitmap(bitmap, 0, 0);
158 break; 158 break;
159 } 159 }
160 case kScanline_Mode: { 160 case kScanline_Mode: {
161 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decod eInfo, NULL, 161 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decod eInfo, NULL,
162 colorPtr, colorCountPtr); 162 colorPtr, colorCountPtr);
163 if (NULL == scanlineDecoder) { 163 if (NULL == scanlineDecoder) {
164 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); 164 return Error::Nonfatal("Cannot use scanline decoder for all imag es");
165 } 165 }
166 const SkImageGenerator::Result result = scanlineDecoder->getScanline s( 166 const SkCodec::Result result = scanlineDecoder->getScanlines(
167 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() ); 167 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() );
168 switch (result) { 168 switch (result) {
169 case SkImageGenerator::kSuccess: 169 case SkCodec::kSuccess:
170 case SkImageGenerator::kIncompleteInput: 170 case SkCodec::kIncompleteInput:
171 break; 171 break;
172 default: 172 default:
173 return SkStringPrintf("%s failed with error message %d", 173 return SkStringPrintf("%s failed with error message %d",
174 fPath.c_str(), (int) result); 174 fPath.c_str(), (int) result);
175 } 175 }
176 canvas->drawBitmap(bitmap, 0, 0); 176 canvas->drawBitmap(bitmap, 0, 0);
177 break; 177 break;
178 } 178 }
179 case kScanline_Subset_Mode: { 179 case kScanline_Subset_Mode: {
180 //this mode decodes the image in divisor*divisor subsets, using a sc anline decoder 180 //this mode decodes the image in divisor*divisor subsets, using a sc anline decoder
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 NULL, colorPtr, colorCountPtr); 224 NULL, colorPtr, colorCountPtr);
225 if (NULL == subsetScanlineDecoder) { 225 if (NULL == subsetScanlineDecoder) {
226 if (x == 0 && y == 0) { 226 if (x == 0 && y == 0) {
227 //first try, image may not be compatible 227 //first try, image may not be compatible
228 return Error::Nonfatal("Cannot use scanline decoder for all images"); 228 return Error::Nonfatal("Cannot use scanline decoder for all images");
229 } else { 229 } else {
230 return "Error scanline decoder is NULL"; 230 return "Error scanline decoder is NULL";
231 } 231 }
232 } 232 }
233 //skip to first line of subset 233 //skip to first line of subset
234 const SkImageGenerator::Result skipResult = 234 const SkCodec::Result skipResult =
235 subsetScanlineDecoder->skipScanlines(y); 235 subsetScanlineDecoder->skipScanlines(y);
236 switch (skipResult) { 236 switch (skipResult) {
237 case SkImageGenerator::kSuccess: 237 case SkCodec::kSuccess:
238 case SkImageGenerator::kIncompleteInput: 238 case SkCodec::kIncompleteInput:
239 break; 239 break;
240 default: 240 default:
241 return SkStringPrintf("%s failed after attempting to skip %d scanlines" 241 return SkStringPrintf("%s failed after attempting to skip %d scanlines"
242 "with error message %d", fPath.c_str(), y, ( int) skipResult); 242 "with error message %d", fPath.c_str(), y, ( int) skipResult);
243 } 243 }
244 //create and set size of subsetBm 244 //create and set size of subsetBm
245 SkBitmap subsetBm; 245 SkBitmap subsetBm;
246 SkIRect bounds = SkIRect::MakeWH(subsetWidth, subsetHeight); 246 SkIRect bounds = SkIRect::MakeWH(subsetWidth, subsetHeight);
247 bounds.setXYWH(0, 0, currentSubsetWidth, currentSubsetHeight ); 247 bounds.setXYWH(0, 0, currentSubsetWidth, currentSubsetHeight );
248 SkAssertResult(largestSubsetBm.extractSubset(&subsetBm, boun ds)); 248 SkAssertResult(largestSubsetBm.extractSubset(&subsetBm, boun ds));
249 SkAutoLockPixels autlockSubsetBm(subsetBm, true); 249 SkAutoLockPixels autlockSubsetBm(subsetBm, true);
250 const SkImageGenerator::Result subsetResult = 250 const SkCodec::Result subsetResult =
251 subsetScanlineDecoder->getScanlines(buffer, currentSubse tHeight, rowBytes); 251 subsetScanlineDecoder->getScanlines(buffer, currentSubse tHeight, rowBytes);
252 switch (subsetResult) { 252 switch (subsetResult) {
253 case SkImageGenerator::kSuccess: 253 case SkCodec::kSuccess:
254 case SkImageGenerator::kIncompleteInput: 254 case SkCodec::kIncompleteInput:
255 break; 255 break;
256 default: 256 default:
257 return SkStringPrintf("%s failed with error message %d", 257 return SkStringPrintf("%s failed with error message %d",
258 fPath.c_str(), (int) subsetResult); 258 fPath.c_str(), (int) subsetResult);
259 } 259 }
260 const size_t bpp = decodeInfo.bytesPerPixel(); 260 const size_t bpp = decodeInfo.bytesPerPixel();
261 /* 261 /*
262 * we copy all the lines at once becuase when calling getSca nlines for 262 * we copy all the lines at once becuase when calling getSca nlines for
263 * interlaced pngs the entire image must be read regardless of the number 263 * interlaced pngs the entire image must be read regardless of the number
264 * of lines requested. Reading an interlaced png in a loop, line-by-line, would 264 * of lines requested. Reading an interlaced png in a loop, line-by-line, would
(...skipping 23 matching lines...) Expand all
288 288
289 // Decode odd stripes 289 // Decode odd stripes
290 SkScanlineDecoder* decoder = codec->getScanlineDecoder(decodeInfo, N ULL, colorPtr, 290 SkScanlineDecoder* decoder = codec->getScanlineDecoder(decodeInfo, N ULL, colorPtr,
291 colorCountPtr); 291 colorCountPtr);
292 if (NULL == decoder) { 292 if (NULL == decoder) {
293 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); 293 return Error::Nonfatal("Cannot use scanline decoder for all imag es");
294 } 294 }
295 for (int i = 0; i < numStripes; i += 2) { 295 for (int i = 0; i < numStripes; i += 2) {
296 // Skip a stripe 296 // Skip a stripe
297 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height); 297 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height);
298 SkImageGenerator::Result result = decoder->skipScanlines(linesTo Skip); 298 SkCodec::Result result = decoder->skipScanlines(linesToSkip);
299 switch (result) { 299 switch (result) {
300 case SkImageGenerator::kSuccess: 300 case SkCodec::kSuccess:
301 case SkImageGenerator::kIncompleteInput: 301 case SkCodec::kIncompleteInput:
302 break; 302 break;
303 default: 303 default:
304 return SkStringPrintf("Cannot skip scanlines for %s.", f Path.c_str()); 304 return SkStringPrintf("Cannot skip scanlines for %s.", f Path.c_str());
305 } 305 }
306 306
307 // Read a stripe 307 // Read a stripe
308 const int startY = (i + 1) * stripeHeight; 308 const int startY = (i + 1) * stripeHeight;
309 const int linesToRead = SkTMin(stripeHeight, height - startY); 309 const int linesToRead = SkTMin(stripeHeight, height - startY);
310 if (linesToRead > 0) { 310 if (linesToRead > 0) {
311 result = decoder->getScanlines(bitmap.getAddr(0, startY), 311 result = decoder->getScanlines(bitmap.getAddr(0, startY),
312 linesToRead, bitmap.rowBytes()); 312 linesToRead, bitmap.rowBytes());
313 switch (result) { 313 switch (result) {
314 case SkImageGenerator::kSuccess: 314 case SkCodec::kSuccess:
315 case SkImageGenerator::kIncompleteInput: 315 case SkCodec::kIncompleteInput:
316 break; 316 break;
317 default: 317 default:
318 return SkStringPrintf("Cannot get scanlines for %s." , fPath.c_str()); 318 return SkStringPrintf("Cannot get scanlines for %s." , fPath.c_str());
319 } 319 }
320 } 320 }
321 } 321 }
322 322
323 // Decode even stripes 323 // Decode even stripes
324 decoder = codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colo rCountPtr); 324 decoder = codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colo rCountPtr);
325 if (NULL == decoder) { 325 if (NULL == decoder) {
326 return "Failed to create second scanline decoder."; 326 return "Failed to create second scanline decoder.";
327 } 327 }
328 for (int i = 0; i < numStripes; i += 2) { 328 for (int i = 0; i < numStripes; i += 2) {
329 // Read a stripe 329 // Read a stripe
330 const int startY = i * stripeHeight; 330 const int startY = i * stripeHeight;
331 const int linesToRead = SkTMin(stripeHeight, height - startY); 331 const int linesToRead = SkTMin(stripeHeight, height - startY);
332 SkImageGenerator::Result result = decoder->getScanlines(bitmap.g etAddr(0, startY), 332 SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0, startY),
333 linesToRead, bitmap.rowBytes()); 333 linesToRead, bitmap.rowBytes());
334 switch (result) { 334 switch (result) {
335 case SkImageGenerator::kSuccess: 335 case SkCodec::kSuccess:
336 case SkImageGenerator::kIncompleteInput: 336 case SkCodec::kIncompleteInput:
337 break; 337 break;
338 default: 338 default:
339 return SkStringPrintf("Cannot get scanlines for %s.", fP ath.c_str()); 339 return SkStringPrintf("Cannot get scanlines for %s.", fP ath.c_str());
340 } 340 }
341 341
342 // Skip a stripe 342 // Skip a stripe
343 const int linesToSkip = SkTMin(stripeHeight, height - (i + 1) * stripeHeight); 343 const int linesToSkip = SkTMin(stripeHeight, height - (i + 1) * stripeHeight);
344 if (linesToSkip > 0) { 344 if (linesToSkip > 0) {
345 result = decoder->skipScanlines(linesToSkip); 345 result = decoder->skipScanlines(linesToSkip);
346 switch (result) { 346 switch (result) {
347 case SkImageGenerator::kSuccess: 347 case SkCodec::kSuccess:
348 case SkImageGenerator::kIncompleteInput: 348 case SkCodec::kIncompleteInput:
349 break; 349 break;
350 default: 350 default:
351 return SkStringPrintf("Cannot skip scanlines for %s. ", fPath.c_str()); 351 return SkStringPrintf("Cannot skip scanlines for %s. ", fPath.c_str());
352 } 352 }
353 } 353 }
354 } 354 }
355 canvas->drawBitmap(bitmap, 0, 0); 355 canvas->drawBitmap(bitmap, 0, 0);
356 break; 356 break;
357 } 357 }
358 } 358 }
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 skr.visit<void>(i, drawsAsSingletonPictures); 989 skr.visit<void>(i, drawsAsSingletonPictures);
990 } 990 }
991 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 991 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
992 992
993 canvas->drawPicture(macroPic); 993 canvas->drawPicture(macroPic);
994 return ""; 994 return "";
995 }); 995 });
996 } 996 }
997 997
998 } // namespace DM 998 } // namespace DM
OLDNEW
« no previous file with comments | « bench/subset/SubsetZoomBench.cpp ('k') | include/codec/SkCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698