Flutter Engine
The Flutter Engine
Classes | Namespaces | Typedefs | Enumerations | Functions | Variables
wacky_yuv_formats.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontStyle.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageGenerator.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/GrTypes.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTDArray.h"
#include "include/private/base/SkTPin.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "include/utils/SkTextUtils.h"
#include "src/base/SkHalf.h"
#include "src/core/SkConvertPixels.h"
#include "src/core/SkYUVMath.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "tools/DecodeUtils.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/gpu/YUVUtils.h"
#include <math.h>
#include <string.h>
#include <initializer_list>
#include <memory>
#include <utility>
#include <vector>
#include "include/effects/SkColorMatrix.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "tools/Resources.h"

Go to the source code of this file.

Classes

class  YUVAPlanarConfig
 
struct  PlaneData
 
class  skiagm::WackyYUVFormatsGM
 
class  skiagm::YUVMakeColorSpaceGM
 
class  YUVSplitterGM
 

Namespaces

namespace  skiagm
 

Typedefs

using Recorder = skgpu::graphite::Recorder
 

Enumerations

enum  YUVFormat {
  kP016_YUVFormat , kP010_YUVFormat , kP016F_YUVFormat , kY416_YUVFormat ,
  kAYUV_YUVFormat , kY410_YUVFormat , kNV12_YUVFormat , kNV21_YUVFormat ,
  kI420_YUVFormat , kYV12_YUVFormat , kLast_YUVFormat = kYV12_YUVFormat
}
 

Functions

static bool has_alpha_channel (YUVFormat format)
 
static void add_arc (SkPath *path, const SkPoint &o1, const SkVector &v1, const SkPoint &o2, const SkVector &v2, SkTDArray< SkRect > *circles, bool takeLongWayRound)
 
static SkPath create_splat (const SkPoint &o, SkScalar innerRadius, SkScalar outerRadius, SkScalar ratio, int numLobes, SkTDArray< SkRect > *circles)
 
static SkBitmap make_bitmap (SkColorType colorType, const SkPath &path, const SkTDArray< SkRect > &circles, bool opaque, bool padWithRed)
 
static void convert_rgba_to_yuva (const float mtx[20], SkColor col, uint8_t yuv[4])
 
static void extract_planes (const SkBitmap &origBM, SkYUVColorSpace yuvColorSpace, SkEncodedOrigin origin, PlaneData *planes)
 
static SkBitmap make_quarter_2_channel (const SkBitmap &fullY, const SkBitmap &quarterU, const SkBitmap &quarterV, bool uv)
 
static SkBitmap make_16 (const SkBitmap &src, SkColorType dstCT, std::function< void(uint16_t *dstPixel, const float *srcPixel)> convert)
 
static uint16_t flt_2_uint16 (float flt)
 
static int create_YUV (const PlaneData &planes, YUVFormat yuvFormat, SkBitmap resultBMs[], bool opaque)
 
static void draw_col_label (SkCanvas *canvas, int x, int yuvColorSpace, bool opaque)
 
static void draw_row_label (SkCanvas *canvas, int y, int yuvFormat)
 
