| OLD | NEW |
| 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" |
| 11 #include "SkColor.h" | 11 #include "SkColor.h" |
| 12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
| 13 #include "SkData.h" | 13 #include "SkData.h" |
| 14 #include "SkFlate.h" | 14 #include "SkFlate.h" |
| 15 #include "SkPDFCatalog.h" | 15 #include "SkPDFCatalog.h" |
| 16 #include "SkRect.h" | 16 #include "SkRect.h" |
| 17 #include "SkStream.h" | 17 #include "SkStream.h" |
| 18 #include "SkString.h" | 18 #include "SkString.h" |
| 19 #include "SkUnPreMultiply.h" | 19 #include "SkUnPreMultiply.h" |
| 20 | 20 |
| 21 static const int kNoColorTransform = 0; | 21 static const int kNoColorTransform = 0; |
| 22 | 22 |
| 23 static bool skip_compression(SkPDFCatalog* catalog) { | 23 static bool skip_compression(SkPDFCatalog* catalog) { |
| 24 return SkToBool(catalog->getDocumentFlags() & | 24 return SkToBool(catalog->getDocumentFlags() & |
| 25 SkPDFDocument::kFavorSpeedOverSize_Flags); | 25 SkPDFDocument::kFavorSpeedOverSize_Flags); |
| 26 } | 26 } |
| 27 | 27 |
| 28 static size_t get_uncompressed_size(const SkBitmap& bitmap, | 28 static size_t get_uncompressed_size(const SkBitmap& bitmap, |
| 29 const SkIRect& srcRect) { | 29 const SkIRect& srcRect) { |
| 30 switch (bitmap.getConfig()) { | 30 switch (bitmap.config()) { |
| 31 case SkBitmap::kIndex8_Config: | 31 case SkBitmap::kIndex8_Config: |
| 32 return srcRect.width() * srcRect.height(); | 32 return srcRect.width() * srcRect.height(); |
| 33 case SkBitmap::kARGB_4444_Config: | 33 case SkBitmap::kARGB_4444_Config: |
| 34 return ((srcRect.width() * 3 + 1) / 2) * srcRect.height(); | 34 return ((srcRect.width() * 3 + 1) / 2) * srcRect.height(); |
| 35 case SkBitmap::kRGB_565_Config: | 35 case SkBitmap::kRGB_565_Config: |
| 36 return srcRect.width() * 3 * srcRect.height(); | 36 return srcRect.width() * 3 * srcRect.height(); |
| 37 case SkBitmap::kARGB_8888_Config: | 37 case SkBitmap::kARGB_8888_Config: |
| 38 return srcRect.width() * 3 * srcRect.height(); | 38 return srcRect.width() * 3 * srcRect.height(); |
| 39 case SkBitmap::kA1_Config: | 39 case SkBitmap::kA1_Config: |
| 40 case SkBitmap::kA8_Config: | 40 case SkBitmap::kA8_Config: |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 484 |
| 485 outBitmap.setImmutable(); | 485 outBitmap.setImmutable(); |
| 486 | 486 |
| 487 return outBitmap; | 487 return outBitmap; |
| 488 } | 488 } |
| 489 | 489 |
| 490 // static | 490 // static |
| 491 SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap, | 491 SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap, |
| 492 const SkIRect& srcRect, | 492 const SkIRect& srcRect, |
| 493 SkPicture::EncodeBitmap encoder) { | 493 SkPicture::EncodeBitmap encoder) { |
| 494 if (bitmap.getConfig() == SkBitmap::kNo_Config) { | 494 if (bitmap.config() == SkBitmap::kNo_Config) { |
| 495 return NULL; | 495 return NULL; |
| 496 } | 496 } |
| 497 | 497 |
| 498 bool isTransparent = false; | 498 bool isTransparent = false; |
| 499 SkAutoTUnref<SkStream> alphaData; | 499 SkAutoTUnref<SkStream> alphaData; |
| 500 if (!bitmap.isOpaque()) { | 500 if (!bitmap.isOpaque()) { |
| 501 // Note that isOpaque is not guaranteed to return false for bitmaps | 501 // Note that isOpaque is not guaranteed to return false for bitmaps |
| 502 // with alpha support but a completely opaque alpha channel, | 502 // with alpha support but a completely opaque alpha channel, |
| 503 // so alphaData may still be NULL if we have a completely opaque | 503 // so alphaData may still be NULL if we have a completely opaque |
| 504 // (or transparent) bitmap. | 504 // (or transparent) bitmap. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 fBitmap.setImmutable(); | 562 fBitmap.setImmutable(); |
| 563 } | 563 } |
| 564 | 564 |
| 565 if (stream != NULL) { | 565 if (stream != NULL) { |
| 566 setData(stream); | 566 setData(stream); |
| 567 fStreamValid = true; | 567 fStreamValid = true; |
| 568 } else { | 568 } else { |
| 569 fStreamValid = false; | 569 fStreamValid = false; |
| 570 } | 570 } |
| 571 | 571 |
| 572 SkBitmap::Config config = fBitmap.getConfig(); | 572 SkBitmap::Config config = fBitmap.config(); |
| 573 | 573 |
| 574 insertName("Type", "XObject"); | 574 insertName("Type", "XObject"); |
| 575 insertName("Subtype", "Image"); | 575 insertName("Subtype", "Image"); |
| 576 | 576 |
| 577 bool alphaOnly = (config == SkBitmap::kA1_Config || | 577 bool alphaOnly = (config == SkBitmap::kA1_Config || |
| 578 config == SkBitmap::kA8_Config); | 578 config == SkBitmap::kA8_Config); |
| 579 | 579 |
| 580 if (!isAlpha && alphaOnly) { | 580 if (!isAlpha && alphaOnly) { |
| 581 // For alpha only images, we stretch a single pixel of black for | 581 // For alpha only images, we stretch a single pixel of black for |
| 582 // the color/shape part. | 582 // the color/shape part. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 // but the new catalog wants it compressed. | 680 // but the new catalog wants it compressed. |
| 681 if (!getSubstitute()) { | 681 if (!getSubstitute()) { |
| 682 SkPDFStream* substitute = SkNEW_ARGS(SkPDFImage, (*this)); | 682 SkPDFStream* substitute = SkNEW_ARGS(SkPDFImage, (*this)); |
| 683 setSubstitute(substitute); | 683 setSubstitute(substitute); |
| 684 catalog->setSubstitute(this, substitute); | 684 catalog->setSubstitute(this, substitute); |
| 685 } | 685 } |
| 686 return false; | 686 return false; |
| 687 } | 687 } |
| 688 return true; | 688 return true; |
| 689 } | 689 } |
| OLD | NEW |