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 SkIRect fSrcRect; | |
62 EncodeToDCTStream fEncoder; | |
63 | |
56 SkTDArray<SkPDFObject*> fResources; | 64 SkTDArray<SkPDFObject*> fResources; |
57 | 65 |
58 /** Create a PDF image XObject. Entries for the image properties are | 66 /** Create a PDF image XObject. Entries for the image properties are |
59 * automatically added to the stream dictionary. | 67 * automatically added to the stream dictionary. |
60 * @param imageData The final raw bits representing the image. | 68 * @param bitmap The image, along with parameters (like config). |
61 * @param bitmap The image parameters to use (Config, etc). | |
62 * @param srcRect The clipping applied to bitmap before generating | 69 * @param srcRect The clipping applied to bitmap before generating |
63 * imageData. | 70 * imageData. |
64 * @param alpha Is this the alpha channel of the bitmap. | 71 * @param encoder A function used to encode the bitmap for compression. |
65 * @param paint Used to calculate alpha, masks, etc. | 72 * May be NULL. |
66 */ | 73 */ |
67 SkPDFImage(SkStream* imageData, const SkBitmap& bitmap, | 74 SkPDFImage(const SkBitmap& bitmap, const SkIRect& srcRect, |
vandebo (ex-Chrome)
2013/08/21 22:37:17
Maybe there should be one constructor that makes a
ducky
2013/08/22 03:48:06
I kind of like having a self-contained constructor
| |
68 const SkIRect& srcRect, bool alpha, EncodeToDCTStream encoder); | 75 EncodeToDCTStream encoder); |
76 | |
77 /** Create a PDF image XObject from a stream and bitmap. The stream is used | |
78 * for the image data, while the bitmap contains contains parameters. | |
vandebo (ex-Chrome)
2013/08/21 22:37:17
contains contains
ducky
2013/08/22 03:48:06
Done.
| |
79 * This is intended to create an alpha SMask, and the behavior when used | |
80 * in other ways is undefined (as in, don't do it). | |
81 * @param stream Uncompressed stream containing image data. | |
82 * @param bitmap The image, along with parameters (like config). | |
83 * @param srcRect The clipping applied to bitmap before generating | |
84 imageData. | |
85 */ | |
86 SkPDFImage(SkStream* stream, const SkBitmap& bitmap, | |
87 const SkIRect& srcRect); | |
88 | |
89 /** Copy constructor, used to generate substitutes. | |
90 * @param image The SkPDFImage to copy. | |
91 */ | |
92 SkPDFImage(SkPDFImage& pdfImage); | |
93 | |
94 | |
95 /** Initialize the image XObject parameters based on fBitmap and | |
96 * fSrcRect, which MUST have been initialized before calling this. | |
97 * Image data is not touched. | |
98 * @param isAlpha Whether or not this image is the alpha channel | |
99 * (SMask) for another image XObject. | |
100 */ | |
101 void initImageParams(bool isAlpha); | |
102 | |
103 /** Returns the fEncoder encoded version of the image data, or NULL | |
104 * if not possible (or desired). | |
105 */ | |
106 SkStream* getCompressedStream(); | |
vandebo (ex-Chrome)
2013/08/21 22:37:17
nit: getDCTCompressedStream()
ducky
2013/08/22 03:48:06
Removed, other style changes rendered this obsolet
| |
107 | |
108 // Populate the stream dictionary. This method returns false if | |
109 // fSubstitute should be used. | |
110 virtual bool populate(SkPDFCatalog* catalog); | |
111 | |
112 typedef SkPDFStream INHERITED; | |
69 }; | 113 }; |
70 | 114 |
71 #endif | 115 #endif |
OLD | NEW |