Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
BitmapTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMallocPixelRef.h"
#include "include/core/SkPixelRef.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkRandom.h"
#include "tests/Test.h"
#include "tools/ToolUtils.h"
#include <cstddef>
#include <initializer_list>

Go to the source code of this file.

Functions

static void test_peekpixels (skiatest::Reporter *reporter)
 
static void test_bigalloc (skiatest::Reporter *reporter)
 
static void test_allocpixels (skiatest::Reporter *reporter)
 
static void test_bigwidth (skiatest::Reporter *reporter)
 
 DEF_TEST (Bitmap, reporter)
 
 DEF_TEST (Bitmap_setColorSpace, r)
 
 DEF_TEST (Bitmap_getColor_Swizzle, r)
 
static void test_erasecolor_premul (skiatest::Reporter *reporter, SkColorType ct, SkColor input, SkColor expected)
 
 DEF_TEST (Bitmap_eraseColor_Premul, r)
 
 DEF_TEST (Bitmap_compute_is_opaque, r)
 
 DEF_TEST (Bitmap_erase_f16_erase_getColor, r)
 
 DEF_TEST (Bitmap_erase_srgb, r)
 
 DEF_TEST (Bitmap_clear_pixelref_keep_info, r)
 
 DEF_TEST (Bitmap_erase, r)
 
static void check_alphas (skiatest::Reporter *reporter, const SkBitmap &bm, bool(*pred)(float expected, float actual), SkColorType ct)
 
static bool unit_compare (float expected, float actual, float tol=1.0f/(1<< 12))
 
static float unit_discretize (float value, float scale)
 
 DEF_TEST (getalphaf, reporter)
 
 DEF_TEST (bitmap_zerowidth_crbug_1103827, reporter)
 

Function Documentation

◆ check_alphas()

static void check_alphas ( skiatest::Reporter reporter,
const SkBitmap bm,
bool(*)(float expected, float actual)  pred,
SkColorType  ct 
)
static

Definition at line 359 of file BitmapTest.cpp.

360 {
361 SkASSERT(bm.width() == 16);
362 SkASSERT(bm.height() == 16);
363
364 int alpha = 0;
365 for (int y = 0; y < 16; ++y) {
366 for (int x = 0; x < 16; ++x) {
367 float expected = alpha / 255.0f;
368 float actual = bm.getAlphaf(x, y);
369 if (!pred(expected, actual)) {
370 ERRORF(reporter, "%s: got %g, want %g\n",
371 ToolUtils::colortype_name(ct), actual, expected);
372 }
373 alpha += 1;
374 }
375 }
376}
reporter
#define SkASSERT(cond)
Definition SkAssert.h:116
#define ERRORF(r,...)
Definition Test.h:293
int width() const
Definition SkBitmap.h:149
float getAlphaf(int x, int y) const
Definition SkBitmap.h:903
int height() const
Definition SkBitmap.h:158
double y
double x
const char * colortype_name(SkColorType ct)
Definition ToolUtils.cpp:65

◆ DEF_TEST() [1/11]

DEF_TEST ( Bitmap  ,
reporter   
)

Definition at line 157 of file BitmapTest.cpp.

157 {
158 // Zero-sized bitmaps are allowed
159 for (int width = 0; width < 2; ++width) {
160 for (int height = 0; height < 2; ++height) {
161 SkBitmap bm;
162 bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height));
163 REPORTER_ASSERT(reporter, setConf);
164 if (setConf) {
165 bm.allocPixels();
166 }
168 }
169 }
170
175}
static void test_peekpixels(skiatest::Reporter *reporter)
static void test_bigwidth(skiatest::Reporter *reporter)
static void test_bigalloc(skiatest::Reporter *reporter)
static void test_allocpixels(skiatest::Reporter *reporter)
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
bool empty() const
Definition SkBitmap.h:210
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Definition SkBitmap.cpp:114
int32_t height
int32_t width
static SkImageInfo MakeN32Premul(int width, int height)

◆ DEF_TEST() [2/11]

DEF_TEST ( Bitmap_clear_pixelref_keep_info  ,
 
)

Definition at line 320 of file BitmapTest.cpp.

320 {
321 SkBitmap bm;
323 bm.setPixelRef(nullptr, 0, 0);
324 SkDEBUGCODE(bm.validate();)
325}
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
void setPixelRef(sk_sp< SkPixelRef > pixelRef, int dx, int dy)
Definition SkBitmap.cpp:182

◆ DEF_TEST() [3/11]

DEF_TEST ( Bitmap_compute_is_opaque  ,
 
)

Definition at line 265 of file BitmapTest.cpp.

265 {
266
267 for (int i = 1; i <= kLastEnum_SkColorType; ++i) {
268 SkColorType ct = (SkColorType) i;
269 SkBitmap bm;
271 bm.allocPixels(SkImageInfo::Make(13, 17, ct, at));
272 bm.eraseColor(SkColorSetARGB(255, 10, 20, 30));
274
275 bm.eraseColor(SkColorSetARGB(128, 255, 255, 255));
276 bool isOpaque = SkBitmap::ComputeIsOpaque(bm);
277 bool shouldBeOpaque = (at == kOpaque_SkAlphaType);
278 REPORTER_ASSERT(r, isOpaque == shouldBeOpaque);
279 }
280}
SkAlphaType
Definition SkAlphaType.h:26
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
SkColorType
Definition SkColorType.h:19
@ kLastEnum_SkColorType
last valid value
Definition SkColorType.h:56
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColor.h:49
SK_API bool SkColorTypeIsAlwaysOpaque(SkColorType ct)
static bool ComputeIsOpaque(const SkBitmap &bm)
Definition SkBitmap.h:358
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ DEF_TEST() [4/11]

DEF_TEST ( Bitmap_erase  ,
 
)

Definition at line 329 of file BitmapTest.cpp.

329 {
330 SkColorType colorTypes[] = {
338 };
339
340 for (SkColorType ct : colorTypes) {
342
343 SkBitmap bm;
344 bm.allocPixels(info);
345
346 bm.eraseColor(0x00000000);
348 REPORTER_ASSERT(r, bm.getColor(0,0) == 0xff000000);
349 } else {
350 REPORTER_ASSERT(r, bm.getColor(0,0) == 0x00000000);
351 }
352
353 bm.eraseColor(0xaabbccdd);
354 REPORTER_ASSERT(r, bm.getColor(0,0) != 0xff000000);
355 REPORTER_ASSERT(r, bm.getColor(0,0) != 0x00000000);
356 }
357}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition SkColorType.h:23
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kRGB_101010x_SkColorType
pixel with 10 bits each for red, green, blue; in 32-bit word
Definition SkColorType.h:29
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition SkColorType.h:22
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition SkColorType.h:25
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition SkColorType.h:27
SkColor getColor(int x, int y) const
Definition SkBitmap.h:874

◆ DEF_TEST() [5/11]

DEF_TEST ( Bitmap_erase_f16_erase_getColor  ,
 
)

Definition at line 283 of file BitmapTest.cpp.

283 {
284 SkRandom random;
285 SkPixmap pm;
286 SkBitmap bm;
288 REPORTER_ASSERT(r, bm.peekPixels(&pm));
289 for (unsigned i = 0; i < 0x100; ++i) {
290 // Test all possible values of blue component.
291 SkColor color1 = (SkColor)((random.nextU() & 0xFFFFFF00) | i);
292 // Test all possible values of alpha component.
293 SkColor color2 = (SkColor)((random.nextU() & 0x00FFFFFF) | (i << 24));
294 for (SkColor color : {color1, color2}) {
295 pm.erase(color);
296 if (SkColorGetA(color) != 0) {
297 REPORTER_ASSERT(r, color == pm.getColor(0, 0));
298 } else {
299 REPORTER_ASSERT(r, 0 == SkColorGetA(pm.getColor(0, 0)));
300 }
301 }
302 }
303}
SkColor4f color
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition SkColorType.h:38
uint32_t SkColor
Definition SkColor.h:37
#define SkColorGetA(color)
Definition SkColor.h:61
bool peekPixels(SkPixmap *pixmap) const
Definition SkBitmap.cpp:635
SkColor getColor(int x, int y) const
Definition SkPixmap.cpp:187
bool erase(SkColor color, const SkIRect &subset) const
Definition SkPixmap.cpp:742
uint32_t nextU()
Definition SkRandom.h:42

