Home | History | Annotate | Download | only in pdf
      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 "SkPDFDevice.h"
     14 #include "SkPDFImageStream.h"
     15 #include "SkPDFTypes.h"
     16 #include "SkRefCnt.h"
     17 
     18 class SkBitmap;
     19 class SkPDFCatalog;
     20 struct SkIRect;
     21 
     22 /** \class SkPDFImage
     23 
     24     An image XObject.
     25 */
     26 
     27 // We could play the same trick here as is done in SkPDFGraphicState, storing
     28 // a copy of the Bitmap object (not the pixels), the pixel generation number,
     29 // and settings used from the paint to canonicalize image objects.
     30 class SkPDFImage : public SkPDFImageStream {
     31 public:
     32     /** Create a new Image XObject to represent the passed bitmap.
     33      *  @param bitmap   The image to encode.
     34      *  @param srcRect  The rectangle to cut out of bitmap.
     35      *  @param paint    Used to calculate alpha, masks, etc.
     36      *  @return  The image XObject or NUll if there is nothing to draw for
     37      *           the given parameters.
     38      */
     39     static SkPDFImage* CreateImage(const SkBitmap& bitmap,
     40                                    const SkIRect& srcRect,
     41                                    EncodeToDCTStream encoder);
     42 
     43     virtual ~SkPDFImage();
     44 
     45     /** Add a Soft Mask (alpha or shape channel) to the image.  Refs mask.
     46      *  @param mask A gray scale image representing the mask.
     47      *  @return The mask argument is returned.
     48      */
     49     SkPDFImage* addSMask(SkPDFImage* mask);
     50 
     51     // The SkPDFObject interface.
     52     virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
     53                               SkTSet<SkPDFObject*>* newResourceObjects);
     54 
     55 private:
     56     SkTDArray<SkPDFObject*> fResources;
     57 
     58     /** Create a PDF image XObject. Entries for the image properties are
     59      *  automatically added to the stream dictionary.
     60      *  @param imageData  The final raw bits representing the image.
     61      *  @param bitmap     The image parameters to use (Config, etc).
     62      *  @param srcRect    The clipping applied to bitmap before generating
     63      *                    imageData.
     64      *  @param alpha      Is this the alpha channel of the bitmap.
     65      *  @param paint      Used to calculate alpha, masks, etc.
     66      */
     67     SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
     68                const SkIRect& srcRect, bool alpha, EncodeToDCTStream encoder);
     69 };
     70 
     71 #endif
     72