Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Functions | Variables
bitmappremul.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"

Go to the source code of this file.

Classes

class  skiagm::BitmapPremulGM
 

Namespaces

namespace  skiagm
 

Functions

static void init_bitmap (SkColorType ct, SkBitmap *bitmap)
 
static sk_sp< SkImagemake_argb8888_gradient ()
 
static sk_sp< SkImagemake_argb4444_gradient ()
 
static sk_sp< SkImagemake_argb8888_stripes ()
 
static sk_sp< SkImagemake_argb4444_stripes ()
 
static sk_sp< SkImagemake_out_of_gamut_image (SkColorType ct)
 
 DEF_SIMPLE_GM (image_out_of_gamut, canvas, 2 *kBoxSize+3 *kPadding, kBoxSize+2 *kPadding)
 

Variables

constexpr int SLIDE_SIZE = 256
 
static constexpr int kBoxSize = 31
 
static constexpr int kPadding = 5
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( image_out_of_gamut  ,
canvas  ,
2 *kBoxSize+3 *  kPadding,
kBoxSize+2 *  kPadding 
)

Definition at line 132 of file bitmappremul.cpp.

132 {
133 // This GM draws an image with out-of-gamut colors (RGB > A). Historically, Skia assumed this
134 // was impossible, and contained numerous asserts and optimizations that would break if the
135 // rule were violated. With color spaces and/or SkSL shaders (among other things), it's no
136 // longer reasonable to make this claim. To catch issues with legacy blitters, this draws both
137 // RGBA and BGRA. (This ensures that we always hit the N32 -> N32 case).
138 canvas->clear(SK_ColorGRAY);
139
142
143 canvas->translate(kPadding, kPadding);
144 canvas->drawImage(rgba, 0, 0);
145 canvas->translate(kBoxSize + kPadding, 0);
146 canvas->drawImage(bgra, 0, 0);
147}
static const uint32_t bgra[kNumPixels]
static const uint32_t rgba[kNumPixels]
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
constexpr SkColor SK_ColorGRAY
Definition SkColor.h:113
static constexpr int kPadding
static sk_sp< SkImage > make_out_of_gamut_image(SkColorType ct)
static constexpr int kBoxSize

◆ init_bitmap()

static void init_bitmap ( SkColorType  ct,
SkBitmap bitmap 
)
static

Definition at line 32 of file bitmappremul.cpp.

32 {
35 bitmap->eraseColor(SK_ColorWHITE);
36}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
constexpr int SLIDE_SIZE
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ make_argb4444_gradient()

static sk_sp< SkImage > make_argb4444_gradient ( )
static

Definition at line 50 of file bitmappremul.cpp.

50 {
53 // Using draw rather than readPixels to suppress dither
55 paint.setBlendMode(SkBlendMode::kSrc);
57 return bitmap.asImage();
58}
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition SkColorType.h:23
static sk_sp< SkImage > make_argb8888_gradient()
static void init_bitmap(SkColorType ct, SkBitmap *bitmap)
const Paint & paint

◆ make_argb4444_stripes()

static sk_sp< SkImage > make_argb4444_stripes ( )
static

Definition at line 79 of file bitmappremul.cpp.

79 {
82 // Using draw rather than readPixels to suppress dither
84 paint.setBlendMode(SkBlendMode::kSrc);
86 return bitmap.asImage();
87}
static sk_sp< SkImage > make_argb8888_stripes()

◆ make_argb8888_gradient()

static sk_sp< SkImage > make_argb8888_gradient ( )
static

Definition at line 38 of file bitmappremul.cpp.

38 {
40 init_bitmap(kN32_SkColorType, &bitmap);
41 for (int y = 0; y < SLIDE_SIZE; y++) {
42 uint32_t* dst = bitmap.getAddr32(0, y);
43 for (int x = 0; x < SLIDE_SIZE; x++) {
44 dst[x] = SkPackARGB32(y, y, y, y);
45 }
46 }
47 return bitmap.asImage();
48}
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
double y
double x
dst
Definition cp.py:12

◆ make_argb8888_stripes()

static sk_sp< SkImage > make_argb8888_stripes ( )
static

Definition at line 60 of file bitmappremul.cpp.

60 {
62 init_bitmap(kN32_SkColorType, &bitmap);
63 uint8_t rowColor = 0;
64 for (int y = 0; y < SLIDE_SIZE; y++) {
65 uint32_t* dst = bitmap.getAddr32(0, y);
66 for (int x = 0; x < SLIDE_SIZE; x++) {
67 dst[x] = SkPackARGB32(rowColor, rowColor,
68 rowColor, rowColor);
69 }
70 if (rowColor == 0) {
71 rowColor = 255;
72 } else {
73 rowColor = 0;
74 }
75 }
76 return bitmap.asImage();
77}

◆ make_out_of_gamut_image()

static sk_sp< SkImage > make_out_of_gamut_image ( SkColorType  ct)
static

Definition at line 120 of file bitmappremul.cpp.

120 {
121 SkBitmap bmp;
122 // Odd dimensions so that we hit the different implementation in the SIMD tail handling
124 for (int y = 0; y < kBoxSize; ++y) {
125 for (int x = 0; x < kBoxSize; ++x) {
126 *bmp.getAddr32(x, y) = (0x40000000 | ((x * 8) << 8) | ((y * 8) << 0));
127 }
128 }
129 return bmp.asImage();
130}
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
sk_sp< SkImage > asImage() const
Definition SkBitmap.cpp:645
uint32_t * getAddr32(int x, int y) const
Definition SkBitmap.h:1260

Variable Documentation

◆ kBoxSize

constexpr int kBoxSize = 31
staticconstexpr

Definition at line 117 of file bitmappremul.cpp.

◆ kPadding

constexpr int kPadding = 5
staticconstexpr

Definition at line 118 of file bitmappremul.cpp.

◆ SLIDE_SIZE

constexpr int SLIDE_SIZE = 256
constexpr

This GM checks that bitmap pixels are unpremultiplied before being exported to other formats. If unpremultiplication is implemented properly, this GM should come out completely white. If not, this GM looks like a row of two greyscale gradients above a row of grey lines. This tests both the ARGB4444 and ARGB8888 bitmap configurations.

Definition at line 30 of file bitmappremul.cpp.