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 "SkPDFStream.h"
14#include "SkPDFTypes.h"
15#include "SkRefCnt.h"
16
17class SkBitmap;
18class SkPaint;
19class SkPDFCatalog;
20struct 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.
30class SkPDFImage : public SkPDFStream {
31public:
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                                   const SkPaint& paint);
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(SkTDArray<SkPDFObject*>* resourceList);
53
54private:
55    SkTDArray<SkPDFObject*> fResources;
56
57    /** Create a PDF image XObject. Entries for the image properties are
58     *  automatically added to the stream dictionary.
59     *  @param imageData  The final raw bits representing the image.
60     *  @param bitmap     The image parameters to use (Config, etc).
61     *  @param srcRect    The clipping applied to bitmap before generating
62     *                    imageData.
63     *  @param alpha      Is this the alpha channel of the bitmap.
64     *  @param paint      Used to calculate alpha, masks, etc.
65     */
66    SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
67               const SkIRect& srcRect, bool alpha, const SkPaint& paint);
68};
69
70#endif
71