OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |