36 std::unique_ptr<uint8_t[]> storage(
new uint8_t[totalBytes]);
37 memset(storage.get(), 0, totalBytes);
39 uint8_t* imageData = storage.get() +
offset;
40 uint8_t* imageStart = imageData + rowBytes * startRow;
46 uint8_t* indexPtr = imageData + startRow * rowBytes;
47 uint8_t* grayPtr = indexPtr;
48 uint32_t* colorPtr = (uint32_t*) indexPtr;
49 uint16_t* color565Ptr = (uint16_t*) indexPtr;
50 for (uint32_t
y = startRow;
y <= endRow;
y++) {
51 for (int32_t
x = 0;
x < imageInfo.
width();
x++) {
53 case kN32_SkColorType:
68 colorPtr = (uint32_t*) indexPtr;
75 const uint32_t
widths[] = { 0, 10, 50 };
79 const uint32_t heights[] = { 1, 5, 10 };
82 const uint32_t paddings[] = { 0, 4 };
86 for (uint32_t
height : heights) {
93 for (uint32_t padding : paddings) {
98 const size_t indexRowBytes =
width + padding;
99 const size_t grayRowBytes = indexRowBytes;
100 const size_t color565RowBytes =
107 for (uint32_t startRow = 0; startRow <
height; startRow++) {
108 for (uint32_t endRow = startRow; endRow <
height; endRow++) {
126 for (
int c = 0; c <= 255; c++) {
168 for (uint32_t
i = 1;
i < 256; ++
i) {
169 const float r = test255(
i);
170 const float e = (255.0f /
i);
175 for (uint32_t
i = 1;
i < 256; ++
i) {
176 const float normalized =
i / 255.0f;
177 const float r =
test1(normalized);
178 const float e = (1.0f / normalized);
183#define SK_OPTS_NS test
184#define SK_OPTS_TARGET SK_OPTS_TARGET_DEFAULT
189 SK_OPTS_NS::reciprocal_alpha_times_255,
190 SK_OPTS_NS::reciprocal_alpha);
195 SK_OPTS_NS::reciprocal_alpha_times_255_portable,
196 SK_OPTS_NS::reciprocal_alpha_portable);
226 const float normalized = comp * (1.0f / 255.0f);
227 const float normalizedA = alpha * (1.0f / 255.0f);
228 const float inverseAlpha = 1.0f / normalizedA;
229 const float unpremul = normalized * inverseAlpha;
230 const float scaledAndPinned =
std::min(255.0f, unpremul * 255.0f);
231 return SK_OPTS_NS::pixel_round_as_RP(scaledAndPinned);
235 for (uint32_t
a = 0;
a < 256; ++
a) {
236 for (uint32_t c = 0; c < 256; ++c) {
238 const float normalizedA =
a * (1.0f / 255.0f);
239 const float invA = SK_OPTS_NS::reciprocal_alpha(normalizedA);
240 const uint32_t actual = SK_OPTS_NS::unpremul_simulating_RP(invA, c);
241 if (actual != expected) {
242 SkDebugf(
"a: %u c: %u expected: %u actual: %u\n",
a, c, expected, actual);
@ kUnknown_SkAlphaType
uninitialized
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
SK_API void SkSwapRB(uint32_t *dest, const uint32_t *src, int count)
static void test_reciprocal_alpha(skiatest::Reporter *reporter, fn_reciprocal test255, fn_reciprocal test1)
DEF_TEST(SwizzlerFill, r)
static void check_fill(skiatest::Reporter *r, const SkImageInfo &imageInfo, uint32_t startRow, uint32_t endRow, size_t rowBytes, uint32_t offset)
uint32_t calcExpected(float alpha, float comp)
float(*)(float) fn_reciprocal
#define REPORTER_ASSERT(r, cond,...)
static void test1(skiatest::Reporter *reporter, SkWriter32 *writer)
static void Fill(const SkImageInfo &info, void *dst, size_t rowBytes, SkCodec::ZeroInitialized zeroInit)
static float min(float r, float g, float b)
Swizzle_8888_u32 RGBA_to_rgbA
Swizzle_8888_u32 RGBA_to_BGRA
Swizzle_8888_u32 RGBA_to_bgrA
SkImageInfo makeWH(int newWidth, int newHeight) const
size_t computeByteSize(size_t rowBytes) const
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)
SkColorType colorType() const
SkImageInfo makeColorType(SkColorType newColorType) const