◆ DEF_TEST() [6/11]

DEF_TEST ( Bitmap_erase_srgb  ,
 
)

Definition at line 307 of file BitmapTest.cpp.

307 {
308 SkBitmap bm;
309 // Use a color spin from SRGB.
310 bm.allocPixels(SkImageInfo::Make(1, 1, kN32_SkColorType, kPremul_SkAlphaType,
311 SkColorSpace::MakeSRGB()->makeColorSpin()));
312 // RED will be converted into the spun color space.
314 // getColor doesn't take the color space into account, so the returned color
315 // is different due to the color spin.
316 REPORTER_ASSERT(r, bm.getColor(0, 0) == SK_ColorBLUE);
317}
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
static sk_sp< SkColorSpace > MakeSRGB()

◆ DEF_TEST() [7/11]

DEF_TEST ( Bitmap_eraseColor_Premul  ,
 
)

This test checks that eraseColor premultiplies the color correctly.

Definition at line 255 of file BitmapTest.cpp.

255 {
256 SkColor color = 0x80FF0080;
262}
static void test_erasecolor_premul(skiatest::Reporter *reporter, SkColorType ct, SkColor input, SkColor expected)
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition SkColorType.h:21

◆ DEF_TEST() [8/11]

DEF_TEST ( Bitmap_getColor_Swizzle  ,
 
)

This test checks that getColor works for both swizzles.

Definition at line 225 of file BitmapTest.cpp.

225 {
229 SkColorType colorTypes[] = {
232 };
233 for (SkColorType ct : colorTypes) {
235 if (!ToolUtils::copy_to(&copy, ct, source)) {
236 ERRORF(r, "SkBitmap::copy failed %d", (int)ct);
237 continue;
238 }
239 REPORTER_ASSERT(r, source.getColor(0, 0) == copy.getColor(0, 0));
240 }
241}
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
SkBitmap source
Definition examples.cpp:28
bool copy_to(SkBitmap *dst, SkColorType dstColorType, const SkBitmap &src)
Definition copy.py:1

◆ DEF_TEST() [9/11]

DEF_TEST ( Bitmap_setColorSpace  ,
 
)

Definition at line 177 of file BitmapTest.cpp.

177 {
178 // Make a 1x1 bitmap holding 50% gray in default colorspace.
181 source.eraseColor(SkColorSetARGB(0xFF, 0x80, 0x80, 0x80));
182
183 // Readback should use the normal sRGB colorspace.
184 const SkImageInfo kReadbackInfo = SkImageInfo::Make(/*width=*/1,
185 /*height=*/1,
186 kN32_SkColorType,
189 // Do readback and verify that the color is gray.
190 uint8_t pixelData[4];
191 REPORTER_ASSERT(r, source.readPixels(kReadbackInfo,
192 pixelData,
193 /*dstRowBytes=*/4,
194 /*srcX=*/0,
195 /*srcY=*/0));
196 REPORTER_ASSERT(r, pixelData[0] == 0x80);
197 REPORTER_ASSERT(r, pixelData[1] == 0x80);
198 REPORTER_ASSERT(r, pixelData[2] == 0x80);
199
200 // Also check the color with getColor4f, which does not honor colorspaces.
201 uint32_t colorRGBA = source.getColor4f(0, 0).toBytes_RGBA();
202 REPORTER_ASSERT(r, colorRGBA == 0xFF808080, "RGBA=%08X", colorRGBA);
203
204 // Convert the SkBitmap's colorspace to linear.
206
207 // Readback again and verify that the color is interpreted differently.
208 REPORTER_ASSERT(r, source.readPixels(kReadbackInfo,
209 pixelData,
210 /*dstRowBytes=*/4,
211 /*srcX=*/0,
212 /*srcY=*/0));
213 REPORTER_ASSERT(r, pixelData[0] == 0xBC, "R:%02X", pixelData[0]);
214 REPORTER_ASSERT(r, pixelData[1] == 0xBC, "G:%02X", pixelData[1]);
215 REPORTER_ASSERT(r, pixelData[2] == 0xBC, "B:%02X", pixelData[2]);
216
217 // Since getColor4f does not honor colorspaces, this should still contain 50% gray.
218 colorRGBA = source.getColor4f(0, 0).toBytes_RGBA();
219 REPORTER_ASSERT(r, colorRGBA == 0xFF808080, "RGBA=%08X", colorRGBA);
220}
SkColor4f getColor4f(int x, int y) const
Definition SkBitmap.h:893
void setColorSpace(sk_sp< SkColorSpace > colorSpace)
Definition SkBitmap.cpp:160
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
Definition SkBitmap.cpp:488
static sk_sp< SkColorSpace > MakeSRGBLinear()

◆ DEF_TEST() [10/11]

DEF_TEST ( bitmap_zerowidth_crbug_1103827  ,
reporter   
)

Definition at line 472 of file BitmapTest.cpp.

472 {
473 const size_t big_rb = 1 << 16;
474
475 struct {
476 int width, height;
477 size_t rowbytes, expected_size;
478 } rec[] = {
479 { 2, 0, big_rb, 0 }, // zero-height means zero-size
480 { 0, 2, big_rb, big_rb }, // zero-width is computed normally
481 };
482
483 for (const auto& r : rec) {
484 auto info = SkImageInfo::Make(r.width, r.height,
486 size_t size = info.computeByteSize(r.rowbytes);
487 REPORTER_ASSERT(reporter, size == r.expected_size);
488
489 SkBitmap bm;
490 bm.setInfo(info, r.rowbytes);
492
493 // Be sure we can actually write to that much memory. If the bitmap underallocated
494 // the buffer, this should trash memory and crash (we hope).
495 bm.allocPixels();
496 sk_bzero(bm.getPixels(), size);
497 }
498}
static void sk_bzero(void *buffer, size_t size)
Definition SkMalloc.h:105
size_t computeByteSize() const
Definition SkBitmap.h:293
void * getPixels() const
Definition SkBitmap.h:283
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259

◆ DEF_TEST() [11/11]

DEF_TEST ( getalphaf  ,
reporter   
)

Definition at line 397 of file BitmapTest.cpp.

397 {
399 SkBitmap bm;
400 bm.allocPixels(info);
401
402 int alpha = 0;
403 for (int y = 0; y < 16; ++y) {
404 for (int x = 0; x < 16; ++x) {
405 *bm.getAddr32(x, y) = alpha++ << 24;
406 }
407 }
408
409 auto nearly = [](float expected, float actual) -> bool {
410 return unit_compare(expected, actual);
411 };
412 auto nearly4bit = [](float expected, float actual) -> bool {
413 expected = unit_discretize(expected, 15);
414 return unit_compare(expected, actual);
415 };
416 auto nearly2bit = [](float expected, float actual) -> bool {
417 expected = unit_discretize(expected, 3);
418 return unit_compare(expected, actual);
419 };
420 auto opaque = [](float expected, float actual) -> bool {
421 return actual == 1.0f;
422 };
423
424 auto nearly_half = [](float expected, float actual) -> bool {
425 return unit_compare(expected, actual, 1.0f/(1<<10));
426 };
427
428 const struct {
430 bool (*fPred)(float, float);
431 } recs[] = {
432 { kRGB_565_SkColorType, opaque },
433 { kGray_8_SkColorType, opaque },
434 { kR8G8_unorm_SkColorType, opaque },
435 { kR16G16_unorm_SkColorType, opaque },
436 { kR16G16_float_SkColorType, opaque },
437 { kRGB_888x_SkColorType, opaque },
438 { kRGB_101010x_SkColorType, opaque },
439
440 { kAlpha_8_SkColorType, nearly },
441 { kA16_unorm_SkColorType, nearly },
442 { kA16_float_SkColorType, nearly_half },
443 { kRGBA_8888_SkColorType, nearly },
444 { kBGRA_8888_SkColorType, nearly },
446 { kRGBA_F16_SkColorType, nearly_half },
447 { kRGBA_F32_SkColorType, nearly },
448
449 { kRGBA_1010102_SkColorType, nearly2bit },
450
451 { kARGB_4444_SkColorType, nearly4bit },
452 };
453
454 for (const auto& rec : recs) {
455 SkBitmap tmp;
456 tmp.allocPixels(bm.info().makeColorType(rec.fColorType));
457 if (bm.readPixels(tmp.pixmap())) {
458 check_alphas(reporter, tmp, rec.fPred, rec.fColorType);
459 } else {
460 SkDebugf("can't readpixels\n");
461 }
462 }
463}
static bool unit_compare(float expected, float actual, float tol=1.0f/(1<< 12))
static void check_alphas(skiatest::Reporter *reporter, const SkBitmap &bm, bool(*pred)(float expected, float actual), SkColorType ct)
static float unit_discretize(float value, float scale)
SkColorType fColorType
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
Definition SkColorType.h:50
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
Definition SkColorType.h:43
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
Definition SkColorType.h:48
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition SkColorType.h:35
@ kA16_float_SkColorType
pixel with a half float for alpha
Definition SkColorType.h:45
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
Definition SkColorType.h:40
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
Definition SkColorType.h:49
@ kR16G16_float_SkColorType
pixel with a half float for red and green
Definition SkColorType.h:46
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
const SkPixmap & pixmap() const
Definition SkBitmap.h:133
const SkImageInfo & info() const
Definition SkBitmap.h:139
uint32_t * getAddr32(int x, int y) const
Definition SkBitmap.h:1260
SkImageInfo makeColorType(SkColorType newColorType) const

◆ test_allocpixels()

static void test_allocpixels ( skiatest::Reporter reporter)
static

Definition at line 68 of file BitmapTest.cpp.

68 {
69 const int width = 10;
70 const int height = 10;
72 const size_t explicitRowBytes = info.minRowBytes() + 24;
73
74 SkBitmap bm;
75 bm.setInfo(info);
76 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
77 bm.allocPixels();
78 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
79 bm.reset();
80 bm.allocPixels(info);
81 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
82
83 bm.setInfo(info, explicitRowBytes);
84 REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes());
85 bm.allocPixels();
86 REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes());
87 bm.reset();
88 bm.allocPixels(info, explicitRowBytes);
89 REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes());
90
91 bm.reset();
92 bm.setInfo(info, 0);
93 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
94 bm.reset();
95 bm.allocPixels(info, 0);
96 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
97
98 bm.reset();
99 bool success = bm.setInfo(info, info.minRowBytes() - 1); // invalid for 32bit
100 REPORTER_ASSERT(reporter, !success);
102
103 for (SkColorType ct : {
122 }) {
123 SkImageInfo imageInfo = info.makeColorType(ct);
124 for (int rowBytesPadding = 1; rowBytesPadding <= 17; rowBytesPadding++) {
125 bm.reset();
126 success = bm.setInfo(imageInfo, imageInfo.minRowBytes() + rowBytesPadding);
127 if (rowBytesPadding % imageInfo.bytesPerPixel() == 0) {
128 REPORTER_ASSERT(reporter, success);
129 success = bm.tryAllocPixels();
130 REPORTER_ASSERT(reporter, success);
131 } else {
132 // Not pixel aligned.
133 REPORTER_ASSERT(reporter, !success);
135 }
136 }
137 }
138}
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
Definition SkColorType.h:36
size_t rowBytes() const
Definition SkBitmap.h:238
bool isNull() const
Definition SkBitmap.h:219
void reset()
Definition SkBitmap.cpp:92
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:271
size_t minRowBytes() const
int bytesPerPixel() const

