Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
BitmapGetColorTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkRect.h"
#include "include/core/SkTypes.h"
#include "tests/Test.h"
#include <array>
#include <cstddef>
#include <cstdint>

Go to the source code of this file.

Functions

 DEF_TEST (GetColor, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( GetColor  ,
reporter   
)

Definition at line 21 of file BitmapGetColorTest.cpp.

21 {
22 static const struct Rec {
24 SkColor fInColor;
25 SkColor fOutColor;
26 } gRec[] = {
27 // todo: add some tests that involve alpha, so we exercise the
28 // unpremultiply aspect of getColor()
29 { kAlpha_8_SkColorType, 0xFF000000, 0xFF000000 },
30 { kAlpha_8_SkColorType, 0, 0 },
31 { kRGB_565_SkColorType, 0xFF00FF00, 0xFF00FF00 },
32 { kRGB_565_SkColorType, 0xFFFF00FF, 0xFFFF00FF },
33 { kN32_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF },
34 { kN32_SkColorType, 0, 0 },
35 { kN32_SkColorType, 0xFF224466, 0xFF224466 },
36 };
37
38 // specify an area that doesn't touch (0,0) and may extend beyond the
39 // bitmap bounds (to test that we catch that in eraseArea
40 const SkColor initColor = 0xFF0000FF;
41 const SkIRect area = { 1, 1, 3, 3 };
42
43 for (size_t i = 0; i < std::size(gRec); i++) {
46 SkBitmap bm;
47 uint32_t storage[4];
48 bm.installPixels(info, storage, info.minRowBytes());
49
50 bm.eraseColor(initColor);
51 bm.eraseArea(area, gRec[i].fInColor);
52
53 SkColor c = bm.getColor(1, 1);
54 REPORTER_ASSERT(reporter, c == gRec[i].fOutColor);
55 }
56}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static const struct @223 gRec[]
reporter
SkColorType fColorType
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
SkColorType
Definition SkColorType.h:19
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition SkColorType.h:21
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition SkColorType.h:22
uint32_t SkColor
Definition SkColor.h:37
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context)
Definition SkBitmap.cpp:323
void eraseArea(const SkIRect &area, SkColor c) const
Definition SkBitmap.h:854
SkColor getColor(int x, int y) const
Definition SkBitmap.h:874
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)