Chromium Code Reviews| 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 bool fStreamValid; | |
| 64 | |
| 56 SkTDArray<SkPDFObject*> fResources; | 65 SkTDArray<SkPDFObject*> fResources; |
| 57 | 66 |
| 58 /** Create a PDF image XObject. Entries for the image properties are | 67 /** Create a PDF image XObject. Entries for the image properties are |
| 59 * automatically added to the stream dictionary. | 68 * automatically added to the stream dictionary. |
| 60 * @param imageData The final raw bits representing the image. | 69 * @param stream The image stream. May be NULL. Otherwise, this |
| 61 * @param bitmap The image parameters to use (Config, etc). | 70 * (instead of the input bitmap) will be used as the |
| 71 * PDF's content stream, possibly with encoding. | |
| 72 * @param bitmap The image. If a stream is not given, its color data | |
| 73 * will be used as the image. If a stream is given, this | |
| 74 * is used for configuration only. | |
| 75 * @param isAlpha Whether or not this is the alpha of an image. | |
| 76 * WARNING: a stream MUST be given if this is true. | |
| 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 /** Initialize the image XObject parameters based on fBitmap and | |
| 91 * fSrcRect, which MUST have been initialized before calling this. | |
| 92 * Image data is not touched. | |
| 93 * @param isAlpha Whether or not this image is the alpha channel | |
| 94 * (SMask) for another image XObject. | |
| 95 */ | |
| 96 void initImageParams(bool isAlpha); | |
|
vandebo (ex-Chrome)
2013/08/23 15:50:19
Remove.
ducky
2013/08/23 17:59:50
Oops. Not sure how that got left in there...
On 2
| |
| 97 | |
| 98 // Populate the stream dictionary. This method returns false if | |
| 99 // fSubstitute should be used. | |
| 100 virtual bool populate(SkPDFCatalog* catalog); | |
| 101 | |
| 102 typedef SkPDFStream INHERITED; | |
| 69 }; | 103 }; |
| 70 | 104 |
| 71 #endif | 105 #endif |
| OLD | NEW |