blob: 922db8f1c10d0fd276e40d74dab585dfab67a92f [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
13/**
14 * SkPDFBitmap wraps a SkBitmap and serializes it as an image Xobject.
15 * It is designed to use a minimal amout of memory, aside from refing
16 * the bitmap's pixels, and its emitObject() does not cache any data.
17 *
18 * As of now, it only supports 8888 bitmaps (the most common case).
19 *
20 * The SkPDFBitmap::Create function will check the canon for duplicates.
21 */
22class SkPDFBitmap : public SkPDFObject {
23public:
24 // Returns NULL on unsupported bitmap;
25 // TODO(halcanary): support other bitmap colortypes and replace
26 // SkPDFImage.
27 static SkPDFBitmap* Create(const SkBitmap&, const SkIRect& subset);
28 ~SkPDFBitmap();
29 void emitObject(SkWStream*, SkPDFCatalog*) SK_OVERRIDE;
30 void addResources(SkTSet<SkPDFObject*>* resourceSet,
31 SkPDFCatalog* catalog) const SK_OVERRIDE;
32 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;
41 SkPDFBitmap(const SkBitmap&, SkPDFObject*);
42 void emitDict(SkWStream*, SkPDFCatalog*, size_t, bool) const;
43};
44
45#endif // SkPDFBitmap_DEFINED