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 "chrome/browser/thumbnails/content_analysis.h" | 5 #include "chrome/browser/thumbnails/content_analysis.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 EXPECT_GT(data_sum, 0U); | 122 EXPECT_GT(data_sum, 0U); |
| 123 EXPECT_EQ(data_sum, all_sum); | 123 EXPECT_EQ(data_sum, all_sum); |
| 124 } | 124 } |
| 125 | 125 |
| 126 TEST_F(ThumbnailContentAnalysisTest, ApplyGradientMagnitudeOnFrame) { | 126 TEST_F(ThumbnailContentAnalysisTest, ApplyGradientMagnitudeOnFrame) { |
| 127 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true); | 127 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true); |
| 128 | 128 |
| 129 // The image consists of a single white block in the centre. | 129 // The image consists of a single white block in the centre. |
| 130 gfx::Rect draw_rect(300, 200, 200, 200); | 130 gfx::Rect draw_rect(300, 200, 200, 200); |
| 131 canvas.FillRect(gfx::Rect(0, 0, 800, 600), SkColorSetRGB(0, 0, 0)); | 131 canvas.FillRect(gfx::Rect(0, 0, 800, 600), SkColorSetRGB(0, 0, 0)); |
| 132 canvas.DrawRect(draw_rect, SkColorSetRGB(255, 255, 255)); | 132 canvas.DrawRect(gfx::RectF(draw_rect), SkColorSetRGB(255, 255, 255)); |
|
Matt Giuca
2017/04/07 06:38:08
Don't cast the Rect to a RectF. Just change the ty
Uzair
2017/04/07 08:50:15
Done.
| |
| 133 | 133 |
| 134 SkBitmap source = canvas.GetBitmap(); | 134 SkBitmap source = canvas.GetBitmap(); |
| 135 | 135 |
| 136 SkBitmap reduced_color; | 136 SkBitmap reduced_color; |
| 137 reduced_color.allocPixels(SkImageInfo::MakeA8(source.width(), | 137 reduced_color.allocPixels(SkImageInfo::MakeA8(source.width(), |
| 138 source.height())); | 138 source.height())); |
| 139 | 139 |
| 140 gfx::Vector3dF transform(0.299f, 0.587f, 0.114f); | 140 gfx::Vector3dF transform(0.299f, 0.587f, 0.114f); |
| 141 EXPECT_TRUE(color_utils::ApplyColorReduction( | 141 EXPECT_TRUE(color_utils::ApplyColorReduction( |
| 142 source, transform, true, &reduced_color)); | 142 source, transform, true, &reduced_color)); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 160 EXPECT_EQ(ImagePixelSum(reduced_color, inner_rect), 0U); | 160 EXPECT_EQ(ImagePixelSum(reduced_color, inner_rect), 0U); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST_F(ThumbnailContentAnalysisTest, ExtractImageProfileInformation) { | 163 TEST_F(ThumbnailContentAnalysisTest, ExtractImageProfileInformation) { |
| 164 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true); | 164 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true); |
| 165 | 165 |
| 166 // The image consists of a white frame drawn in the centre. | 166 // The image consists of a white frame drawn in the centre. |
| 167 gfx::Rect draw_rect(100, 100, 200, 100); | 167 gfx::Rect draw_rect(100, 100, 200, 100); |
| 168 gfx::Rect image_rect(0, 0, 800, 600); | 168 gfx::Rect image_rect(0, 0, 800, 600); |
| 169 canvas.FillRect(image_rect, SkColorSetRGB(0, 0, 0)); | 169 canvas.FillRect(image_rect, SkColorSetRGB(0, 0, 0)); |
| 170 canvas.DrawRect(draw_rect, SkColorSetRGB(255, 255, 255)); | 170 canvas.DrawRect(gfx::RectF(draw_rect), SkColorSetRGB(255, 255, 255)); |
| 171 | 171 |
| 172 SkBitmap source = canvas.GetBitmap(); | 172 SkBitmap source = canvas.GetBitmap(); |
| 173 SkBitmap reduced_color; | 173 SkBitmap reduced_color; |
| 174 reduced_color.allocPixels(SkImageInfo::MakeA8(source.width(), | 174 reduced_color.allocPixels(SkImageInfo::MakeA8(source.width(), |
| 175 source.height())); | 175 source.height())); |
| 176 | 176 |
| 177 gfx::Vector3dF transform(1, 0, 0); | 177 gfx::Vector3dF transform(1, 0, 0); |
| 178 EXPECT_TRUE(color_utils::ApplyColorReduction( | 178 EXPECT_TRUE(color_utils::ApplyColorReduction( |
| 179 source, transform, true, &reduced_color)); | 179 source, transform, true, &reduced_color)); |
| 180 std::vector<float> column_profile; | 180 std::vector<float> column_profile; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 } | 222 } |
| 223 | 223 |
| 224 TEST_F(ThumbnailContentAnalysisTest, | 224 TEST_F(ThumbnailContentAnalysisTest, |
| 225 ExtractImageProfileInformationWithClosing) { | 225 ExtractImageProfileInformationWithClosing) { |
| 226 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true); | 226 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true); |
| 227 | 227 |
| 228 // The image consists of a two white frames drawn side by side, with a | 228 // The image consists of a two white frames drawn side by side, with a |
| 229 // single-pixel vertical gap in between. | 229 // single-pixel vertical gap in between. |
| 230 gfx::Rect image_rect(0, 0, 800, 600); | 230 gfx::Rect image_rect(0, 0, 800, 600); |
| 231 canvas.FillRect(image_rect, SkColorSetRGB(0, 0, 0)); | 231 canvas.FillRect(image_rect, SkColorSetRGB(0, 0, 0)); |
| 232 canvas.DrawRect(gfx::Rect(300, 250, 99, 100), SkColorSetRGB(255, 255, 255)); | 232 canvas.DrawRect(gfx::RectF(300, 250, 99, 100), SkColorSetRGB(255, 255, 255)); |
| 233 canvas.DrawRect(gfx::Rect(401, 250, 99, 100), SkColorSetRGB(255, 255, 255)); | 233 canvas.DrawRect(gfx::RectF(401, 250, 99, 100), SkColorSetRGB(255, 255, 255)); |
| 234 | 234 |
| 235 SkBitmap source = canvas.GetBitmap(); | 235 SkBitmap source = canvas.GetBitmap(); |
| 236 SkBitmap reduced_color; | 236 SkBitmap reduced_color; |
| 237 reduced_color.allocPixels(SkImageInfo::MakeA8(source.width(), | 237 reduced_color.allocPixels(SkImageInfo::MakeA8(source.width(), |
| 238 source.height())); | 238 source.height())); |
| 239 | 239 |
| 240 gfx::Vector3dF transform(1, 0, 0); | 240 gfx::Vector3dF transform(1, 0, 0); |
| 241 EXPECT_TRUE(color_utils::ApplyColorReduction( | 241 EXPECT_TRUE(color_utils::ApplyColorReduction( |
| 242 source, transform, true, &reduced_color)); | 242 source, transform, true, &reduced_color)); |
| 243 std::vector<float> column_profile; | 243 std::vector<float> column_profile; |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 | 614 |
| 615 // 'Fine print' at the bottom. | 615 // 'Fine print' at the bottom. |
| 616 const int fine_print = 8; | 616 const int fine_print = 8; |
| 617 const SkColor print_color = SkColorSetRGB(45, 30, 30); | 617 const SkColor print_color = SkColorSetRGB(45, 30, 30); |
| 618 for (int y = footer_rect.y() + fine_print; | 618 for (int y = footer_rect.y() + fine_print; |
| 619 y < footer_rect.bottom() - fine_print; | 619 y < footer_rect.bottom() - fine_print; |
| 620 y += 2 * fine_print) { | 620 y += 2 * fine_print) { |
| 621 for (int x = footer_rect.x() + fine_print; | 621 for (int x = footer_rect.x() + fine_print; |
| 622 x < footer_rect.right() - fine_print; | 622 x < footer_rect.right() - fine_print; |
| 623 x += 2 * fine_print) { | 623 x += 2 * fine_print) { |
| 624 canvas.DrawRect(gfx::Rect(x, y, fine_print, fine_print), print_color); | 624 canvas.DrawRect(gfx::RectF(x, y, fine_print, fine_print), print_color); |
| 625 } | 625 } |
| 626 } | 626 } |
| 627 | 627 |
| 628 // Blocky content at the top. | 628 // Blocky content at the top. |
| 629 const int block_size = header_rect.height() - margin_vertical; | 629 const int block_size = header_rect.height() - margin_vertical; |
| 630 for (int x = header_rect.x() + margin_horizontal; | 630 for (int x = header_rect.x() + margin_horizontal; |
| 631 x < header_rect.right() - block_size; | 631 x < header_rect.right() - block_size; |
| 632 x += block_size + margin_horizontal) { | 632 x += block_size + margin_horizontal) { |
| 633 const int half_block = block_size / 2 - 5; | 633 const int half_block = block_size / 2 - 5; |
| 634 const SkColor block_color = SkColorSetRGB(255, 255, 255); | 634 const SkColor block_color = SkColorSetRGB(255, 255, 255); |
| 635 const int y = header_rect.y() + margin_vertical / 2; | 635 const int y = header_rect.y() + margin_vertical / 2; |
| 636 int second_col = x + half_block + 10; | 636 int second_col = x + half_block + 10; |
| 637 int second_row = y + half_block + 10; | 637 int second_row = y + half_block + 10; |
| 638 canvas.FillRect(gfx::Rect(x, y, half_block, block_size), block_color); | 638 canvas.FillRect(gfx::Rect(x, y, half_block, block_size), block_color); |
| 639 canvas.FillRect(gfx::Rect(second_col, y, half_block, half_block), | 639 canvas.FillRect(gfx::Rect(second_col, y, half_block, half_block), |
| 640 block_color); | 640 block_color); |
| 641 canvas.FillRect(gfx::Rect(second_col, second_row, half_block, half_block), | 641 canvas.FillRect(gfx::Rect(second_col, second_row, half_block, half_block), |
| 642 block_color); | 642 block_color); |
| 643 } | 643 } |
| 644 | 644 |
| 645 // Now the main body. Mostly text with some 'pictures'. | 645 // Now the main body. Mostly text with some 'pictures'. |
| 646 for (int y = body_rect.y() + fine_print; | 646 for (int y = body_rect.y() + fine_print; |
| 647 y < body_rect.bottom() - fine_print; | 647 y < body_rect.bottom() - fine_print; |
| 648 y += 2 * fine_print) { | 648 y += 2 * fine_print) { |
| 649 for (int x = body_rect.x() + fine_print; | 649 for (int x = body_rect.x() + fine_print; |
| 650 x < body_rect.right() - fine_print; | 650 x < body_rect.right() - fine_print; |
| 651 x += 2 * fine_print) { | 651 x += 2 * fine_print) { |
| 652 canvas.DrawRect(gfx::Rect(x, y, fine_print, fine_print), print_color); | 652 canvas.DrawRect(gfx::RecFt(x, y, fine_print, fine_print), print_color); |
|
Matt Giuca
2017/04/07 06:38:08
RectF
Uzair
2017/04/07 08:50:15
Apologies for the mistake.
| |
| 653 } | 653 } |
| 654 } | 654 } |
| 655 | 655 |
| 656 for (int line = 0; line < 3; ++line) { | 656 for (int line = 0; line < 3; ++line) { |
| 657 int alignment = line % 2; | 657 int alignment = line % 2; |
| 658 const int y = body_rect.y() + | 658 const int y = body_rect.y() + |
| 659 body_rect.height() / 3 * line + margin_vertical; | 659 body_rect.height() / 3 * line + margin_vertical; |
| 660 const int x = body_rect.x() + | 660 const int x = body_rect.x() + |
| 661 alignment * body_rect.width() / 2 + margin_vertical; | 661 alignment * body_rect.width() / 2 + margin_vertical; |
| 662 gfx::Rect pict_rect(x, y, | 662 gfx::Rect pict_rect(x, y, |
| 663 body_rect.width() / 2 - 2 * margin_vertical, | 663 body_rect.width() / 2 - 2 * margin_vertical, |
| 664 body_rect.height() / 3 - 2 * margin_vertical); | 664 body_rect.height() / 3 - 2 * margin_vertical); |
| 665 canvas.FillRect(pict_rect, SkColorSetRGB(255, 255, 255)); | 665 canvas.FillRect(pict_rect, SkColorSetRGB(255, 255, 255)); |
| 666 canvas.DrawRect(pict_rect, SkColorSetRGB(0, 0, 0)); | 666 canvas.DrawRect(gfx::RectF(pict_rect), SkColorSetRGB(0, 0, 0)); |
| 667 } | 667 } |
| 668 | 668 |
| 669 SkBitmap source = canvas.GetBitmap(); | 669 SkBitmap source = canvas.GetBitmap(); |
| 670 | 670 |
| 671 SkBitmap result = CreateRetargetedThumbnailImage( | 671 SkBitmap result = CreateRetargetedThumbnailImage( |
| 672 source, gfx::Size(424, 264), 2.5); | 672 source, gfx::Size(424, 264), 2.5); |
| 673 EXPECT_FALSE(result.empty()); | 673 EXPECT_FALSE(result.empty()); |
| 674 | 674 |
| 675 // Given the nature of computation We can't really assert much here about the | 675 // Given the nature of computation We can't really assert much here about the |
| 676 // image itself. We know it should have been computed, should be smaller than | 676 // image itself. We know it should have been computed, should be smaller than |
| 677 // the original and it must not be zero. | 677 // the original and it must not be zero. |
| 678 EXPECT_LT(result.width(), image_size.width()); | 678 EXPECT_LT(result.width(), image_size.width()); |
| 679 EXPECT_LT(result.height(), image_size.height()); | 679 EXPECT_LT(result.height(), image_size.height()); |
| 680 | 680 |
| 681 int histogram[256] = {}; | 681 int histogram[256] = {}; |
| 682 color_utils::BuildLumaHistogram(result, histogram); | 682 color_utils::BuildLumaHistogram(result, histogram); |
| 683 int non_zero_color_count = std::count_if( | 683 int non_zero_color_count = std::count_if( |
| 684 histogram, histogram + 256, [](int value) { return value > 0; }); | 684 histogram, histogram + 256, [](int value) { return value > 0; }); |
| 685 EXPECT_GT(non_zero_color_count, 4); | 685 EXPECT_GT(non_zero_color_count, 4); |
| 686 | 686 |
| 687 } | 687 } |
| 688 | 688 |
| 689 } // namespace thumbnailing_utils | 689 } // namespace thumbnailing_utils |
| OLD | NEW |