OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
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 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 streamBytes, strlen(streamBytes), true)); | 146 streamBytes, strlen(streamBytes), true)); |
147 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get())); | 147 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get())); |
148 SimpleCheckObjectOutput( | 148 SimpleCheckObjectOutput( |
149 reporter, stream.get(), | 149 reporter, stream.get(), |
150 "<</Length 12\n>> stream\nTest\nFoo\tBar\nendstream"); | 150 "<</Length 12\n>> stream\nTest\nFoo\tBar\nendstream"); |
151 stream->insert("Attribute", new SkPDFInt(42))->unref(); | 151 stream->insert("Attribute", new SkPDFInt(42))->unref(); |
152 SimpleCheckObjectOutput(reporter, stream.get(), | 152 SimpleCheckObjectOutput(reporter, stream.get(), |
153 "<</Length 12\n/Attribute 42\n>> stream\n" | 153 "<</Length 12\n/Attribute 42\n>> stream\n" |
154 "Test\nFoo\tBar\nendstream"); | 154 "Test\nFoo\tBar\nendstream"); |
155 | 155 |
156 if (SkFlate::HaveFlate()) { | 156 #ifndef SK_NO_FLATE |
| 157 { |
157 char streamBytes2[] = "This is a longer string, so that compression " | 158 char streamBytes2[] = "This is a longer string, so that compression " |
158 "can do something with it. With shorter strings, " | 159 "can do something with it. With shorter strings, " |
159 "the short circuit logic cuts in and we end up " | 160 "the short circuit logic cuts in and we end up " |
160 "with an uncompressed string."; | 161 "with an uncompressed string."; |
161 SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2, | 162 SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2, |
162 strlen(streamBytes2))); | 163 strlen(streamBytes2))); |
163 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get())); | 164 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get())); |
164 | 165 |
165 SkDynamicMemoryWStream compressedByteStream; | 166 SkDynamicMemoryWStream compressedByteStream; |
166 SkFlate::Deflate(streamData2.get(), &compressedByteStream); | 167 SkFlate::Deflate(streamData2.get(), &compressedByteStream); |
(...skipping 13 matching lines...) Expand all Loading... |
180 SkDynamicMemoryWStream expectedResult2; | 181 SkDynamicMemoryWStream expectedResult2; |
181 expectedResult2.writeText("<</Filter /FlateDecode\n/Length 116\n" | 182 expectedResult2.writeText("<</Filter /FlateDecode\n/Length 116\n" |
182 ">> stream\n"); | 183 ">> stream\n"); |
183 expectedResult2.write(compressedData->data(), compressedData->size()); | 184 expectedResult2.write(compressedData->data(), compressedData->size()); |
184 expectedResult2.writeText("\nendstream"); | 185 expectedResult2.writeText("\nendstream"); |
185 SkAutoDataUnref expectedResultData2(expectedResult2.copyToData()); | 186 SkAutoDataUnref expectedResultData2(expectedResult2.copyToData()); |
186 CheckObjectOutput(reporter, stream.get(), | 187 CheckObjectOutput(reporter, stream.get(), |
187 (const char*) expectedResultData2->data(), | 188 (const char*) expectedResultData2->data(), |
188 expectedResultData2->size(), true, true); | 189 expectedResultData2->size(), true, true); |
189 } | 190 } |
| 191 #endif // SK_NO_FLATE |
190 } | 192 } |
191 | 193 |
192 static void TestCatalog(skiatest::Reporter* reporter) { | 194 static void TestCatalog(skiatest::Reporter* reporter) { |
193 SkPDFCatalog catalog((SkPDFDocument::Flags)0); | 195 SkPDFCatalog catalog((SkPDFDocument::Flags)0); |
194 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); | 196 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); |
195 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); | 197 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); |
196 SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3)); | 198 SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3)); |
197 int1.get()->ref(); | 199 int1.get()->ref(); |
198 SkAutoTUnref<SkPDFInt> int1Again(int1.get()); | 200 SkAutoTUnref<SkPDFInt> int1Again(int1.get()); |
199 | 201 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 "/Width 1\n" | 278 "/Width 1\n" |
277 "/Height 1\n" | 279 "/Height 1\n" |
278 "/ColorSpace /DeviceRGB\n" | 280 "/ColorSpace /DeviceRGB\n" |
279 "/BitsPerComponent 8\n" | 281 "/BitsPerComponent 8\n" |
280 "/Length 3\n" | 282 "/Length 3\n" |
281 ">> stream", | 283 ">> stream", |
282 true); | 284 true); |
283 } | 285 } |
284 | 286 |
285 static void TestFlateDecode(skiatest::Reporter* reporter) { | 287 static void TestFlateDecode(skiatest::Reporter* reporter) { |
286 if (!SkFlate::HaveFlate()) { | 288 #ifndef SK_NO_FLATE |
287 return; | |
288 } | |
289 SkBitmap bitmap; | 289 SkBitmap bitmap; |
290 setup_bitmap(&bitmap, 10, 10); | 290 setup_bitmap(&bitmap, 10, 10); |
291 TestImage(reporter, bitmap, | 291 TestImage(reporter, bitmap, |
292 "/Subtype /Image\n" | 292 "/Subtype /Image\n" |
293 "/Width 10\n" | 293 "/Width 10\n" |
294 "/Height 10\n" | 294 "/Height 10\n" |
295 "/ColorSpace /DeviceRGB\n" | 295 "/ColorSpace /DeviceRGB\n" |
296 "/BitsPerComponent 8\n" | 296 "/BitsPerComponent 8\n" |
297 "/Filter /FlateDecode\n" | 297 "/Filter /FlateDecode\n" |
298 "/Length 13\n" | 298 "/Length 13\n" |
299 ">> stream", | 299 ">> stream", |
300 false); | 300 false); |
| 301 #endif // SK_NO_FLATE |
301 } | 302 } |
302 | 303 |
303 static void TestDCTDecode(skiatest::Reporter* reporter) { | 304 static void TestDCTDecode(skiatest::Reporter* reporter) { |
304 SkBitmap bitmap; | 305 SkBitmap bitmap; |
305 setup_bitmap(&bitmap, 32, 32); | 306 setup_bitmap(&bitmap, 32, 32); |
306 TestImage(reporter, bitmap, | 307 TestImage(reporter, bitmap, |
307 "/Subtype /Image\n" | 308 "/Subtype /Image\n" |
308 "/Width 32\n" | 309 "/Width 32\n" |
309 "/Height 32\n" | 310 "/Height 32\n" |
310 "/ColorSpace /DeviceRGB\n" | 311 "/ColorSpace /DeviceRGB\n" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 | 476 |
476 // Filter just created; should be unvisited. | 477 // Filter just created; should be unvisited. |
477 REPORTER_ASSERT(reporter, !filter->visited()); | 478 REPORTER_ASSERT(reporter, !filter->visited()); |
478 SkPaint paint; | 479 SkPaint paint; |
479 paint.setImageFilter(filter.get()); | 480 paint.setImageFilter(filter.get()); |
480 canvas.drawRect(SkRect::MakeWH(100, 100), paint); | 481 canvas.drawRect(SkRect::MakeWH(100, 100), paint); |
481 | 482 |
482 // Filter was used in rendering; should be visited. | 483 // Filter was used in rendering; should be visited. |
483 REPORTER_ASSERT(reporter, filter->visited()); | 484 REPORTER_ASSERT(reporter, filter->visited()); |
484 } | 485 } |
OLD | NEW |