Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: third_party/libwebp/utils/rescaler.h

Issue 1546003002: libwebp: update to 0.5.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 'defines' exists Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifdef __cplusplus 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 #define WEBP_RESCALER_RFIX 32 // fixed-point precision for multiplies
24 #define WEBP_RESCALER_ONE (1ull << WEBP_RESCALER_RFIX)
25 #define WEBP_RESCALER_FRAC(x, y) \
26 ((uint32_t)(((uint64_t)(x) << WEBP_RESCALER_RFIX) / (y)))
27
23 // Structure used for on-the-fly rescaling 28 // Structure used for on-the-fly rescaling
24 typedef uint32_t rescaler_t; // type for side-buffer 29 typedef uint32_t rescaler_t; // type for side-buffer
25 typedef struct { 30 typedef struct WebPRescaler WebPRescaler;
31 struct WebPRescaler {
26 int x_expand; // true if we're expanding in the x direction 32 int x_expand; // true if we're expanding in the x direction
27 int y_expand; // true if we're expanding in the y direction 33 int y_expand; // true if we're expanding in the y direction
28 int num_channels; // bytes to jump between pixels 34 int num_channels; // bytes to jump between pixels
29 uint32_t fx_scale; // fixed-point scaling factors 35 uint32_t fx_scale; // fixed-point scaling factors
30 uint32_t fy_scale; // '' 36 uint32_t fy_scale; // ''
31 uint32_t fxy_scale; // '' 37 uint32_t fxy_scale; // ''
32 int y_accum; // vertical accumulator 38 int y_accum; // vertical accumulator
33 int y_add, y_sub; // vertical increments 39 int y_add, y_sub; // vertical increments
34 int x_add, x_sub; // horizontal increments 40 int x_add, x_sub; // horizontal increments
35 int src_width, src_height; // source dimensions 41 int src_width, src_height; // source dimensions
36 int dst_width, dst_height; // destination dimensions 42 int dst_width, dst_height; // destination dimensions
37 int src_y, dst_y; // row counters for input and output 43 int src_y, dst_y; // row counters for input and output
38 uint8_t* dst; 44 uint8_t* dst;
39 int dst_stride; 45 int dst_stride;
40 rescaler_t* irow, *frow; // work buffer 46 rescaler_t* irow, *frow; // work buffer
41 } WebPRescaler; 47 };
42 48
43 // Initialize a rescaler given scratch area 'work' and dimensions of src & dst. 49 // Initialize a rescaler given scratch area 'work' and dimensions of src & dst.
44 void WebPRescalerInit(WebPRescaler* const rescaler, 50 void WebPRescalerInit(WebPRescaler* const rescaler,
45 int src_width, int src_height, 51 int src_width, int src_height,
46 uint8_t* const dst, 52 uint8_t* const dst,
47 int dst_width, int dst_height, int dst_stride, 53 int dst_width, int dst_height, int dst_stride,
48 int num_channels, 54 int num_channels,
49 rescaler_t* const work); 55 rescaler_t* const work);
50 56
57 // If either 'scaled_width' or 'scaled_height' (but not both) is 0 the value
58 // will be calculated preserving the aspect ratio, otherwise the values are
59 // left unmodified. Returns true on success, false if either value is 0 after
60 // performing the scaling calculation.
61 int WebPRescalerGetScaledDimensions(int src_width, int src_height,
62 int* const scaled_width,
63 int* const scaled_height);
64
51 // Returns the number of input lines needed next to produce one output line, 65 // Returns the number of input lines needed next to produce one output line,
52 // considering that the maximum available input lines are 'max_num_lines'. 66 // considering that the maximum available input lines are 'max_num_lines'.
53 int WebPRescaleNeededLines(const WebPRescaler* const rescaler, 67 int WebPRescaleNeededLines(const WebPRescaler* const rescaler,
54 int max_num_lines); 68 int max_num_lines);
55 69
56 // Import multiple rows over all channels, until at least one row is ready to 70 // Import multiple rows over all channels, until at least one row is ready to
57 // be exported. Returns the actual number of lines that were imported. 71 // be exported. Returns the actual number of lines that were imported.
58 int WebPRescalerImport(WebPRescaler* const rescaler, int num_rows, 72 int WebPRescalerImport(WebPRescaler* const rescaler, int num_rows,
59 const uint8_t* src, int src_stride); 73 const uint8_t* src, int src_stride);
60 74
61 // 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.
62 int WebPRescalerExport(WebPRescaler* const rescaler); 76 int WebPRescalerExport(WebPRescaler* const rescaler);
63 void WebPRescalerImportRow(WebPRescaler* const wrk,
64 const uint8_t* src);
65 // Export one row (starting at x_out position) from rescaler.
66 void WebPRescalerExportRow(WebPRescaler* const wrk);
67 77
68 // Return true if input is finished 78 // Return true if input is finished
69 static WEBP_INLINE 79 static WEBP_INLINE
70 int WebPRescalerInputDone(const WebPRescaler* const rescaler) { 80 int WebPRescalerInputDone(const WebPRescaler* const rescaler) {
71 return (rescaler->src_y >= rescaler->src_height); 81 return (rescaler->src_y >= rescaler->src_height);
72 } 82 }
73 // Return true if output is finished 83 // Return true if output is finished
74 static WEBP_INLINE 84 static WEBP_INLINE
75 int WebPRescalerOutputDone(const WebPRescaler* const rescaler) { 85 int WebPRescalerOutputDone(const WebPRescaler* const rescaler) {
76 return (rescaler->dst_y >= rescaler->dst_height); 86 return (rescaler->dst_y >= rescaler->dst_height);
77 } 87 }
78 88
79 // Return true if there are pending output rows ready. 89 // Return true if there are pending output rows ready.
80 static WEBP_INLINE 90 static WEBP_INLINE
81 int WebPRescalerHasPendingOutput(const WebPRescaler* const rescaler) { 91 int WebPRescalerHasPendingOutput(const WebPRescaler* const rescaler) {
82 return !WebPRescalerOutputDone(rescaler) && (rescaler->y_accum <= 0); 92 return !WebPRescalerOutputDone(rescaler) && (rescaler->y_accum <= 0);
83 } 93 }
84 94
85 //------------------------------------------------------------------------------ 95 //------------------------------------------------------------------------------
86 96
87 #ifdef __cplusplus 97 #ifdef __cplusplus
88 } // extern "C" 98 } // extern "C"
89 #endif 99 #endif
90 100
91 #endif /* WEBP_UTILS_RESCALER_H_ */ 101 #endif /* WEBP_UTILS_RESCALER_H_ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698