| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 struct SkIRect; | 22 struct SkIRect; |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Return the mose efficient availible encoding of the given bitmap. | 25 * Return the mose efficient availible encoding of the given bitmap. |
| 26 * | 26 * |
| 27 * If the bitmap has encoded JPEG data and that data can be embedded | 27 * If the bitmap has encoded JPEG data and that data can be embedded |
| 28 * into the PDF output stream directly, use that. Otherwise, fall | 28 * into the PDF output stream directly, use that. Otherwise, fall |
| 29 * back on SkPDFImage::CreateImage. | 29 * back on SkPDFImage::CreateImage. |
| 30 */ | 30 */ |
| 31 SkPDFObject* SkPDFCreateImageObject( | 31 SkPDFObject* SkPDFCreateImageObject( |
| 32 const SkBitmap&, const SkIRect& subset, SkPicture::EncodeBitmap); | 32 const SkBitmap&, const SkIRect& subset, SkData* (*)(size_t*, const SkBit
map&)); |
| 33 | 33 |
| 34 /** \class SkPDFImage | 34 /** \class SkPDFImage |
| 35 | 35 |
| 36 An image XObject. | 36 An image XObject. |
| 37 */ | 37 */ |
| 38 | 38 |
| 39 // We could play the same trick here as is done in SkPDFGraphicState, storing | 39 // We could play the same trick here as is done in SkPDFGraphicState, storing |
| 40 // a copy of the Bitmap object (not the pixels), the pixel generation number, | 40 // a copy of the Bitmap object (not the pixels), the pixel generation number, |
| 41 // and settings used from the paint to canonicalize image objects. | 41 // and settings used from the paint to canonicalize image objects. |
| 42 class SkPDFImage : public SkPDFStream { | 42 class SkPDFImage : public SkPDFStream { |
| 43 public: | 43 public: |
| 44 /** Create a new Image XObject to represent the passed bitmap. | 44 /** Create a new Image XObject to represent the passed bitmap. |
| 45 * @param bitmap The image to encode. | 45 * @param bitmap The image to encode. |
| 46 * @param srcRect The rectangle to cut out of bitmap. | 46 * @param srcRect The rectangle to cut out of bitmap. |
| 47 * @param paint Used to calculate alpha, masks, etc. | 47 * @param paint Used to calculate alpha, masks, etc. |
| 48 * @return The image XObject or NUll if there is nothing to draw for | 48 * @return The image XObject or NUll if there is nothing to draw for |
| 49 * the given parameters. | 49 * the given parameters. |
| 50 */ | 50 */ |
| 51 static SkPDFImage* CreateImage(const SkBitmap& bitmap, | 51 static SkPDFImage* CreateImage(const SkBitmap& bitmap, |
| 52 const SkIRect& srcRect, | 52 const SkIRect& srcRect, |
| 53 SkPicture::EncodeBitmap encoder); | 53 SkData* (*encoder)(size_t*, const SkBitmap&))
; |
| 54 | 54 |
| 55 virtual ~SkPDFImage(); | 55 virtual ~SkPDFImage(); |
| 56 | 56 |
| 57 bool isEmpty() { | 57 bool isEmpty() { |
| 58 return fSrcRect.isEmpty(); | 58 return fSrcRect.isEmpty(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 SkBitmap fBitmap; | 62 SkBitmap fBitmap; |
| 63 bool fIsAlpha; | 63 bool fIsAlpha; |
| 64 SkIRect fSrcRect; | 64 SkIRect fSrcRect; |
| 65 SkPicture::EncodeBitmap fEncoder; | 65 SkData* (*fEncoder)(size_t*, const SkBitmap&); |
| 66 bool fStreamValid; | 66 bool fStreamValid; |
| 67 | 67 |
| 68 /** Create a PDF image XObject. Entries for the image properties are | 68 /** Create a PDF image XObject. Entries for the image properties are |
| 69 * automatically added to the stream dictionary. | 69 * automatically added to the stream dictionary. |
| 70 * @param stream The image stream. May be NULL. Otherwise, this | 70 * @param stream The image stream. May be NULL. Otherwise, this |
| 71 * (instead of the input bitmap) will be used as the | 71 * (instead of the input bitmap) will be used as the |
| 72 * PDF's content stream, possibly with lossless encoding. | 72 * PDF's content stream, possibly with lossless encoding. |
| 73 * Will be duplicated, and left in indeterminate state. | 73 * Will be duplicated, and left in indeterminate state. |
| 74 * @param bitmap The image. If a stream is not given, its color data | 74 * @param bitmap The image. If a stream is not given, its color data |
| 75 * will be used as the image. If a stream is given, this | 75 * will be used as the image. If a stream is given, this |
| 76 * is used for configuration only. | 76 * is used for configuration only. |
| 77 * @param isAlpha Whether or not this is the alpha of an image. | 77 * @param isAlpha Whether or not this is the alpha of an image. |
| 78 * @param srcRect The clipping applied to bitmap before generating | 78 * @param srcRect The clipping applied to bitmap before generating |
| 79 * imageData. | 79 * imageData. |
| 80 * @param encoder A function used to encode the bitmap for compression. | 80 * @param encoder A function used to encode the bitmap for compression. |
| 81 * May be NULL. | 81 * May be NULL. |
| 82 */ | 82 */ |
| 83 SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha, | 83 SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha, |
| 84 const SkIRect& srcRect, SkPicture::EncodeBitmap encoder); | 84 const SkIRect& srcRect, SkData* (*encoder)(size_t*, const SkBitma
p&)); |
| 85 | 85 |
| 86 /** Copy constructor, used to generate substitutes. | 86 /** Copy constructor, used to generate substitutes. |
| 87 * @param image The SkPDFImage to copy. | 87 * @param image The SkPDFImage to copy. |
| 88 */ | 88 */ |
| 89 SkPDFImage(SkPDFImage& pdfImage); | 89 SkPDFImage(SkPDFImage& pdfImage); |
| 90 | 90 |
| 91 // Populate the stream dictionary. This method returns false if | 91 // Populate the stream dictionary. This method returns false if |
| 92 // fSubstitute should be used. | 92 // fSubstitute should be used. |
| 93 virtual bool populate(SkPDFCatalog* catalog); | 93 virtual bool populate(SkPDFCatalog* catalog); |
| 94 | 94 |
| 95 typedef SkPDFStream INHERITED; | 95 typedef SkPDFStream INHERITED; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 #endif | 98 #endif |
| OLD | NEW |