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