blob: 48b0157da997544ef09ae5ad547cfe9a19239228 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 The Android Open Source Project
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000010#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;
ctguil@chromium.org9db86bb2011-03-04 21:43:27 +000020struct SkIRect;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000021
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.
vandebo@chromium.org421d6442011-07-20 17:39:01 +000030class SkPDFImage : public SkPDFStream {
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000031public:
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000032 /** 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.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000038 */
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000039 static SkPDFImage* CreateImage(const SkBitmap& bitmap,
40 const SkIRect& srcRect,
41 const SkPaint& paint);
42
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000043 virtual ~SkPDFImage();
44
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000045 /** Add a Soft Mask (alpha or shape channel) to the image. Refs mask.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000046 * @param mask A gray scale image representing the mask.
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000047 * @return The mask argument is returned.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000048 */
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000049 SkPDFImage* addSMask(SkPDFImage* mask);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000050
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000051 // The SkPDFObject interface.
edisonn@google.com5bd26d32013-02-28 14:01:44 +000052 virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000053
54private:
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000055 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);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000068};
69
70#endif