Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Unified Diff: tools/render_pdfs_main.cpp

Issue 25054002: Use SkPicture::ExtractBitmap callback in pdf too. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix return on another funtion with signature change Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/PdfRenderer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/render_pdfs_main.cpp
diff --git a/tools/render_pdfs_main.cpp b/tools/render_pdfs_main.cpp
index f4435021c3b7c41690836999045cc5666170fdc4..a7100645281045ace38a2d6745baaa1985a40473 100644
--- a/tools/render_pdfs_main.cpp
+++ b/tools/render_pdfs_main.cpp
@@ -12,6 +12,7 @@
#include "SkImageEncoder.h"
#include "SkOSFile.h"
#include "SkPicture.h"
+#include "SkPixelRef.h"
#include "SkStream.h"
#include "SkTArray.h"
#include "PdfRenderer.h"
@@ -81,30 +82,33 @@ static bool replace_filename_extension(SkString* path,
}
int gJpegQuality = 100;
-static bool encode_to_dct_stream(SkWStream* stream, const SkBitmap& bitmap, const SkIRect& rect) {
- if (gJpegQuality == -1) return false;
-
- SkIRect bitmapBounds;
- SkBitmap subset;
- const SkBitmap* bitmapToUse = &bitmap;
- bitmap.getBounds(&bitmapBounds);
- if (rect != bitmapBounds) {
- SkAssertResult(bitmap.extractSubset(&subset, rect));
- bitmapToUse = ⊂
- }
+static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap) {
+ if (gJpegQuality == -1) {
+ return NULL;
+ }
+ SkBitmap bm = bitmap;
#if defined(SK_BUILD_FOR_MAC)
- // Workaround bug #1043 where bitmaps with referenced pixels cause
- // CGImageDestinationFinalize to crash
- SkBitmap copy;
- bitmapToUse->deepCopyTo(&copy, bitmapToUse->config());
- bitmapToUse = ©
+ // Workaround bug #1043 where bitmaps with referenced pixels cause
+ // CGImageDestinationFinalize to crash
+ SkBitmap copy;
+ bitmap.deepCopyTo(&copy, bitmap.config());
+ bm = copy;
#endif
- return SkImageEncoder::EncodeStream(stream,
- *bitmapToUse,
- SkImageEncoder::kJPEG_Type,
- gJpegQuality);
+ SkPixelRef* pr = bm.pixelRef();
+ if (pr != NULL) {
+ SkData* data = pr->refEncodedData();
+ if (data != NULL) {
+ *pixelRefOffset = bm.pixelRefOffset();
+ return data;
+ }
+ }
+
+ *pixelRefOffset = 0;
+ return SkImageEncoder::EncodeData(bm,
+ SkImageEncoder::kJPEG_Type,
+ gJpegQuality);
}
/** Builds the output filename. path = dir/name, and it replaces expected
@@ -264,7 +268,7 @@ int tool_main_core(int argc, char** argv) {
SkTArray<SkString> inputs;
SkAutoTUnref<sk_tools::PdfRenderer>
- renderer(SkNEW_ARGS(sk_tools::SimplePdfRenderer, (encode_to_dct_stream)));
+ renderer(SkNEW_ARGS(sk_tools::SimplePdfRenderer, (encode_to_dct_data)));
SkASSERT(renderer.get());
SkString outputDir;
« no previous file with comments | « tools/PdfRenderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698