35 "Zero or more images or directories where to find PNG images to test with "
36 "PNGCodecGM. Directories are scanned non-recursively. All files are assumed to be "
40 "One of \"get-all-pixels\", \"incremental\" or \"zero-init\".");
43 "One of \"force-grayscale\", "
44 "\"force-nonnative-premul-color\" or \"get-from-canvas\".");
45DEFINE_string(pngCodecDstAlphaType,
"",
"One of \"premul\" or \"unpremul\".");
50 return "kUnknown_SkColorType";
52 return "kAlpha_8_SkColorType";
54 return "kRGB_565_SkColorType";
56 return "kARGB_4444_SkColorType";
58 return "kRGBA_8888_SkColorType";
60 return "kRGB_888x_SkColorType";
62 return "kBGRA_8888_SkColorType";
64 return "kRGBA_1010102_SkColorType";
66 return "kBGRA_1010102_SkColorType";
68 return "kRGB_101010x_SkColorType";
70 return "kBGR_101010x_SkColorType";
72 return "kBGR_101010x_XR_SkColorType";
74 return "kGray_8_SkColorType";
76 return "kRGBA_F16Norm_SkColorType";
78 return "kRGBA_F16_SkColorType";
80 return "kRGBA_F32_SkColorType";
82 return "kR8G8_unorm_SkColorType";
84 return "kA16_float_SkColorType";
86 return "kR16G16_float_SkColorType";
88 return "kA16_unorm_SkColorType";
90 return "kR16G16_unorm_SkColorType";
92 return "kR16G16B16A16_unorm_SkColorType";
94 return "kSRGBA_8888_SkColorType";
96 return "kR8_unorm_SkColorType";
98 return "kRGBA_10x6_SkColorType";
100 return "kBGRA_10101010_XR_SkColorType";
108 return "kUnknown_SkAlphaType";
110 return "kOpaque_SkAlphaType";
112 return "kPremul_SkAlphaType";
114 return "kUnpremul_SkAlphaType";
132 return {.errorMsg =
SkStringPrintf(
"Could not create codec for \"%s\": %s.",
137 return {.codec = std::move(codec)};
164 switch (decodeMode) {
166 return "kGetAllPixels";
168 return "kIncremental";
176 switch (dstColorType) {
178 return "kForceGrayscale";
180 return "kForceNonNativePremulColor";
182 return "kGetFromCanvas";
195 , fDecodeMode(decodeMode)
196 , fDstColorType(dstColorType)
197 , fDstAlphaType(dstAlphaType) {}
205 return std::map<std::string, std::string>{
207 {
"source_type",
"image"},
229 return decodeResult.
codec->dimensions();
237 *errorMsg = decodeResult.
errorMsg.c_str();
238 return DrawResult::kFail;
240 std::unique_ptr<SkCodec> codec = std::move(decodeResult.
codec);
243 if (*errorMsg = validateCanvasColorTypeAndGetDecodeInfo(&decodeInfo,
246 return DrawResult::kFail;
249 SkISize size = codec->dimensions();
253 const size_t rowBytes = size.width() * bpp;
259 memset(pixels.
get(), 0, size.height() * rowBytes);
275 switch (fDecodeMode) {
278 switch (codec->getPixels(decodeInfo, pixels.
get(), rowBytes, &
options)) {
287 *errorMsg =
SkStringPrintf(
"Couldn't getPixels %s.", fPath.c_str());
288 return DrawResult::kFail;
291 drawToCanvas(canvas, bitmapInfo, pixels.
get(), rowBytes);
295 void* dst = pixels.
get();
298 codec->startIncrementalDecode(decodeInfo, dst, rowBytes, &
options)) {
300 auto result = codec->incrementalDecode(&rowsDecoded);
302 codec->fillIncompleteImage(decodeInfo,
310 *errorMsg =
"Could not start incremental decode";
311 return DrawResult::kFail;
313 drawToCanvas(canvas, bitmapInfo, dst, rowBytes);
318 *errorMsg =
"Invalid fDecodeMode";
319 return DrawResult::kFail;
321 return DrawResult::kOk;
333 switch (fDstColorType) {
337 "canvas color type %s and destination color type %s are redundant",
348 "canvas color type %s and destination color type %s are redundant",
352#ifdef SK_PMCOLOR_IS_RGBA
363 "image \"%s\" has alpha type %s; this is incompatible with with "
364 "canvas color type %s and destination color type %s",
391 swapRbIfNecessary(
bitmap);
404 for (
int y = 0;
y <
bitmap.height();
y++) {
405 uint32_t* row = (uint32_t*)
bitmap.getAddr(0,
y);
441 "image \"%s\" has color type %s; this is incompatible with the given "
442 "dstColorType argument: %s (expected image color type: %s)",
453 "image \"%s\" has alpha type %s; this is incompatible with the given "
454 "dstAlphaType argument: %s",
474 if (
SkString errorMsg = FLAGS_pngCodecDecodeMode.parseAndValidate(
475 "--pngCodecDecodeMode", decodeModeValues, decodeMode);
477 return errorMsg.
c_str();
483 {
SkString(
"force-nonnative-premul-color"),
486 if (
SkString errorMsg = FLAGS_pngCodecDstColorType.parseAndValidate(
487 "--pngCodecDstColorType", dstColorTypeValues, dstColorType);
489 return errorMsg.
c_str();
496 if (
SkString errorMsg = FLAGS_pngCodecDstAlphaType.parseAndValidate(
497 "--pngCodecDstAlphaType", dstAlphaTypeValues, dstAlphaType);
499 return errorMsg.
c_str();
523 return "Failed to collect images.";
528 if (std::string errorMsg =
#define DEFINE_string(name, defaultValue, helpString)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kUnknown_SkAlphaType
uninitialized
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
@ kRGBA_10x6_SkColorType
pixel with 10 used bits (most significant) followed by 6 unused
@ kBGR_101010x_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kRGB_101010x_SkColorType
pixel with 10 bits each for red, green, blue; in 32-bit word
@ kSRGBA_8888_SkColorType
@ 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
@ kBGRA_10101010_XR_SkColorType
pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
@ 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
@ kBGRA_1010102_SkColorType
10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
@ kA16_float_SkColorType
pixel with a half float for alpha
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
@ kUnknown_SkColorType
uninitialized
@ kR16G16_float_SkColorType
pixel with a half float for red and green
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static bool left(const SkPoint &p0, const SkPoint &p1)
SK_API SkString static SkString SkStringPrintf()
SkISize getISize() override
static constexpr const char * DstColorTypeToString(DstColorType dstColorType)
bool isBazelOnly() const override
SkString getName() const override
@ kForceNonNativePremulColor
static constexpr const char * DecodeModeToString(DecodeMode decodeMode)
std::map< std::string, std::string > getGoldKeys() const override
PNGCodecGM(std::string path, DecodeMode decodeMode, DstColorType dstColorType, SkAlphaType dstAlphaType)
DrawResult onDraw(SkCanvas *canvas, SkString *errorMsg) override
SkImageInfo imageInfo() const
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
static const char * ResultToString(Result)
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkData > MakeFromFileName(const char path[])
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
static SkString Basename(const char *fullPath)
const char * c_str() const
GM(SkColor backgroundColor=SK_ColorWHITE)
#define DEF_GM_REGISTERER_FN(FN)
std::array< MockImage, 3 > images
bool CollectImages(const CommandLineFlags::StringArray &dir, skia_private::TArray< SkString > *output)
Swizzle_8888_u32 RGBA_to_BGRA
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
void Register(skiagm::GM *gm)
static std::string parse_and_validate_flags(PNGCodecGM::DecodeMode *decodeMode, PNGCodecGM::DstColorType *dstColorType, SkAlphaType *dstAlphaType)
static DecodeResult decode(std::string path)
static std::string registerGMsForImage(std::string path, PNGCodecGM::DecodeMode decodeMode, PNGCodecGM::DstColorType dstColorType, SkAlphaType dstAlphaType)
static constexpr const char * sk_alpha_type_to_str(SkAlphaType alphaType)
static constexpr const char * sk_color_type_to_str(SkColorType colorType)
std::unique_ptr< SkCodec > codec
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
size_t computeByteSize(size_t rowBytes) const
SkImageInfo makeDimensions(SkISize newSize) const
int bytesPerPixel() const
SkImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const
SkAlphaType alphaType() const
SkColorType colorType() const
SkImageInfo makeColorType(SkColorType newColorType) const