aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-20 16:34:34 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-20 16:34:34 +0000
commit85e9db0347fb64e26ca702340cd641c5dda328c4 (patch)
tree2f68394f9466d921e96fdb9e12e840017aee560d /src/utils
parentedd18989acedcf3d8e0061799c895efc589ce19d (diff)
The CL adds libpoppler to DEPS and adds a libpoppler-cpp gyp target for Linux, Windows, and Mac. This does not currently change the GM tool to use poppler - that will be a refactor job in a separate CL.
Several third-party libraries are pulled in, and platform-specific headers are included under third_party/(library name). Chromium style READMEs containing a description of the library, as well as a LICENSE file are also included in that directory. (is there a Skia-specific style for these?) R=vandebo@chromium.org, edisonn@google.com, djsollen@chromium.org, bungeman@chromium.org, open-source-third-party-reviews@google.com, thestig@chromium.org Author: richardlin@chromium.org Review URL: https://chromiumcodereview.appspot.com/20220002 git-svn-id: http://skia.googlecode.com/svn/trunk@10823 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/SkPDFRasterizer.cpp73
-rw-r--r--src/utils/SkPDFRasterizer.h15
2 files changed, 88 insertions, 0 deletions
diff --git a/src/utils/SkPDFRasterizer.cpp b/src/utils/SkPDFRasterizer.cpp
new file mode 100644
index 0000000000..3fd2728a16
--- /dev/null
+++ b/src/utils/SkPDFRasterizer.cpp
@@ -0,0 +1,73 @@
+
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifdef SK_BUILD_FOR_WIN32
+#pragma warning(push)
+#pragma warning(disable : 4530)
+#endif
+
+#include <poppler-document.h>
+#include <poppler-image.h>
+#include <poppler-page.h>
+#include <poppler-page-renderer.h>
+
+#include "SkPDFRasterizer.h"
+#include "SkColorPriv.h"
+
+bool SkPopplerRasterizePDF(SkStream* pdf, SkBitmap* output) {
+ size_t size = pdf->getLength();
+ void* buffer = sk_malloc_throw(size);
+ pdf->read(buffer, size);
+
+ SkAutoTDelete<poppler::document> doc(
+ poppler::document::load_from_raw_data((const char*)buffer, size));
+ if (!doc.get() || doc->is_locked()) {
+ return false;
+ }
+
+ SkAutoTDelete<poppler::page> page(doc->create_page(0));
+ poppler::page_renderer renderer;
+ poppler::image image = renderer.render_page(page.get());
+
+ if (!image.is_valid() || image.format() != poppler::image::format_argb32) {
+ return false;
+ }
+
+ size_t width = image.width(), height = image.height();
+ size_t rowSize = image.bytes_per_row();
+ char *imgData = image.data();
+
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ if (!bitmap.allocPixels()) {
+ return false;
+ }
+ bitmap.eraseColor(SK_ColorWHITE);
+ SkPMColor* bitmapPixels = (SkPMColor*)bitmap.getPixels();
+
+ // do pixel-by-pixel copy to deal with RGBA ordering conversions
+ for (size_t y = 0; y < height; y++) {
+ char *rowData = imgData;
+ for (size_t x = 0; x < width; x++) {
+ uint8_t a = rowData[3];
+ uint8_t r = rowData[2];
+ uint8_t g = rowData[1];
+ uint8_t b = rowData[0];
+
+ *bitmapPixels = SkPreMultiplyARGB(a, r, g, b);
+
+ bitmapPixels++;
+ rowData += 4;
+ }
+ imgData += rowSize;
+ }
+
+ output->swap(bitmap);
+
+ return true;
+}
diff --git a/src/utils/SkPDFRasterizer.h b/src/utils/SkPDFRasterizer.h
new file mode 100644
index 0000000000..4a4083cc21
--- /dev/null
+++ b/src/utils/SkPDFRasterizer.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef SkPDFRasterizer_DEFINED
+#define SkPDFRasterizer_DEFINED
+
+#include "SkBitmap.h"
+#include "SkStream.h"
+
+bool SkPopplerRasterizePDF(SkStream* pdf, SkBitmap* output);
+
+#endif