michael@0: michael@0: /* michael@0: * Copyright 2010 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkPDFImage_DEFINED michael@0: #define SkPDFImage_DEFINED michael@0: michael@0: #include "SkPicture.h" michael@0: #include "SkPDFDevice.h" michael@0: #include "SkPDFStream.h" michael@0: #include "SkPDFTypes.h" michael@0: #include "SkRefCnt.h" michael@0: michael@0: class SkBitmap; michael@0: class SkPDFCatalog; michael@0: struct SkIRect; michael@0: michael@0: /** \class SkPDFImage michael@0: michael@0: An image XObject. michael@0: */ michael@0: michael@0: // We could play the same trick here as is done in SkPDFGraphicState, storing michael@0: // a copy of the Bitmap object (not the pixels), the pixel generation number, michael@0: // and settings used from the paint to canonicalize image objects. michael@0: class SkPDFImage : public SkPDFStream { michael@0: public: michael@0: /** Create a new Image XObject to represent the passed bitmap. michael@0: * @param bitmap The image to encode. michael@0: * @param srcRect The rectangle to cut out of bitmap. michael@0: * @param paint Used to calculate alpha, masks, etc. michael@0: * @return The image XObject or NUll if there is nothing to draw for michael@0: * the given parameters. michael@0: */ michael@0: static SkPDFImage* CreateImage(const SkBitmap& bitmap, michael@0: const SkIRect& srcRect, michael@0: SkPicture::EncodeBitmap encoder); michael@0: michael@0: virtual ~SkPDFImage(); michael@0: michael@0: /** Add a Soft Mask (alpha or shape channel) to the image. Refs mask. michael@0: * @param mask A gray scale image representing the mask. michael@0: * @return The mask argument is returned. michael@0: */ michael@0: SkPDFImage* addSMask(SkPDFImage* mask); michael@0: michael@0: bool isEmpty() { michael@0: return fSrcRect.isEmpty(); michael@0: } michael@0: michael@0: // The SkPDFObject interface. michael@0: virtual void getResources(const SkTSet& knownResourceObjects, michael@0: SkTSet* newResourceObjects); michael@0: michael@0: private: michael@0: SkBitmap fBitmap; michael@0: bool fIsAlpha; michael@0: SkIRect fSrcRect; michael@0: SkPicture::EncodeBitmap fEncoder; michael@0: bool fStreamValid; michael@0: michael@0: SkTDArray fResources; michael@0: michael@0: /** Create a PDF image XObject. Entries for the image properties are michael@0: * automatically added to the stream dictionary. michael@0: * @param stream The image stream. May be NULL. Otherwise, this michael@0: * (instead of the input bitmap) will be used as the michael@0: * PDF's content stream, possibly with lossless encoding. michael@0: * @param bitmap The image. If a stream is not given, its color data michael@0: * will be used as the image. If a stream is given, this michael@0: * is used for configuration only. michael@0: * @param isAlpha Whether or not this is the alpha of an image. michael@0: * @param srcRect The clipping applied to bitmap before generating michael@0: * imageData. michael@0: * @param encoder A function used to encode the bitmap for compression. michael@0: * May be NULL. michael@0: */ michael@0: SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha, michael@0: const SkIRect& srcRect, SkPicture::EncodeBitmap encoder); michael@0: michael@0: /** Copy constructor, used to generate substitutes. michael@0: * @param image The SkPDFImage to copy. michael@0: */ michael@0: SkPDFImage(SkPDFImage& pdfImage); michael@0: michael@0: // Populate the stream dictionary. This method returns false if michael@0: // fSubstitute should be used. michael@0: virtual bool populate(SkPDFCatalog* catalog); michael@0: michael@0: typedef SkPDFStream INHERITED; michael@0: }; michael@0: michael@0: #endif