◆ test_bigalloc()

static void test_bigalloc ( skiatest::Reporter reporter)
static

Definition at line 56 of file BitmapTest.cpp.

56 {
57 const int width = 0x40000001;
58 const int height = 0x00000096;
60
61 SkBitmap bm;
63
66}
SK_API sk_sp< SkPixelRef > MakeAllocate(const SkImageInfo &, size_t rowBytes)

◆ test_bigwidth()

static void test_bigwidth ( skiatest::Reporter reporter)
static

Definition at line 140 of file BitmapTest.cpp.

140 {
141 SkBitmap bm;
142 int width = 1 << 29; // *4 will be the high-bit of 32bit int
143
147
148 // for a 4-byte config, this width will compute a rowbytes of 0x80000000,
149 // which does not fit in a int32_t. setConfig should detect this, and fail.
150
151 // TODO: perhaps skia can relax this, and only require that rowBytes fit
152 // in a uint32_t (or larger), but for now this is the constraint.
153
154 REPORTER_ASSERT(reporter, !bm.setInfo(info.makeColorType(kN32_SkColorType)));
155}
static SkImageInfo MakeA8(int width, int height)

◆ test_erasecolor_premul()

static void test_erasecolor_premul ( skiatest::Reporter reporter,
SkColorType  ct,
SkColor  input,
SkColor  expected 
)
static

