Flutter Engine
The Flutter Engine
Functions | Variables
SkImageTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "tests/Test.h"
#include <cstdint>

Go to the source code of this file.

Functions

 DEF_TEST (SkImageFromBitmap_extractSubset, reporter)
 

Variables

static const int gWidth = 20
 
static const int gHeight = 20
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( SkImageFromBitmap_extractSubset  ,
reporter   
)

Definition at line 25 of file SkImageTest.cpp.

25 {
27 {
28 SkBitmap srcBitmap;
29 srcBitmap.allocN32Pixels(gWidth, gHeight);
30 srcBitmap.eraseColor(SK_ColorRED);
31 SkCanvas canvas(srcBitmap);
32 SkIRect r = SkIRect::MakeXYWH(5, 5, gWidth - 5, gWidth - 5);
33 SkPaint p;
34 p.setColor(SK_ColorGREEN);
35 canvas.drawIRect(r, p);
36 SkBitmap dstBitmap;
37 srcBitmap.extractSubset(&dstBitmap, r);
38 image = dstBitmap.asImage();
39 }
40
41 SkBitmap tgt;
43 SkCanvas canvas(tgt);
44 canvas.clear(SK_ColorTRANSPARENT);
45 canvas.drawImage(image, 0, 0);
46
47 uint32_t pixel = 0;
49 tgt.readPixels(info, &pixel, 4, 0, 0);
51 tgt.readPixels(info, &pixel, 4, gWidth - 6, gWidth - 6);
53
54 tgt.readPixels(info, &pixel, 4, gWidth - 5, gWidth - 5);
56}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
reporter
Definition: FontMgrTest.cpp:39
kUnpremul_SkAlphaType
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
static const int gWidth
Definition: SkImageTest.cpp:21
static const int gHeight
Definition: SkImageTest.cpp:22
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
bool extractSubset(SkBitmap *dst, const SkIRect &subset) const
Definition: SkBitmap.cpp:453
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
Definition: SkBitmap.cpp:488
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
sk_sp< const SkImage > image
Definition: SkRecords.h:269
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

Variable Documentation

◆ gHeight

const int gHeight = 20
static

Definition at line 22 of file SkImageTest.cpp.

◆ gWidth

const int gWidth = 20
static

Definition at line 21 of file SkImageTest.cpp.