Flutter Engine
The Flutter Engine
jpg_color_cube.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
9
13#include "include/core/SkData.h"
16#include "include/core/SkSize.h"
22
23#include <utility>
24
25namespace skiagm {
26
27class ColorCubeGM : public GM {
28public:
30
31protected:
32 SkString getName() const override { return SkString("jpg-color-cube"); }
33
34 SkISize getISize() override { return SkISize::Make(512, 512); }
35
36 void onOnceBeforeDraw() override {
37 SkBitmap bmp;
38 bmp.allocN32Pixels(512, 512, true);
39 int bX = 0, bY = 0;
40 for (int b = 0; b < 64; ++b) {
41 for (int r = 0; r < 64; ++r) {
42 for (int g = 0; g < 64; ++g) {
43 *bmp.getAddr32(bX + r, bY + g) = SkPackARGB32(255,
44 SkTPin(r * 4, 0, 255),
45 SkTPin(g * 4, 0, 255),
46 SkTPin(b * 4, 0, 255));
47 }
48 }
49 bX += 64;
50 if (bX >= 512) {
51 bX = 0;
52 bY += 64;
53 }
54 }
57 fImage = SkImages::DeferredFromEncodedData(stream.detachAsData());
58 }
59
60 void onDraw(SkCanvas* canvas) override {
61 canvas->drawImage(fImage, 0, 0);
62 }
63
64private:
65 sk_sp<SkImage> fImage;
66
67 using INHERITED = GM;
68};
69
70DEF_GM( return new ColorCubeGM; )
71} // namespace skiagm
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorPriv.h:106
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
const SkPixmap & pixmap() const
Definition: SkBitmap.h:133
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
uint32_t * getAddr32(int x, int y) const
Definition: SkBitmap.h:1260
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
void onOnceBeforeDraw() override
void onDraw(SkCanvas *canvas) override
SkString getName() const override
SkISize getISize() override
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
static bool b
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20