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

Unified Diff: src/pdf/SkPDFDevice.cpp

Issue 27236007: Implement perspective for bitmaps in pdf. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: code cleanup Created 7 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFDevice.cpp
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 43117a2b2fc4d5760d692cb50970070721d71b0c..bccb007bec079a9c0d8fd188bb699a31f56b146c 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -2028,13 +2028,82 @@ int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) {
return resourceIndex;
}
-void SkPDFDevice::internalDrawBitmap(const SkMatrix& matrix,
+static void setup_transparent_bitmap(SkBitmap* bitmap, int width, int height) {
+ bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ bitmap->allocPixels();
+ bitmap->eraseColor(SK_ColorTRANSPARENT);
+}
+
+void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix,
const SkClipStack* clipStack,
- const SkRegion& clipRegion,
- const SkBitmap& bitmap,
- const SkIRect* srcRect,
+ const SkRegion& origClipRegion,
+ const SkBitmap& origBitmap2,
+ const SkIRect* origSrcRect,
const SkPaint& paint) {
- // TODO(edisonn): Perspective matrix support implemented here
+ SkMatrix matrix = origMatrix;
+ SkRegion all;
+ const SkRegion* clipRegion = &origClipRegion;
+ SkBitmap origBitmap;
+ SkBitmap bitmap = origBitmap;
+ const SkIRect* srcRect = origSrcRect;
+
+ // Raster the bitmap using perspective in a new bitmap.
+ if (matrix.hasPerspective()) {
+ if (origSrcRect) {
+ if (!origBitmap2.extractSubset(&origBitmap, *origSrcRect)) {
+ return;
+ }
+ } else {
+ origBitmap = origBitmap2;
+ }
+ srcRect = NULL;
+
+ // Transform the bitmap in the new space.
+ SkPath path;
+ path.addRect(SkRect::MakeWH(SkIntToScalar(origBitmap.width()),
+ SkIntToScalar(origBitmap.height())));
+ path.transform(matrix);
+
+ // Retrieve the bounds of the new shape.
+ SkRect bounds = path.getBounds();
vandebo (ex-Chrome) 2013/10/15 21:41:32 Should this be further constrained by the current
edisonn 2013/10/16 15:08:03 This is an optimization. I will add a todo. in a n
+
+ // TODO(edisonn): add DPI settings. Currently 1 pixel/point, which does not look great,
vandebo (ex-Chrome) 2013/10/15 21:41:32 nit: 80 cols
edisonn 2013/10/16 15:08:03 this file is already 100c
vandebo (ex-Chrome) 2013/10/16 16:46:41 Hardly, 31/2073 lines and most of those are over b
edisonn 2013/10/16 18:28:51 Done.
+ // but it is not producing large PDFs.
+
+ // Create transparent bitmap.
+ setup_transparent_bitmap(&bitmap, bounds.width(), bounds.height());
+
+ SkAutoTUnref<SkBitmapDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap)));
+ SkCanvas canvas(device);
+
+ // Find where (0,0) gets mapped in the new space.
+ SkPoint zeroZero = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0));
vandebo (ex-Chrome) 2013/10/15 21:41:32 zeroZero isn't used.
edisonn 2013/10/16 15:08:03 Done.
+ matrix.mapPoints(&zeroZero, 1);
+
+ SkScalar deltaX = bounds.left();
+ SkScalar deltaY = bounds.top();
+
+ SkMatrix matrix2 = matrix;
+ matrix2.postTranslate(-deltaX, -deltaY);
+
+ // Translate the draw in the new canvas, so we perfectly fit the shape in the bitmap.
+ canvas.setMatrix(matrix2);
+
+ canvas.drawBitmap(origBitmap, SkIntToScalar(0), SkIntToScalar(0));
+
+ // Make sure the final bits ar in the bitmap.
vandebo (ex-Chrome) 2013/10/15 21:41:32 ar -> are
edisonn 2013/10/16 15:08:03 Done.
+ canvas.flush();
+
+ // In the new space, we use the identity matrix translated.
+ matrix.setTranslate(deltaX, deltaY);
+ all.setRect(SkIRect::MakeXYWH(SkScalarToFixed(bounds.x()),
+ SkScalarToFixed(bounds.y()),
+ SkScalarToFixed(bounds.width()),
+ SkScalarToFixed(bounds.height())));
+ clipRegion = &all;
+ srcRect = NULL;
+ }
+
SkMatrix scaled;
// Adjust for origin flip.
scaled.setScale(SK_Scalar1, -SK_Scalar1);
@@ -2044,7 +2113,8 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& matrix,
scaled.postScale(SkIntToScalar(subset.width()),
SkIntToScalar(subset.height()));
scaled.postConcat(matrix);
- ScopedContentEntry content(this, clipStack, clipRegion, scaled, paint);
+
+ ScopedContentEntry content(this, clipStack, *clipRegion, scaled, paint);
if (!content.entry()) {
return;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698