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 | |
| 13 | #include "SkPDFStream.h" |
| 14 | #include "SkPDFTypes.h" |
| 15 | #include "SkRefCnt.h" |
| 16 | |
| 17 | class SkBitmap; |
| 18 | class SkPaint; |
| 19 | class SkPDFCatalog; |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 20 | struct SkIRect; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 21 | |
| 22 | /** \class SkPDFImage |
| 23 | |
| 24 | An image XObject. |
| 25 | */ |
| 26 | |
| 27 | // We could play the same trick here as is done in SkPDFGraphicState, storing |
| 28 | // a copy of the Bitmap object (not the pixels), the pixel generation number, |
| 29 | // and settings used from the paint to canonicalize image objects. |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 30 | class SkPDFImage : public SkPDFStream { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 31 | public: |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 32 | /** Create a new Image XObject to represent the passed bitmap. |
| 33 | * @param bitmap The image to encode. |
| 34 | * @param srcRect The rectangle to cut out of bitmap. |
| 35 | * @param paint Used to calculate alpha, masks, etc. |
| 36 | * @return The image XObject or NUll if there is nothing to draw for |
| 37 | * the given parameters. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 38 | */ |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 39 | static SkPDFImage* CreateImage(const SkBitmap& bitmap, |
| 40 | const SkIRect& srcRect, |
| 41 | const SkPaint& paint); |
| 42 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 43 | virtual ~SkPDFImage(); |
| 44 | |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 45 | /** 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] | 46 | * @param mask A gray scale image representing the mask. |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 47 | * @return The mask argument is returned. |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 48 | */ |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 49 | SkPDFImage* addSMask(SkPDFImage* mask); |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 50 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 51 | // The SkPDFObject interface. |
edisonn@google.com | 5bd26d3 | 2013-02-28 14:01:44 +0000 | [diff] [blame] | 52 | virtual void getResources(SkTDArray<SkPDFObject*>* resourceList); |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 53 | |
| 54 | private: |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 55 | SkTDArray<SkPDFObject*> fResources; |
| 56 | |
| 57 | /** Create a PDF image XObject. Entries for the image properties are |
| 58 | * automatically added to the stream dictionary. |
| 59 | * @param imageData The final raw bits representing the image. |
| 60 | * @param bitmap The image parameters to use (Config, etc). |
| 61 | * @param srcRect The clipping applied to bitmap before generating |
| 62 | * imageData. |
| 63 | * @param alpha Is this the alpha channel of the bitmap. |
| 64 | * @param paint Used to calculate alpha, masks, etc. |
| 65 | */ |
| 66 | SkPDFImage(SkStream* imageData, const SkBitmap& bitmap, |
| 67 | const SkIRect& srcRect, bool alpha, const SkPaint& paint); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | #endif |