OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "Test.h" | 7 #include "Test.h" |
8 | 8 |
9 #include "Resources.h" | |
9 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
10 #include "SkDocument.h" | 11 #include "SkDocument.h" |
11 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
12 #include "SkStream.h" | 13 #include "SkStream.h" |
13 | 14 |
14 static void test_empty(skiatest::Reporter* reporter) { | 15 static void test_empty(skiatest::Reporter* reporter) { |
15 SkDynamicMemoryWStream stream; | 16 SkDynamicMemoryWStream stream; |
16 | 17 |
17 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream)); | 18 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream)); |
18 | 19 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 } | 104 } |
104 | 105 |
105 DEF_TEST(document_tests, reporter) { | 106 DEF_TEST(document_tests, reporter) { |
106 REQUIRE_PDF_DOCUMENT(document_tests, reporter); | 107 REQUIRE_PDF_DOCUMENT(document_tests, reporter); |
107 test_empty(reporter); | 108 test_empty(reporter); |
108 test_abort(reporter); | 109 test_abort(reporter); |
109 test_abortWithFile(reporter); | 110 test_abortWithFile(reporter); |
110 test_file(reporter); | 111 test_file(reporter); |
111 test_close(reporter); | 112 test_close(reporter); |
112 } | 113 } |
114 | |
115 static SkData* encode_dct(const SkPixmap& pixmap) { | |
116 SkBitmap bm; | |
117 return bm.installPixels(pixmap.info(), | |
118 const_cast<void*>(pixmap.addr()), | |
119 pixmap.rowBytes(), | |
120 pixmap.ctable(), | |
121 nullptr, nullptr) | |
122 ? SkImageEncoder::EncodeData(bm, SkImageEncoder::kJPEG_Type, 85) | |
dogben
2015/12/07 20:34:17
nit: Why not use the other override of EncodeData?
| |
123 : nullptr; | |
124 } | |
125 | |
126 size_t count_bytes(const SkBitmap& bm, bool useDCT) { | |
127 SkDynamicMemoryWStream stream; | |
128 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream)); | |
129 if (useDCT) { | |
130 doc->setDCTEncoder(&encode_dct); | |
131 } | |
132 SkCanvas* canvas = doc->beginPage(64, 64); | |
133 canvas->drawBitmap(bm, 0, 0); | |
134 doc->endPage(); | |
135 doc->close(); | |
136 return stream.bytesWritten(); | |
137 } | |
138 | |
139 DEF_TEST(document_dct_encoder, r) { | |
140 REQUIRE_PDF_DOCUMENT(document_dct_encoder, r); | |
141 SkBitmap bm; | |
142 if (GetResourceAsBitmap("mandrill_64.png", &bm)) { | |
143 // Lossy encoding works better on photographs. | |
144 REPORTER_ASSERT(r, count_bytes(bm, true) < count_bytes(bm, false)); | |
145 } | |
146 } | |
OLD | NEW |