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

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: 2015-12-09 (Wednesday) 13:41:21 EST 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..c3a5f0e04165846749a4203861ad250396f94dd1 100644
--- a/tests/PDFDocumentTest.cpp
+++ b/tests/PDFDocumentTest.cpp
@@ -6,10 +6,12 @@
*/
#include "Test.h"
+#include "Resources.h"
#include "SkCanvas.h"
#include "SkDocument.h"
#include "SkOSFile.h"
#include "SkStream.h"
+#include "SkPixelSerializer.h"
static void test_empty(skiatest::Reporter* reporter) {
SkDynamicMemoryWStream stream;
@@ -110,3 +112,45 @@ DEF_TEST(document_tests, reporter) {
test_file(reporter);
test_close(reporter);
}
+
+namespace {
+class JPEGSerializer final : public SkPixelSerializer {
+ bool onUseEncodedData(const void*, size_t) override { return true; }
+ SkData* onEncode(const SkPixmap& pixmap) override {
+ SkBitmap bm;
+ return bm.installPixels(pixmap.info(),
+ pixmap.writable_addr(),
+ pixmap.rowBytes(),
+ pixmap.ctable(),
+ nullptr, nullptr)
+ ? SkImageEncoder::EncodeData(bm, SkImageEncoder::kJPEG_Type, 85)
+ : nullptr;
+ }
+};
+} // namespace
+
+size_t count_bytes(const SkBitmap& bm, bool useDCT) {
+ SkDynamicMemoryWStream stream;
+ SkAutoTUnref<SkDocument> doc;
+ if (useDCT) {
+ SkAutoTUnref<SkPixelSerializer> serializer(new JPEGSerializer);
+ doc.reset(SkDocument::CreatePDF(
+ &stream, SK_ScalarDefaultRasterDPI, serializer));
+ } else {
+ doc.reset(SkDocument::CreatePDF(&stream));
+ }
+ 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