| 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 DrawRectWithColor(SkCanvas* canvas, |
| 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( |
| 519 SkRect::MakeLTRB(SkIntToScalar(left), SkIntToScalar(top), |
| 520 SkIntToScalar(right), SkIntToScalar(bottom)), |
| 521 paint); |
| 522 } |
| 523 |
| 509 // Check that Rotate provides the desired results | 524 // Check that Rotate provides the desired results |
| 510 TEST(SkBitmapOperationsTest, RotateImage) { | 525 TEST(SkBitmapOperationsTest, RotateImage) { |
| 511 const int src_w = 6, src_h = 4; | 526 const int src_w = 6, src_h = 4; |
| 512 SkBitmap src; | 527 SkBitmap src; |
| 513 // Create a simple 4 color bitmap: | 528 // Create a simple 4 color bitmap: |
| 514 // RRRBBB | 529 // RRRBBB |
| 515 // RRRBBB | 530 // RRRBBB |
| 516 // GGGYYY | 531 // GGGYYY |
| 517 // GGGYYY | 532 // GGGYYY |
| 518 src.allocN32Pixels(src_w, src_h); | 533 src.allocN32Pixels(src_w, src_h); |
| 519 | 534 |
| 520 SkCanvas canvas(src); | 535 SkCanvas canvas(src); |
| 521 src.eraseARGB(0, 0, 0, 0); | 536 src.eraseARGB(0, 0, 0, 0); |
| 522 SkRegion region; | |
| 523 | 537 |
| 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. | 538 // This region is a semi-transparent red to test non-opaque pixels. |
| 527 canvas.drawColor(0x1FFF0000, SkXfermode::kSrc_Mode); | 539 DrawRectWithColor(&canvas, 0, 0, src_w / 2, src_h / 2, 0x1FFF0000); |
| 528 region.setRect(src_w / 2, 0, src_w, src_h / 2); | 540 DrawRectWithColor(&canvas, src_w / 2, 0, src_w, src_h / 2, SK_ColorBLUE); |
| 529 canvas.setClipRegion(region); | 541 DrawRectWithColor(&canvas, 0, src_h / 2, src_w / 2, src_h, SK_ColorGREEN); |
| 530 canvas.drawColor(SK_ColorBLUE, SkXfermode::kSrc_Mode); | 542 DrawRectWithColor(&canvas, src_w / 2, src_h / 2, src_w, src_h, |
| 531 region.setRect(0, src_h / 2, src_w / 2, src_h); | 543 SK_ColorYELLOW); |
| 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 | 544 |
| 539 SkBitmap rotate90, rotate180, rotate270; | 545 SkBitmap rotate90, rotate180, rotate270; |
| 540 rotate90 = SkBitmapOperations::Rotate(src, | 546 rotate90 = SkBitmapOperations::Rotate(src, |
| 541 SkBitmapOperations::ROTATION_90_CW); | 547 SkBitmapOperations::ROTATION_90_CW); |
| 542 rotate180 = SkBitmapOperations::Rotate(src, | 548 rotate180 = SkBitmapOperations::Rotate(src, |
| 543 SkBitmapOperations::ROTATION_180_CW); | 549 SkBitmapOperations::ROTATION_180_CW); |
| 544 rotate270 = SkBitmapOperations::Rotate(src, | 550 rotate270 = SkBitmapOperations::Rotate(src, |
| 545 SkBitmapOperations::ROTATION_270_CW); | 551 SkBitmapOperations::ROTATION_270_CW); |
| 546 | 552 |
| 547 ASSERT_EQ(rotate90.width(), src.height()); | 553 ASSERT_EQ(rotate90.width(), src.height()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 558 | 564 |
| 559 for (int x=0; x < src_w; ++x) { | 565 for (int x=0; x < src_w; ++x) { |
| 560 for (int y=0; y < src_h; ++y) { | 566 for (int y=0; y < src_h; ++y) { |
| 561 ASSERT_EQ(*src.getAddr32(x,y), *rotate90.getAddr32(src_h - (y+1),x)); | 567 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))); | 568 ASSERT_EQ(*src.getAddr32(x,y), *rotate270.getAddr32(y, src_w - (x+1))); |
| 563 ASSERT_EQ(*src.getAddr32(x,y), | 569 ASSERT_EQ(*src.getAddr32(x,y), |
| 564 *rotate180.getAddr32(src_w - (x+1), src_h - (y+1))); | 570 *rotate180.getAddr32(src_w - (x+1), src_h - (y+1))); |
| 565 } | 571 } |
| 566 } | 572 } |
| 567 } | 573 } |
| OLD | NEW |