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

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

Issue 1545223002: Switch to standard integer types in chrome/browser/, part 4 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 12 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
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 <stddef.h>
8 #include <stdint.h>
9
7 #include <algorithm> 10 #include <algorithm>
8 #include <cmath> 11 #include <cmath>
9 #include <deque> 12 #include <deque>
10 #include <functional> 13 #include <functional>
11 #include <limits> 14 #include <limits>
12 #include <numeric> 15 #include <numeric>
13 #include <vector> 16 #include <vector>
14 17
15 #include "base/logging.h" 18 #include "base/logging.h"
16 #include "skia/ext/convolver.h" 19 #include "skia/ext/convolver.h"
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 0, intermediate.bytesPerPixel(), 314 0, intermediate.bytesPerPixel(),
312 smoothing_filter, 315 smoothing_filter,
313 image_size, 316 image_size,
314 input_bitmap->getAddr8(0, 0), 317 input_bitmap->getAddr8(0, 0),
315 static_cast<int>(input_bitmap->rowBytes()), 318 static_cast<int>(input_bitmap->rowBytes()),
316 0, input_bitmap->bytesPerPixel(), false); 319 0, input_bitmap->bytesPerPixel(), false);
317 if (smoothed_max < 127) { 320 if (smoothed_max < 127) {
318 int bit_shift = 8 - static_cast<int>( 321 int bit_shift = 8 - static_cast<int>(
319 std::log10(static_cast<float>(smoothed_max)) / std::log10(2.0f)); 322 std::log10(static_cast<float>(smoothed_max)) / std::log10(2.0f));
320 for (int r = 0; r < image_size.height(); ++r) { 323 for (int r = 0; r < image_size.height(); ++r) {
321 uint8* row = input_bitmap->getAddr8(0, r); 324 uint8_t* row = input_bitmap->getAddr8(0, r);
322 for (int c = 0; c < image_size.width(); ++c, ++row) { 325 for (int c = 0; c < image_size.width(); ++c, ++row) {
323 *row <<= bit_shift; 326 *row <<= bit_shift;
324 } 327 }
325 } 328 }
326 } 329 }
327 330
328 skia::RecursiveFilter gradient_filter( 331 skia::RecursiveFilter gradient_filter(
329 kernel_sigma, skia::RecursiveFilter::FIRST_DERIVATIVE); 332 kernel_sigma, skia::RecursiveFilter::FIRST_DERIVATIVE);
330 skia::SingleChannelRecursiveGaussianX( 333 skia::SingleChannelRecursiveGaussianX(
331 input_bitmap->getAddr8(0, 0), 334 input_bitmap->getAddr8(0, 0),
(...skipping 10 matching lines...) Expand all
342 0, input_bitmap->bytesPerPixel(), 345 0, input_bitmap->bytesPerPixel(),
343 gradient_filter, 346 gradient_filter,
344 image_size, 347 image_size,
345 intermediate2.getAddr8(0, 0), 348 intermediate2.getAddr8(0, 0),
346 static_cast<int>(intermediate2.rowBytes()), 349 static_cast<int>(intermediate2.rowBytes()),
347 0, intermediate2.bytesPerPixel(), true); 350 0, intermediate2.bytesPerPixel(), true);
348 } 351 }
349 352
350 unsigned grad_max = 0; 353 unsigned grad_max = 0;
351 for (int r = 0; r < image_size.height(); ++r) { 354 for (int r = 0; r < image_size.height(); ++r) {
352 const uint8* grad_x_row = intermediate.getAddr8(0, r); 355 const uint8_t* grad_x_row = intermediate.getAddr8(0, r);
353 const uint8* grad_y_row = intermediate2.getAddr8(0, r); 356 const uint8_t* grad_y_row = intermediate2.getAddr8(0, r);
354 for (int c = 0; c < image_size.width(); ++c) { 357 for (int c = 0; c < image_size.width(); ++c) {
355 unsigned grad_x = grad_x_row[c]; 358 unsigned grad_x = grad_x_row[c];
356 unsigned grad_y = grad_y_row[c]; 359 unsigned grad_y = grad_y_row[c];
357 grad_max = std::max(grad_max, grad_x * grad_x + grad_y * grad_y); 360 grad_max = std::max(grad_max, grad_x * grad_x + grad_y * grad_y);
358 } 361 }
359 } 362 }
360 363
361 int bit_shift = 0; 364 int bit_shift = 0;
362 if (grad_max > 255) 365 if (grad_max > 255)
363 bit_shift = static_cast<int>( 366 bit_shift = static_cast<int>(
364 std::log10(static_cast<float>(grad_max)) / std::log10(2.0f)) - 7; 367 std::log10(static_cast<float>(grad_max)) / std::log10(2.0f)) - 7;
365 for (int r = 0; r < image_size.height(); ++r) { 368 for (int r = 0; r < image_size.height(); ++r) {
366 const uint8* grad_x_row = intermediate.getAddr8(0, r); 369 const uint8_t* grad_x_row = intermediate.getAddr8(0, r);
367 const uint8* grad_y_row = intermediate2.getAddr8(0, r); 370 const uint8_t* grad_y_row = intermediate2.getAddr8(0, r);
368 uint8* target_row = input_bitmap->getAddr8(0, r); 371 uint8_t* target_row = input_bitmap->getAddr8(0, r);
369 for (int c = 0; c < image_size.width(); ++c) { 372 for (int c = 0; c < image_size.width(); ++c) {
370 unsigned grad_x = grad_x_row[c]; 373 unsigned grad_x = grad_x_row[c];
371 unsigned grad_y = grad_y_row[c]; 374 unsigned grad_y = grad_y_row[c];
372 target_row[c] = (grad_x * grad_x + grad_y * grad_y) >> bit_shift; 375 target_row[c] = (grad_x * grad_x + grad_y * grad_y) >> bit_shift;
373 } 376 }
374 } 377 }
375 } 378 }
376 379
377 void ExtractImageProfileInformation(const SkBitmap& input_bitmap, 380 void ExtractImageProfileInformation(const SkBitmap& input_bitmap,
378 const gfx::Rect& area, 381 const gfx::Rect& area,
(...skipping 12 matching lines...) Expand all
391 DCHECK_LE(area.bottom(), input_bitmap.height()); 394 DCHECK_LE(area.bottom(), input_bitmap.height());
392 395
393 // Make sure rows and columns are allocated and initialized to 0. 396 // Make sure rows and columns are allocated and initialized to 0.
394 rows->clear(); 397 rows->clear();
395 columns->clear(); 398 columns->clear();
396 rows->resize(area.height(), 0); 399 rows->resize(area.height(), 0);
397 columns->resize(area.width(), 0); 400 columns->resize(area.width(), 0);
398 401
399 for (int r = 0; r < area.height(); ++r) { 402 for (int r = 0; r < area.height(); ++r) {
400 // Points to the first byte of the row in the rectangle. 403 // Points to the first byte of the row in the rectangle.
401 const uint8* image_row = input_bitmap.getAddr8(area.x(), r + area.y()); 404 const uint8_t* image_row = input_bitmap.getAddr8(area.x(), r + area.y());
402 unsigned row_sum = 0; 405 unsigned row_sum = 0;
403 for (int c = 0; c < area.width(); ++c, ++image_row) { 406 for (int c = 0; c < area.width(); ++c, ++image_row) {
404 row_sum += *image_row; 407 row_sum += *image_row;
405 (*columns)[c] += *image_row; 408 (*columns)[c] += *image_row;
406 } 409 }
407 (*rows)[r] = row_sum; 410 (*rows)[r] = row_sum;
408 } 411 }
409 412
410 if (apply_log) { 413 if (apply_log) {
411 // Generally for processing we will need to take logarithm of this data. 414 // Generally for processing we will need to take logarithm of this data.
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 682
680 // Allocate the target image. 683 // Allocate the target image.
681 SkBitmap target; 684 SkBitmap target;
682 target.allocPixels(bitmap.info().makeWH(target_column_count, 685 target.allocPixels(bitmap.info().makeWH(target_column_count,
683 target_row_count)); 686 target_row_count));
684 687
685 int target_row = 0; 688 int target_row = 0;
686 for (int r = 0; r < bitmap.height(); ++r) { 689 for (int r = 0; r < bitmap.height(); ++r) {
687 if (!rows[r]) 690 if (!rows[r])
688 continue; // We can just skip this one. 691 continue; // We can just skip this one.
689 uint8* src_row = 692 uint8_t* src_row =
690 static_cast<uint8*>(bitmap.getPixels()) + r * bitmap.rowBytes(); 693 static_cast<uint8_t*>(bitmap.getPixels()) + r * bitmap.rowBytes();
691 uint8* insertion_target = static_cast<uint8*>(target.getPixels()) + 694 uint8_t* insertion_target = static_cast<uint8_t*>(target.getPixels()) +
692 target_row * target.rowBytes(); 695 target_row * target.rowBytes();
693 int left_copy_pixel = -1; 696 int left_copy_pixel = -1;
694 for (int c = 0; c < bitmap.width(); ++c) { 697 for (int c = 0; c < bitmap.width(); ++c) {
695 if (left_copy_pixel < 0 && columns[c]) { 698 if (left_copy_pixel < 0 && columns[c]) {
696 left_copy_pixel = c; // Next time we will start copying from here. 699 left_copy_pixel = c; // Next time we will start copying from here.
697 } else if (left_copy_pixel >= 0 && !columns[c]) { 700 } else if (left_copy_pixel >= 0 && !columns[c]) {
698 // This closes a fragment we want to copy. We do it now. 701 // This closes a fragment we want to copy. We do it now.
699 size_t bytes_to_copy = (c - left_copy_pixel) * bitmap.bytesPerPixel(); 702 size_t bytes_to_copy = (c - left_copy_pixel) * bitmap.bytesPerPixel();
700 memcpy(insertion_target, 703 memcpy(insertion_target,
701 src_row + left_copy_pixel * bitmap.bytesPerPixel(), 704 src_row + left_copy_pixel * bitmap.bytesPerPixel(),
702 bytes_to_copy); 705 bytes_to_copy);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 target_size, 764 target_size,
762 &included_rows, 765 &included_rows,
763 &included_columns); 766 &included_columns);
764 767
765 // Use the original image and computed inclusion vectors to create a resized 768 // Use the original image and computed inclusion vectors to create a resized
766 // image. 769 // image.
767 return ComputeDecimatedImage(source_bitmap, included_rows, included_columns); 770 return ComputeDecimatedImage(source_bitmap, included_rows, included_columns);
768 } 771 }
769 772
770 } // namespace thumbnailing_utils 773 } // namespace 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