Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 1 | // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 | // |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license |
| 4 | // that can be found in the COPYING file in the root of the source |
| 5 | // tree. An additional intellectual property rights grant can be found |
| 6 | // in the file PATENTS. All contributing project authors may |
| 7 | // be found in the AUTHORS file in the root of the source tree. |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 8 | // ----------------------------------------------------------------------------- |
| 9 | // |
| 10 | // Rescaling functions |
| 11 | // |
| 12 | // Author: Skal (pascal.massimino@gmail.com) |
| 13 | |
| 14 | #ifndef WEBP_UTILS_RESCALER_H_ |
| 15 | #define WEBP_UTILS_RESCALER_H_ |
| 16 | |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 17 | #ifdef __cplusplus |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 18 | extern "C" { |
| 19 | #endif |
| 20 | |
James Zern | 9e80ee9 | 2015-03-17 18:54:21 -0700 | [diff] [blame] | 21 | #include "../webp/types.h" |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 22 | |
| 23 | // Structure used for on-the-fly rescaling |
| 24 | typedef struct { |
| 25 | int x_expand; // true if we're expanding in the x direction |
| 26 | int num_channels; // bytes to jump between pixels |
| 27 | int fy_scale, fx_scale; // fixed-point scaling factor |
| 28 | int64_t fxy_scale; // '' |
| 29 | // we need hpel-precise add/sub increments, for the downsampled U/V planes. |
| 30 | int y_accum; // vertical accumulator |
| 31 | int y_add, y_sub; // vertical increments (add ~= src, sub ~= dst) |
| 32 | int x_add, x_sub; // horizontal increments (add ~= src, sub ~= dst) |
| 33 | int src_width, src_height; // source dimensions |
| 34 | int dst_width, dst_height; // destination dimensions |
| 35 | uint8_t* dst; |
| 36 | int dst_stride; |
| 37 | int32_t* irow, *frow; // work buffer |
| 38 | } WebPRescaler; |
| 39 | |
| 40 | // Initialize a rescaler given scratch area 'work' and dimensions of src & dst. |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 41 | void WebPRescalerInit(WebPRescaler* const rescaler, |
| 42 | int src_width, int src_height, |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 43 | uint8_t* const dst, |
| 44 | int dst_width, int dst_height, int dst_stride, |
| 45 | int num_channels, |
| 46 | int x_add, int x_sub, |
| 47 | int y_add, int y_sub, |
| 48 | int32_t* const work); |
| 49 | |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 50 | // Returns the number of input lines needed next to produce one output line, |
| 51 | // considering that the maximum available input lines are 'max_num_lines'. |
| 52 | int WebPRescaleNeededLines(const WebPRescaler* const rescaler, |
| 53 | int max_num_lines); |
| 54 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 55 | // Import multiple rows over all channels, until at least one row is ready to |
| 56 | // be exported. Returns the actual number of lines that were imported. |
| 57 | int WebPRescalerImport(WebPRescaler* const rescaler, int num_rows, |
| 58 | const uint8_t* src, int src_stride); |
| 59 | |
Vikas Arora | 33f74da | 2014-07-25 13:53:32 -0700 | [diff] [blame] | 60 | // Import a row of data and save its contribution in the rescaler. |
| 61 | // 'channel' denotes the channel number to be imported. |
| 62 | extern void (*WebPRescalerImportRow)(WebPRescaler* const wrk, |
| 63 | const uint8_t* const src, int channel); |
| 64 | // Export one row (starting at x_out position) from rescaler. |
| 65 | extern void (*WebPRescalerExportRow)(WebPRescaler* const wrk, int x_out); |
| 66 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 67 | // Return true if there is pending output rows ready. |
| 68 | static WEBP_INLINE |
| 69 | int WebPRescalerHasPendingOutput(const WebPRescaler* const rescaler) { |
| 70 | return (rescaler->y_accum <= 0); |
| 71 | } |
| 72 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 73 | // Export as many rows as possible. Return the numbers of rows written. |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 74 | int WebPRescalerExport(WebPRescaler* const rescaler); |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 75 | |
| 76 | //------------------------------------------------------------------------------ |
| 77 | |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 78 | #ifdef __cplusplus |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 79 | } // extern "C" |
| 80 | #endif |
| 81 | |
| 82 | #endif /* WEBP_UTILS_RESCALER_H_ */ |