static sk_sp< SkColorFilteryuv_to_rgb_colorfilter ()
 
 skiagm::DEF_GM (return new WackyYUVFormatsGM(false, false, false, WackyYUVFormatsGM::Type::kFromTextures);) DEF_GM(return new WackyYUVFormatsGM(false
 
 skiagm::DEF_GM (return new WackyYUVFormatsGM(true, false, false, WackyYUVFormatsGM::Type::kFromTextures);) DEF_GM(return new WackyYUVFormatsGM(false
 
 skiagm::DEF_GM (return new WackyYUVFormatsGM(false, false, false, WackyYUVFormatsGM::Type::kFromGenerator);) DEF_GM(return new WackyYUVFormatsGM(false
 
static void draw_diff (SkCanvas *canvas, SkScalar x, SkScalar y, const SkImage *a, const SkImage *b)
 

Variables

static const int kTileWidthHeight = 128
 
static const int kLabelWidth = 64
 
static const int kLabelHeight = 32
 
static const int kSubsetPadding = 8
 
static const int kPad = 1
 
const SkYUVColorSpace color_space_array []
 
 skiagm::true
 
 skiagm::false
 

Typedef Documentation

◆ Recorder

Definition at line 68 of file wacky_yuv_formats.cpp.

Enumeration Type Documentation

◆ YUVFormat

enum YUVFormat
Enumerator
kP016_YUVFormat 
kP010_YUVFormat 
kP016F_YUVFormat 
kY416_YUVFormat 
kAYUV_YUVFormat 
kY410_YUVFormat 
kNV12_YUVFormat 
kNV21_YUVFormat 
kI420_YUVFormat 
kYV12_YUVFormat 
kLast_YUVFormat 

Definition at line 70 of file wacky_yuv_formats.cpp.

70 {
71 // 4:2:0 formats, 24 bpp
72 kP016_YUVFormat, // 16-bit Y plane + 2x2 down sampled interleaved U/V plane (2 textures)
73 // 4:2:0 formats, "15 bpp" (but really 24 bpp)
74 kP010_YUVFormat, // same as kP016 except "10 bpp". Note that it is the same memory layout
75 // except that the bottom 6 bits are zeroed out (2 textures)
76 // TODO: we're cheating a bit w/ P010 and just treating it as unorm 16. This means its
77 // fully saturated values are 65504 rather than 65535 (that is just .9995 out of 1.0 though).
78
79 // This is laid out the same as kP016 and kP010 but uses F16 unstead of U16. In this case
80 // the 10 bits/channel vs 16 bits/channel distinction isn't relevant.
82
83 // 4:4:4 formats, 64 bpp
84 kY416_YUVFormat, // 16-bit AVYU values all interleaved (1 texture)
85
86 // 4:4:4 formats, 32 bpp
87 kAYUV_YUVFormat, // 8-bit YUVA values all interleaved (1 texture)
88 kY410_YUVFormat, // AVYU w/ 10bpp for YUV and 2 for A all interleaved (1 texture)
89
90 // 4:2:0 formats, 12 bpp
91 kNV12_YUVFormat, // 8-bit Y plane + 2x2 down sampled interleaved U/V planes (2 textures)
92 kNV21_YUVFormat, // same as kNV12 but w/ U/V reversed in the interleaved texture (2 textures)
93
94 kI420_YUVFormat, // 8-bit Y plane + separate 2x2 down sampled U and V planes (3 textures)
95 kYV12_YUVFormat, // 8-bit Y plane + separate 2x2 down sampled V and U planes (3 textures)
96
98};
@ kAYUV_YUVFormat
@ kNV21_YUVFormat
@ kLast_YUVFormat
@ kNV12_YUVFormat
@ kP016F_YUVFormat
@ kP010_YUVFormat
@ kY410_YUVFormat
@ kI420_YUVFormat
@ kP016_YUVFormat
@ kYV12_YUVFormat
@ kY416_YUVFormat

Function Documentation

◆ add_arc()

static void add_arc ( SkPath path,
const SkPoint o1,
const SkVector v1,
const SkPoint o2,
const SkVector v2,
SkTDArray< SkRect > *  circles,
bool  takeLongWayRound 
)
static

Definition at line 248 of file wacky_yuv_formats.cpp.

251 {
252
253 SkVector v3 = { -v1.fY, v1.fX };
254 SkVector v4 = { v2.fY, -v2.fX };
255
256 SkScalar t = ((o2.fX - o1.fX) * v4.fY - (o2.fY - o1.fY) * v4.fX) / v3.cross(v4);
257 SkPoint center = { o1.fX + t * v3.fX, o1.fY + t * v3.fY };
258
259 SkRect r = { center.fX - t, center.fY - t, center.fX + t, center.fY + t };
260
261 if (circles) {
262 circles->push_back(r);
263 }
264
265 SkVector startV = o1 - center, endV = o2 - center;
266 startV.normalize();
267 endV.normalize();
268
269 SkScalar startDeg = SkRadiansToDegrees(SkScalarATan2(startV.fY, startV.fX));
270 SkScalar endDeg = SkRadiansToDegrees(SkScalarATan2(endV.fY, endV.fX));
271
272 startDeg += 360.0f;
273 startDeg = fmodf(startDeg, 360.0f);
274
275 endDeg += 360.0f;
276 endDeg = fmodf(endDeg, 360.0f);
277
278 if (endDeg < startDeg) {
279 endDeg += 360.0f;
280 }
281
282 SkScalar sweepDeg = SkTAbs(endDeg - startDeg);
283 if (!takeLongWayRound) {
284 sweepDeg = sweepDeg - 360;
285 }
286
287 path->arcTo(r, startDeg, sweepDeg, false);
288}
static SkV4 v4(SkV3 v, SkScalar w)
Definition: SkM44.cpp:329
#define SkScalarATan2(y, x)
Definition: SkScalar.h:50
#define SkRadiansToDegrees(radians)
Definition: SkScalar.h:78
static T SkTAbs(T value)
Definition: SkTemplates.h:43
static SkScalar center(float pos0, float pos1)
Vec2Value v2
void push_back(const T &v)
Definition: SkTDArray.h:219
float SkScalar
Definition: extension.cpp:12
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
float fX
x-axis value
Definition: SkPoint_impl.h:164
float cross(const SkVector &vec) const
Definition: SkPoint_impl.h:545
float fY
y-axis value
Definition: SkPoint_impl.h:165
bool normalize()
Definition: SkPoint.cpp:22

◆ convert_rgba_to_yuva()

static void convert_rgba_to_yuva ( const float  mtx[20],
SkColor  col,
uint8_t  yuv[4] 
)
static

Definition at line 397 of file wacky_yuv_formats.cpp.

397 {
398 const uint8_t r = SkColorGetR(col);
399 const uint8_t g = SkColorGetG(col);
400 const uint8_t b = SkColorGetB(col);
401
402 yuv[0] = SkTPin(SkScalarRoundToInt(mtx[ 0]*r + mtx[ 1]*g + mtx[ 2]*b + mtx[ 4]*255), 0, 255);
403 yuv[1] = SkTPin(SkScalarRoundToInt(mtx[ 5]*r + mtx[ 6]*g + mtx[ 7]*b + mtx[ 9]*255), 0, 255);
404 yuv[2] = SkTPin(SkScalarRoundToInt(mtx[10]*r + mtx[11]*g + mtx[12]*b + mtx[14]*255), 0, 255);
405 yuv[3] = SkColorGetA(col);
406}
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
#define SkColorGetA(color)
Definition: SkColor.h:61
#define SkColorGetB(color)
Definition: SkColor.h:73
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
static bool b

◆ create_splat()

static SkPath create_splat ( const SkPoint o,
SkScalar  innerRadius,
SkScalar  outerRadius,
SkScalar  ratio,
int  numLobes,
SkTDArray< SkRect > *  circles 
)
static

Definition at line 290 of file wacky_yuv_formats.cpp.

291 {
292 if (numLobes <= 1) {
293 return SkPath();
294 }
295
296 SkPath p;
297
298 int numDivisions = 2 * numLobes;
299 SkScalar fullLobeDegrees = 360.0f / numLobes;
300 SkScalar outDegrees = ratio * fullLobeDegrees / (ratio + 1.0f);
301 SkScalar innerDegrees = fullLobeDegrees / (ratio + 1.0f);
302 SkMatrix outerStep, innerStep;
303 outerStep.setRotate(outDegrees);
304 innerStep.setRotate(innerDegrees);
305 SkVector curV = SkVector::Make(0.0f, 1.0f);
306
307 if (circles) {
308 circles->push_back(SkRect::MakeLTRB(o.fX - innerRadius, o.fY - innerRadius,
309 o.fX + innerRadius, o.fY + innerRadius));
310 }
311
312 p.moveTo(o.fX + innerRadius * curV.fX, o.fY + innerRadius * curV.fY);
313
314 for (int i = 0; i < numDivisions; ++i) {
315
316 SkVector nextV;
317 if (0 == (i % 2)) {
318 nextV = outerStep.mapVector(curV.fX, curV.fY);
319
320 SkPoint top = SkPoint::Make(o.fX + outerRadius * curV.fX,
321 o.fY + outerRadius * curV.fY);
322 SkPoint nextTop = SkPoint::Make(o.fX + outerRadius * nextV.fX,
323 o.fY + outerRadius * nextV.fY);
324
325 p.lineTo(top);
326 add_arc(&p, top, curV, nextTop, nextV, circles, true);
327 } else {
328 nextV = innerStep.mapVector(curV.fX, curV.fY);
329
330 SkPoint bot = SkPoint::Make(o.fX + innerRadius * curV.fX,
331 o.fY + innerRadius * curV.fY);
332 SkPoint nextBot = SkPoint::Make(o.fX + innerRadius * nextV.fX,
333 o.fY + innerRadius * nextV.fY);
334
335 p.lineTo(bot);
336 add_arc(&p, bot, curV, nextBot, nextV, nullptr, false);
337 }
338
339 curV = nextV;
340 }
341
342 p.close();
343
344 return p;
345}
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:452
void mapVector(SkScalar dx, SkScalar dy, SkVector *result) const
Definition: SkMatrix.h:1524
Definition: SkPath.h:59
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
static void add_arc(SkPath *path, const SkPoint &o1, const SkVector &v1, const SkPoint &o2, const SkVector &v2, SkTDArray< SkRect > *circles, bool takeLongWayRound)

◆ create_YUV()

static int create_YUV ( const PlaneData planes,
YUVFormat  yuvFormat,
SkBitmap  resultBMs[],
bool  opaque 
)
static

Definition at line 566 of file wacky_yuv_formats.cpp.

569 {
570 int nextLayer = 0;
571
572 switch (yuvFormat) {
573 case kY416_YUVFormat: {
574 resultBMs[nextLayer++] = make_16(planes.fFull, kR16G16B16A16_unorm_SkColorType,
575 [] (uint16_t* dstPixel, const float* srcPixel) {
576 dstPixel[0] = flt_2_uint16(srcPixel[1]); // U
577 dstPixel[1] = flt_2_uint16(srcPixel[0]); // Y
578 dstPixel[2] = flt_2_uint16(srcPixel[2]); // V
579 dstPixel[3] = flt_2_uint16(srcPixel[3]); // A
580 });
581 break;
582 }
583 case kAYUV_YUVFormat: {
584 SkBitmap yuvaFull;
585
586 yuvaFull.allocPixels(SkImageInfo::Make(planes.fYFull.width(), planes.fYFull.height(),
588
589 for (int y = 0; y < planes.fYFull.height(); ++y) {
590 for (int x = 0; x < planes.fYFull.width(); ++x) {
591
592 uint8_t Y = *planes.fYFull.getAddr8(x, y);
593 uint8_t U = *planes.fUFull.getAddr8(x, y);
594 uint8_t V = *planes.fVFull.getAddr8(x, y);
595 uint8_t A = *planes.fAFull.getAddr8(x, y);
596
597 // NOT premul!
598 // V and Y swapped to match RGBA layout
599 SkColor c = SkColorSetARGB(A, V, U, Y);
600 *yuvaFull.getAddr32(x, y) = c;
601 }
602 }
603
604 resultBMs[nextLayer++] = yuvaFull;
605 break;
606 }
607 case kY410_YUVFormat: {
608 SkBitmap yuvaFull;
609 uint32_t Y, U, V;
610 uint8_t A;
611
612 yuvaFull.allocPixels(SkImageInfo::Make(planes.fYFull.width(), planes.fYFull.height(),
615
616 for (int y = 0; y < planes.fYFull.height(); ++y) {
617 for (int x = 0; x < planes.fYFull.width(); ++x) {
618
619 Y = SkScalarRoundToInt((*planes.fYFull.getAddr8(x, y) / 255.0f) * 1023.0f);
620 U = SkScalarRoundToInt((*planes.fUFull.getAddr8(x, y) / 255.0f) * 1023.0f);
621 V = SkScalarRoundToInt((*planes.fVFull.getAddr8(x, y) / 255.0f) * 1023.0f);
622 A = SkScalarRoundToInt((*planes.fAFull.getAddr8(x, y) / 255.0f) * 3.0f);
623
624 // NOT premul!
625 *yuvaFull.getAddr32(x, y) = (A << 30) | (V << 20) | (Y << 10) | (U << 0);
626 }
627 }
628
629 resultBMs[nextLayer++] = yuvaFull;
630 break;
631 }
632 case kP016_YUVFormat: // fall through
633 case kP010_YUVFormat: {
634 resultBMs[nextLayer++] = make_16(planes.fFull, kA16_unorm_SkColorType,
635 [tenBitsPP = (yuvFormat == kP010_YUVFormat)]
636 (uint16_t* dstPixel, const float* srcPixel) {
637 uint16_t val16 = flt_2_uint16(srcPixel[0]);
638 dstPixel[0] = tenBitsPP ? (val16 & 0xFFC0)
639 : val16;
640 });
641 resultBMs[nextLayer++] = make_16(planes.fQuarter, kR16G16_unorm_SkColorType,
642 [tenBitsPP = (yuvFormat == kP010_YUVFormat)]
643 (uint16_t* dstPixel, const float* srcPixel) {
644 uint16_t u16 = flt_2_uint16(srcPixel[1]);
645 uint16_t v16 = flt_2_uint16(srcPixel[2]);
646 dstPixel[0] = tenBitsPP ? (u16 & 0xFFC0) : u16;
647 dstPixel[1] = tenBitsPP ? (v16 & 0xFFC0) : v16;
648 });
649 if (!opaque) {
650 resultBMs[nextLayer++] = make_16(planes.fFull, kA16_unorm_SkColorType,
651 [tenBitsPP = (yuvFormat == kP010_YUVFormat)]
652 (uint16_t* dstPixel, const float* srcPixel) {
653 uint16_t val16 = flt_2_uint16(srcPixel[3]);
654 dstPixel[0] = tenBitsPP ? (val16 & 0xFFC0)
655 : val16;
656 });
657 }
658 return nextLayer;
659 }
660 case kP016F_YUVFormat: {
661 resultBMs[nextLayer++] = make_16(planes.fFull, kA16_float_SkColorType,
662 [] (uint16_t* dstPixel, const float* srcPixel) {
663 dstPixel[0] = SkFloatToHalf(srcPixel[0]);
664 });
665 resultBMs[nextLayer++] = make_16(planes.fQuarter, kR16G16_float_SkColorType,
666 [] (uint16_t* dstPixel, const float* srcPixel) {
667 dstPixel[0] = SkFloatToHalf(srcPixel[1]);
668 dstPixel[1] = SkFloatToHalf(srcPixel[2]);
669 });
670 if (!opaque) {
671 resultBMs[nextLayer++] = make_16(planes.fFull, kA16_float_SkColorType,
672 [] (uint16_t* dstPixel, const float* srcPixel) {
673 dstPixel[0] = SkFloatToHalf(srcPixel[3]);
674 });
675 }
676 return nextLayer;
677 }
678 case kNV12_YUVFormat: {
679 SkBitmap uvQuarter = make_quarter_2_channel(planes.fYFull,
680 planes.fUQuarter,
681 planes.fVQuarter, true);
682 resultBMs[nextLayer++] = planes.fYFull;
683 resultBMs[nextLayer++] = uvQuarter;
684 break;
685 }
686 case kNV21_YUVFormat: {
687 SkBitmap vuQuarter = make_quarter_2_channel(planes.fYFull,
688 planes.fUQuarter,
689 planes.fVQuarter, false);
690 resultBMs[nextLayer++] = planes.fYFull;
691 resultBMs[nextLayer++] = vuQuarter;
692 break;
693 }
694 case kI420_YUVFormat:
695 resultBMs[nextLayer++] = planes.fYFull;
696 resultBMs[nextLayer++] = planes.fUQuarter;
697 resultBMs[nextLayer++] = planes.fVQuarter;
698 break;
699 case kYV12_YUVFormat:
700 resultBMs[nextLayer++] = planes.fYFull;
701 resultBMs[nextLayer++] = planes.fVQuarter;
702 resultBMs[nextLayer++] = planes.fUQuarter;
703 break;
704 }
705
706 if (!opaque && !has_alpha_channel(yuvFormat)) {
707 resultBMs[nextLayer++] = planes.fAFull;
708 }
709 return nextLayer;
710}
kUnpremul_SkAlphaType
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
Definition: SkColorType.h:50
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
Definition: SkColorType.h:48
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kA16_float_SkColorType
pixel with a half float for alpha
Definition: SkColorType.h:45
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition: SkColorType.h:27
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
Definition: SkColorType.h:49
@ kR16G16_float_SkColorType
pixel with a half float for red and green
Definition: SkColorType.h:46
uint32_t SkColor
Definition: SkColor.h:37
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
static const SkScalar Y
Definition: StrokeBench.cpp:55
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
uint8_t * getAddr8(int x, int y) const
Definition: SkBitmap.h:1270
int width() const
Definition: SkBitmap.h:149
int height() const
Definition: SkBitmap.h:158
uint32_t * getAddr32(int x, int y) const
Definition: SkBitmap.h:1260
T __attribute__((ext_vector_type(N))) V
double y
double x
#define V(name)
Definition: raw_object.h:125
SkBitmap fUQuarter
SkBitmap fVQuarter
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static SkBitmap make_quarter_2_channel(const SkBitmap &fullY, const SkBitmap &quarterU, const SkBitmap &quarterV, bool uv)
static SkBitmap make_16(const SkBitmap &src, SkColorType dstCT, std::function< void(uint16_t *dstPixel, const float *srcPixel)> convert)
static bool has_alpha_channel(YUVFormat format)

◆ draw_col_label()

static void draw_col_label ( SkCanvas canvas,
int  x,
int  yuvColorSpace,
bool  opaque 
)
static

Definition at line 712 of file wacky_yuv_formats.cpp.

712 {
713 static const char* kYUVColorSpaceNames[] = {"JPEG", "601", "709F", "709L",
714 "2020_8F", "2020_8L", "2020_10L", "2020_12F",
715 "FCCL", "SMPTE240L","YDZDXL", "GBRL",
716 "YCGCO_8F", "YCGCO_8L", "YCGCO_10F","YCGCO_12F",
717 "YCGCO_12L","Identity"};
718 static_assert(std::size(kYUVColorSpaceNames) == std::size(color_space_array));
719
722 font.setEdging(SkFont::Edging::kAlias);
723
724 SkRect textRect;
725 SkString colLabel;
726
727 colLabel.printf("%s", kYUVColorSpaceNames[yuvColorSpace]);
728 font.measureText(colLabel.c_str(), colLabel.size(), SkTextEncoding::kUTF8, &textRect);
729 int y = textRect.height();
730
732
733 colLabel.printf("%s", opaque ? "Opaque" : "Transparent");
734
735 font.measureText(colLabel.c_str(), colLabel.size(), SkTextEncoding::kUTF8, &textRect);
736 y += textRect.height();
737
739}
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static constexpr SkFontStyle Bold()
Definition: SkFontStyle.h:69
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133
static void DrawString(SkCanvas *canvas, const char text[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint, Align align=kLeft_Align)
Definition: SkTextUtils.h:34
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkTypeface > CreatePortableTypeface(const char *name, SkFontStyle style)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
constexpr float height() const
Definition: SkRect.h:769
const SkYUVColorSpace color_space_array[]

◆ draw_diff()

static void draw_diff ( SkCanvas canvas,
SkScalar  x,
SkScalar  y,
const SkImage a,
const SkImage b 
)
static

Definition at line 1227 of file wacky_yuv_formats.cpp.

1228 {
1230 a->makeShader(SkSamplingOptions()),
1231 b->makeShader(SkSamplingOptions()));
1232 SkPaint paint;
1233 paint.setShader(sh);
1234 canvas->save();
1235 canvas->translate(x, y);
1236 canvas->drawRect(SkRect::MakeWH(a->width(), a->height()), paint);
1237
1238 SkColorMatrix cm;
1239 cm.setScale(64, 64, 64);
1240 paint.setShader(sh->makeWithColorFilter(SkColorFilters::Matrix(cm)));
1241 canvas->translate(0, a->height());
1242 canvas->drawRect(SkRect::MakeWH(a->width(), a->height()), paint);
1243
1244 canvas->restore();
1245}
@ kDifference
rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
void setScale(float rScale, float gScale, float bScale, float aScale=1.0f)
struct MyStruct a[10]
SK_API sk_sp< SkShader > Blend(SkBlendMode mode, sk_sp< SkShader > dst, sk_sp< SkShader > src)
sh
Definition: run_sh.py:10
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ draw_row_label()

static void draw_row_label ( SkCanvas canvas,
int  y,
int  yuvFormat 
)
static

Definition at line 741 of file wacky_yuv_formats.cpp.

741 {
742 static const char* kYUVFormatNames[] = {
743 "P016", "P010", "P016F", "Y416", "AYUV", "Y410", "NV12", "NV21", "I420", "YV12"
744 };
745 static_assert(std::size(kYUVFormatNames) == kLast_YUVFormat + 1);
746
749 font.setEdging(SkFont::Edging::kAlias);
750
751 SkRect textRect;
752 SkString rowLabel;
753
754 rowLabel.printf("%s", kYUVFormatNames[yuvFormat]);
755 font.measureText(rowLabel.c_str(), rowLabel.size(), SkTextEncoding::kUTF8, &textRect);
756 y += kTileWidthHeight/2 + textRect.height()/2;
757
758 canvas->drawString(rowLabel, 0, y, font, paint);
759}
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
static const int kTileWidthHeight

◆ extract_planes()

static void extract_planes ( const SkBitmap origBM,
SkYUVColorSpace  yuvColorSpace,
SkEncodedOrigin  origin,
PlaneData planes 
)
static

Definition at line 408 of file wacky_yuv_formats.cpp.

411 {
412 SkImageInfo ii = origBM.info();
414 ii = ii.makeWH(ii.height(), ii.width());
415 }
416 SkBitmap orientedBM;
417 orientedBM.allocPixels(ii);
418 SkCanvas canvas(orientedBM);
419 SkMatrix matrix = SkEncodedOriginToMatrix(origin, origBM.width(), origBM.height());
420 SkAssertResult(matrix.invert(&matrix));
421 canvas.concat(matrix);
422 canvas.drawImage(origBM.asImage(), 0, 0);
423
424 if (yuvColorSpace == kIdentity_SkYUVColorSpace) {
425 // To test the identity color space we use JPEG YUV planes
426 yuvColorSpace = kJPEG_SkYUVColorSpace;
427 }
428
429 SkASSERT(!(ii.width() % 2));
430 SkASSERT(!(ii.height() % 2));
431 planes->fYFull.allocPixels(
433 planes->fUFull.allocPixels(
435 planes->fVFull.allocPixels(
438 planes->fUQuarter.allocPixels(SkImageInfo::Make(ii.width()/2, ii.height()/2,
440 planes->fVQuarter.allocPixels(SkImageInfo::Make(ii.width()/2, ii.height()/2,
442
443 planes->fFull.allocPixels(
445 planes->fQuarter.allocPixels(SkImageInfo::Make(ii.width()/2, ii.height()/2,
447
448 float mtx[20];
449 SkColorMatrix_RGB2YUV(yuvColorSpace, mtx);
450
451 SkColor4f* dst = (SkColor4f *) planes->fFull.getAddr(0, 0);
452 for (int y = 0; y < orientedBM.height(); ++y) {
453 for (int x = 0; x < orientedBM.width(); ++x) {
454 SkColor col = orientedBM.getColor(x, y);
455
456 uint8_t yuva[4];
457
458 convert_rgba_to_yuva(mtx, col, yuva);
459
460 *planes->fYFull.getAddr8(x, y) = yuva[0];
461 *planes->fUFull.getAddr8(x, y) = yuva[1];
462 *planes->fVFull.getAddr8(x, y) = yuva[2];
463 *planes->fAFull.getAddr8(x, y) = yuva[3];
464
465 // TODO: render in F32 rather than converting here
466 dst->fR = yuva[0] / 255.0f;
467 dst->fG = yuva[1] / 255.0f;
468 dst->fB = yuva[2] / 255.0f;
469 dst->fA = yuva[3] / 255.0f;
470 ++dst;
471 }
472 }
473
474 dst = (SkColor4f *) planes->fQuarter.getAddr(0, 0);
475 for (int y = 0; y < orientedBM.height()/2; ++y) {
476 for (int x = 0; x < orientedBM.width()/2; ++x) {
477 uint32_t yAccum = 0, uAccum = 0, vAccum = 0, aAccum = 0;
478
479 yAccum += *planes->fYFull.getAddr8(2*x, 2*y);
480 yAccum += *planes->fYFull.getAddr8(2*x+1, 2*y);
481 yAccum += *planes->fYFull.getAddr8(2*x, 2*y+1);
482 yAccum += *planes->fYFull.getAddr8(2*x+1, 2*y+1);
483
484 uAccum += *planes->fUFull.getAddr8(2*x, 2*y);
485 uAccum += *planes->fUFull.getAddr8(2*x+1, 2*y);
486 uAccum += *planes->fUFull.getAddr8(2*x, 2*y+1);
487 uAccum += *planes->fUFull.getAddr8(2*x+1, 2*y+1);
488
489 *planes->fUQuarter.getAddr8(x, y) = uAccum / 4.0f;
490
491 vAccum += *planes->fVFull.getAddr8(2*x, 2*y);
492 vAccum += *planes->fVFull.getAddr8(2*x+1, 2*y);
493 vAccum += *planes->fVFull.getAddr8(2*x, 2*y+1);
494 vAccum += *planes->fVFull.getAddr8(2*x+1, 2*y+1);
495
496 *planes->fVQuarter.getAddr8(x, y) = vAccum / 4.0f;
497
498 aAccum += *planes->fAFull.getAddr8(2*x, 2*y);
499 aAccum += *planes->fAFull.getAddr8(2*x+1, 2*y);
500 aAccum += *planes->fAFull.getAddr8(2*x, 2*y+1);
501 aAccum += *planes->fAFull.getAddr8(2*x+1, 2*y+1);
502
503 // TODO: render in F32 rather than converting here
504 dst->fR = yAccum / (4.0f * 255.0f);
505 dst->fG = uAccum / (4.0f * 255.0f);
506 dst->fB = vAccum / (4.0f * 255.0f);
507 dst->fA = aAccum / (4.0f * 255.0f);
508 ++dst;
509 }
510 }
511}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition: SkColorType.h:35
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
Definition: SkColorType.h:40
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
static SkMatrix SkEncodedOriginToMatrix(SkEncodedOrigin origin, int w, int h)
@ kJPEG_SkYUVColorSpace
Definition: SkImageInfo.h:98
@ kIdentity_SkYUVColorSpace
maps Y->R, U->G, V->B
Definition: SkImageInfo.h:93
void SkColorMatrix_RGB2YUV(SkYUVColorSpace cs, float m[20])
Definition: SkYUVMath.cpp:389
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
SkColor getColor(int x, int y) const
Definition: SkBitmap.h:874
void * getAddr(int x, int y) const
Definition: SkBitmap.cpp:406
const SkImageInfo & info() const
Definition: SkBitmap.h:139
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
dst
Definition: cp.py:12
SkImageInfo makeWH(int newWidth, int newHeight) const
Definition: SkImageInfo.h:444
SkISize dimensions() const
Definition: SkImageInfo.h:421
int width() const
Definition: SkImageInfo.h:365
int height() const
Definition: SkImageInfo.h:371
static SkImageInfo MakeA8(int width, int height)
static void convert_rgba_to_yuva(const float mtx[20], SkColor col, uint8_t yuv[4])

◆ flt_2_uint16()

static uint16_t flt_2_uint16 ( float  flt)
static

Definition at line 563 of file wacky_yuv_formats.cpp.

563{ return SkScalarRoundToInt(flt * 65535.0f); }

◆ has_alpha_channel()

static bool has_alpha_channel ( YUVFormat  format)
static

Definition at line 102 of file wacky_yuv_formats.cpp.

102 {
103 switch (format) {
104 case kP016_YUVFormat: return false;
105 case kP010_YUVFormat: return false;
106 case kP016F_YUVFormat: return false;
107 case kY416_YUVFormat: return true;
108 case kAYUV_YUVFormat: return true;
109 case kY410_YUVFormat: return true;
110 case kNV12_YUVFormat: return false;
111 case kNV21_YUVFormat: return false;
112 case kI420_YUVFormat: return false;
113 case kYV12_YUVFormat: return false;
114 }
116}
#define SkUNREACHABLE
Definition: SkAssert.h:135
uint32_t uint32_t * format

◆ make_16()

static SkBitmap make_16 ( const SkBitmap src,
SkColorType  dstCT,
std::function< void(uint16_t *dstPixel, const float *srcPixel)>  convert 
)
static

Definition at line 543 of file wacky_yuv_formats.cpp.

544 {
545 SkASSERT(src.colorType() == kRGBA_F32_SkColorType);
546
548
549 result.allocPixels(SkImageInfo::Make(src.dimensions(), dstCT, kUnpremul_SkAlphaType));
550
551 for (int y = 0; y < src.height(); ++y) {
552 for (int x = 0; x < src.width(); ++x) {
553 const float* srcPixel = (const float*) src.getAddr(x, y);
554 uint16_t* dstPixel = (uint16_t*) result.getAddr(x, y);
555
556 convert(dstPixel, srcPixel);
557 }
558 }
559
560 return result;
561}
static Editor::Movement convert(skui::Key key)
GAsyncResult * result

◆ make_bitmap()

static SkBitmap make_bitmap ( SkColorType  colorType,
const SkPath path,
const SkTDArray< SkRect > &  circles,
bool  opaque,
bool  padWithRed 
)
static

Definition at line 347 of file wacky_yuv_formats.cpp.

348 {
349 const SkColor kGreen = ToolUtils::color_to_565(SkColorSetARGB(0xFF, 178, 240, 104));
350 const SkColor kBlue = ToolUtils::color_to_565(SkColorSetARGB(0xFF, 173, 167, 252));
351 const SkColor kYellow = ToolUtils::color_to_565(SkColorSetARGB(0xFF, 255, 221, 117));
352 const SkColor kMagenta = ToolUtils::color_to_565(SkColorSetARGB(0xFF, 255, 60, 217));
353 const SkColor kCyan = ToolUtils::color_to_565(SkColorSetARGB(0xFF, 45, 237, 205));
354
355 int widthHeight = kTileWidthHeight + (padWithRed ? 2 * kSubsetPadding : 0);
356
357 SkImageInfo ii = SkImageInfo::Make(widthHeight, widthHeight,
359
360 SkBitmap bm;
361 bm.allocPixels(ii);
362
363 std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(ii,
364 bm.getPixels(),
365 bm.rowBytes());
366 if (padWithRed) {
367 canvas->clear(SK_ColorRED);
368 canvas->translate(kSubsetPadding, kSubsetPadding);
370 }
371 canvas->clear(opaque ? kGreen : SK_ColorTRANSPARENT);
372
374 paint.setAntiAlias(false); // serialize-8888 doesn't seem to work well w/ partial transparency
375 paint.setColor(kBlue);
376
377 canvas->drawPath(path, paint);
378
379 paint.setBlendMode(SkBlendMode::kSrc);
380 for (int i = 0; i < circles.size(); ++i) {
382 switch (i % 3) {
383 case 0: color = kYellow; break;
384 case 1: color = kMagenta; break;
385 default: color = kCyan; break;
386 }
387 paint.setColor(color);
388 paint.setAlpha(opaque ? 0xFF : 0x40);
389 SkRect r = circles[i];
390 r.inset(r.width()/4, r.height()/4);
391 canvas->drawOval(r, paint);
392 }
393
394 return bm;
395}
static const uint64_t kGreen
static const uint64_t kBlue
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
size_t rowBytes() const
Definition: SkBitmap.h:238
void * getPixels() const
Definition: SkBitmap.h:283
static std::unique_ptr< SkCanvas > MakeRasterDirect(const SkImageInfo &info, void *pixels, size_t rowBytes, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:2801
int size() const
Definition: SkTDArray.h:138
DlColor color
constexpr SkColor4f kMagenta
Definition: SkColor.h:445
constexpr SkColor4f kCyan
Definition: SkColor.h:444
constexpr SkColor4f kYellow
Definition: SkColor.h:443
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139
void inset(float dx, float dy)
Definition: SkRect.h:1060
constexpr float width() const
Definition: SkRect.h:762
static const int kSubsetPadding

◆ make_quarter_2_channel()

static SkBitmap make_quarter_2_channel ( const SkBitmap fullY,
const SkBitmap quarterU,
const SkBitmap quarterV,
bool  uv 
)
static

Definition at line 515 of file wacky_yuv_formats.cpp.

518 {
520
521 result.allocPixels(SkImageInfo::Make(fullY.width()/2,
522 fullY.height()/2,
525
526 for (int y = 0; y < fullY.height()/2; ++y) {
527 for (int x = 0; x < fullY.width()/2; ++x) {
528 uint8_t u8 = *quarterU.getAddr8(x, y);
529 uint8_t v8 = *quarterV.getAddr8(x, y);
530
531 if (uv) {
532 *result.getAddr16(x, y) = (v8 << 8) | u8;
533 } else {
534 *result.getAddr16(x, y) = (u8 << 8) | v8;
535 }
536 }
537 }
538
539 return result;
540}
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
Definition: SkColorType.h:43

◆ yuv_to_rgb_colorfilter()

static sk_sp< SkColorFilter > yuv_to_rgb_colorfilter ( )
static

Definition at line 761 of file wacky_yuv_formats.cpp.

761 {
762 static const float kJPEGConversionMatrix[20] = {
763 1.0f, 0.0f, 1.402f, 0.0f, -180.0f/255,
764 1.0f, -0.344136f, -0.714136f, 0.0f, 136.0f/255,
765 1.0f, 1.772f, 0.0f, 0.0f, -227.6f/255,
766 0.0f, 0.0f, 0.0f, 1.0f, 0.0f
767 };
768
769 return SkColorFilters::Matrix(kJPEGConversionMatrix);
770}

Variable Documentation

◆ color_space_array

const SkYUVColorSpace color_space_array[]
Initial value:
= {
}
@ kRec709_Full_SkYUVColorSpace
describes HDTV range
Definition: SkImageInfo.h:71
@ kYCgCo_10bit_Full_SkYUVColorSpace
Definition: SkImageInfo.h:89
@ kYCgCo_12bit_Full_SkYUVColorSpace
Definition: SkImageInfo.h:91
@ kYCgCo_12bit_Limited_SkYUVColorSpace
Definition: SkImageInfo.h:92
@ kGBR_Limited_SkYUVColorSpace
Definition: SkImageInfo.h:86
@ kBT2020_8bit_Limited_SkYUVColorSpace
Definition: SkImageInfo.h:74
@ kYCgCo_8bit_Limited_SkYUVColorSpace
Definition: SkImageInfo.h:88
@ kFCC_Limited_SkYUVColorSpace
Definition: SkImageInfo.h:80
@ kYCgCo_8bit_Full_SkYUVColorSpace
describes YCgCo matrix
Definition: SkImageInfo.h:87
@ kBT2020_8bit_Full_SkYUVColorSpace
describes UHDTV range, non-constant-luminance
Definition: SkImageInfo.h:73
@ kRec601_Limited_SkYUVColorSpace
describes SDTV range
Definition: SkImageInfo.h:70
@ kRec709_Limited_SkYUVColorSpace
Definition: SkImageInfo.h:72
@ kSMPTE240_Limited_SkYUVColorSpace
Definition: SkImageInfo.h:82
@ kBT2020_12bit_Full_SkYUVColorSpace
Definition: SkImageInfo.h:77
@ kBT2020_10bit_Limited_SkYUVColorSpace
Definition: SkImageInfo.h:76
@ kYDZDX_Limited_SkYUVColorSpace
Definition: SkImageInfo.h:84
@ kJPEG_Full_SkYUVColorSpace
describes full range
Definition: SkImageInfo.h:69

Definition at line 225 of file wacky_yuv_formats.cpp.

◆ kLabelHeight

const int kLabelHeight = 32
static

Definition at line 64 of file wacky_yuv_formats.cpp.

◆ kLabelWidth

const int kLabelWidth = 64
static

Definition at line 63 of file wacky_yuv_formats.cpp.

◆ kPad

const int kPad = 1
static

Definition at line 66 of file wacky_yuv_formats.cpp.

◆ kSubsetPadding

const int kSubsetPadding = 8
static

Definition at line 65 of file wacky_yuv_formats.cpp.

◆ kTileWidthHeight

const int kTileWidthHeight = 128
static

Definition at line 62 of file wacky_yuv_formats.cpp.