3 * Copyright 2010 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkPDFImage_DEFINED
11 #define SkPDFImage_DEFINED
13 #include "SkPicture.h"
14 #include "SkPDFDevice.h"
15 #include "SkPDFStream.h"
16 #include "SkPDFTypes.h"
25 * Return the mose efficient availible encoding of the given bitmap.
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
29 * back on SkPDFImage::CreateImage.
31 SkPDFObject* SkPDFCreateImageObject(
32 const SkBitmap&, const SkIRect& subset, SkPicture::EncodeBitmap);
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,
41 // and settings used from the paint to canonicalize image objects.
42 class SkPDFImage : public SkPDFStream {
44 /** Create a new Image XObject to represent the passed bitmap.
45 * @param bitmap The image to encode.
46 * @param srcRect The rectangle to cut out of bitmap.
47 * @param paint Used to calculate alpha, masks, etc.
48 * @return The image XObject or NUll if there is nothing to draw for
49 * the given parameters.
51 static SkPDFImage* CreateImage(const SkBitmap& bitmap,
52 const SkIRect& srcRect,
53 SkPicture::EncodeBitmap encoder);
55 virtual ~SkPDFImage();
57 /** Add a Soft Mask (alpha or shape channel) to the image. Refs mask.
58 * @param mask A gray scale image representing the mask.
59 * @return The mask argument is returned.
61 SkPDFImage* addSMask(SkPDFImage* mask);
64 return fSrcRect.isEmpty();
67 // The SkPDFObject interface.
68 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
69 SkTSet<SkPDFObject*>* newResourceObjects);
75 SkPicture::EncodeBitmap fEncoder;
78 SkTDArray<SkPDFObject*> fResources;
80 /** Create a PDF image XObject. Entries for the image properties are
81 * automatically added to the stream dictionary.
82 * @param stream The image stream. May be NULL. Otherwise, this
83 * (instead of the input bitmap) will be used as the
84 * PDF's content stream, possibly with lossless encoding.
85 * @param bitmap The image. If a stream is not given, its color data
86 * will be used as the image. If a stream is given, this
87 * is used for configuration only.
88 * @param isAlpha Whether or not this is the alpha of an image.
89 * @param srcRect The clipping applied to bitmap before generating
91 * @param encoder A function used to encode the bitmap for compression.
94 SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha,
95 const SkIRect& srcRect, SkPicture::EncodeBitmap encoder);
97 /** Copy constructor, used to generate substitutes.
98 * @param image The SkPDFImage to copy.
100 SkPDFImage(SkPDFImage& pdfImage);
102 // Populate the stream dictionary. This method returns false if
103 // fSubstitute should be used.
104 virtual bool populate(SkPDFCatalog* catalog);
106 typedef SkPDFStream INHERITED;