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

Side by Side Diff: src/pdf/SkPDFImage.cpp

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase, just in case. Created 5 years, 11 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/pdf/SkPDFImage.h ('k') | src/pdf/SkPDFShader.cpp » ('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 2010 The Android Open Source Project 2 * Copyright 2010 The Android Open Source Project
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 "SkPDFImage.h" 8 #include "SkPDFImage.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 const SkIRect& srcRect, 232 const SkIRect& srcRect,
233 bool extractAlpha, bool* isTransparent) { 233 bool extractAlpha, bool* isTransparent) {
234 SkColorType colorType = bitmap.colorType(); 234 SkColorType colorType = bitmap.colorType();
235 if (extractAlpha && (kIndex_8_SkColorType == colorType || 235 if (extractAlpha && (kIndex_8_SkColorType == colorType ||
236 kRGB_565_SkColorType == colorType)) { 236 kRGB_565_SkColorType == colorType)) {
237 if (isTransparent != NULL) { 237 if (isTransparent != NULL) {
238 *isTransparent = false; 238 *isTransparent = false;
239 } 239 }
240 return NULL; 240 return NULL;
241 } 241 }
242 bool isOpaque = true;
243 bool transparent = extractAlpha;
244 SkStream* stream = NULL;
245 242
246 SkAutoLockPixels lock(bitmap); 243 SkAutoLockPixels lock(bitmap);
247 if (NULL == bitmap.getPixels()) { 244 if (NULL == bitmap.getPixels()) {
248 return NULL; 245 return NULL;
249 } 246 }
250 247
248 bool isOpaque = true;
249 bool transparent = extractAlpha;
250 SkAutoTDelete<SkStream> stream;
251
251 switch (colorType) { 252 switch (colorType) {
252 case kIndex_8_SkColorType: 253 case kIndex_8_SkColorType:
253 if (!extractAlpha) { 254 if (!extractAlpha) {
254 stream = extract_index8_image(bitmap, srcRect); 255 stream.reset(extract_index8_image(bitmap, srcRect));
255 } 256 }
256 break; 257 break;
257 case kARGB_4444_SkColorType: 258 case kARGB_4444_SkColorType:
258 stream = extract_argb4444_data(bitmap, srcRect, extractAlpha, 259 stream.reset(extract_argb4444_data(bitmap, srcRect, extractAlpha,
259 &isOpaque, &transparent); 260 &isOpaque, &transparent));
260 break; 261 break;
261 case kRGB_565_SkColorType: 262 case kRGB_565_SkColorType:
262 if (!extractAlpha) { 263 if (!extractAlpha) {
263 stream = extract_rgb565_image(bitmap, srcRect); 264 stream.reset(extract_rgb565_image(bitmap, srcRect));
264 } 265 }
265 break; 266 break;
266 case kN32_SkColorType: 267 case kN32_SkColorType:
267 stream = extract_argb8888_data(bitmap, srcRect, extractAlpha, 268 stream.reset(extract_argb8888_data(bitmap, srcRect, extractAlpha,
268 &isOpaque, &transparent); 269 &isOpaque, &transparent));
269 break; 270 break;
270 case kAlpha_8_SkColorType: 271 case kAlpha_8_SkColorType:
271 if (!extractAlpha) { 272 if (!extractAlpha) {
272 stream = create_black_image(); 273 stream.reset(create_black_image());
273 } else { 274 } else {
274 stream = extract_a8_alpha(bitmap, srcRect, 275 stream.reset(extract_a8_alpha(bitmap, srcRect,
275 &isOpaque, &transparent); 276 &isOpaque, &transparent));
276 } 277 }
277 break; 278 break;
278 default: 279 default:
279 SkASSERT(false); 280 SkASSERT(false);
280 } 281 }
281 282
282 if (isTransparent != NULL) { 283 if (isTransparent != NULL) {
283 *isTransparent = transparent; 284 *isTransparent = transparent;
284 } 285 }
285 if (extractAlpha && (transparent || isOpaque)) { 286 if (extractAlpha && (transparent || isOpaque)) {
286 SkSafeUnref(stream);
287 return NULL; 287 return NULL;
288 } 288 }
289 return stream; 289 return stream.detach();
290 } 290 }
291 291
292 static SkPDFArray* make_indexed_color_space(SkColorTable* table) { 292 static SkPDFArray* make_indexed_color_space(SkColorTable* table) {
293 SkPDFArray* result = new SkPDFArray(); 293 SkPDFArray* result = new SkPDFArray();
294 result->reserve(4); 294 result->reserve(4);
295 result->appendName("Indexed"); 295 result->appendName("Indexed");
296 result->appendName("DeviceRGB"); 296 result->appendName("DeviceRGB");
297 result->appendInt(table->count() - 1); 297 result->appendInt(table->count() - 1);
298 298
299 // Potentially, this could be represented in fewer bytes with a stream. 299 // Potentially, this could be represented in fewer bytes with a stream.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 461
462 // static 462 // static
463 SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap, 463 SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap,
464 const SkIRect& srcRect, 464 const SkIRect& srcRect,
465 SkPicture::EncodeBitmap encoder) { 465 SkPicture::EncodeBitmap encoder) {
466 if (bitmap.colorType() == kUnknown_SkColorType) { 466 if (bitmap.colorType() == kUnknown_SkColorType) {
467 return NULL; 467 return NULL;
468 } 468 }
469 469
470 bool isTransparent = false; 470 bool isTransparent = false;
471 SkAutoTUnref<SkStream> alphaData; 471 SkAutoTDelete<SkStream> alphaData;
472 if (!bitmap.isOpaque()) { 472 if (!bitmap.isOpaque()) {
473 // Note that isOpaque is not guaranteed to return false for bitmaps 473 // Note that isOpaque is not guaranteed to return false for bitmaps
474 // with alpha support but a completely opaque alpha channel, 474 // with alpha support but a completely opaque alpha channel,
475 // so alphaData may still be NULL if we have a completely opaque 475 // so alphaData may still be NULL if we have a completely opaque
476 // (or transparent) bitmap. 476 // (or transparent) bitmap.
477 alphaData.reset( 477 alphaData.reset(
478 extract_image_data(bitmap, srcRect, true, &isTransparent)); 478 extract_image_data(bitmap, srcRect, true, &isTransparent));
479 } 479 }
480 if (isTransparent) { 480 if (isTransparent) {
481 return NULL; 481 return NULL;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 632
633 insertName("Filter", "DCTDecode"); 633 insertName("Filter", "DCTDecode");
634 insertInt("ColorTransform", kNoColorTransform); 634 insertInt("ColorTransform", kNoColorTransform);
635 insertInt("Length", this->dataSize()); 635 insertInt("Length", this->dataSize());
636 setState(kCompressed_State); 636 setState(kCompressed_State);
637 return true; 637 return true;
638 } 638 }
639 } 639 }
640 // Fallback method 640 // Fallback method
641 if (!fStreamValid) { 641 if (!fStreamValid) {
642 SkAutoTUnref<SkStream> stream( 642 SkAutoTDelete<SkStream> stream(
643 extract_image_data(fBitmap, fSrcRect, fIsAlpha, NULL)); 643 extract_image_data(fBitmap, fSrcRect, fIsAlpha, NULL));
644 this->setData(stream); 644 this->setData(stream);
645 fStreamValid = true; 645 fStreamValid = true;
646 } 646 }
647 return INHERITED::populate(catalog); 647 return INHERITED::populate(catalog);
648 } else if (getState() == kNoCompression_State && 648 } else if (getState() == kNoCompression_State &&
649 !skip_compression(catalog) && 649 !skip_compression(catalog) &&
650 (SkFlate::HaveFlate() || fEncoder)) { 650 (SkFlate::HaveFlate() || fEncoder)) {
651 // Compression has not been requested when the stream was first created, 651 // Compression has not been requested when the stream was first created,
652 // but the new catalog wants it compressed. 652 // but the new catalog wants it compressed.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) { 744 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) {
745 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap)); 745 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap));
746 if (is_jfif_jpeg(encodedData)) { 746 if (is_jfif_jpeg(encodedData)) {
747 return SkNEW_ARGS(PDFJPEGImage, 747 return SkNEW_ARGS(PDFJPEGImage,
748 (encodedData, bitmap.width(), bitmap.height())); 748 (encodedData, bitmap.width(), bitmap.height()));
749 } 749 }
750 } 750 }
751 #endif 751 #endif
752 return SkPDFImage::CreateImage(bitmap, subset, encoder); 752 return SkPDFImage::CreateImage(bitmap, subset, encoder);
753 } 753 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFImage.h ('k') | src/pdf/SkPDFShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698