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