1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC.
2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h"
4cb93a386Sopenharmony_ci// HASH=8aa8ca63dff4641dfc6ea8a3c555d59c
5cb93a386Sopenharmony_ciREG_FIDDLE(Image_readPixels, 256, 256, false, 3) {
6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) {
7cb93a386Sopenharmony_ci    canvas->scale(.5f, .5f);
8cb93a386Sopenharmony_ci    const int width = 32;
9cb93a386Sopenharmony_ci    const int height = 32;
10cb93a386Sopenharmony_ci    std::vector<int32_t> dstPixels;
11cb93a386Sopenharmony_ci    dstPixels.resize(height * width * 4);
12cb93a386Sopenharmony_ci    SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
13cb93a386Sopenharmony_ci    for (int y = 0; y < 512; y += height ) {
14cb93a386Sopenharmony_ci        for (int x = 0; x < 512; x += width ) {
15cb93a386Sopenharmony_ci            if (image->readPixels(nullptr, info, &dstPixels.front(), width * 4, x, y)) {
16cb93a386Sopenharmony_ci                SkPixmap dstPixmap(info, &dstPixels.front(), width * 4);
17cb93a386Sopenharmony_ci                SkBitmap bitmap;
18cb93a386Sopenharmony_ci                bitmap.installPixels(dstPixmap);
19cb93a386Sopenharmony_ci                canvas->drawImage(bitmap.asImage(), 0, 0);
20cb93a386Sopenharmony_ci            }
21cb93a386Sopenharmony_ci            canvas->translate(48, 0);
22cb93a386Sopenharmony_ci        }
23cb93a386Sopenharmony_ci        canvas->translate(-16 * 48, 48);
24cb93a386Sopenharmony_ci    }
25cb93a386Sopenharmony_ci}
26cb93a386Sopenharmony_ci}  // END FIDDLE
27