37static SkPMColor convert_yuva_to_rgba(
const float mtx[20], uint8_t yuva[4]) {
59 int shift =
static_cast<int>(channel) * 8;
60 return static_cast<uint8_t
>((pixel >> shift) & 0xff);
70 , fPixmaps(
std::move(pixmaps)) {}
76 const Options&)
override {
78 fFlattened.allocPixels(
info);
86 SkMatrix om = fPixmaps.yuvaInfo().originMatrix();
88 float normX = 1.f/
info.width();
89 float normY = 1.f/
info.height();
94 for (
int y = 0;
y <
info.height(); ++
y) {
95 for (
int x = 0;
x <
info.width(); ++
x) {
102 uint8_t yuva[4] = {0, 0, 0, 255};
107 const auto& pmap = fPixmaps.plane(yuvaLocations[c].fPlane);
108 yuva[c] = look_up(xy1, pmap, yuvaLocations[c].fChannel);
112 const auto& pmap = fPixmaps.plane(aPlane);
113 yuva[3] = look_up(xy1, pmap, aChan);
117 *fFlattened.getAddr32(
x,
y) = convert_yuva_to_rgba(mtx, yuva);
122 return fFlattened.readPixels(
info, pixels, rowBytes, 0, 0);
127 *
info = fPixmaps.pixmapsInfo();
128 return info->isValid();
133 for (
int i = 0; i < pixmaps.
numPlanes(); ++i) {
137 fPixmaps.plane(i).readPixels(pixmaps.
plane(i));
152MakeYUVAPlanesAsA8(
SkImage* src,
167 std::array<sk_sp<SkImage>, 4> planes;
168 for (
int i = 0; i < n; ++i) {
185 std::copy_n(rgbToYUV + 5*i, 5, m + 15);
187 surf->getCanvas()->drawImageRect(src,
191 planes[i] = surf->makeImageSnapshot();
197 return {planes,
info};
204 if (
image->reset(std::move(data), mipmapped, std::move(cs))) {
215 if (
image->reset(std::move(pixmaps), mipmapped, std::move(cs))) {
223 if (this->ensureYUVImage(rContext,
type)) {
224 size_t idx =
static_cast<size_t>(
type);
225 SkASSERT(idx < std::size(fYUVImage));
226 return fYUVImage[idx];
232#if defined(SK_GRAPHITE)
234 if (this->ensureYUVImage(recorder,
type)) {
235 size_t idx =
static_cast<size_t>(
type);
236 SkASSERT(idx < std::size(fYUVImage));
237 return fYUVImage[idx];
245 fMipmapped = mipmapped;
260 if (!codec->getYUVAPlanes(fPixmaps)) {
264 fColorSpace = std::move(cs);
276 fMipmapped = mipmapped;
278 fPixmaps = std::move(pixmaps);
282 fColorSpace = std::move(cs);
288 size_t idx =
static_cast<size_t>(
type);
289 SkASSERT(idx < std::size(fYUVImage));
290 if (fYUVImage[idx] && fYUVImage[idx]->isValid(rContext)) {
296 if (!rContext || rContext->
abandoned()) {
307 auto generator = std::make_unique<Generator>(fPixmaps, fColorSpace);
312 if (!rContext || rContext->
abandoned()) {
318 for (
int i = 0; i < fPixmaps.
numPlanes(); ++i) {
319 mbets[i] = sk_gpu_test::ManagedBackendTexture::MakeFromPixmap(
323 skgpu::Renderable::kNo,
324 skgpu::Protected::kNo);
334 if (!yuvaTextures.isValid()) {
337 void* planeRelContext =
338 sk_gpu_test::ManagedBackendTexture::MakeYUVAReleaseContext(mbets);
343 sk_gpu_test::ManagedBackendTexture::ReleaseProc,
351 return fYUVImage[idx] !=
nullptr;
354#if defined(SK_GRAPHITE)
360 size_t idx =
static_cast<size_t>(
type);
361 SkASSERT(idx < std::size(fYUVImage));
362 if (fYUVImage[idx] &&
as_IB(fYUVImage[idx])->isGraphiteBacked()) {
374 {fMipmapped == skgpu::Mipmapped::kYes},
380 auto generator = std::make_unique<Generator>(fPixmaps, fColorSpace);
391 for (
int i = 0; i < fPixmaps.
numPlanes(); ++i) {
393 mbets[i] = sk_gpu_test::ManagedGraphiteTexture::MakeFromPixmap(
397 skgpu::Renderable::kNo,
398 skgpu::Protected::kNo);
405 YUVABackendTextures yuvaTextures(recorder,
408 if (!yuvaTextures.isValid()) {
411 void* imageRelContext =
412 sk_gpu_test::ManagedGraphiteTexture::MakeYUVAReleaseContext(mbets);
417 sk_gpu_test::ManagedGraphiteTexture::ImageReleaseProc,
430 if (fMipmapped == skgpu::Mipmapped::kYes) {
431 genMipmaps = GenerateMipmapsFromBase::kYes;
434 for (
int i = 0; i < fPixmaps.
numPlanes(); ++i) {
435 const auto& plane = fPixmaps.
plane(i);
437 if (fMipmapped == skgpu::Mipmapped::kYes) {
438 mbet = ManagedGraphiteTexture::MakeUnInit(recorder,
440 skgpu::Mipmapped::kYes,
441 skgpu::Renderable::kNo);
450 levels.push_back(plane);
451 for (
int l = 0; l < levelCnt; ++l) {
454 level.alloc(plane.info().makeDimensions(dims));
456 levels.push_back(level);
457 levelStorage.push_back(std::move(level));
465 mbet = ManagedGraphiteTexture::MakeFromPixmap(recorder,
467 skgpu::Mipmapped::kNo,
468 skgpu::Renderable::kNo);
480 ManagedGraphiteTexture::ImageReleaseProc,
481 mbet->releaseContext());
492 return fYUVImage[idx] !=
nullptr;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kTopLeft_GrSurfaceOrigin
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
#define SkAssertResult(cond)
static SkPMColor SkPremultiplyARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kUnknown_SkColorType
uninitialized
constexpr SkColor SK_ColorRED
@ kTopLeft_SkEncodedOrigin
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
static SkImage_Base * as_IB(SkImage *image)
static std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
void swap(sk_sp< T > &a, sk_sp< T > &b)
#define SkScalarRoundToInt(x)
#define SkScalarFloorToInt(x)
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
void SkColorMatrix_RGB2YUV(SkYUVColorSpace cs, float m[20])
void SkColorMatrix_YUV2RGB(SkYUVColorSpace cs, float m[20])
virtual GrDirectContext * asDirectContext()
bool abandoned() override
static std::unique_ptr< SkImageGenerator > MakeFromEncodedCodec(sk_sp< SkData >, std::optional< SkAlphaType >=std::nullopt)
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
const SkImageInfo & getInfo() const
virtual bool onGetYUVAPlanes(const SkYUVAPixmaps &)
virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes &, SkYUVAPixmapInfo *) const
virtual bool onGetPixels(const SkImageInfo &, void *, size_t, const Options &)
SkPoint mapPoint(SkPoint pt) const
bool invert(SkMatrix *inverse) const
static SkISize ComputeLevelSize(int baseWidth, int baseHeight, int level)
static int ComputeLevelCount(int baseWidth, int baseHeight)
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes) const
SkColorType colorType() const
const SkImageInfo & info() const
SkISize dimensions() const
@ kY_U_V_A
Plane 0: Y, Plane 1: U, Plane 2: V, Plane 3: A.
@ kY_U_V
Plane 0: Y, Plane 1: U, Plane 2: V.
static constexpr int kMaxPlanes
std::array< YUVALocation, kYUVAChannelCount > YUVALocations
static int PlaneDimensions(SkISize imageDimensions, PlaneConfig, Subsampling, SkEncodedOrigin, SkISize planeDimensions[kMaxPlanes])
static constexpr SupportedDataTypes All()
const SkYUVAInfo & yuvaInfo() const
const SkPixmap & plane(int i) const
static SkYUVAPixmaps Allocate(const SkYUVAPixmapInfo &yuvaPixmapInfo)
static SkYUVAPixmaps MakeCopy(const SkYUVAPixmaps &src)
sk_sp< SkImage > refImage(GrRecordingContext *rContext, Type)
static std::unique_ptr< LazyYUVImage > Make(sk_sp< SkData > data, skgpu::Mipmapped=skgpu::Mipmapped::kNo, sk_sp< SkColorSpace >=nullptr)
bool updateBackendTexture(const BackendTexture &, const SkPixmap srcData[], int numLevels)
std::vector< std::shared_ptr< FakeTexture > > textures
SK_API sk_sp< SkImage > TextureFromYUVAPixmaps(GrRecordingContext *context, const SkYUVAPixmaps &pixmaps, skgpu::Mipmapped buildMips, bool limitToMaxTextureSize, sk_sp< SkColorSpace > imageColorSpace)
SK_API sk_sp< SkImage > DeferredFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)
SK_API sk_sp< SkImage > TextureFromYUVATextures(GrRecordingContext *context, const GrYUVABackendTextures &yuvaTextures, sk_sp< SkColorSpace > imageColorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SK_API sk_sp< SkImage > TextureFromYUVAImages(skgpu::graphite::Recorder *recorder, const SkYUVAInfo &yuvaInfo, SkSpan< const sk_sp< SkImage > > images, sk_sp< SkColorSpace > imageColorSpace)
SK_API sk_sp< SkImage > WrapTexture(skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, skgpu::Origin origin, GenerateMipmapsFromBase generateMipmapsFromBase, TextureReleaseProc=nullptr, ReleaseContext=nullptr)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
std::function< UnitlessTime(int)> Generator
SkImageInfo makeWH(int newWidth, int newHeight) const
SkImageInfo makeColorType(SkColorType newColorType) const
static SkImageInfo MakeA8(int width, int height)
constexpr float y() const
constexpr float x() const
static SkRect Make(const SkISize &size)
static bool AreValidLocations(const SkYUVAInfo::YUVALocations &locations, int *numPlanes=nullptr)