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