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

Side by Side Diff: tests/PDFJpegEmbedTest.cpp

Issue 1810813003: update callsites for Make image factories (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: start to take advantage of sk_sp drawImage Created 4 years, 9 months 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 unified diff | Download patch
« no previous file with comments | « tests/ImageTest.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return data; // May return nullptr. 49 return data; // May return nullptr.
50 } 50 }
51 51
52 /** 52 /**
53 * Test that for Jpeg files that use the JFIF colorspace, they are 53 * Test that for Jpeg files that use the JFIF colorspace, they are
54 * directly embedded into the PDF (without re-encoding) when that 54 * directly embedded into the PDF (without re-encoding) when that
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 sk_sp<SkData> mandrillData(load_resource(r, test, "mandrill_512_q075.jpg"));
60 load_resource(r, test, "mandrill_512_q075.jpg")); 60 sk_sp<SkData> cmykData(load_resource(r, test, "CMYK.jpg"));
61 SkAutoTUnref<SkData> cmykData(load_resource(r, test, "CMYK.jpg"));
62 if (!mandrillData || !cmykData) { 61 if (!mandrillData || !cmykData) {
63 return; 62 return;
64 } 63 }
65 //////////////////////////////////////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////////////////////
66 SkDynamicMemoryWStream pdf; 65 SkDynamicMemoryWStream pdf;
67 SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf)); 66 SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf));
68 SkCanvas* canvas = document->beginPage(642, 1028); 67 SkCanvas* canvas = document->beginPage(642, 1028);
69 68
70 canvas->clear(SK_ColorLTGRAY); 69 canvas->clear(SK_ColorLTGRAY);
71 70
72 SkBitmap bm1(bitmap_from_data(mandrillData)); 71 SkBitmap bm1(bitmap_from_data(mandrillData.get()));
73 canvas->drawBitmap(bm1, 65.0, 0.0, nullptr); 72 canvas->drawBitmap(bm1, 65.0, 0.0, nullptr);
74 SkBitmap bm2(bitmap_from_data(cmykData)); 73 SkBitmap bm2(bitmap_from_data(cmykData.get()));
75 canvas->drawBitmap(bm2, 0.0, 512.0, nullptr); 74 canvas->drawBitmap(bm2, 0.0, 512.0, nullptr);
76 75
77 canvas->flush(); 76 canvas->flush();
78 document->endPage(); 77 document->endPage();
79 document->close(); 78 document->close();
80 SkAutoTUnref<SkData> pdfData(pdf.copyToData()); 79 SkAutoTUnref<SkData> pdfData(pdf.copyToData());
81 SkASSERT(pdfData); 80 SkASSERT(pdfData);
82 pdf.reset(); 81 pdf.reset();
83 82
84 REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData)); 83 REPORTER_ASSERT(r, is_subset_of(mandrillData.get(), pdfData.get()));
85 84
86 // This JPEG uses a nonstandard colorspace - it can not be 85 // This JPEG uses a nonstandard colorspace - it can not be
87 // embedded into the PDF directly. 86 // embedded into the PDF directly.
88 REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData)); 87 REPORTER_ASSERT(r, !is_subset_of(cmykData.get(), pdfData.get()));
89 //////////////////////////////////////////////////////////////////////////// 88 ////////////////////////////////////////////////////////////////////////////
90 pdf.reset(); 89 pdf.reset();
91 document.reset(SkDocument::CreatePDF(&pdf)); 90 document.reset(SkDocument::CreatePDF(&pdf));
92 canvas = document->beginPage(642, 1028); 91 canvas = document->beginPage(642, 1028);
93 92
94 canvas->clear(SK_ColorLTGRAY); 93 canvas->clear(SK_ColorLTGRAY);
95 94
96 SkAutoTUnref<SkImage> im1(SkImage::NewFromEncoded(mandrillData)); 95 sk_sp<SkImage> im1(SkImage::MakeFromEncoded(mandrillData));
97 canvas->drawImage(im1, 65.0, 0.0, nullptr); 96 canvas->drawImage(im1.get(), 65.0, 0.0, nullptr);
98 SkAutoTUnref<SkImage> im2(SkImage::NewFromEncoded(cmykData)); 97 sk_sp<SkImage> im2(SkImage::MakeFromEncoded(cmykData));
99 canvas->drawImage(im2, 0.0, 512.0, nullptr); 98 canvas->drawImage(im2.get(), 0.0, 512.0, nullptr);
100 99
101 canvas->flush(); 100 canvas->flush();
102 document->endPage(); 101 document->endPage();
103 document->close(); 102 document->close();
104 pdfData.reset(pdf.copyToData()); 103 pdfData.reset(pdf.copyToData());
105 SkASSERT(pdfData); 104 SkASSERT(pdfData);
106 pdf.reset(); 105 pdf.reset();
107 106
108 REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData)); 107 REPORTER_ASSERT(r, is_subset_of(mandrillData.get(), pdfData.get()));
109 108
110 // This JPEG uses a nonstandard colorspace - it can not be 109 // This JPEG uses a nonstandard colorspace - it can not be
111 // embedded into the PDF directly. 110 // embedded into the PDF directly.
112 REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData)); 111 REPORTER_ASSERT(r, !is_subset_of(cmykData.get(), pdfData.get()));
113 } 112 }
114 113
115 #include "SkJpegInfo.h" 114 #include "SkJpegInfo.h"
116 115
117 DEF_TEST(JpegIdentification, r) { 116 DEF_TEST(JpegIdentification, r) {
118 static struct { 117 static struct {
119 const char* path; 118 const char* path;
120 bool isJfif; 119 bool isJfif;
121 SkJFIFInfo::Type type; 120 SkJFIFInfo::Type type;
122 } kTests[] = {{"CMYK.jpg", false, SkJFIFInfo::kGrayscale}, 121 } kTests[] = {{"CMYK.jpg", false, SkJFIFInfo::kGrayscale},
(...skipping 17 matching lines...) Expand all
140 continue; // not applicable 139 continue; // not applicable
141 } 140 }
142 if (kTests[i].type != info.fType) { 141 if (kTests[i].type != info.fType) {
143 ERRORF(r, "%s failed jfif type test", kTests[i].path); 142 ERRORF(r, "%s failed jfif type test", kTests[i].path);
144 continue; 143 continue;
145 } 144 }
146 INFOF(r, "\nJpegIdentification: %s [%d x %d]\n", kTests[i].path, 145 INFOF(r, "\nJpegIdentification: %s [%d x %d]\n", kTests[i].path,
147 info.fSize.width(), info.fSize.height()); 146 info.fSize.width(), info.fSize.height());
148 } 147 }
149 } 148 }
OLDNEW
« no previous file with comments | « tests/ImageTest.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698