aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFBitmap.h
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-02-18 11:29:56 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-18 11:29:57 -0800
commit1b5c604d9d344537941b11b136348edfc39f236c (patch)
tree72110f65007d2e0af1cc525376488ed360b6a07d /src/pdf/SkPDFBitmap.h
parent0babd3c61987428a5c532f65be9d98c7ac583e0d (diff)
PDF: Add (low-memory) SkPDFBitmap class
Also: Add SkDeflateWStream and associated unit tests. SkPDFBitmap is a replacement for SkPDFImage. As of now, it only supports 8888 bitmaps (the most common case). SkPDFBitmap takes very little extra memory (aside from refing the bitmap's pixels), and its emitObject() does not cache any data. The SkPDFBitmap::Create function will check the canon for duplicates. This can reduce the size of the output PDF. Motivation: this gives another ~40% decrease in PDF memory overhead TODO: Support other ColorTypes and scrap SkPDFImage. BUG=skia:3030 Review URL: https://codereview.chromium.org/918813002
Diffstat (limited to 'src/pdf/SkPDFBitmap.h')
-rw-r--r--src/pdf/SkPDFBitmap.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/pdf/SkPDFBitmap.h b/src/pdf/SkPDFBitmap.h
new file mode 100644
index 0000000000..922db8f1c1
--- /dev/null
+++ b/src/pdf/SkPDFBitmap.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef SkPDFBitmap_DEFINED
+#define SkPDFBitmap_DEFINED
+
+#include "SkPDFTypes.h"
+#include "SkBitmap.h"
+
+/**
+ * SkPDFBitmap wraps a SkBitmap and serializes it as an image Xobject.
+ * It is designed to use a minimal amout of memory, aside from refing
+ * the bitmap's pixels, and its emitObject() does not cache any data.
+ *
+ * As of now, it only supports 8888 bitmaps (the most common case).
+ *
+ * The SkPDFBitmap::Create function will check the canon for duplicates.
+ */
+class SkPDFBitmap : public SkPDFObject {
+public:
+ // Returns NULL on unsupported bitmap;
+ // TODO(halcanary): support other bitmap colortypes and replace
+ // SkPDFImage.
+ static SkPDFBitmap* Create(const SkBitmap&, const SkIRect& subset);
+ ~SkPDFBitmap();
+ void emitObject(SkWStream*, SkPDFCatalog*) SK_OVERRIDE;
+ void addResources(SkTSet<SkPDFObject*>* resourceSet,
+ SkPDFCatalog* catalog) const SK_OVERRIDE;
+ bool equals(const SkBitmap& other) const {
+ return fBitmap.getGenerationID() == other.getGenerationID() &&
+ fBitmap.pixelRefOrigin() == other.pixelRefOrigin() &&
+ fBitmap.dimensions() == other.dimensions();
+ }
+
+private:
+ const SkBitmap fBitmap;
+ const SkAutoTUnref<SkPDFObject> fSMask;
+ SkPDFBitmap(const SkBitmap&, SkPDFObject*);
+ void emitDict(SkWStream*, SkPDFCatalog*, size_t, bool) const;
+};
+
+#endif // SkPDFBitmap_DEFINED