OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 | 7 |
8 #include "SkDocument.h" | 8 #include "SkDocument.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkImageGenerator.h" | 10 #include "SkImageGenerator.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 */ | 56 */ |
57 DEF_TEST(PDFJpegEmbedTest, r) { | 57 DEF_TEST(PDFJpegEmbedTest, r) { |
58 const char test[] = "PDFJpegEmbedTest"; | 58 const char test[] = "PDFJpegEmbedTest"; |
59 sk_sp<SkData> mandrillData(load_resource(r, test, "mandrill_512_q075.jpg")); | 59 sk_sp<SkData> mandrillData(load_resource(r, test, "mandrill_512_q075.jpg")); |
60 sk_sp<SkData> cmykData(load_resource(r, test, "CMYK.jpg")); | 60 sk_sp<SkData> cmykData(load_resource(r, test, "CMYK.jpg")); |
61 if (!mandrillData || !cmykData) { | 61 if (!mandrillData || !cmykData) { |
62 return; | 62 return; |
63 } | 63 } |
64 //////////////////////////////////////////////////////////////////////////// | 64 //////////////////////////////////////////////////////////////////////////// |
65 SkDynamicMemoryWStream pdf; | 65 SkDynamicMemoryWStream pdf; |
66 SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf)); | 66 sk_sp<SkDocument> document(SkDocument::MakePDF(&pdf)); |
67 SkCanvas* canvas = document->beginPage(642, 1028); | 67 SkCanvas* canvas = document->beginPage(642, 1028); |
68 | 68 |
69 canvas->clear(SK_ColorLTGRAY); | 69 canvas->clear(SK_ColorLTGRAY); |
70 | 70 |
71 SkBitmap bm1(bitmap_from_data(mandrillData.get())); | 71 SkBitmap bm1(bitmap_from_data(mandrillData.get())); |
72 canvas->drawBitmap(bm1, 65.0, 0.0, nullptr); | 72 canvas->drawBitmap(bm1, 65.0, 0.0, nullptr); |
73 SkBitmap bm2(bitmap_from_data(cmykData.get())); | 73 SkBitmap bm2(bitmap_from_data(cmykData.get())); |
74 canvas->drawBitmap(bm2, 0.0, 512.0, nullptr); | 74 canvas->drawBitmap(bm2, 0.0, 512.0, nullptr); |
75 | 75 |
76 canvas->flush(); | 76 canvas->flush(); |
77 document->endPage(); | 77 document->endPage(); |
78 document->close(); | 78 document->close(); |
79 SkAutoTUnref<SkData> pdfData(pdf.copyToData()); | 79 SkAutoTUnref<SkData> pdfData(pdf.copyToData()); |
80 SkASSERT(pdfData); | 80 SkASSERT(pdfData); |
81 pdf.reset(); | 81 pdf.reset(); |
82 | 82 |
83 REPORTER_ASSERT(r, is_subset_of(mandrillData.get(), pdfData.get())); | 83 REPORTER_ASSERT(r, is_subset_of(mandrillData.get(), pdfData.get())); |
84 | 84 |
85 // This JPEG uses a nonstandard colorspace - it can not be | 85 // This JPEG uses a nonstandard colorspace - it can not be |
86 // embedded into the PDF directly. | 86 // embedded into the PDF directly. |
87 REPORTER_ASSERT(r, !is_subset_of(cmykData.get(), pdfData.get())); | 87 REPORTER_ASSERT(r, !is_subset_of(cmykData.get(), pdfData.get())); |
88 //////////////////////////////////////////////////////////////////////////// | 88 //////////////////////////////////////////////////////////////////////////// |
89 pdf.reset(); | 89 pdf.reset(); |
90 document.reset(SkDocument::CreatePDF(&pdf)); | 90 document = SkDocument::MakePDF(&pdf); |
91 canvas = document->beginPage(642, 1028); | 91 canvas = document->beginPage(642, 1028); |
92 | 92 |
93 canvas->clear(SK_ColorLTGRAY); | 93 canvas->clear(SK_ColorLTGRAY); |
94 | 94 |
95 sk_sp<SkImage> im1(SkImage::MakeFromEncoded(mandrillData)); | 95 sk_sp<SkImage> im1(SkImage::MakeFromEncoded(mandrillData)); |
96 canvas->drawImage(im1.get(), 65.0, 0.0, nullptr); | 96 canvas->drawImage(im1.get(), 65.0, 0.0, nullptr); |
97 sk_sp<SkImage> im2(SkImage::MakeFromEncoded(cmykData)); | 97 sk_sp<SkImage> im2(SkImage::MakeFromEncoded(cmykData)); |
98 canvas->drawImage(im2.get(), 0.0, 512.0, nullptr); | 98 canvas->drawImage(im2.get(), 0.0, 512.0, nullptr); |
99 | 99 |
100 canvas->flush(); | 100 canvas->flush(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 continue; // not applicable | 139 continue; // not applicable |
140 } | 140 } |
141 if (kTests[i].type != info.fType) { | 141 if (kTests[i].type != info.fType) { |
142 ERRORF(r, "%s failed jfif type test", kTests[i].path); | 142 ERRORF(r, "%s failed jfif type test", kTests[i].path); |
143 continue; | 143 continue; |
144 } | 144 } |
145 INFOF(r, "\nJpegIdentification: %s [%d x %d]\n", kTests[i].path, | 145 INFOF(r, "\nJpegIdentification: %s [%d x %d]\n", kTests[i].path, |
146 info.fSize.width(), info.fSize.height()); | 146 info.fSize.width(), info.fSize.height()); |
147 } | 147 } |
148 } | 148 } |
OLD | NEW |