OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkBitmapDevice.h" |
| 9 #include "SkImagePriv.h" |
| 10 #include "Test.h" |
| 11 |
| 12 static const int gWidth = 20; |
| 13 static const int gHeight = 20; |
| 14 |
| 15 // Tests that SkNewImageFromBitmap obeys pixelref origin. |
| 16 DEF_TEST(SkImageFromBitmap_extractSubset, reporter) { |
| 17 SkAutoTUnref<SkImage> image; |
| 18 { |
| 19 SkBitmap srcBitmap; |
| 20 srcBitmap.allocN32Pixels(gWidth, gHeight); |
| 21 srcBitmap.eraseColor(SK_ColorRED); |
| 22 SkBitmapDevice dev(srcBitmap); |
| 23 SkCanvas canvas(&dev); |
| 24 SkIRect r = SkIRect::MakeXYWH(5, 5, gWidth - 5, gWidth - 5); |
| 25 SkPaint p; |
| 26 p.setColor(SK_ColorGREEN); |
| 27 canvas.drawIRect(r, p); |
| 28 SkBitmap dstBitmap; |
| 29 srcBitmap.extractSubset(&dstBitmap, r); |
| 30 image.reset(SkNewImageFromBitmap(dstBitmap, true, NULL)); |
| 31 } |
| 32 |
| 33 SkBitmap tgt; |
| 34 tgt.allocN32Pixels(gWidth, gHeight); |
| 35 SkBitmapDevice dev(tgt); |
| 36 SkCanvas canvas(&dev); |
| 37 canvas.clear(SK_ColorTRANSPARENT); |
| 38 canvas.drawImage(image, 0, 0, NULL); |
| 39 |
| 40 uint32_t pixel = 0; |
| 41 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 42 canvas.readPixels(info, &pixel, 4, 0, 0); |
| 43 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 44 canvas.readPixels(info, &pixel, 4, gWidth - 6, gWidth - 6); |
| 45 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 46 |
| 47 canvas.readPixels(info, &pixel, 4, gWidth - 5, gWidth - 5); |
| 48 REPORTER_ASSERT(reporter, pixel == SK_ColorTRANSPARENT); |
| 49 } |
OLD | NEW |