2012-03-22 11:30:20 +01:00
|
|
|
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
//
|
2013-06-07 08:05:58 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the COPYING file in the root of the source
|
|
|
|
// tree. An additional intellectual property rights grant can be found
|
|
|
|
// in the file PATENTS. All contributing project authors may
|
|
|
|
// be found in the AUTHORS file in the root of the source tree.
|
2012-03-22 11:30:20 +01:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Rescaling functions
|
|
|
|
//
|
2012-07-20 01:09:47 +02:00
|
|
|
// Author: Skal (pascal.massimino@gmail.com)
|
2012-03-22 11:30:20 +01:00
|
|
|
|
2017-10-21 04:26:52 +02:00
|
|
|
#ifndef WEBP_UTILS_RESCALER_UTILS_H_
|
|
|
|
#define WEBP_UTILS_RESCALER_UTILS_H_
|
2012-03-22 11:30:20 +01:00
|
|
|
|
2013-11-25 23:43:12 +01:00
|
|
|
#ifdef __cplusplus
|
2012-03-22 11:30:20 +01:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-10-07 23:15:11 +02:00
|
|
|
#include "src/webp/types.h"
|
2012-03-22 11:30:20 +01:00
|
|
|
|
2015-09-25 14:34:02 +02:00
|
|
|
#define WEBP_RESCALER_RFIX 32 // fixed-point precision for multiplies
|
|
|
|
#define WEBP_RESCALER_ONE (1ull << WEBP_RESCALER_RFIX)
|
2015-09-25 17:36:11 +02:00
|
|
|
#define WEBP_RESCALER_FRAC(x, y) \
|
|
|
|
((uint32_t)(((uint64_t)(x) << WEBP_RESCALER_RFIX) / (y)))
|
2015-01-10 15:46:00 +01:00
|
|
|
|
2012-03-22 11:30:20 +01:00
|
|
|
// Structure used for on-the-fly rescaling
|
2015-09-25 14:34:02 +02:00
|
|
|
typedef uint32_t rescaler_t; // type for side-buffer
|
2015-01-10 15:46:00 +01:00
|
|
|
typedef struct WebPRescaler WebPRescaler;
|
|
|
|
struct WebPRescaler {
|
2012-03-22 11:30:20 +01:00
|
|
|
int x_expand; // true if we're expanding in the x direction
|
2015-08-19 06:33:18 +02:00
|
|
|
int y_expand; // true if we're expanding in the y direction
|
2012-03-22 11:30:20 +01:00
|
|
|
int num_channels; // bytes to jump between pixels
|
2015-09-18 10:45:03 +02:00
|
|
|
uint32_t fx_scale; // fixed-point scaling factors
|
|
|
|
uint32_t fy_scale; // ''
|
2015-09-25 14:34:02 +02:00
|
|
|
uint32_t fxy_scale; // ''
|
2012-03-22 11:30:20 +01:00
|
|
|
int y_accum; // vertical accumulator
|
2015-08-19 06:33:18 +02:00
|
|
|
int y_add, y_sub; // vertical increments
|
|
|
|
int x_add, x_sub; // horizontal increments
|
2012-03-22 11:30:20 +01:00
|
|
|
int src_width, src_height; // source dimensions
|
|
|
|
int dst_width, dst_height; // destination dimensions
|
2015-09-18 10:45:03 +02:00
|
|
|
int src_y, dst_y; // row counters for input and output
|
2012-03-22 11:30:20 +01:00
|
|
|
uint8_t* dst;
|
|
|
|
int dst_stride;
|
2015-09-18 10:45:03 +02:00
|
|
|
rescaler_t* irow, *frow; // work buffer
|
2015-01-10 15:46:00 +01:00
|
|
|
};
|
2012-03-22 11:30:20 +01:00
|
|
|
|
|
|
|
// Initialize a rescaler given scratch area 'work' and dimensions of src & dst.
|
2021-06-25 15:23:16 +02:00
|
|
|
// Returns false in case of error.
|
|
|
|
int WebPRescalerInit(WebPRescaler* const rescaler,
|
2013-07-26 21:05:42 +02:00
|
|
|
int src_width, int src_height,
|
2012-03-22 11:30:20 +01:00
|
|
|
uint8_t* const dst,
|
|
|
|
int dst_width, int dst_height, int dst_stride,
|
|
|
|
int num_channels,
|
2015-09-18 10:45:03 +02:00
|
|
|
rescaler_t* const work);
|
2012-03-22 11:30:20 +01:00
|
|
|
|
2015-08-14 05:50:38 +02:00
|
|
|
// If either 'scaled_width' or 'scaled_height' (but not both) is 0 the value
|
|
|
|
// will be calculated preserving the aspect ratio, otherwise the values are
|
|
|
|
// left unmodified. Returns true on success, false if either value is 0 after
|
|
|
|
// performing the scaling calculation.
|
|
|
|
int WebPRescalerGetScaledDimensions(int src_width, int src_height,
|
|
|
|
int* const scaled_width,
|
|
|
|
int* const scaled_height);
|
|
|
|
|
2013-07-26 21:05:42 +02:00
|
|
|
// Returns the number of input lines needed next to produce one output line,
|
|
|
|
// considering that the maximum available input lines are 'max_num_lines'.
|
|
|
|
int WebPRescaleNeededLines(const WebPRescaler* const rescaler,
|
|
|
|
int max_num_lines);
|
|
|
|
|
2012-03-22 11:30:20 +01:00
|
|
|
// Import multiple rows over all channels, until at least one row is ready to
|
|
|
|
// be exported. Returns the actual number of lines that were imported.
|
|
|
|
int WebPRescalerImport(WebPRescaler* const rescaler, int num_rows,
|
|
|
|
const uint8_t* src, int src_stride);
|
|
|
|
|
2015-09-18 10:45:03 +02:00
|
|
|
// Export as many rows as possible. Return the numbers of rows written.
|
|
|
|
int WebPRescalerExport(WebPRescaler* const rescaler);
|
|
|
|
|
|
|
|
// Return true if input is finished
|
2012-03-22 11:30:20 +01:00
|
|
|
static WEBP_INLINE
|
2015-09-18 10:45:03 +02:00
|
|
|
int WebPRescalerInputDone(const WebPRescaler* const rescaler) {
|
|
|
|
return (rescaler->src_y >= rescaler->src_height);
|
|
|
|
}
|
|
|
|
// Return true if output is finished
|
|
|
|
static WEBP_INLINE
|
|
|
|
int WebPRescalerOutputDone(const WebPRescaler* const rescaler) {
|
|
|
|
return (rescaler->dst_y >= rescaler->dst_height);
|
2012-03-22 11:30:20 +01:00
|
|
|
}
|
|
|
|
|
2015-09-18 10:45:03 +02:00
|
|
|
// Return true if there are pending output rows ready.
|
|
|
|
static WEBP_INLINE
|
|
|
|
int WebPRescalerHasPendingOutput(const WebPRescaler* const rescaler) {
|
|
|
|
return !WebPRescalerOutputDone(rescaler) && (rescaler->y_accum <= 0);
|
|
|
|
}
|
2012-03-22 11:30:20 +01:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2013-11-25 23:43:12 +01:00
|
|
|
#ifdef __cplusplus
|
2012-03-22 11:30:20 +01:00
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2018-08-22 23:46:53 +02:00
|
|
|
#endif // WEBP_UTILS_RESCALER_UTILS_H_
|