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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 } // namespace | 228 } // namespace |
229 | 229 |
230 namespace thumbnailing_utils { | 230 namespace thumbnailing_utils { |
231 | 231 |
232 void ApplyGaussianGradientMagnitudeFilter(SkBitmap* input_bitmap, | 232 void ApplyGaussianGradientMagnitudeFilter(SkBitmap* input_bitmap, |
233 float kernel_sigma) { | 233 float kernel_sigma) { |
234 // The purpose of this function is to highlight salient | 234 // The purpose of this function is to highlight salient |
235 // (attention-attracting?) features of the image for use in image | 235 // (attention-attracting?) features of the image for use in image |
236 // retargeting. | 236 // retargeting. |
237 SkAutoLockPixels source_lock(*input_bitmap); | |
238 DCHECK(input_bitmap); | 237 DCHECK(input_bitmap); |
239 DCHECK(input_bitmap->getPixels()); | 238 DCHECK(input_bitmap->getPixels()); |
240 DCHECK_EQ(kAlpha_8_SkColorType, input_bitmap->colorType()); | 239 DCHECK_EQ(kAlpha_8_SkColorType, input_bitmap->colorType()); |
241 | 240 |
242 // To perform computations we will need one intermediate buffer. It can | 241 // To perform computations we will need one intermediate buffer. It can |
243 // very well be just another bitmap. | 242 // very well be just another bitmap. |
244 const SkISize image_size = SkISize::Make(input_bitmap->width(), | 243 const SkISize image_size = SkISize::Make(input_bitmap->width(), |
245 input_bitmap->height()); | 244 input_bitmap->height()); |
246 SkBitmap intermediate; | 245 SkBitmap intermediate; |
247 intermediate.allocPixels(input_bitmap->info().makeWH(image_size.width(), | 246 intermediate.allocPixels(input_bitmap->info().makeWH(image_size.width(), |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 } | 375 } |
377 } | 376 } |
378 } | 377 } |
379 | 378 |
380 void ExtractImageProfileInformation(const SkBitmap& input_bitmap, | 379 void ExtractImageProfileInformation(const SkBitmap& input_bitmap, |
381 const gfx::Rect& area, | 380 const gfx::Rect& area, |
382 const gfx::Size& target_size, | 381 const gfx::Size& target_size, |
383 bool apply_log, | 382 bool apply_log, |
384 std::vector<float>* rows, | 383 std::vector<float>* rows, |
385 std::vector<float>* columns) { | 384 std::vector<float>* columns) { |
386 SkAutoLockPixels source_lock(input_bitmap); | |
387 DCHECK(rows); | 385 DCHECK(rows); |
388 DCHECK(columns); | 386 DCHECK(columns); |
389 DCHECK(input_bitmap.getPixels()); | 387 DCHECK(input_bitmap.getPixels()); |
390 DCHECK_EQ(kAlpha_8_SkColorType, input_bitmap.colorType()); | 388 DCHECK_EQ(kAlpha_8_SkColorType, input_bitmap.colorType()); |
391 DCHECK_GE(area.x(), 0); | 389 DCHECK_GE(area.x(), 0); |
392 DCHECK_GE(area.y(), 0); | 390 DCHECK_GE(area.y(), 0); |
393 DCHECK_LE(area.right(), input_bitmap.width()); | 391 DCHECK_LE(area.right(), input_bitmap.width()); |
394 DCHECK_LE(area.bottom(), input_bitmap.height()); | 392 DCHECK_LE(area.bottom(), input_bitmap.height()); |
395 | 393 |
396 // Make sure rows and columns are allocated and initialized to 0. | 394 // Make sure rows and columns are allocated and initialized to 0. |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 } else { | 655 } else { |
658 included_columns->resize(column_profile.size()); | 656 included_columns->resize(column_profile.size()); |
659 for (size_t i = 0; i < column_profile.size(); ++i) | 657 for (size_t i = 0; i < column_profile.size(); ++i) |
660 (*included_columns)[i] = column_profile[i] > column_threshold; | 658 (*included_columns)[i] = column_profile[i] > column_threshold; |
661 } | 659 } |
662 } | 660 } |
663 | 661 |
664 SkBitmap ComputeDecimatedImage(const SkBitmap& bitmap, | 662 SkBitmap ComputeDecimatedImage(const SkBitmap& bitmap, |
665 const std::vector<bool>& rows, | 663 const std::vector<bool>& rows, |
666 const std::vector<bool>& columns) { | 664 const std::vector<bool>& columns) { |
667 SkAutoLockPixels source_lock(bitmap); | |
668 DCHECK(bitmap.getPixels()); | 665 DCHECK(bitmap.getPixels()); |
669 DCHECK_GT(bitmap.bytesPerPixel(), 0); | 666 DCHECK_GT(bitmap.bytesPerPixel(), 0); |
670 DCHECK_EQ(bitmap.width(), static_cast<int>(columns.size())); | 667 DCHECK_EQ(bitmap.width(), static_cast<int>(columns.size())); |
671 DCHECK_EQ(bitmap.height(), static_cast<int>(rows.size())); | 668 DCHECK_EQ(bitmap.height(), static_cast<int>(rows.size())); |
672 | 669 |
673 unsigned target_row_count = std::count(rows.begin(), rows.end(), true); | 670 unsigned target_row_count = std::count(rows.begin(), rows.end(), true); |
674 unsigned target_column_count = std::count( | 671 unsigned target_column_count = std::count( |
675 columns.begin(), columns.end(), true); | 672 columns.begin(), columns.end(), true); |
676 | 673 |
677 if (target_row_count == 0 || target_column_count == 0) | 674 if (target_row_count == 0 || target_column_count == 0) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 target_size, | 761 target_size, |
765 &included_rows, | 762 &included_rows, |
766 &included_columns); | 763 &included_columns); |
767 | 764 |
768 // Use the original image and computed inclusion vectors to create a resized | 765 // Use the original image and computed inclusion vectors to create a resized |
769 // image. | 766 // image. |
770 return ComputeDecimatedImage(source_bitmap, included_rows, included_columns); | 767 return ComputeDecimatedImage(source_bitmap, included_rows, included_columns); |
771 } | 768 } |
772 | 769 |
773 } // namespace thumbnailing_utils | 770 } // namespace thumbnailing_utils |
OLD | NEW |