blob: a08cdb5a7dff0f4dc55ce00efa2af64491107b2a [file] [log] [blame]
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkPDFImage_DEFINED
18#define SkPDFImage_DEFINED
19
20#include "SkPDFStream.h"
21#include "SkPDFTypes.h"
22#include "SkRefCnt.h"
23
24class SkBitmap;
25class SkPaint;
26class SkPDFCatalog;
ctguil@chromium.org9db86bb2011-03-04 21:43:27 +000027struct SkIRect;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000028
29/** \class SkPDFImage
30
31 An image XObject.
32*/
33
34// We could play the same trick here as is done in SkPDFGraphicState, storing
35// a copy of the Bitmap object (not the pixels), the pixel generation number,
36// and settings used from the paint to canonicalize image objects.
vandebo@chromium.org421d6442011-07-20 17:39:01 +000037class SkPDFImage : public SkPDFStream {
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000038public:
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000039 /** Create a new Image XObject to represent the passed bitmap.
40 * @param bitmap The image to encode.
41 * @param srcRect The rectangle to cut out of bitmap.
42 * @param paint Used to calculate alpha, masks, etc.
43 * @return The image XObject or NUll if there is nothing to draw for
44 * the given parameters.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000045 */
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000046 static SkPDFImage* CreateImage(const SkBitmap& bitmap,
47 const SkIRect& srcRect,
48 const SkPaint& paint);
49
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000050 virtual ~SkPDFImage();
51
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000052 /** Add a Soft Mask (alpha or shape channel) to the image. Refs mask.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000053 * @param mask A gray scale image representing the mask.
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000054 * @return The mask argument is returned.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000055 */
vandebo@chromium.orgf7c15762011-02-01 22:19:44 +000056 SkPDFImage* addSMask(SkPDFImage* mask);
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000057
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000058 // The SkPDFObject interface.
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000059 virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
60
61private:
vandebo@chromium.org1cfa2c42011-01-31 19:35:43 +000062 SkTDArray<SkPDFObject*> fResources;
63
64 /** Create a PDF image XObject. Entries for the image properties are
65 * automatically added to the stream dictionary.
66 * @param imageData The final raw bits representing the image.
67 * @param bitmap The image parameters to use (Config, etc).
68 * @param srcRect The clipping applied to bitmap before generating
69 * imageData.
70 * @param alpha Is this the alpha channel of the bitmap.
71 * @param paint Used to calculate alpha, masks, etc.
72 */
73 SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
74 const SkIRect& srcRect, bool alpha, const SkPaint& paint);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000075};
76
77#endif