Chromium Code Reviews| 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)); |
| + } |
| +} |