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=b77a73c4baa63a4a8e2a4fdd96144d0b
5cb93a386Sopenharmony_ciREG_FIDDLE(Image_readPixels_2, 256, 256, false, 3) {
6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) {
7cb93a386Sopenharmony_ci    std::vector<int32_t> srcPixels;
8cb93a386Sopenharmony_ci    int rowBytes = image->width() * 4;
9cb93a386Sopenharmony_ci    int quarterWidth = image->width() / 4;
10cb93a386Sopenharmony_ci    int quarterHeight = image->height() / 4;
11cb93a386Sopenharmony_ci    srcPixels.resize(image->height() * rowBytes);
12cb93a386Sopenharmony_ci    for (int y = 0; y < 4; ++y) {
13cb93a386Sopenharmony_ci        for (int x = 0; x < 4; ++x) {
14cb93a386Sopenharmony_ci            SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight),
15cb93a386Sopenharmony_ci                    &srcPixels.front() + x * image->height() * quarterWidth +
16cb93a386Sopenharmony_ci                    y * quarterWidth, rowBytes);
17cb93a386Sopenharmony_ci            image->readPixels(nullptr, pixmap, x * quarterWidth, y * quarterHeight);
18cb93a386Sopenharmony_ci        }
19cb93a386Sopenharmony_ci    }
20cb93a386Sopenharmony_ci    canvas->scale(.5f, .5f);
21cb93a386Sopenharmony_ci    SkBitmap bitmap;
22cb93a386Sopenharmony_ci    bitmap.installPixels(SkImageInfo::MakeN32Premul(image->width(), image->height()),
23cb93a386Sopenharmony_ci                             &srcPixels.front(), rowBytes);
24cb93a386Sopenharmony_ci    canvas->drawImage(bitmap.asImage(), 0, 0);
25cb93a386Sopenharmony_ci}
26cb93a386Sopenharmony_ci}  // END FIDDLE
27