blob: 31f894086ee3949e20e952d205ed818ac3b01f7d [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
edisonn@google.comd9dfa182013-04-24 13:01:01 +000013#include "SkPDFDevice.h"
14#include "SkPDFImageStream.h"
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000015#include "SkPDFTypes.h"
16#include "SkRefCnt.h"
17
18class SkBitmap;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000019class 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.
edisonn@google.comd9dfa182013-04-24 13:01:01 +000030class SkPDFImage : public SkPDFImageStream {
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,
edisonn@google.comd9dfa182013-04-24 13:01:01 +000040 const SkIRect& srcRect,
41 EncodeToDCTStream encoder);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000042
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.com6addb192013-04-02 15:33:08 +000052 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
53 SkTSet<SkPDFObject*>* newResourceObjects);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000054
55private:
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000056 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,
edisonn@google.comd9dfa182013-04-24 13:01:01 +000068 const SkIRect& srcRect, bool alpha, EncodeToDCTStream encoder);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000069};
70
71#endif