Flutter Engine
The Flutter Engine
Classes | Macros | Functions
imagemagnifier.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPixelRef.h"
#include "include/core/SkRRect.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypeface.h"
#include "include/effects/SkImageFilters.h"
#include "src/base/SkRandom.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/timer/TimeUtils.h"
#include <utility>

Go to the source code of this file.

Classes

class  ImageMagnifierBounds
 

Macros

#define WIDTH   500
 
#define HEIGHT   500
 
#define WIDTH_HEIGHT   256
 

Functions

static void draw_content (SkCanvas *canvas, float maxTextSize, int count)
 
 DEF_SIMPLE_GM_BG (imagemagnifier, canvas, WIDTH, HEIGHT, SK_ColorBLACK)
 
static sk_sp< SkImagemake_img ()
 
 DEF_SIMPLE_GM_BG (imagemagnifier_cropped, canvas, WIDTH_HEIGHT, WIDTH_HEIGHT, SK_ColorBLACK)
 

Macro Definition Documentation

◆ HEIGHT

#define HEIGHT   500

Definition at line 32 of file imagemagnifier.cpp.

◆ WIDTH

#define WIDTH   500

Definition at line 31 of file imagemagnifier.cpp.

◆ WIDTH_HEIGHT

#define WIDTH_HEIGHT   256

Definition at line 59 of file imagemagnifier.cpp.

Function Documentation

◆ DEF_SIMPLE_GM_BG() [1/2]

DEF_SIMPLE_GM_BG ( imagemagnifier  ,
canvas  ,
WIDTH  ,
HEIGHT  ,
SK_ColorBLACK   
)

Definition at line 48 of file imagemagnifier.cpp.

48 {
49 SkPaint filterPaint;
50 filterPaint.setImageFilter(
52 SkFilterMode::kLinear, nullptr));
53 canvas->saveLayer(nullptr, &filterPaint);
54 draw_content(canvas, 300.f, 25);
55 canvas->restore();
56}
static sk_sp< SkImageFilter > Magnifier(const SkRect &lensBounds, SkScalar zoomAmount, SkScalar inset, const SkSamplingOptions &sampling, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
#define WIDTH
static void draw_content(SkCanvas *canvas, float maxTextSize, int count)
#define HEIGHT
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ DEF_SIMPLE_GM_BG() [2/2]

DEF_SIMPLE_GM_BG ( imagemagnifier_cropped  ,
canvas  ,
WIDTH_HEIGHT  ,
WIDTH_HEIGHT  ,
SK_ColorBLACK   
)

Definition at line 83 of file imagemagnifier.cpp.

83 {
85
86 // Crop out a 16 pixel ring around the result
87 const SkIRect cropRect = SkIRect::MakeXYWH(16, 16, WIDTH_HEIGHT-32, WIDTH_HEIGHT-32);
88
89 SkPaint filterPaint;
92 WIDTH_HEIGHT / (WIDTH_HEIGHT - 96.f), 64.f, {},
93 std::move(imageSource), &cropRect));
94
95 canvas->saveLayer(nullptr, &filterPaint);
96 canvas->restore();
97}
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
#define WIDTH_HEIGHT
static sk_sp< SkImage > make_img()
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104

◆ draw_content()

static void draw_content ( SkCanvas canvas,
float  maxTextSize,
int  count 
)
static

Definition at line 34 of file imagemagnifier.cpp.

34 {
35 const char* str = "The quick brown fox jumped over the lazy dog.";
36 SkRandom rand;
38 for (int i = 0; i < count; ++i) {
39 int x = rand.nextULessThan(WIDTH);
40 int y = rand.nextULessThan(HEIGHT);
42 paint.setColor(ToolUtils::color_to_565(rand.nextBits(24) | 0xFF000000));
43 font.setSize(rand.nextRangeScalar(0, maxTextSize));
45 }
46}
int count
Definition: FontMgrTest.cpp:50
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition: SkRandom.h:106
uint32_t nextULessThan(uint32_t count)
Definition: SkRandom.h:93
uint32_t nextBits(unsigned bitCount)
Definition: SkRandom.h:72
const Paint & paint
Definition: color_source.cc:38
double y
double x
SkFont DefaultPortableFont()
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139
font
Font Metadata and Metrics.

◆ make_img()

static sk_sp< SkImage > make_img ( )
static

Definition at line 61 of file imagemagnifier.cpp.

61 {
63 bitmap.allocN32Pixels(WIDTH_HEIGHT, WIDTH_HEIGHT);
64 SkCanvas canvas(bitmap);
65
66 canvas.clear(0x0);
67
69 paint.setColor(SK_ColorBLUE);
70
71 for (float pos = 0; pos < WIDTH_HEIGHT; pos += 16) {
72 canvas.drawLine(0, pos, SkIntToScalar(WIDTH_HEIGHT), pos, paint);
73 canvas.drawLine(pos, 0, pos, SkIntToScalar(WIDTH_HEIGHT), paint);
74 }
75
78 result.setPixelRef(sk_ref_sp(bitmap.pixelRef()), 0, 0);
79
80 return result.asImage();
81}
SkPoint pos
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
GAsyncResult * result
Definition: bitmap.py:1
static SkImageInfo MakeS32(int width, int height, SkAlphaType at)