36#include <webp/decode.h>
40#include <initializer_list>
87 for (
int i = 0;
i <
src.height();
i++) {
88 success = encoder1->encodeRows(1);
93 for (
int i = 0;
i <
src.height();
i+=3) {
94 success = encoder2->encodeRows(3);
99 success = encoder3->encodeRows(200);
137 if (
a.info() !=
b.info()) {
141 SkASSERT(kN32_SkColorType ==
a.colorType());
142 for (
int y = 0;
y <
a.height();
y++) {
143 for (
int x = 0;
x <
a.width();
x++) {
168 auto canvas =
surface->getCanvas();
169 canvas->drawImage(
image, 0, 0);
173 if (!
surface->makeImageSnapshot()->readPixels(
nullptr, bm.
pixmap(), 0, 0)) {
174 ERRORF(r,
"failed to readPixels! ct: %i\tat: %i\n", ct, at);
233 std::vector<std::string>& comments,
const char* keyword,
const char*
text) {
234 comments.push_back(keyword);
235 comments.push_back(
text);
240 std::vector<std::string> commentStrings;
243 pushComment(commentStrings,
"have some",
"spaces in both");
245 std::string longKey(PNG_KEYWORD_MAX_LENGTH,
'x');
247 commentStrings.push_back(longKey);
250 commentStrings.push_back(longKey +
"x");
252 commentStrings.push_back(
"");
254 std::vector<const char*> commentPointers;
255 std::vector<size_t> commentSizes;
256 for(
auto& str : commentStrings) {
257 commentPointers.push_back(str.c_str());
258 commentSizes.push_back(str.length() + 1);
262 commentSizes.data(), commentStrings.size());
269 std::vector<char>
output(
dst.bytesWritten());
275 const char kExpected1[] =
276 "\x00\x00\x00\x08tEXtkey\x00text\x9e\xe7\x66\x51";
277 const char kExpected2[] =
278 "\x00\x00\x00\x0etEXttest\x00something\x29\xba\xef\xac";
279 const char kExpected3[] =
280 "\x00\x00\x00\x18tEXthave some\x00spaces in both\x8d\x69\x34\x2d";
281 std::string longKeyRecord =
"tEXt" + longKey;
282 std::string tooLongRecord =
"tExt" + longKey +
"x";
284 auto search1 = std::search(
output.begin(),
output.end(),
285 kExpected1, kExpected1 +
sizeof(kExpected1));
286 auto search2 = std::search(
output.begin(),
output.end(),
287 kExpected2, kExpected2 +
sizeof(kExpected2));
288 auto search3 = std::search(
output.begin(),
output.end(),
289 kExpected3, kExpected3 +
sizeof(kExpected3));
290 auto search4 = std::search(
output.begin(),
output.end(),
291 longKeyRecord.begin(), longKeyRecord.end());
292 auto search5 = std::search(
output.begin(),
output.end(),
293 tooLongRecord.begin(), tooLongRecord.end());
346#ifndef SK_BUILD_FOR_GOOGLE3
356 auto dataLossLess =
stream.detachAsData();
362 auto dataLossy =
stream.detachAsData();
371 auto printFormat = [](
int f) {
373 case kMixed:
return "mixed";
374 case kLossy:
return "lossy";
375 case kLossless:
return "lossless";
376 default:
return "unknown";
381 ERRORF(r,
"Failed to encode. Expected %s", printFormat(expected));
385 WebPBitstreamFeatures features;
386 auto status = WebPGetFeatures(
data->bytes(),
data->size(), &features);
387 if (status != VP8_STATUS_OK) {
388 ERRORF(r,
"Encode had an error %i. Expected %s", status, printFormat(expected));
392 if (expected != features.format) {
393 ERRORF(r,
"Expected %s encode, but got format %s", printFormat(expected),
394 printFormat(features.format));
398 test(dataLossy, kLossy);
399 test(dataLossLess, kLossless);
457 const int frameCount = 3;
458 const int width = 16;
461 std::vector<SkBitmap> bitmaps(frameCount);
462 std::vector<SkEncoder::Frame> frames(frameCount);
463 std::vector<int> durations = {50, 100, 150};
466 for (
int i = 0;
i < frameCount;
i++) {
467 bitmaps[
i].allocPixels(
info);
470 frames[
i].duration = durations[
i];
483 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
486 for (
size_t i = 0;
i < frameInfos.size(); ++
i) {
524 std::vector<SkEncoder::Frame> frames = {frame1, frame2};
542 bool success =
false;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static bool almost_equals(SkPMColor a, SkPMColor b, int tolerance)
static std::unique_ptr< SkEncoder > make(SkEncodedImageFormat format, SkWStream *dst, const SkPixmap &src)
static void testPngComments(const SkPixmap &src, SkPngEncoder::Options &options, skiatest::Reporter *r)
static void pushComment(std::vector< std::string > &comments, const char *keyword, const char *text)
static void test_encode(skiatest::Reporter *r, SkEncodedImageFormat format)
static bool encode(SkEncodedImageFormat format, SkWStream *dst, const SkPixmap &src)
sk_bzero(glyphs, sizeof(glyphs))
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
#define SkASSERT_RELEASE(cond)
#define SkGetPackedB32(packed)
#define SkGetPackedR32(packed)
#define SkGetPackedA32(packed)
#define SkGetPackedG32(packed)
@ 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
@ kUnknown_SkColorType
uninitialized
constexpr SkColor SK_ColorYELLOW
constexpr SkColor SK_ColorBLUE
constexpr SkColor SK_ColorRED
constexpr SkColor SK_ColorGREEN
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
#define REPORTER_ASSERT(r, cond,...)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
size_t computeByteSize() const
const SkPixmap & pixmap() const
void allocN32Pixels(int width, int height, bool isOpaque=false)
bool peekPixels(SkPixmap *pixmap) const
void eraseColor(SkColor4f) const
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
static const char * ResultToString(Result)
static sk_sp< SkDataTable > MakeCopyArrays(const void *const *ptrs, const size_t sizes[], int count)
bool equals(const SkData *other) const
sk_sp< SkData > detachAsData()
bool asLegacyBitmap(SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
uint32_t uint32_t * format
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
SK_API std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap &src, const Options &options)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
SK_API std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap &src, const Options &options)
sk_sp< const SkImage > image
PODArray< SkColor > colors
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API bool EncodeAnimated(SkWStream *dst, SkSpan< const SkEncoder::Frame > src, const Options &options)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
def Format(template, **parameters)
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
std::shared_ptr< const fml::Mapping > data