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.
|
|
|
|
*/
|
|
|
|
|
2015-06-22 16:46:59 +00:00
|
|
|
#include "SkCanvas.h"
|
2015-02-24 06:12:12 +00:00
|
|
|
#include "SkImagePriv.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
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);
|
2016-03-17 17:51:11 +00:00
|
|
|
image = SkImage::MakeFromBitmap(dstBitmap);
|
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);
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas.drawImage(image, 0, 0, nullptr);
|
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);
|
2015-02-24 06:12:12 +00:00
|
|
|
canvas.readPixels(info, &pixel, 4, 0, 0);
|
|
|
|
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
|
|
|
canvas.readPixels(info, &pixel, 4, gWidth - 6, gWidth - 6);
|
|
|
|
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
|
|
|
|
|
|
|
canvas.readPixels(info, &pixel, 4, gWidth - 5, gWidth - 5);
|
|
|
|
REPORTER_ASSERT(reporter, pixel == SK_ColorTRANSPARENT);
|
|
|
|
}
|