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 <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <cstdlib> | 9 #include <cstdlib> |
10 #include <functional> | 10 #include <functional> |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 gfx::Size(100, 100), | 382 gfx::Size(100, 100), |
383 gfx::Point(500, 200), | 383 gfx::Point(500, 200), |
384 gfx::Point(200, 0))); | 384 gfx::Point(200, 0))); |
385 ASSERT_TRUE(CompareImageFragments(source, | 385 ASSERT_TRUE(CompareImageFragments(source, |
386 result, | 386 result, |
387 gfx::Size(100, 100), | 387 gfx::Size(100, 100), |
388 gfx::Point(100, 400), | 388 gfx::Point(100, 400), |
389 gfx::Point(0, 0))); | 389 gfx::Point(0, 0))); |
390 } | 390 } |
391 | 391 |
392 TEST_F(ThumbnailContentAnalysisTest, CreateRetargettedThumbnailImage) { | 392 TEST_F(ThumbnailContentAnalysisTest, CreateRetargetedThumbnailImage) { |
393 gfx::Size image_size(1200, 1300); | 393 gfx::Size image_size(1200, 1300); |
394 gfx::Canvas canvas(image_size, ui::SCALE_FACTOR_100P, true); | 394 gfx::Canvas canvas(image_size, ui::SCALE_FACTOR_100P, true); |
395 | 395 |
396 // The following will create a 'fake image' consisting of color blocks placed | 396 // The following will create a 'fake image' consisting of color blocks placed |
397 // on a neutral background. The entire layout is supposed to mimic a | 397 // on a neutral background. The entire layout is supposed to mimic a |
398 // screenshot of a web page. | 398 // screenshot of a web page. |
399 // The tested function is supposed to locate the interesing areas in the | 399 // The tested function is supposed to locate the interesing areas in the |
400 // middle. | 400 // middle. |
401 const int margin_horizontal = 60; | 401 const int margin_horizontal = 60; |
402 const int margin_vertical = 20; | 402 const int margin_vertical = 20; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 gfx::Rect pict_rect(x, y, | 468 gfx::Rect pict_rect(x, y, |
469 body_rect.width() / 2 - 2 * margin_vertical, | 469 body_rect.width() / 2 - 2 * margin_vertical, |
470 body_rect.height() / 3 - 2 * margin_vertical); | 470 body_rect.height() / 3 - 2 * margin_vertical); |
471 canvas.FillRect(pict_rect, SkColorSetRGB(255, 255, 255)); | 471 canvas.FillRect(pict_rect, SkColorSetRGB(255, 255, 255)); |
472 canvas.DrawRect(pict_rect, SkColorSetRGB(0, 0, 0)); | 472 canvas.DrawRect(pict_rect, SkColorSetRGB(0, 0, 0)); |
473 } | 473 } |
474 | 474 |
475 SkBitmap source = | 475 SkBitmap source = |
476 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 476 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
477 | 477 |
478 SkBitmap result = CreateRetargettedThumbnailImage( | 478 SkBitmap result = CreateRetargetedThumbnailImage( |
479 source, gfx::Size(424, 264), 2.5); | 479 source, gfx::Size(424, 264), 2.5); |
480 EXPECT_FALSE(result.empty()); | 480 EXPECT_FALSE(result.empty()); |
481 | 481 |
482 // Given the nature of computation We can't really assert much here about the | 482 // Given the nature of computation We can't really assert much here about the |
483 // image itself. We know it should have been computed, should be smaller than | 483 // image itself. We know it should have been computed, should be smaller than |
484 // the original and it must not be zero. | 484 // the original and it must not be zero. |
485 EXPECT_LT(result.width(), image_size.width()); | 485 EXPECT_LT(result.width(), image_size.width()); |
486 EXPECT_LT(result.height(), image_size.height()); | 486 EXPECT_LT(result.height(), image_size.height()); |
487 | 487 |
488 int histogram[256] = {}; | 488 int histogram[256] = {}; |
489 color_utils::BuildLumaHistogram(result, histogram); | 489 color_utils::BuildLumaHistogram(result, histogram); |
490 int non_zero_color_count = std::count_if( | 490 int non_zero_color_count = std::count_if( |
491 histogram, histogram + 256, std::bind2nd(std::greater<int>(), 0)); | 491 histogram, histogram + 256, std::bind2nd(std::greater<int>(), 0)); |
492 EXPECT_GT(non_zero_color_count, 4); | 492 EXPECT_GT(non_zero_color_count, 4); |
493 | 493 |
494 } | 494 } |
495 | 495 |
496 } // namespace thumbnailing_utils | 496 } // namespace thumbnailing_utils |
OLD | NEW |