2019-03-15 18:22:51 +00:00
|
|
|
// Copyright 2019 Google LLC.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/fiddle/examples.h"
|
2019-03-15 18:22:51 +00:00
|
|
|
// HASH=b2cbbbbcffb618865d8aae3bc04b2a62
|
2019-03-18 20:06:34 +00:00
|
|
|
REG_FIDDLE(Bitmap_readPixels, 256, 128, false, 0) {
|
2019-03-15 18:22:51 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
const int width = 256;
|
|
|
|
const int height = 64;
|
|
|
|
SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
|
|
|
|
SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
|
|
|
|
SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
|
2019-04-03 14:27:45 +00:00
|
|
|
SK_ARRAY_COUNT(gradColors), SkTileMode::kClamp));
|
2019-03-15 18:22:51 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(srcInfo);
|
|
|
|
SkCanvas srcCanvas(bitmap);
|
|
|
|
srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
|
2021-01-27 22:09:40 +00:00
|
|
|
canvas->drawImage(bitmap.asImage(), 0, 0);
|
2019-03-15 18:22:51 +00:00
|
|
|
SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
|
|
|
|
std::vector<int16_t> dstPixels;
|
|
|
|
dstPixels.resize(height * width);
|
|
|
|
bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0);
|
|
|
|
SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
|
|
|
|
bitmap.installPixels(dstPixmap);
|
2021-01-27 22:09:40 +00:00
|
|
|
canvas->drawImage(bitmap.asImage(), 0, 64);
|
2019-03-15 18:22:51 +00:00
|
|
|
}
|
|
|
|
} // END FIDDLE
|