Flutter Engine
The Flutter Engine
Classes | Functions | Variables
readpixels.cpp File Reference
#include "gm/gm.h"
#include "include/codec/SkCodec.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPicture.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "modules/skcms/skcms.h"
#include "tools/Resources.h"
#include <string.h>
#include <memory>
#include <utility>

Go to the source code of this file.

Classes

class  ReadPixelsGM
 
class  ReadPixelsCodecGM
 
class  ReadPixelsPictureGM
 

Functions

static sk_sp< SkImagemake_raster_image (SkColorType colorType)
 
static sk_sp< SkImagemake_codec_image ()
 
static void draw_contents (SkCanvas *canvas)
 
static sk_sp< SkImagemake_picture_image ()
 
static sk_sp< SkColorSpacemake_parametric_transfer_fn (const SkColorSpacePrimaries &primaries)
 
static sk_sp< SkColorSpacemake_wide_gamut ()
 
static sk_sp< SkColorSpacemake_small_gamut ()
 
static void draw_image (GrDirectContext *dContext, SkCanvas *canvas, SkImage *image, SkColorType dstColorType, SkAlphaType dstAlphaType, sk_sp< SkColorSpace > dstColorSpace, SkImage::CachingHint hint)
 

Variables

static const int kWidth = 64
 
static const int kHeight = 64
 

Function Documentation

◆ draw_contents()

static void draw_contents ( SkCanvas canvas)
static

Definition at line 55 of file readpixels.cpp.

55 {
58 paint.setStrokeWidth(20);
59 paint.setColor(0xFF800000);
60 canvas->drawCircle(40, 40, 35, paint);
61 paint.setColor(0xFF008000);
62 canvas->drawCircle(50, 50, 35, paint);
63 paint.setColor(0xFF000080);
64 canvas->drawCircle(60, 60, 35, paint);
65}
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
const Paint & paint
Definition: color_source.cc:38

◆ draw_image()

static void draw_image ( GrDirectContext dContext,
SkCanvas canvas,
SkImage image,
SkColorType  dstColorType,
SkAlphaType  dstAlphaType,
sk_sp< SkColorSpace dstColorSpace,
SkImage::CachingHint  hint 
)
static

Definition at line 112 of file readpixels.cpp.

114 {
115 size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(dstColorType);
117 SkImageInfo dstInfo = SkImageInfo::Make(image->width(), image->height(), dstColorType,
118 dstAlphaType, dstColorSpace);
119 if (!image->readPixels(dContext, dstInfo, data->writable_data(), rowBytes, 0, 0, hint)) {
120 memset(data->writable_data(), 0, rowBytes * image->height());
121 }
122
123 // Now that we have called readPixels(), dump the raw pixels into an srgb image.
125 sk_sp<SkImage> raw = SkImages::RasterFromData(dstInfo.makeColorSpace(srgb), data, rowBytes);
126 canvas->drawImage(raw.get(), 0.0f, 0.0f);
127}
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
Definition: SkImageInfo.cpp:16
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
bool readPixels(GrDirectContext *context, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
Definition: SkImage.cpp:42
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
T * get() const
Definition: SkRefCnt.h:303
SK_API sk_sp< SkImage > RasterFromData(const SkImageInfo &info, sk_sp< SkData > pixels, size_t rowBytes)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ make_codec_image()

static sk_sp< SkImage > make_codec_image ( )
static

Definition at line 50 of file readpixels.cpp.

50 {
51 sk_sp<SkData> encoded = GetResourceAsData("images/randPixels.png");
53}
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition: Resources.cpp:42
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)

◆ make_parametric_transfer_fn()

static sk_sp< SkColorSpace > make_parametric_transfer_fn ( const SkColorSpacePrimaries primaries)
static

Definition at line 78 of file readpixels.cpp.

78 {
79 skcms_Matrix3x3 toXYZD50;
80 SkAssertResult(primaries.toXYZD50(&toXYZD50));
81 skcms_TransferFunction fn = { 1.8f, 1.f, 0.f, 0.f, 0.f, 0.f, 0.f };
82 return SkColorSpace::MakeRGB(fn, toXYZD50);
83}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
static sk_sp< SkColorSpace > MakeRGB(const skcms_TransferFunction &transferFn, const skcms_Matrix3x3 &toXYZ)
bool toXYZD50(skcms_Matrix3x3 *toXYZD50) const

◆ make_picture_image()

static sk_sp< SkImage > make_picture_image ( )
static

Definition at line 67 of file readpixels.cpp.

67 {
68 SkPictureRecorder recorder;
72 nullptr,
73 nullptr,
76}
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
SK_API sk_sp< SkImage > DeferredFromPicture(sk_sp< SkPicture > picture, const SkISize &dimensions, const SkMatrix *matrix, const SkPaint *paint, BitDepth bitDepth, sk_sp< SkColorSpace > colorSpace, SkSurfaceProps props)
@ kU8
uses 8-bit unsigned int per color component
static const int kHeight
Definition: readpixels.cpp:35
static const int kWidth
Definition: readpixels.cpp:34
static void draw_contents(SkCanvas *canvas)
Definition: readpixels.cpp:55
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623

◆ make_raster_image()

static sk_sp< SkImage > make_raster_image ( SkColorType  colorType)
static

Definition at line 37 of file readpixels.cpp.

37 {
38 std::unique_ptr<SkStream> stream(GetResourceAsStream("images/google_chrome.ico"));
39 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromStream(std::move(stream));
40 if (!codec) {
41 return nullptr;
42 }
43
44 SkImageInfo info = codec->getInfo().makeWH(kWidth, kHeight)
45 .makeColorType(colorType)
46 .makeAlphaType(kPremul_SkAlphaType);
47 return std::get<0>(codec->getImage(info));
48}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
Definition: Resources.cpp:31
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
Definition: SkCodec.cpp:163
const myers::Point & get< 0 >(const myers::Segment &s)
Definition: Myers.h:80

◆ make_small_gamut()

static sk_sp< SkColorSpace > make_small_gamut ( )
static

Definition at line 99 of file readpixels.cpp.

99 {
100 SkColorSpacePrimaries primaries;
101 primaries.fRX = 0.50f;
102 primaries.fRY = 0.33f;
103 primaries.fGX = 0.30f;
104 primaries.fGY = 0.50f;
105 primaries.fBX = 0.25f;
106 primaries.fBY = 0.16f;
107 primaries.fWX = 0.3127f;
108 primaries.fWY = 0.3290f;
109 return make_parametric_transfer_fn(primaries);
110}
static sk_sp< SkColorSpace > make_parametric_transfer_fn(const SkColorSpacePrimaries &primaries)
Definition: readpixels.cpp:78

◆ make_wide_gamut()

static sk_sp< SkColorSpace > make_wide_gamut ( )
static

Definition at line 85 of file readpixels.cpp.

85 {
86 // ProPhoto
87 SkColorSpacePrimaries primaries;
88 primaries.fRX = 0.7347f;
89 primaries.fRY = 0.2653f;
90 primaries.fGX = 0.1596f;
91 primaries.fGY = 0.8404f;
92 primaries.fBX = 0.0366f;
93 primaries.fBY = 0.0001f;
94 primaries.fWX = 0.34567f;
95 primaries.fWY = 0.35850f;
96 return make_parametric_transfer_fn(primaries);
97}

Variable Documentation

◆ kHeight

const int kHeight = 64
static

Definition at line 35 of file readpixels.cpp.

◆ kWidth

const int kWidth = 64
static

Definition at line 34 of file readpixels.cpp.