Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkImageTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
16#include "include/core/SkRect.h"
18#include "tests/Test.h"
19#include <cstdint>
20
21static const int gWidth = 20;
22static const int gHeight = 20;
23
24// Tests that SkNewImageFromBitmap obeys pixelref origin.
25DEF_TEST(SkImageFromBitmap_extractSubset, reporter) {
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);
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
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
static const int gHeight
#define DEF_TEST(name, reporter)
Definition Test.h:312
#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
void drawIRect(const SkIRect &rect, const SkPaint &paint)
Definition SkCanvas.h:1358
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
sk_sp< SkImage > image
Definition examples.cpp:29
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)