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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 * makes sense. | 55 * makes sense. |
56 */ | 56 */ |
57 DEF_TEST(PDFJpegEmbedTest, r) { | 57 DEF_TEST(PDFJpegEmbedTest, r) { |
58 const char test[] = "PDFJpegEmbedTest"; | 58 const char test[] = "PDFJpegEmbedTest"; |
59 SkAutoTUnref<SkData> mandrillData( | 59 SkAutoTUnref<SkData> mandrillData( |
60 load_resource(r, test, "mandrill_512_q075.jpg")); | 60 load_resource(r, test, "mandrill_512_q075.jpg")); |
61 SkAutoTUnref<SkData> cmykData(load_resource(r, test, "CMYK.jpg")); | 61 SkAutoTUnref<SkData> cmykData(load_resource(r, test, "CMYK.jpg")); |
62 if (!mandrillData || !cmykData) { | 62 if (!mandrillData || !cmykData) { |
63 return; | 63 return; |
64 } | 64 } |
65 | 65 //////////////////////////////////////////////////////////////////////////// |
66 SkDynamicMemoryWStream pdf; | 66 SkDynamicMemoryWStream pdf; |
67 SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf)); | 67 SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf)); |
68 SkCanvas* canvas = document->beginPage(642, 1028); | 68 SkCanvas* canvas = document->beginPage(642, 1028); |
69 | 69 |
70 canvas->clear(SK_ColorLTGRAY); | 70 canvas->clear(SK_ColorLTGRAY); |
71 | 71 |
72 SkBitmap bm1(bitmap_from_data(mandrillData)); | 72 SkBitmap bm1(bitmap_from_data(mandrillData)); |
73 canvas->drawBitmap(bm1, 65.0, 0.0, nullptr); | 73 canvas->drawBitmap(bm1, 65.0, 0.0, nullptr); |
74 SkBitmap bm2(bitmap_from_data(cmykData)); | 74 SkBitmap bm2(bitmap_from_data(cmykData)); |
75 canvas->drawBitmap(bm2, 0.0, 512.0, nullptr); | 75 canvas->drawBitmap(bm2, 0.0, 512.0, nullptr); |
76 | 76 |
77 canvas->flush(); | 77 canvas->flush(); |
78 document->endPage(); | 78 document->endPage(); |
79 document->close(); | 79 document->close(); |
80 SkAutoTUnref<SkData> pdfData(pdf.copyToData()); | 80 SkAutoTUnref<SkData> pdfData(pdf.copyToData()); |
81 SkASSERT(pdfData); | 81 SkASSERT(pdfData); |
82 pdf.reset(); | 82 pdf.reset(); |
83 | 83 |
84 REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData)); | 84 REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData)); |
85 | 85 |
86 // This JPEG uses a nonstandard colorspace - it can not be | 86 // This JPEG uses a nonstandard colorspace - it can not be |
87 // embedded into the PDF directly. | 87 // embedded into the PDF directly. |
88 REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData)); | 88 REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData)); |
| 89 //////////////////////////////////////////////////////////////////////////// |
| 90 pdf.reset(); |
| 91 document.reset(SkDocument::CreatePDF(&pdf)); |
| 92 canvas = document->beginPage(642, 1028); |
| 93 |
| 94 canvas->clear(SK_ColorLTGRAY); |
| 95 |
| 96 SkAutoTUnref<SkImage> im1(SkImage::NewFromEncoded(mandrillData)); |
| 97 canvas->drawImage(im1, 65.0, 0.0, nullptr); |
| 98 SkAutoTUnref<SkImage> im2(SkImage::NewFromEncoded(cmykData)); |
| 99 canvas->drawImage(im2, 0.0, 512.0, nullptr); |
| 100 |
| 101 canvas->flush(); |
| 102 document->endPage(); |
| 103 document->close(); |
| 104 pdfData.reset(pdf.copyToData()); |
| 105 SkASSERT(pdfData); |
| 106 pdf.reset(); |
| 107 |
| 108 REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData)); |
| 109 |
| 110 // This JPEG uses a nonstandard colorspace - it can not be |
| 111 // embedded into the PDF directly. |
| 112 REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData)); |
89 } | 113 } |
90 | 114 |
91 #include "SkJpegInfo.h" | 115 #include "SkJpegInfo.h" |
92 | 116 |
93 DEF_TEST(JpegIdentification, r) { | 117 DEF_TEST(JpegIdentification, r) { |
94 static struct { | 118 static struct { |
95 const char* path; | 119 const char* path; |
96 bool isJfif; | 120 bool isJfif; |
97 SkJFIFInfo::Type type; | 121 SkJFIFInfo::Type type; |
98 } kTests[] = {{"CMYK.jpg", false, SkJFIFInfo::kGrayscale}, | 122 } kTests[] = {{"CMYK.jpg", false, SkJFIFInfo::kGrayscale}, |
(...skipping 15 matching lines...) Expand all Loading... |
114 } | 138 } |
115 if (!isJfif) { | 139 if (!isJfif) { |
116 continue; // not applicable | 140 continue; // not applicable |
117 } | 141 } |
118 if (kTests[i].type != info.fType) { | 142 if (kTests[i].type != info.fType) { |
119 ERRORF(r, "%s failed jfif type test", kTests[i].path); | 143 ERRORF(r, "%s failed jfif type test", kTests[i].path); |
120 continue; | 144 continue; |
121 } | 145 } |
122 if (r->verbose()) { | 146 if (r->verbose()) { |
123 SkDebugf("\nJpegIdentification: %s [%d x %d]\n", kTests[i].path, | 147 SkDebugf("\nJpegIdentification: %s [%d x %d]\n", kTests[i].path, |
124 info.fWidth, info.fHeight); | 148 info.fSize.width(), info.fSize.height()); |
125 } | 149 } |
126 } | 150 } |
127 } | 151 } |
OLD | NEW |