blob: d41466f4fe79d3144a232ce40f0a5b6a0e05f6f7 [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;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000018class SkPDFCatalog;
ctguil@chromium.org9db86bb2011-03-04 21:43:27 +000019struct SkIRect;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000020
21/** \class SkPDFImage
22
23 An image XObject.
24*/
25
26// We could play the same trick here as is done in SkPDFGraphicState, storing
27// a copy of the Bitmap object (not the pixels), the pixel generation number,
28// and settings used from the paint to canonicalize image objects.
vandebo@chromium.org421d6442011-07-20 17:39:01 +000029class SkPDFImage : public SkPDFStream {
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000030public:
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000031 /** Create a new Image XObject to represent the passed bitmap.
32 * @param bitmap The image to encode.
33 * @param srcRect The rectangle to cut out of bitmap.
34 * @param paint Used to calculate alpha, masks, etc.
35 * @return The image XObject or NUll if there is nothing to draw for
36 * the given parameters.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000037 */
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000038 static SkPDFImage* CreateImage(const SkBitmap& bitmap,
sugoi@google.come2e81132013-03-05 18:35:55 +000039 const SkIRect& srcRect);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000040
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000041 virtual ~SkPDFImage();
42
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000043 /** Add a Soft Mask (alpha or shape channel) to the image. Refs mask.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000044 * @param mask A gray scale image representing the mask.
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000045 * @return The mask argument is returned.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000046 */
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000047 SkPDFImage* addSMask(SkPDFImage* mask);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000048
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000049 // The SkPDFObject interface.
edisonn@google.com6addb192013-04-02 15:33:08 +000050 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
51 SkTSet<SkPDFObject*>* newResourceObjects);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000052
53private:
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000054 SkTDArray<SkPDFObject*> fResources;
55
56 /** Create a PDF image XObject. Entries for the image properties are
57 * automatically added to the stream dictionary.
58 * @param imageData The final raw bits representing the image.
59 * @param bitmap The image parameters to use (Config, etc).
60 * @param srcRect The clipping applied to bitmap before generating
61 * imageData.
62 * @param alpha Is this the alpha channel of the bitmap.
63 * @param paint Used to calculate alpha, masks, etc.
64 */
65 SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
sugoi@google.come2e81132013-03-05 18:35:55 +000066 const SkIRect& srcRect, bool alpha);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000067};
68
69#endif