blob: 52d323d0eedd8e969a1c66f2b2b3e231b141d10c [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"
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000014#include "SkPDFStream.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.
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +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,
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
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000051 bool isEmpty() {
52 return fSrcRect.isEmpty();
53 }
54
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000055 // The SkPDFObject interface.
edisonn@google.com6addb192013-04-02 15:33:08 +000056 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
57 SkTSet<SkPDFObject*>* newResourceObjects);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000058
59private:
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000060 SkBitmap fBitmap;
61 bool fIsAlpha;
62 SkIRect fSrcRect;
63 EncodeToDCTStream fEncoder;
64 bool fStreamValid;
65
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000066 SkTDArray<SkPDFObject*> fResources;
67
68 /** Create a PDF image XObject. Entries for the image properties are
69 * automatically added to the stream dictionary.
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000070 * @param stream The image stream. May be NULL. Otherwise, this
71 * (instead of the input bitmap) will be used as the
72 * PDF's content stream, possibly with lossless encoding.
73 * @param bitmap The image. If a stream is not given, its color data
74 * will be used as the image. If a stream is given, this
75 * is used for configuration only.
76 * @param isAlpha Whether or not this is the alpha of an image.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000077 * @param srcRect The clipping applied to bitmap before generating
78 * imageData.
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000079 * @param encoder A function used to encode the bitmap for compression.
80 * May be NULL.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000081 */
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000082 SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha,
83 const SkIRect& srcRect, EncodeToDCTStream encoder);
84
85 /** Copy constructor, used to generate substitutes.
86 * @param image The SkPDFImage to copy.
87 */
88 SkPDFImage(SkPDFImage& pdfImage);
89
90 // Populate the stream dictionary. This method returns false if
91 // fSubstitute should be used.
92 virtual bool populate(SkPDFCatalog* catalog);
93
94 typedef SkPDFStream INHERITED;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000095};
96
97#endif