Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: chrome/browser/thumbnails/content_analysis.cc

Issue 15458003: Plugs in the new thumbnailing algorithm to ThumbnailTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed up a compile problem (indpendent change). Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <deque> 9 #include <deque>
10 #include <functional> 10 #include <functional>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 } // namespace 67 } // namespace
68 68
69 namespace thumbnailing_utils { 69 namespace thumbnailing_utils {
70 70
71 void ApplyGaussianGradientMagnitudeFilter(SkBitmap* input_bitmap, 71 void ApplyGaussianGradientMagnitudeFilter(SkBitmap* input_bitmap,
72 float kernel_sigma) { 72 float kernel_sigma) {
73 // The purpose of this function is to highlight salient 73 // The purpose of this function is to highlight salient
74 // (attention-attracting?) features of the image for use in image 74 // (attention-attracting?) features of the image for use in image
75 // retargetting. 75 // retargeting.
76 SkAutoLockPixels source_lock(*input_bitmap); 76 SkAutoLockPixels source_lock(*input_bitmap);
77 DCHECK(input_bitmap); 77 DCHECK(input_bitmap);
78 DCHECK(input_bitmap->getPixels()); 78 DCHECK(input_bitmap->getPixels());
79 DCHECK_EQ(SkBitmap::kA8_Config, input_bitmap->config()); 79 DCHECK_EQ(SkBitmap::kA8_Config, input_bitmap->config());
80 80
81 // To perform computations we will need one intermediate buffer. It can 81 // To perform computations we will need one intermediate buffer. It can
82 // very well be just another bitmap. 82 // very well be just another bitmap.
83 const SkISize image_size = SkISize::Make(input_bitmap->width(), 83 const SkISize image_size = SkISize::Make(input_bitmap->width(),
84 input_bitmap->height()); 84 input_bitmap->height());
85 SkBitmap intermediate; 85 SkBitmap intermediate;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 memcpy(insertion_target, 417 memcpy(insertion_target,
418 src_row + left_copy_pixel * bitmap.bytesPerPixel(), 418 src_row + left_copy_pixel * bitmap.bytesPerPixel(),
419 bytes_to_copy); 419 bytes_to_copy);
420 } 420 }
421 target_row++; 421 target_row++;
422 } 422 }
423 423
424 return target; 424 return target;
425 } 425 }
426 426
427 SkBitmap CreateRetargettedThumbnailImage( 427 SkBitmap CreateRetargetedThumbnailImage(
428 const SkBitmap& source_bitmap, 428 const SkBitmap& source_bitmap,
429 const gfx::Size& target_size, 429 const gfx::Size& target_size,
430 float kernel_sigma) { 430 float kernel_sigma) {
431 // First thing we need for this method is to color-reduce the source_bitmap. 431 // First thing we need for this method is to color-reduce the source_bitmap.
432 SkBitmap reduced_color; 432 SkBitmap reduced_color;
433 reduced_color.setConfig( 433 reduced_color.setConfig(
434 SkBitmap::kA8_Config, source_bitmap.width(), source_bitmap.height()); 434 SkBitmap::kA8_Config, source_bitmap.width(), source_bitmap.height());
435 reduced_color.allocPixels(); 435 reduced_color.allocPixels();
436 436
437 if (!color_utils::ComputePrincipalComponentImage(source_bitmap, 437 if (!color_utils::ComputePrincipalComponentImage(source_bitmap,
438 &reduced_color)) { 438 &reduced_color)) {
439 // CCIR601 luminance conversion vector. 439 // CCIR601 luminance conversion vector.
440 gfx::Vector3dF transform(0.299f, 0.587f, 0.114f); 440 gfx::Vector3dF transform(0.299f, 0.587f, 0.114f);
441 if (!color_utils::ApplyColorReduction( 441 if (!color_utils::ApplyColorReduction(
442 source_bitmap, transform, true, &reduced_color)) { 442 source_bitmap, transform, true, &reduced_color)) {
443 DLOG(WARNING) << "Failed to compute luminance image from a screenshot. " 443 DLOG(WARNING) << "Failed to compute luminance image from a screenshot. "
444 << "Cannot compute retargetted thumbnail."; 444 << "Cannot compute retargeted thumbnail.";
445 return SkBitmap(); 445 return SkBitmap();
446 } 446 }
447 DLOG(WARNING) << "Could not compute principal color image for a thumbnail. " 447 DLOG(WARNING) << "Could not compute principal color image for a thumbnail. "
448 << "Using luminance instead."; 448 << "Using luminance instead.";
449 } 449 }
450 450
451 // Turn 'color-reduced' image into the 'energy' image. 451 // Turn 'color-reduced' image into the 'energy' image.
452 ApplyGaussianGradientMagnitudeFilter(&reduced_color, kernel_sigma); 452 ApplyGaussianGradientMagnitudeFilter(&reduced_color, kernel_sigma);
453 453
454 // Extract vertical and horizontal projection of image features. 454 // Extract vertical and horizontal projection of image features.
(...skipping 21 matching lines...) Expand all
476 column_profile.end(), 476 column_profile.end(),
477 included_columns.begin(), 477 included_columns.begin(),
478 std::bind2nd(std::greater<float>(), threshold_columns)); 478 std::bind2nd(std::greater<float>(), threshold_columns));
479 479
480 // Use the original image and computed inclusion vectors to create a resized 480 // Use the original image and computed inclusion vectors to create a resized
481 // image. 481 // image.
482 return ComputeDecimatedImage(source_bitmap, included_rows, included_columns); 482 return ComputeDecimatedImage(source_bitmap, included_rows, included_columns);
483 } 483 }
484 484
485 } // thumbnailing_utils 485 } // thumbnailing_utils
OLDNEW
« no previous file with comments | « chrome/browser/thumbnails/content_analysis.h ('k') | chrome/browser/thumbnails/content_analysis_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698