2015-02-24 06:12:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2020-12-23 15:11:33 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "src/core/SkImagePriv.h"
|
|
|
|
#include "tests/Test.h"
|
2015-02-24 06:12:12 +00:00
|
|
|
|
|
|
|
static const int gWidth = 20;
|
|
|
|
static const int gHeight = 20;
|
|
|
|
|
|
|
|
// Tests that SkNewImageFromBitmap obeys pixelref origin.
|
|
|
|
DEF_TEST(SkImageFromBitmap_extractSubset, reporter) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image;
|
2015-02-24 06:12:12 +00:00
|
|
|
{
|
|
|
|
SkBitmap srcBitmap;
|
|
|
|
srcBitmap.allocN32Pixels(gWidth, gHeight);
|
|
|
|
srcBitmap.eraseColor(SK_ColorRED);
|
2015-06-22 16:46:59 +00:00
|
|
|
SkCanvas canvas(srcBitmap);
|
2015-02-24 06:12:12 +00:00
|
|
|
SkIRect r = SkIRect::MakeXYWH(5, 5, gWidth - 5, gWidth - 5);
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorGREEN);
|
|
|
|
canvas.drawIRect(r, p);
|
|
|
|
SkBitmap dstBitmap;
|
|
|
|
srcBitmap.extractSubset(&dstBitmap, r);
|
2020-12-23 16:50:36 +00:00
|
|
|
image = dstBitmap.asImage();
|
2015-02-24 06:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap tgt;
|
|
|
|
tgt.allocN32Pixels(gWidth, gHeight);
|
2015-06-22 16:46:59 +00:00
|
|
|
SkCanvas canvas(tgt);
|
2015-02-24 06:12:12 +00:00
|
|
|
canvas.clear(SK_ColorTRANSPARENT);
|
2021-01-28 02:21:08 +00:00
|
|
|
canvas.drawImage(image, 0, 0);
|
2015-02-24 06:12:12 +00:00
|
|
|
|
|
|
|
uint32_t pixel = 0;
|
2015-03-06 15:16:00 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType);
|
2017-07-21 18:24:29 +00:00
|
|
|
tgt.readPixels(info, &pixel, 4, 0, 0);
|
2015-02-24 06:12:12 +00:00
|
|
|
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
2017-07-21 18:24:29 +00:00
|
|
|
tgt.readPixels(info, &pixel, 4, gWidth - 6, gWidth - 6);
|
2015-02-24 06:12:12 +00:00
|
|
|
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
|
|
|
|
2017-07-21 18:24:29 +00:00
|
|
|
tgt.readPixels(info, &pixel, 4, gWidth - 5, gWidth - 5);
|
2015-02-24 06:12:12 +00:00
|
|
|
REPORTER_ASSERT(reporter, pixel == SK_ColorTRANSPARENT);
|
|
|
|
}
|