39#include <initializer_list>
81 U8CPU g = (n >> 8) & 0xff;
82 U8CPU r = (n >> 16) & 0xff;
91 const uint8_t* c =
reinterpret_cast<const uint8_t*
>(addr);
95 b =
static_cast<U8CPU>(c[0]);
96 g =
static_cast<U8CPU>(c[1]);
97 r =
static_cast<U8CPU>(c[2]);
98 a =
static_cast<U8CPU>(c[3]);
102 r =
static_cast<U8CPU>(c[0]);
103 g =
static_cast<U8CPU>(c[1]);
104 b =
static_cast<U8CPU>(c[2]);
106 a =
static_cast<U8CPU>(c[3]);
125 intptr_t pixels =
reinterpret_cast<intptr_t
>(bmp.
getPixels());
150 intptr_t pixels =
reinterpret_cast<intptr_t
>(
bitmap->getPixels());
151 for (
int y = 0;
y <
h; ++
y) {
152 for (
int x = 0;
x <
w; ++
x) {
155 uint8_t* alpha =
reinterpret_cast<uint8_t*
>(pixels +
y *
bitmap->rowBytes() +
x);
166 if (!didPremulConversion) {
189 bool checkSurfacePixels,
bool checkBitmapPixels,
194 SkASSERT(checkSurfacePixels || checkBitmapPixels);
201 if (!clippedSrcRect.
intersect(srcRect)) {
205 for (
int by = 0; by < bh; ++by) {
206 for (
int bx = 0; bx < bw; ++bx) {
207 int devx = bx + srcRect.
fLeft;
208 int devy = by + srcRect.
fTop;
209 const uint8_t* alpha =
bitmap.getAddr8(bx, by);
211 if (clippedSrcRect.
contains(devx, devy)) {
212 if (checkSurfacePixels) {
216 if (surfaceAlpha != *alpha) {
218 "Expected readback alpha (%d, %d) value 0x%02x, got 0x%02x. ",
219 bx, by, surfaceAlpha, *alpha);
223 }
else if (checkBitmapPixels) {
225 if (origDstAlpha != *alpha) {
226 ERRORF(
reporter,
"Expected clipped out area of readback to be unchanged. "
227 "Expected 0x%02x, got 0x%02x", origDstAlpha, *alpha);
235 for (
int by = 0; by < bh; ++by) {
236 for (
int bx = 0; bx < bw; ++bx) {
237 int devx = bx + srcRect.
fLeft;
238 int devy = by + srcRect.
fTop;
240 const uint32_t* pixel =
bitmap.getAddr32(bx, by);
242 if (clippedSrcRect.
contains(devx, devy)) {
243 if (checkSurfacePixels) {
246 surfacePMColor &= 0xFF000000;
249 surfacePMColor |= 0xFF000000;
255 "Expected readback pixel (%d, %d) value 0x%08x, got 0x%08x. "
256 "Readback was unpremul: %d",
257 bx, by, surfacePMColor, pmPixel, didPremul);
261 }
else if (checkBitmapPixels) {
263 if (origDstPixel != *pixel) {
264 ERRORF(
reporter,
"Expected clipped out area of readback to be unchanged. "
265 "Expected 0x%08x, got 0x%08x", origDstPixel, *pixel);
363 bool startsWithPixels = !bmp.
isNull();
364 if (startsWithPixels) {
367 uint32_t idBefore =
surface->generationID();
369 uint32_t idAfter =
surface->generationID();
376 "Read succeed=%d unexpectedly, src ct/at: %d/%d, dst ct/at: %d/%d",
382 if (success || startsWithPixels) {
384 startsWithPixels, surfaceInfo);
409 0xFF0000FF, 0xFF00FF00, 0xFFFF0000, 0xFFFFFFFF, 0xFF000000
412 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFFFF, 0xFF000000
471 bool success = src->readPixels(
nullptr, dstPixmap, 0, 0);
548 auto dstII = srcII.makeColorType(
colorType);
549 size_t badRowBytes = (surf->width() + 1)*bpp - 1;
550 auto storage = std::make_unique<char[]>(badRowBytes*surf->height());
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static void fill_src_canvas(SkCanvas *canvas)
static const uint32_t kNumPixels
static void test_conversion(skiatest::Reporter *r, const SkImageInfo &dstInfo, const SkImageInfo &srcInfo)
static const uint16_t rgba4444[kNumPixels]
static const uint32_t bgra[kNumPixels]
static const SkRect DEV_RECT_S
static const uint8_t alpha8[kNumPixels]
static bool check_read_pixel(SkPMColor a, SkPMColor b, bool didPremulConversion)
static void fill_dst_bmp_with_init_data(SkBitmap *bitmap)
static const uint16_t rgb565[kNumPixels]
static SkPMColor get_src_color(int x, int y)
static const uint64_t kGreen
static sk_sp< SkImage > make_src_image()
static void test_readpixels(skiatest::Reporter *reporter, const sk_sp< SkSurface > &surface, const SkImageInfo &surfaceInfo)
static const uint32_t rgba[kNumPixels]
static SkPMColor convert_to_pmcolor(SkColorType ct, SkAlphaType at, const uint32_t *addr, bool *doUnpremul)
static const uint64_t kAlpha
static const struct @443 gReadPixelsConfigs[]
bool read_should_succeed(const SkIRect &srcRect, const SkImageInfo &dstInfo, const SkImageInfo &srcInfo)
static SkPMColor get_dst_bmp_init_color(int x, int y, int w)
static const uint64_t kBlue
static const uint64_t f16[kNumPixels]
static const void * five_reference_pixels(SkColorType colorType)
static const uint64_t kRed
const SkIRect gReadPixelsTestRects[]
static const SkIRect DEV_RECT
static const uint8_t gray8[kNumPixels]
static void init_bitmap(SkBitmap *bitmap, const SkIRect &rect, TightRowBytes tightRB, SkColorType ct, SkAlphaType at)
static bool check_read(skiatest::Reporter *reporter, const SkBitmap &bitmap, int x, int y, bool checkSurfacePixels, bool checkBitmapPixels, const SkImageInfo &surfaceInfo)
static constexpr T SkAlign4(T x)
@ kUnknown_SkAlphaType
uninitialized
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
#define SkDEBUGFAIL(message)
#define SK_R16_MASK_IN_PLACE
#define SK_G16_MASK_IN_PLACE
#define SK_B16_MASK_IN_PLACE
#define SkGetPackedB32(packed)
#define SkGetPackedR32(packed)
static SkPMColor SkPremultiplyARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
#define SkGetPackedA32(packed)
#define SkGetPackedG32(packed)
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kLastEnum_SkColorType
last valid value
@ 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
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
@ kUnknown_SkColorType
uninitialized
static constexpr uint16_t SK_Half1
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
static bool SkImageInfoIsValid(const SkImageInfo &info)
static bool SkImageInfoValidConversion(const SkImageInfo &dst, const SkImageInfo &src)
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
static U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b)
static int32_t SkAbs32(int32_t value)
#define DEF_TEST(name, reporter)
#define REPORTER_ASSERT(r, cond,...)
sk_sp< SkImage > asImage() const
const SkImageInfo & info() const
int bytesPerPixel() const
void allocN32Pixels(int width, int height, bool isOpaque=false)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void setMatrix(const SkM44 &matrix)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
static sk_sp< SkColorSpace > MakeSRGB()
static const SkMatrix & I()
SK_API sk_sp< SkImage > RasterFromPixmap(const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
bool intersect(const SkIRect &r)
static bool Intersects(const SkIRect &a, const SkIRect &b)
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
int32_t fTop
smaller y-axis bounds
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
int32_t fLeft
smaller x-axis bounds
bool contains(int32_t x, int32_t y) const
static SkImageInfo MakeN32Premul(int width, int height)
size_t minRowBytes() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkAlphaType alphaType() const
SkColorType colorType() const
static constexpr SkRect MakeWH(float w, float h)