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

Unified Diff: tests/PDFDocumentTest.cpp

Issue 1505763003: SkDocument::setDCTEncoder() for old versions of webkit (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove compile flag; unit test Created 5 years 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 | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/PDFDocumentTest.cpp
diff --git a/tests/PDFDocumentTest.cpp b/tests/PDFDocumentTest.cpp
index 04c3ede6aa4c595ae7ea6799c23e9d26b1f5d90a..0a693e7bd45ed3b231f0b42689a7314ef1652d5e 100644
--- a/tests/PDFDocumentTest.cpp
+++ b/tests/PDFDocumentTest.cpp
@@ -6,6 +6,7 @@
*/
#include "Test.h"
+#include "Resources.h"
#include "SkCanvas.h"
#include "SkDocument.h"
#include "SkOSFile.h"
@@ -110,3 +111,36 @@ DEF_TEST(document_tests, reporter) {
test_file(reporter);
test_close(reporter);
}
+
+static SkData* encode_dct(const SkPixmap& pixmap) {
+ SkBitmap bm;
+ return bm.installPixels(pixmap.info(),
+ const_cast<void*>(pixmap.addr()),
+ pixmap.rowBytes(),
+ pixmap.ctable(),
+ nullptr, nullptr)
+ ? SkImageEncoder::EncodeData(bm, SkImageEncoder::kJPEG_Type, 85)
dogben 2015/12/07 20:34:17 nit: Why not use the other override of EncodeData?
+ : nullptr;
+}
+
+size_t count_bytes(const SkBitmap& bm, bool useDCT) {
+ SkDynamicMemoryWStream stream;
+ SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream));
+ if (useDCT) {
+ doc->setDCTEncoder(&encode_dct);
+ }
+ SkCanvas* canvas = doc->beginPage(64, 64);
+ canvas->drawBitmap(bm, 0, 0);
+ doc->endPage();
+ doc->close();
+ return stream.bytesWritten();
+}
+
+DEF_TEST(document_dct_encoder, r) {
+ REQUIRE_PDF_DOCUMENT(document_dct_encoder, r);
+ SkBitmap bm;
+ if (GetResourceAsBitmap("mandrill_64.png", &bm)) {
+ // Lossy encoding works better on photographs.
+ REPORTER_ASSERT(r, count_bytes(bm, true) < count_bytes(bm, false));
+ }
+}
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698