Definition at line 243 of file BitmapTest.cpp.

244 {
245 SkBitmap bm;
247 bm.eraseColor(input);
248 INFOF(reporter, "expected: %x actual: %x\n", expected, bm.getColor(0, 0));
249 REPORTER_ASSERT(reporter, bm.getColor(0, 0) == expected);
250}
#define INFOF(REPORTER,...)
Definition Test.h:298

◆ test_peekpixels()

static void test_peekpixels ( skiatest::Reporter reporter)
static

Definition at line 31 of file BitmapTest.cpp.

31 {
33
34 SkPixmap pmap;
35 SkBitmap bm;
36
37 // empty should return false
38 REPORTER_ASSERT(reporter, !bm.peekPixels(nullptr));
40
41 // no pixels should return false
43 REPORTER_ASSERT(reporter, !bm.peekPixels(nullptr));
45
46 // real pixels should return true
47 bm.allocPixels(info);
50 REPORTER_ASSERT(reporter, pmap.info() == bm.info());
51 REPORTER_ASSERT(reporter, pmap.addr() == bm.getPixels());
53}
size_t rowBytes() const
Definition SkPixmap.h:145
const SkImageInfo & info() const
Definition SkPixmap.h:135
const void * addr() const
Definition SkPixmap.h:153

◆ unit_compare()

static bool unit_compare ( float  expected,
float  actual,
float  tol = 1.0f/(1<<12) 
)
static

Definition at line 378 of file BitmapTest.cpp.

378 {
379 SkASSERT(expected >= 0 && expected <= 1);
380 SkASSERT( actual >= 0 && actual <= 1);
381 if (expected == 0 || expected == 1) {
382 return actual == expected;
383 } else {
384 return SkScalarNearlyEqual(expected, actual, tol);
385 }
386}
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:107

◆ unit_discretize()

static float unit_discretize ( float  value,
float  scale 
)
static

Definition at line 388 of file BitmapTest.cpp.

388 {
389 SkASSERT(value >= 0 && value <= 1);
390 if (value == 1) {
391 return 1;
392 } else {
393 return std::floor(value * scale + 0.5f) / scale;
394 }
395}
const Scalar scale