Flutter Engine
The Flutter Engine
Functions
PDFJpegEmbedTest.cpp File Reference
#include "include/codec/SkEncodedOrigin.h"
#include "include/codec/SkJpegDecoder.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkData.h"
#include "include/core/SkDocument.h"
#include "include/core/SkImage.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkStream.h"
#include "include/core/SkTypes.h"
#include "include/docs/SkPDFDocument.h"
#include "include/private/SkEncodedInfo.h"
#include "src/pdf/SkPDFBitmap.h"
#include "tests/Test.h"
#include "tools/Resources.h"
#include <array>
#include <cstdint>
#include <cstring>

Go to the source code of this file.

Functions

static bool is_subset_of (SkData *smaller, SkData *larger)
 
static sk_sp< SkDataload_resource (skiatest::Reporter *r, const char *test, const char *filename)
 
 DEF_TEST (SkPDF_JpegEmbedTest, r)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( SkPDF_JpegEmbedTest  ,
 
)

Test that for Jpeg files that use the JFIF colorspace, they are directly embedded into the PDF (without re-encoding) when that makes sense.

Definition at line 60 of file PDFJpegEmbedTest.cpp.

60 {
61 REQUIRE_PDF_DOCUMENT(SkPDF_JpegEmbedTest, r);
62 const char test[] = "SkPDF_JpegEmbedTest";
63 sk_sp<SkData> mandrillData(load_resource(r, test, "images/mandrill_512_q075.jpg"));
64 sk_sp<SkData> cmykData(load_resource(r, test, "images/CMYK.jpg"));
65 sk_sp<SkData> yuvICCData(load_resource(r, test, "images/crbug999986.jpeg"));
66 sk_sp<SkData> cmykICCData(load_resource(r, test, "images/crbug1465627.jpeg"));
67
68 if (!mandrillData || !cmykData || !yuvICCData || !cmykICCData) {
69 REPORTER_ASSERT(r, false, "Could not load all images");
70 return;
71 }
72 ////////////////////////////////////////////////////////////////////////////
74 auto document = SkPDF::MakeDocument(&pdf);
75 SkCanvas* canvas = document->beginPage(642, 2048);
76
77 canvas->clear(SK_ColorLTGRAY);
78
80 canvas->drawImage(im1, 65.0, 0.0);
82 canvas->drawImage(im2, 0.0, 512.0);
83
84 // This should be the same blue as the dark spot seen in the image.
85 SkPaint bluePaint;
86 bluePaint.setColor(SkColorSetARGB(255, 0, 59, 103));
87 canvas->drawRect(SkRect::MakeXYWH(0, 1000, 642, 24), bluePaint);
89 canvas->drawImage(im3, 0.0, 1024.0);
90
92 canvas->drawImage(im4, 0.0, 1536.0);
93
94 document->endPage();
95 document->close();
96 sk_sp<SkData> pdfData = pdf.detachAsData();
97 SkASSERT(pdfData);
98
99 #ifndef SK_PDF_BASE85_BINARY
100 REPORTER_ASSERT(r, is_subset_of(mandrillData.get(), pdfData.get()));
101 #endif
102
103 // This JPEG uses a nonstandard colorspace - it can not be
104 // embedded into the PDF directly.
105 REPORTER_ASSERT(r, !is_subset_of(cmykData.get(), pdfData.get()));
106
107 if ((false)) {
108 SkFILEWStream s("/tmp/jpegembed.pdf");
109 REPORTER_ASSERT(r, s.write(pdfData->data(), pdfData->size()));
110 s.flush();
111 s.fsync();
112 }
113}
static sk_sp< SkData > load_resource(skiatest::Reporter *r, const char *test, const char *filename)
static bool is_subset_of(SkData *smaller, SkData *larger)
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorLTGRAY
Definition: SkColor.h:118
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER)
Definition: Test.h:485
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
const void * data() const
Definition: SkData.h:37
size_t size() const
Definition: SkData.h:30
sk_sp< SkData > detachAsData()
Definition: SkStream.cpp:707
void setColor(SkColor color)
Definition: SkPaint.cpp:119
T * get() const
Definition: SkRefCnt.h:303
struct MyStruct s
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ is_subset_of()

static bool is_subset_of ( SkData smaller,
SkData larger 
)
static

Definition at line 29 of file PDFJpegEmbedTest.cpp.

29 {
30 SkASSERT(smaller && larger);
31 if (smaller->size() > larger->size()) {
32 return false;
33 }
34 size_t size = smaller->size();
35 size_t size_diff = larger->size() - size;
36 for (size_t i = 0; i <= size_diff; ++i) {
37 if (0 == memcmp(larger->bytes() + i, smaller->bytes(), size)) {
38 return true;
39 }
40 }
41 return false;
42}
const uint8_t * bytes() const
Definition: SkData.h:43
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ load_resource()

static sk_sp< SkData > load_resource ( skiatest::Reporter r,
const char *  test,
const char *  filename 
)
static

Definition at line 45 of file PDFJpegEmbedTest.cpp.

46 {
48 if (!data) {
49 INFOF(r, "\n%s: Resource '%s' can not be found.\n",
50 test, filename);
51 }
52 return data; // May return nullptr.
53}
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition: Resources.cpp:42
#define INFOF(REPORTER,...)
Definition: Test.h:298
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63