epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 The Android Open Source Project |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 10 | #ifndef SkPDFImage_DEFINED |
| 11 | #define SkPDFImage_DEFINED |
| 12 | |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 13 | #include "SkPicture.h" |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 14 | #include "SkPDFDevice.h" |
commit-bot@chromium.org | 181fcb4 | 2013-08-23 19:06:53 +0000 | [diff] [blame] | 15 | #include "SkPDFStream.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 16 | #include "SkPDFTypes.h" |
| 17 | #include "SkRefCnt.h" |
| 18 | |
| 19 | class SkBitmap; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 20 | class SkPDFCatalog; |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 21 | struct SkIRect; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 22 | |
| 23 | /** \class SkPDFImage |
| 24 | |
| 25 | An image XObject. |
| 26 | */ |
| 27 | |
| 28 | // We could play the same trick here as is done in SkPDFGraphicState, storing |
| 29 | // a copy of the Bitmap object (not the pixels), the pixel generation number, |
| 30 | // and settings used from the paint to canonicalize image objects. |
commit-bot@chromium.org | 181fcb4 | 2013-08-23 19:06:53 +0000 | [diff] [blame] | 31 | class SkPDFImage : public SkPDFStream { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 32 | public: |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 33 | /** Create a new Image XObject to represent the passed bitmap. |
| 34 | * @param bitmap The image to encode. |
| 35 | * @param srcRect The rectangle to cut out of bitmap. |
| 36 | * @param paint Used to calculate alpha, masks, etc. |
| 37 | * @return The image XObject or NUll if there is nothing to draw for |
| 38 | * the given parameters. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 39 | */ |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 40 | static SkPDFImage* CreateImage(const SkBitmap& bitmap, |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 41 | const SkIRect& srcRect, |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 42 | SkPicture::EncodeBitmap encoder); |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 43 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 44 | virtual ~SkPDFImage(); |
| 45 | |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 46 | /** Add a Soft Mask (alpha or shape channel) to the image. Refs mask. |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 47 | * @param mask A gray scale image representing the mask. |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 48 | * @return The mask argument is returned. |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 49 | */ |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 50 | SkPDFImage* addSMask(SkPDFImage* mask); |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 51 | |
commit-bot@chromium.org | 181fcb4 | 2013-08-23 19:06:53 +0000 | [diff] [blame] | 52 | bool isEmpty() { |
| 53 | return fSrcRect.isEmpty(); |
| 54 | } |
| 55 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 56 | // The SkPDFObject interface. |
edisonn@google.com | 6addb19 | 2013-04-02 15:33:08 +0000 | [diff] [blame] | 57 | virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, |
| 58 | SkTSet<SkPDFObject*>* newResourceObjects); |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 59 | |
| 60 | private: |
commit-bot@chromium.org | 181fcb4 | 2013-08-23 19:06:53 +0000 | [diff] [blame] | 61 | SkBitmap fBitmap; |
| 62 | bool fIsAlpha; |
| 63 | SkIRect fSrcRect; |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 64 | SkPicture::EncodeBitmap fEncoder; |
commit-bot@chromium.org | 181fcb4 | 2013-08-23 19:06:53 +0000 | [diff] [blame] | 65 | bool fStreamValid; |
| 66 | |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 67 | SkTDArray<SkPDFObject*> fResources; |
| 68 | |
| 69 | /** Create a PDF image XObject. Entries for the image properties are |
| 70 | * automatically added to the stream dictionary. |
commit-bot@chromium.org | 181fcb4 | 2013-08-23 19:06:53 +0000 | [diff] [blame] | 71 | * @param stream The image stream. May be NULL. Otherwise, this |
| 72 | * (instead of the input bitmap) will be used as the |
| 73 | * PDF's content stream, possibly with lossless encoding. |
| 74 | * @param bitmap The image. If a stream is not given, its color data |
| 75 | * will be used as the image. If a stream is given, this |
| 76 | * is used for configuration only. |
| 77 | * @param isAlpha Whether or not this is the alpha of an image. |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 78 | * @param srcRect The clipping applied to bitmap before generating |
| 79 | * imageData. |
commit-bot@chromium.org | 181fcb4 | 2013-08-23 19:06:53 +0000 | [diff] [blame] | 80 | * @param encoder A function used to encode the bitmap for compression. |
| 81 | * May be NULL. |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 82 | */ |
commit-bot@chromium.org | 181fcb4 | 2013-08-23 19:06:53 +0000 | [diff] [blame] | 83 | SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha, |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 84 | const SkIRect& srcRect, SkPicture::EncodeBitmap encoder); |
commit-bot@chromium.org | 181fcb4 | 2013-08-23 19:06:53 +0000 | [diff] [blame] | 85 | |
| 86 | /** Copy constructor, used to generate substitutes. |
| 87 | * @param image The SkPDFImage to copy. |
| 88 | */ |
| 89 | SkPDFImage(SkPDFImage& pdfImage); |
| 90 | |
| 91 | // Populate the stream dictionary. This method returns false if |
| 92 | // fSubstitute should be used. |
| 93 | virtual bool populate(SkPDFCatalog* catalog); |
| 94 | |
| 95 | typedef SkPDFStream INHERITED; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | #endif |