blob: 10f8be627077f7c6e7f84e220934a2db35e5eb60 [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
commit-bot@chromium.org608ea652013-10-03 19:29:21 +000013#include "SkPicture.h"
edisonn@google.comd9dfa182013-04-24 13:01:01 +000014#include "SkPDFDevice.h"
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000015#include "SkPDFStream.h"
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000016#include "SkPDFTypes.h"
17#include "SkRefCnt.h"
18
19class SkBitmap;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000020class SkPDFCatalog;
ctguil@chromium.org9db86bb2011-03-04 21:43:27 +000021struct SkIRect;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000022
23/** \class SkPDFImage
24
25 An image XObject.
26*/
27
28// We could play the same trick here as is done in SkPDFGraphicState, storing
29// a copy of the Bitmap object (not the pixels), the pixel generation number,
30// and settings used from the paint to canonicalize image objects.
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000031class SkPDFImage : public SkPDFStream {
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000032public:
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000033 /** Create a new Image XObject to represent the passed bitmap.
34 * @param bitmap The image to encode.
35 * @param srcRect The rectangle to cut out of bitmap.
36 * @param paint Used to calculate alpha, masks, etc.
37 * @return The image XObject or NUll if there is nothing to draw for
38 * the given parameters.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000039 */
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000040 static SkPDFImage* CreateImage(const SkBitmap& bitmap,
edisonn@google.comd9dfa182013-04-24 13:01:01 +000041 const SkIRect& srcRect,
commit-bot@chromium.org608ea652013-10-03 19:29:21 +000042 SkPicture::EncodeBitmap encoder);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000043
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000044 virtual ~SkPDFImage();
45
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000046 /** Add a Soft Mask (alpha or shape channel) to the image. Refs mask.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000047 * @param mask A gray scale image representing the mask.
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000048 * @return The mask argument is returned.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000049 */
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000050 SkPDFImage* addSMask(SkPDFImage* mask);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000051
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000052 bool isEmpty() {
53 return fSrcRect.isEmpty();
54 }
55
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000056 // The SkPDFObject interface.
edisonn@google.com6addb192013-04-02 15:33:08 +000057 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
58 SkTSet<SkPDFObject*>* newResourceObjects);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000059
60private:
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000061 SkBitmap fBitmap;
62 bool fIsAlpha;
63 SkIRect fSrcRect;
commit-bot@chromium.org608ea652013-10-03 19:29:21 +000064 SkPicture::EncodeBitmap fEncoder;
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000065 bool fStreamValid;
66
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000067 SkTDArray<SkPDFObject*> fResources;
68
69 /** Create a PDF image XObject. Entries for the image properties are
70 * automatically added to the stream dictionary.
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000071 * @param stream The image stream. May be NULL. Otherwise, this
72 * (instead of the input bitmap) will be used as the
73 * PDF's content stream, possibly with lossless encoding.
74 * @param bitmap The image. If a stream is not given, its color data
75 * will be used as the image. If a stream is given, this
76 * is used for configuration only.
77 * @param isAlpha Whether or not this is the alpha of an image.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000078 * @param srcRect The clipping applied to bitmap before generating
79 * imageData.
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000080 * @param encoder A function used to encode the bitmap for compression.
81 * May be NULL.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000082 */
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000083 SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha,
commit-bot@chromium.org608ea652013-10-03 19:29:21 +000084 const SkIRect& srcRect, SkPicture::EncodeBitmap encoder);
commit-bot@chromium.org181fcb42013-08-23 19:06:53 +000085
86 /** Copy constructor, used to generate substitutes.
87 * @param image The SkPDFImage to copy.
88 */
89 SkPDFImage(SkPDFImage& pdfImage);
90
91 // Populate the stream dictionary. This method returns false if
92 // fSubstitute should be used.
93 virtual bool populate(SkPDFCatalog* catalog);
94
95 typedef SkPDFStream INHERITED;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000096};
97
98#endif