1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/pdf/SkPDFImage.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2010 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkPDFImage_DEFINED 1.14 +#define SkPDFImage_DEFINED 1.15 + 1.16 +#include "SkPicture.h" 1.17 +#include "SkPDFDevice.h" 1.18 +#include "SkPDFStream.h" 1.19 +#include "SkPDFTypes.h" 1.20 +#include "SkRefCnt.h" 1.21 + 1.22 +class SkBitmap; 1.23 +class SkPDFCatalog; 1.24 +struct SkIRect; 1.25 + 1.26 +/** \class SkPDFImage 1.27 + 1.28 + An image XObject. 1.29 +*/ 1.30 + 1.31 +// We could play the same trick here as is done in SkPDFGraphicState, storing 1.32 +// a copy of the Bitmap object (not the pixels), the pixel generation number, 1.33 +// and settings used from the paint to canonicalize image objects. 1.34 +class SkPDFImage : public SkPDFStream { 1.35 +public: 1.36 + /** Create a new Image XObject to represent the passed bitmap. 1.37 + * @param bitmap The image to encode. 1.38 + * @param srcRect The rectangle to cut out of bitmap. 1.39 + * @param paint Used to calculate alpha, masks, etc. 1.40 + * @return The image XObject or NUll if there is nothing to draw for 1.41 + * the given parameters. 1.42 + */ 1.43 + static SkPDFImage* CreateImage(const SkBitmap& bitmap, 1.44 + const SkIRect& srcRect, 1.45 + SkPicture::EncodeBitmap encoder); 1.46 + 1.47 + virtual ~SkPDFImage(); 1.48 + 1.49 + /** Add a Soft Mask (alpha or shape channel) to the image. Refs mask. 1.50 + * @param mask A gray scale image representing the mask. 1.51 + * @return The mask argument is returned. 1.52 + */ 1.53 + SkPDFImage* addSMask(SkPDFImage* mask); 1.54 + 1.55 + bool isEmpty() { 1.56 + return fSrcRect.isEmpty(); 1.57 + } 1.58 + 1.59 + // The SkPDFObject interface. 1.60 + virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, 1.61 + SkTSet<SkPDFObject*>* newResourceObjects); 1.62 + 1.63 +private: 1.64 + SkBitmap fBitmap; 1.65 + bool fIsAlpha; 1.66 + SkIRect fSrcRect; 1.67 + SkPicture::EncodeBitmap fEncoder; 1.68 + bool fStreamValid; 1.69 + 1.70 + SkTDArray<SkPDFObject*> fResources; 1.71 + 1.72 + /** Create a PDF image XObject. Entries for the image properties are 1.73 + * automatically added to the stream dictionary. 1.74 + * @param stream The image stream. May be NULL. Otherwise, this 1.75 + * (instead of the input bitmap) will be used as the 1.76 + * PDF's content stream, possibly with lossless encoding. 1.77 + * @param bitmap The image. If a stream is not given, its color data 1.78 + * will be used as the image. If a stream is given, this 1.79 + * is used for configuration only. 1.80 + * @param isAlpha Whether or not this is the alpha of an image. 1.81 + * @param srcRect The clipping applied to bitmap before generating 1.82 + * imageData. 1.83 + * @param encoder A function used to encode the bitmap for compression. 1.84 + * May be NULL. 1.85 + */ 1.86 + SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha, 1.87 + const SkIRect& srcRect, SkPicture::EncodeBitmap encoder); 1.88 + 1.89 + /** Copy constructor, used to generate substitutes. 1.90 + * @param image The SkPDFImage to copy. 1.91 + */ 1.92 + SkPDFImage(SkPDFImage& pdfImage); 1.93 + 1.94 + // Populate the stream dictionary. This method returns false if 1.95 + // fSubstitute should be used. 1.96 + virtual bool populate(SkPDFCatalog* catalog); 1.97 + 1.98 + typedef SkPDFStream INHERITED; 1.99 +}; 1.100 + 1.101 +#endif