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=818e4e1191e39d2a642902cbf253b399 5cb93a386Sopenharmony_ciREG_FIDDLE(ImageInfo_computeOffset, 256, 128, false, 0) { 6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) { 7cb93a386Sopenharmony_ci uint8_t pixels[][12] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, 8cb93a386Sopenharmony_ci { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, 9cb93a386Sopenharmony_ci { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, 10cb93a386Sopenharmony_ci { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, 11cb93a386Sopenharmony_ci { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 12cb93a386Sopenharmony_ci { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, 13cb93a386Sopenharmony_ci { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, 14cb93a386Sopenharmony_ci { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} }; 15cb93a386Sopenharmony_ci SkImageInfo imageInfo = SkImageInfo::MakeA8(8, 8); 16cb93a386Sopenharmony_ci SkBitmap bitmap; 17cb93a386Sopenharmony_ci bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0])); 18cb93a386Sopenharmony_ci SkPaint paint; 19cb93a386Sopenharmony_ci paint.setColor(SK_ColorRED); 20cb93a386Sopenharmony_ci canvas->drawImageRect(bitmap.asImage(), SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), 21cb93a386Sopenharmony_ci SkSamplingOptions(), &paint, SkCanvas::kStrict_SrcRectConstraint); 22cb93a386Sopenharmony_ci size_t offset = imageInfo.computeOffset(2, 3, sizeof(pixels[0])); 23cb93a386Sopenharmony_ci pixels[0][offset] = 0x7F; 24cb93a386Sopenharmony_ci offset = imageInfo.computeOffset(5, 3, sizeof(pixels[0])); 25cb93a386Sopenharmony_ci pixels[0][offset] = 0x7F; 26cb93a386Sopenharmony_ci bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0])); 27cb93a386Sopenharmony_ci canvas->drawImageRect(bitmap.asImage(), SkRect::MakeWH(8, 8), SkRect::MakeWH(128, 128), 28cb93a386Sopenharmony_ci SkSamplingOptions(), &paint, SkCanvas::kStrict_SrcRectConstraint); 29cb93a386Sopenharmony_ci} 30cb93a386Sopenharmony_ci} // END FIDDLE 31