blob: 6816ed65c29a67534acb09646005a08523f782e5 [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();
mtklein36352bf2015-03-25 18:17:31 -070030 void emitObject(SkWStream*, SkPDFCatalog*) override;
31 void addResources(SkPDFCatalog*) const override;
halcanary1b5c6042015-02-18 11:29:56 -080032 bool equals(const SkBitmap& other) const {
33 return fBitmap.getGenerationID() == other.getGenerationID() &&
34 fBitmap.pixelRefOrigin() == other.pixelRefOrigin() &&
35 fBitmap.dimensions() == other.dimensions();
36 }
37
38private:
39 const SkBitmap fBitmap;
40 const SkAutoTUnref<SkPDFObject> fSMask;
halcanary2e3f9d82015-02-27 12:41:03 -080041 SkPDFBitmap(const SkBitmap&, SkPDFObject*);
halcanarydb0dcc72015-03-20 12:31:52 -070042 void emitDict(SkWStream*, SkPDFCatalog*, size_t) const;
halcanary1b5c6042015-02-18 11:29:56 -080043};
44
45#endif // SkPDFBitmap_DEFINED