Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Functions | Variables
orientation.cpp File Reference
#include "gm/gm.h"
#include "include/codec/SkEncodedOrigin.h"
#include "include/core/SkBlurTypes.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkMaskFilter.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "tools/DecodeUtils.h"
#include "tools/EncodeUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Macros

#define MAKE_GM(subsample)
 

Functions

static void make_images ()
 
static void draw (SkCanvas *canvas, const char *suffix)
 

Variables

static constexpr int kImgW = 100
 
static constexpr int kImgH = 80
 

Macro Definition Documentation

◆ MAKE_GM

#define MAKE_GM (   subsample)
Value:
DEF_SIMPLE_GM(orientation_##subsample, canvas, 4*kImgW, 2*kImgH) { \
draw(canvas, "_" #subsample); \
}
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
static constexpr int kImgH
static constexpr int kImgW

Definition at line 151 of file orientation.cpp.

151 { \
152 draw(canvas, "_" #subsample); \
153}

Function Documentation

◆ draw()

static void draw ( SkCanvas canvas,
const char *  suffix 
)
static

Definition at line 129 of file orientation.cpp.

129 {
130 // Avoid unused function warning.
131 if ((false)) {
132 make_images();
133 }
134 canvas->save();
135 for (char i = '1'; i <= '8'; i++) {
136 SkString path = SkStringPrintf("images/orientation/%c%s.jpg", i, suffix);
138 if (!image) {
139 continue;
140 }
141 canvas->drawImage(image, 0, 0);
142 if ('4' == i) {
143 canvas->restore();
144 canvas->translate(0, image->height());
145 } else {
146 canvas->translate(image->width(), 0);
147 }
148 }
149}
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
int save()
Definition SkCanvas.cpp:451
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
sk_sp< SkImage > image
Definition examples.cpp:29
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition DecodeUtils.h:25
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
static void make_images()

◆ make_images()

static void make_images ( )
static

This function was used to create the images used by these test. It saves them as PNGs (so they are lossless). Then the following bash script was used to create the oriented JPGs with imagemagick and exiftool: #!/bin/bash

for s in 444 422 420 440 411 410; do for i in {1..8}; do magick convert $i.png -sampling-factor ${s:0:1}:${s:1:1}:${s:2:1} $i_$s.jpg; exiftool -orientation=$i -n -m -overwrite_original $i_$s.jpg; done done

Definition at line 42 of file orientation.cpp.

42 {
43 for (int i = 1; i <= 8; ++i) {
45 SkEncodedOrigin origin = static_cast<SkEncodedOrigin>(i);
46 // We apply the inverse transformation to the PNG we generate, convert the PNG to a
47 // a JPEG using magick, then modify the JPEG's tag using exiftool (without modifying the
48 // stored JPEG data).
49 if (origin >= kLeftTop_SkEncodedOrigin) {
50 // The last four SkEncodedOrigin values involve 90 degree rotations
51 using std::swap;
52 swap(size.fWidth, size.fHeight);
53 }
54 using std::swap;
55 auto surf = SkSurfaces::Raster(
57 auto* canvas = surf->getCanvas();
59 SkAssertResult(m.invert(&m));
60 canvas->concat(m);
61 canvas->clear(SK_ColorBLACK);
63 paint.setColor(SK_ColorRED);
64 SkScalar midX = kImgW / 2.f;
65 SkScalar midY = kImgH / 2.f;
66 SkScalar w = midX - 1;
67 SkScalar h = midY - 1;
68 canvas->drawRect(SkRect::MakeXYWH(1, 1, w, h), paint);
69 paint.setColor(SK_ColorBLUE);
70 canvas->drawRect(SkRect::MakeXYWH(midX, 1, w, h), paint);
71 paint.setColor(SK_ColorGREEN);
72 canvas->drawRect(SkRect::MakeXYWH(1, midY, w, h), paint);
73 paint.setColor(SK_ColorYELLOW);
74 canvas->drawRect(SkRect::MakeXYWH(midX, midY, w, h), paint);
76
77 SkPaint blurPaint;
79 blurPaint.setColor(SK_ColorBLACK);
80 paint.setColor(SK_ColorWHITE);
81
82 auto drawLabel = [&](const char* string, SkScalar x, SkScalar y) {
83 canvas->save();
84 canvas->translate(1, 1);
85 canvas->drawString(string, x, y, font, blurPaint);
86 canvas->restore();
87 canvas->drawString(string, x, y, font, paint);
88 };
89
90 auto measure = [&font](const char* text) {
92 font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
93 return bounds;
94 };
95
96 static constexpr SkScalar kPad = 3.f;
98
99 bounds = measure("top");
100 drawLabel("top", midX - bounds.centerX(), -bounds.top() + kPad);
101
102 bounds = measure("bottom");
103 drawLabel("bottom", midX - bounds.centerX(), kImgH - kPad - bounds.bottom());
104
105 // It looks weird if "left" and "right" and the number at the center aren't vertically
106 // aligned.
107 SkScalar baseY = midY - measure("leftright").centerY();
108 bounds = measure("left");
109 drawLabel("left", kPad - bounds.left(), baseY);
110
111 bounds = measure("right");
112 drawLabel("right", kImgW - kPad - bounds.right(), baseY);
113
114 SkString num = SkStringPrintf("%d", i);
115 bounds = measure(num.c_str());
116 drawLabel(num.c_str(), midX - bounds.centerX(), baseY);
117 num.append(".png");
118 SkPixmap pm;
119 surf->makeImageSnapshot()->peekPixels(&pm);
121 }
122}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkAssertResult(cond)
Definition SkAssert.h:123
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition SkBlurTypes.h:12
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
constexpr SkColor SK_ColorYELLOW
Definition SkColor.h:139
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
SkEncodedOrigin
@ kLeftTop_SkEncodedOrigin
static SkMatrix SkEncodedOriginToMatrix(SkEncodedOrigin origin, int w, int h)
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition SkRefCnt.h:341
constexpr int kPad
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setMaskFilter(sk_sp< SkMaskFilter > maskFilter)
void append(const char text[])
Definition SkString.h:203
const char * c_str() const
Definition SkString.h:133
const Paint & paint
float SkScalar
Definition extension.cpp:12
std::u16string text
double y
double x
Optional< SkRect > bounds
Definition SkRecords.h:189
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
sk_sp< SkTypeface > DefaultPortableTypeface()
bool EncodeImageToPngFile(const char *path, const SkBitmap &src)
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
font
Font Metadata and Metrics.
SkScalar w
SkScalar h
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

Variable Documentation

◆ kImgH

constexpr int kImgH = 80
staticconstexpr

Definition at line 26 of file orientation.cpp.

◆ kImgW

constexpr int kImgW = 100
staticconstexpr

Definition at line 25 of file orientation.cpp.