blob: 02a79df24e8389ea5afd6f7bdc8923434b57d7bf [file] [log] [blame]
halcanary1b5c6042015-02-18 11:29:56 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#ifndef SkPDFBitmap_DEFINED
8#define SkPDFBitmap_DEFINED
9
10#include "SkPDFTypes.h"
11#include "SkBitmap.h"
12
halcanary792c80f2015-02-20 07:21:05 -080013class SkPDFCanon;
14
halcanary1b5c6042015-02-18 11:29:56 -080015/**
16 * SkPDFBitmap wraps a SkBitmap and serializes it as an image Xobject.
17 * It is designed to use a minimal amout of memory, aside from refing
18 * the bitmap's pixels, and its emitObject() does not cache any data.
19 *
halcanarydb0dcc72015-03-20 12:31:52 -070020 * If !bitmap.isImmutable(), then a copy of the bitmap must be made;
21 * there is no way around this.
halcanary1b5c6042015-02-18 11:29:56 -080022 *
23 * The SkPDFBitmap::Create function will check the canon for duplicates.
24 */
25class SkPDFBitmap : public SkPDFObject {
26public:
27 // Returns NULL on unsupported bitmap;
halcanarydb0dcc72015-03-20 12:31:52 -070028 static SkPDFBitmap* Create(SkPDFCanon*, const SkBitmap&);
halcanary1b5c6042015-02-18 11:29:56 -080029 ~SkPDFBitmap();
30 void emitObject(SkWStream*, SkPDFCatalog*) SK_OVERRIDE;
31 void addResources(SkTSet<SkPDFObject*>* resourceSet,
32 SkPDFCatalog* catalog) const SK_OVERRIDE;
33 bool equals(const SkBitmap& other) const {
34 return fBitmap.getGenerationID() == other.getGenerationID() &&
35 fBitmap.pixelRefOrigin() == other.pixelRefOrigin() &&
36 fBitmap.dimensions() == other.dimensions();
37 }
38
39private:
40 const SkBitmap fBitmap;
41 const SkAutoTUnref<SkPDFObject> fSMask;
halcanary2e3f9d82015-02-27 12:41:03 -080042 SkPDFBitmap(const SkBitmap&, SkPDFObject*);
halcanarydb0dcc72015-03-20 12:31:52 -070043 void emitDict(SkWStream*, SkPDFCatalog*, size_t) const;
halcanary1b5c6042015-02-18 11:29:56 -080044};
45
46#endif // SkPDFBitmap_DEFINED