Path: blob/master/thirdparty/libwebp/src/utils/rescaler_utils.h
9912 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.49// Returns false in case of error.50int WebPRescalerInit(WebPRescaler* const rescaler,51int src_width, int src_height,52uint8_t* const dst,53int dst_width, int dst_height, int dst_stride,54int num_channels,55rescaler_t* const work);5657// If either 'scaled_width' or 'scaled_height' (but not both) is 0 the value58// will be calculated preserving the aspect ratio, otherwise the values are59// left unmodified. Returns true on success, false if either value is 0 after60// performing the scaling calculation.61int WebPRescalerGetScaledDimensions(int src_width, int src_height,62int* const scaled_width,63int* const scaled_height);6465// Returns the number of input lines needed next to produce one output line,66// considering that the maximum available input lines are 'max_num_lines'.67int WebPRescaleNeededLines(const WebPRescaler* const rescaler,68int max_num_lines);6970// Import multiple rows over all channels, until at least one row is ready to71// be exported. Returns the actual number of lines that were imported.72int WebPRescalerImport(WebPRescaler* const rescaler, int num_rows,73const uint8_t* src, int src_stride);7475// Export as many rows as possible. Return the numbers of rows written.76int WebPRescalerExport(WebPRescaler* const rescaler);7778// Return true if input is finished79static WEBP_INLINE80int WebPRescalerInputDone(const WebPRescaler* const rescaler) {81return (rescaler->src_y >= rescaler->src_height);82}83// Return true if output is finished84static WEBP_INLINE85int WebPRescalerOutputDone(const WebPRescaler* const rescaler) {86return (rescaler->dst_y >= rescaler->dst_height);87}8889// Return true if there are pending output rows ready.90static WEBP_INLINE91int WebPRescalerHasPendingOutput(const WebPRescaler* const rescaler) {92return !WebPRescalerOutputDone(rescaler) && (rescaler->y_accum <= 0);93}9495//------------------------------------------------------------------------------9697#ifdef __cplusplus98} // extern "C"99#endif100101#endif // WEBP_UTILS_RESCALER_UTILS_H_102103104