blob: 5f399549b37e254a2c10a3f864dc5cde0743c006 [file] [log] [blame]
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/macros.h"
#include "ui/base/resource/scale_factor.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
namespace thumbnails {
// The result of clipping. This can be used to determine if the
// generated thumbnail is good or not.
enum ClipResult {
// Clipping is not done yet.
// The source image is smaller.
// Wider than tall by twice or more, clip horizontally.
// Wider than tall, clip horizontally.
// Taller than wide, clip vertically.
// The source and destination aspect ratios are identical.
bool IsGoodClipping(ClipResult clip_result);
// The implementation of the 'classic' thumbnail cropping algorithm. It is not
// content-driven in any meaningful way (save for score calculation). Rather,
// the choice of a cropping region is based on relation between source and
// target sizes. The selected source region is then rescaled into the target
// thumbnail image.
// Provides information necessary to crop-and-resize image data from a source
// canvas of |source_size|. Auxiliary |scale_factor| helps compute the target
// thumbnail size to be copied from the backing store, in pixels. Parameters
// of the required copy operation are assigned to |clipping_rect| (cropping
// rectangle for the source canvas) and |copy_size| (the size of the copied
// bitmap in pixels). The return value indicates the type of clipping that
// will be done.
ClipResult GetCanvasCopyInfo(const gfx::Size& source_size,
ui::ScaleFactor scale_factor,
const gfx::Size& target_size,
gfx::Rect* clipping_rect,
gfx::Size* copy_size);
// Returns the size copied from the backing store. |thumbnail_size| is in
// DIP, returned size in pixels.
gfx::Size GetCopySizeForThumbnail(ui::ScaleFactor scale_factor,
const gfx::Size& thumbnail_size);
gfx::Rect GetClippingRect(const gfx::Size& source_size,
const gfx::Size& desired_size,
ClipResult* clip_result);
} // namespace thumbnails