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