blob: eae6877a129c7abd90f5e95988012677f0bacfb1 [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 *
20 * As of now, it only supports 8888 bitmaps (the most common case).
21 *
22 * The SkPDFBitmap::Create function will check the canon for duplicates.
23 */
24class SkPDFBitmap : public SkPDFObject {
25public:
26 // Returns NULL on unsupported bitmap;
27 // TODO(halcanary): support other bitmap colortypes and replace
28 // SkPDFImage.
halcanary792c80f2015-02-20 07:21:05 -080029 static SkPDFBitmap* Create(SkPDFCanon*,
30 const SkBitmap&,
31 const SkIRect& subset);
halcanary1b5c6042015-02-18 11:29:56 -080032 ~SkPDFBitmap();
33 void emitObject(SkWStream*, SkPDFCatalog*) SK_OVERRIDE;
34 void addResources(SkTSet<SkPDFObject*>* resourceSet,
35 SkPDFCatalog* catalog) const SK_OVERRIDE;
36 bool equals(const SkBitmap& other) const {
37 return fBitmap.getGenerationID() == other.getGenerationID() &&
38 fBitmap.pixelRefOrigin() == other.pixelRefOrigin() &&
39 fBitmap.dimensions() == other.dimensions();
40 }
41
42private:
halcanary792c80f2015-02-20 07:21:05 -080043 SkPDFCanon* const fCanon;
halcanary1b5c6042015-02-18 11:29:56 -080044 const SkBitmap fBitmap;
45 const SkAutoTUnref<SkPDFObject> fSMask;
halcanary792c80f2015-02-20 07:21:05 -080046 SkPDFBitmap(SkPDFCanon*, const SkBitmap&, SkPDFObject*);
halcanary1b5c6042015-02-18 11:29:56 -080047 void emitDict(SkWStream*, SkPDFCatalog*, size_t, bool) const;
48};
49
50#endif // SkPDFBitmap_DEFINED