Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/skbitmap_operations.h" | 5 #include "ui/gfx/skbitmap_operations.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 EXPECT_EQ(2, result.height()); | 499 EXPECT_EQ(2, result.height()); |
| 500 | 500 |
| 501 SkAutoLockPixels lock(result); | 501 SkAutoLockPixels lock(result); |
| 502 for (int x = 0; x < input.width(); ++x) { | 502 for (int x = 0; x < input.width(); ++x) { |
| 503 for (int y = 0; y < input.height(); ++y) { | 503 for (int y = 0; y < input.height(); ++y) { |
| 504 EXPECT_EQ(*input.getAddr32(x, y), *result.getAddr32(y, x)); | 504 EXPECT_EQ(*input.getAddr32(x, y), *result.getAddr32(y, x)); |
| 505 } | 505 } |
| 506 } | 506 } |
| 507 } | 507 } |
| 508 | 508 |
| 509 void SetRectColor(SkCanvas* canvas, | |
|
danakj
2016/09/19 19:35:51
Can you name this DrawRectWithColor? Set sounds li
reed1
2016/09/19 19:42:38
Done.
| |
| 510 int left, | |
| 511 int top, | |
| 512 int right, | |
| 513 int bottom, | |
| 514 SkColor color) { | |
| 515 SkPaint paint; | |
| 516 paint.setColor(color); | |
| 517 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
| 518 canvas->drawRect(SkRect::Make({left, top, right, bottom}), paint); | |
|
danakj
2016/09/19 19:35:52
Can you use SkIRect::MakeLTRB() so we can see the
reed1
2016/09/19 19:42:38
Done.
| |
| 519 } | |
| 520 | |
| 509 // Check that Rotate provides the desired results | 521 // Check that Rotate provides the desired results |
| 510 TEST(SkBitmapOperationsTest, RotateImage) { | 522 TEST(SkBitmapOperationsTest, RotateImage) { |
| 511 const int src_w = 6, src_h = 4; | 523 const int src_w = 6, src_h = 4; |
| 512 SkBitmap src; | 524 SkBitmap src; |
| 513 // Create a simple 4 color bitmap: | 525 // Create a simple 4 color bitmap: |
| 514 // RRRBBB | 526 // RRRBBB |
| 515 // RRRBBB | 527 // RRRBBB |
| 516 // GGGYYY | 528 // GGGYYY |
| 517 // GGGYYY | 529 // GGGYYY |
| 518 src.allocN32Pixels(src_w, src_h); | 530 src.allocN32Pixels(src_w, src_h); |
| 519 | 531 |
| 520 SkCanvas canvas(src); | 532 SkCanvas canvas(src); |
| 521 src.eraseARGB(0, 0, 0, 0); | 533 src.eraseARGB(0, 0, 0, 0); |
| 522 SkRegion region; | |
| 523 | 534 |
| 524 region.setRect(0, 0, src_w / 2, src_h / 2); | |
| 525 canvas.setClipRegion(region); | |
| 526 // This region is a semi-transparent red to test non-opaque pixels. | 535 // This region is a semi-transparent red to test non-opaque pixels. |
| 527 canvas.drawColor(0x1FFF0000, SkXfermode::kSrc_Mode); | 536 SetRectColor(&canvas, 0, 0, src_w / 2, src_h / 2, 0x1FFF0000); |
| 528 region.setRect(src_w / 2, 0, src_w, src_h / 2); | 537 SetRectColor(&canvas, src_w / 2, 0, src_w, src_h / 2, SK_ColorBLUE); |
| 529 canvas.setClipRegion(region); | 538 SetRectColor(&canvas, 0, src_h / 2, src_w / 2, src_h, SK_ColorGREEN); |
| 530 canvas.drawColor(SK_ColorBLUE, SkXfermode::kSrc_Mode); | 539 SetRectColor(&canvas, src_w / 2, src_h / 2, src_w, src_h, SK_ColorYELLOW); |
| 531 region.setRect(0, src_h / 2, src_w / 2, src_h); | |
| 532 canvas.setClipRegion(region); | |
| 533 canvas.drawColor(SK_ColorGREEN, SkXfermode::kSrc_Mode); | |
| 534 region.setRect(src_w / 2, src_h / 2, src_w, src_h); | |
| 535 canvas.setClipRegion(region); | |
| 536 canvas.drawColor(SK_ColorYELLOW, SkXfermode::kSrc_Mode); | |
| 537 canvas.flush(); | |
| 538 | 540 |
| 539 SkBitmap rotate90, rotate180, rotate270; | 541 SkBitmap rotate90, rotate180, rotate270; |
| 540 rotate90 = SkBitmapOperations::Rotate(src, | 542 rotate90 = SkBitmapOperations::Rotate(src, |
| 541 SkBitmapOperations::ROTATION_90_CW); | 543 SkBitmapOperations::ROTATION_90_CW); |
| 542 rotate180 = SkBitmapOperations::Rotate(src, | 544 rotate180 = SkBitmapOperations::Rotate(src, |
| 543 SkBitmapOperations::ROTATION_180_CW); | 545 SkBitmapOperations::ROTATION_180_CW); |
| 544 rotate270 = SkBitmapOperations::Rotate(src, | 546 rotate270 = SkBitmapOperations::Rotate(src, |
| 545 SkBitmapOperations::ROTATION_270_CW); | 547 SkBitmapOperations::ROTATION_270_CW); |
| 546 | 548 |
| 547 ASSERT_EQ(rotate90.width(), src.height()); | 549 ASSERT_EQ(rotate90.width(), src.height()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 558 | 560 |
| 559 for (int x=0; x < src_w; ++x) { | 561 for (int x=0; x < src_w; ++x) { |
| 560 for (int y=0; y < src_h; ++y) { | 562 for (int y=0; y < src_h; ++y) { |
| 561 ASSERT_EQ(*src.getAddr32(x,y), *rotate90.getAddr32(src_h - (y+1),x)); | 563 ASSERT_EQ(*src.getAddr32(x,y), *rotate90.getAddr32(src_h - (y+1),x)); |
| 562 ASSERT_EQ(*src.getAddr32(x,y), *rotate270.getAddr32(y, src_w - (x+1))); | 564 ASSERT_EQ(*src.getAddr32(x,y), *rotate270.getAddr32(y, src_w - (x+1))); |
| 563 ASSERT_EQ(*src.getAddr32(x,y), | 565 ASSERT_EQ(*src.getAddr32(x,y), |
| 564 *rotate180.getAddr32(src_w - (x+1), src_h - (y+1))); | 566 *rotate180.getAddr32(src_w - (x+1), src_h - (y+1))); |
| 565 } | 567 } |
| 566 } | 568 } |
| 567 } | 569 } |
| OLD | NEW |