Path: blob/master/3rdparty/libwebp/src/utils/rescaler_utils.h
16358 views
// Copyright 2012 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Rescaling functions10//11// Author: Skal ([email protected])1213#ifndef WEBP_UTILS_RESCALER_UTILS_H_14#define WEBP_UTILS_RESCALER_UTILS_H_1516#ifdef __cplusplus17extern "C" {18#endif1920#include "src/webp/types.h"2122#define WEBP_RESCALER_RFIX 32 // fixed-point precision for multiplies23#define WEBP_RESCALER_ONE (1ull << WEBP_RESCALER_RFIX)24#define WEBP_RESCALER_FRAC(x, y) \25((uint32_t)(((uint64_t)(x) << WEBP_RESCALER_RFIX) / (y)))2627// Structure used for on-the-fly rescaling28typedef uint32_t rescaler_t; // type for side-buffer29typedef struct WebPRescaler WebPRescaler;30struct WebPRescaler {31int x_expand; // true if we're expanding in the x direction32int y_expand; // true if we're expanding in the y direction33int num_channels; // bytes to jump between pixels34uint32_t fx_scale; // fixed-point scaling factors35uint32_t fy_scale; // ''36uint32_t fxy_scale; // ''37int y_accum; // vertical accumulator38int y_add, y_sub; // vertical increments39int x_add, x_sub; // horizontal increments40int src_width, src_height; // source dimensions41int dst_width, dst_height; // destination dimensions42int src_y, dst_y; // row counters for input and output43uint8_t* dst;44int dst_stride;45rescaler_t* irow, *frow; // work buffer46};4748// Initialize a rescaler given scratch area 'work' and dimensions of src & dst.49void WebPRescalerInit(WebPRescaler* const rescaler,50int src_width, int src_height,51uint8_t* const dst,52int dst_width, int dst_height, int dst_stride,53int num_channels,54rescaler_t* const work);5556// If either 'scaled_width' or 'scaled_height' (but not both) is 0 the value57// will be calculated preserving the aspect ratio, otherwise the values are58// left unmodified. Returns true on success, false if either value is 0 after59// performing the scaling calculation.60int WebPRescalerGetScaledDimensions(int src_width, int src_height,61int* const scaled_width,62int* const scaled_height);6364// Returns the number of input lines needed next to produce one output line,65// considering that the maximum available input lines are 'max_num_lines'.66int WebPRescaleNeededLines(const WebPRescaler* const rescaler,67int max_num_lines);6869// Import multiple rows over all channels, until at least one row is ready to70// be exported. Returns the actual number of lines that were imported.71int WebPRescalerImport(WebPRescaler* const rescaler, int num_rows,72const uint8_t* src, int src_stride);7374// Export as many rows as possible. Return the numbers of rows written.75int WebPRescalerExport(WebPRescaler* const rescaler);7677// Return true if input is finished78static WEBP_INLINE79int WebPRescalerInputDone(const WebPRescaler* const rescaler) {80return (rescaler->src_y >= rescaler->src_height);81}82// Return true if output is finished83static WEBP_INLINE84int WebPRescalerOutputDone(const WebPRescaler* const rescaler) {85return (rescaler->dst_y >= rescaler->dst_height);86}8788// Return true if there are pending output rows ready.89static WEBP_INLINE90int WebPRescalerHasPendingOutput(const WebPRescaler* const rescaler) {91return !WebPRescalerOutputDone(rescaler) && (rescaler->y_accum <= 0);92}9394//------------------------------------------------------------------------------9596#ifdef __cplusplus97} // extern "C"98#endif99100#endif /* WEBP_UTILS_RESCALER_UTILS_H_ */101102103