vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SkPDFImage_DEFINED |
| 18 | #define SkPDFImage_DEFINED |
| 19 | |
| 20 | #include "SkPDFStream.h" |
| 21 | #include "SkPDFTypes.h" |
| 22 | #include "SkRefCnt.h" |
| 23 | |
| 24 | class SkBitmap; |
| 25 | class SkPaint; |
| 26 | class SkPDFCatalog; |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 27 | struct SkIRect; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 28 | |
| 29 | /** \class SkPDFImage |
| 30 | |
| 31 | An image XObject. |
| 32 | */ |
| 33 | |
| 34 | // We could play the same trick here as is done in SkPDFGraphicState, storing |
| 35 | // a copy of the Bitmap object (not the pixels), the pixel generation number, |
| 36 | // and settings used from the paint to canonicalize image objects. |
| 37 | class SkPDFImage : public SkPDFObject { |
| 38 | public: |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 39 | /** Create a new Image XObject to represent the passed bitmap. |
| 40 | * @param bitmap The image to encode. |
| 41 | * @param srcRect The rectangle to cut out of bitmap. |
| 42 | * @param paint Used to calculate alpha, masks, etc. |
| 43 | * @return The image XObject or NUll if there is nothing to draw for |
| 44 | * the given parameters. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 45 | */ |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 46 | static SkPDFImage* CreateImage(const SkBitmap& bitmap, |
| 47 | const SkIRect& srcRect, |
| 48 | const SkPaint& paint); |
| 49 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 50 | virtual ~SkPDFImage(); |
| 51 | |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 52 | /** 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] | 53 | * @param mask A gray scale image representing the mask. |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 54 | * @return The mask argument is returned. |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 55 | */ |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 56 | SkPDFImage* addSMask(SkPDFImage* mask); |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 57 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 58 | // The SkPDFObject interface. |
| 59 | virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, |
| 60 | bool indirect); |
| 61 | virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
vandebo@chromium.org | 1cfa2c4 | 2011-01-31 19:35:43 +0000 | [diff] [blame] | 62 | virtual void getResources(SkTDArray<SkPDFObject*>* resourceList); |
| 63 | |
| 64 | private: |
| 65 | SkRefPtr<SkPDFStream> fStream; |
| 66 | SkTDArray<SkPDFObject*> fResources; |
| 67 | |
| 68 | /** Create a PDF image XObject. Entries for the image properties are |
| 69 | * automatically added to the stream dictionary. |
| 70 | * @param imageData The final raw bits representing the image. |
| 71 | * @param bitmap The image parameters to use (Config, etc). |
| 72 | * @param srcRect The clipping applied to bitmap before generating |
| 73 | * imageData. |
| 74 | * @param alpha Is this the alpha channel of the bitmap. |
| 75 | * @param paint Used to calculate alpha, masks, etc. |
| 76 | */ |
| 77 | SkPDFImage(SkStream* imageData, const SkBitmap& bitmap, |
| 78 | const SkIRect& srcRect, bool alpha, const SkPaint& paint); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 79 | |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 80 | /** Add the value to the stream dictionary with the given key. Refs value. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 81 | * @param key The key for this dictionary entry. |
| 82 | * @param value The value for this dictionary entry. |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 83 | * @return The value argument is returned. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 84 | */ |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 85 | SkPDFObject* insert(SkPDFName* key, SkPDFObject* value); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 86 | |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 87 | /** Add the value to the stream dictionary with the given key. Refs value. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 88 | * @param key The text of the key for this dictionary entry. |
| 89 | * @param value The value for this dictionary entry. |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 90 | * @return The value argument is returned. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 91 | */ |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 92 | SkPDFObject* insert(const char key[], SkPDFObject* value); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | #endif |