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=b2cbbbbcffb618865d8aae3bc04b2a62 5cb93a386Sopenharmony_ciREG_FIDDLE(Bitmap_readPixels, 256, 128, false, 0) { 6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) { 7cb93a386Sopenharmony_ci const int width = 256; 8cb93a386Sopenharmony_ci const int height = 64; 9cb93a386Sopenharmony_ci SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height); 10cb93a386Sopenharmony_ci SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; 11cb93a386Sopenharmony_ci SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } }; 12cb93a386Sopenharmony_ci SkPaint paint; 13cb93a386Sopenharmony_ci paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, 14cb93a386Sopenharmony_ci SK_ARRAY_COUNT(gradColors), SkTileMode::kClamp)); 15cb93a386Sopenharmony_ci SkBitmap bitmap; 16cb93a386Sopenharmony_ci bitmap.allocPixels(srcInfo); 17cb93a386Sopenharmony_ci SkCanvas srcCanvas(bitmap); 18cb93a386Sopenharmony_ci srcCanvas.drawRect(SkRect::MakeWH(width, height), paint); 19cb93a386Sopenharmony_ci canvas->drawImage(bitmap.asImage(), 0, 0); 20cb93a386Sopenharmony_ci SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType); 21cb93a386Sopenharmony_ci std::vector<int16_t> dstPixels; 22cb93a386Sopenharmony_ci dstPixels.resize(height * width); 23cb93a386Sopenharmony_ci bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0); 24cb93a386Sopenharmony_ci SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2); 25cb93a386Sopenharmony_ci bitmap.installPixels(dstPixmap); 26cb93a386Sopenharmony_ci canvas->drawImage(bitmap.asImage(), 0, 64); 27cb93a386Sopenharmony_ci} 28cb93a386Sopenharmony_ci} // END FIDDLE 29