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 #include <assert.h> | 14 #include <assert.h> |
15 #include <stdlib.h> | 15 #include <stdlib.h> |
16 #include "./rescaler.h" | 16 #include "./rescaler.h" |
17 | 17 |
18 //------------------------------------------------------------------------------ | 18 //------------------------------------------------------------------------------ |
19 | 19 |
20 #if defined(__cplusplus) || defined(c_plusplus) | |
21 extern "C" { | |
22 #endif | |
23 | |
24 #define RFIX 30 | 20 #define RFIX 30 |
25 #define MULT_FIX(x, y) (((int64_t)(x) * (y) + (1 << (RFIX - 1))) >> RFIX) | 21 #define MULT_FIX(x, y) (((int64_t)(x) * (y) + (1 << (RFIX - 1))) >> RFIX) |
26 | 22 |
27 void WebPRescalerInit(WebPRescaler* const wrk, int src_width, int src_height, | 23 void WebPRescalerInit(WebPRescaler* const wrk, int src_width, int src_height, |
28 uint8_t* const dst, int dst_width, int dst_height, | 24 uint8_t* const dst, int dst_width, int dst_height, |
29 int dst_stride, int num_channels, int x_add, int x_sub, | 25 int dst_stride, int num_channels, int x_add, int x_sub, |
30 int y_add, int y_sub, int32_t* const work) { | 26 int y_add, int y_sub, int32_t* const work) { |
31 wrk->x_expand = (src_width < dst_width); | 27 wrk->x_expand = (src_width < dst_width); |
32 wrk->src_width = src_width; | 28 wrk->src_width = src_width; |
33 wrk->src_height = src_height; | 29 wrk->src_height = src_height; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 return NULL; | 112 return NULL; |
117 } | 113 } |
118 } | 114 } |
119 | 115 |
120 #undef MULT_FIX | 116 #undef MULT_FIX |
121 #undef RFIX | 117 #undef RFIX |
122 | 118 |
123 //------------------------------------------------------------------------------ | 119 //------------------------------------------------------------------------------ |
124 // all-in-one calls | 120 // all-in-one calls |
125 | 121 |
| 122 int WebPRescaleNeededLines(const WebPRescaler* const wrk, int max_num_lines) { |
| 123 const int num_lines = (wrk->y_accum + wrk->y_sub - 1) / wrk->y_sub; |
| 124 return (num_lines > max_num_lines) ? max_num_lines : num_lines; |
| 125 } |
| 126 |
126 int WebPRescalerImport(WebPRescaler* const wrk, int num_lines, | 127 int WebPRescalerImport(WebPRescaler* const wrk, int num_lines, |
127 const uint8_t* src, int src_stride) { | 128 const uint8_t* src, int src_stride) { |
128 int total_imported = 0; | 129 int total_imported = 0; |
129 while (total_imported < num_lines && wrk->y_accum > 0) { | 130 while (total_imported < num_lines && wrk->y_accum > 0) { |
130 int channel; | 131 int channel; |
131 for (channel = 0; channel < wrk->num_channels; ++channel) { | 132 for (channel = 0; channel < wrk->num_channels; ++channel) { |
132 WebPRescalerImportRow(wrk, src, channel); | 133 WebPRescalerImportRow(wrk, src, channel); |
133 } | 134 } |
134 src += src_stride; | 135 src += src_stride; |
135 ++total_imported; | 136 ++total_imported; |
136 wrk->y_accum -= wrk->y_sub; | 137 wrk->y_accum -= wrk->y_sub; |
137 } | 138 } |
138 return total_imported; | 139 return total_imported; |
139 } | 140 } |
140 | 141 |
141 int WebPRescalerExport(WebPRescaler* const rescaler) { | 142 int WebPRescalerExport(WebPRescaler* const rescaler) { |
142 int total_exported = 0; | 143 int total_exported = 0; |
143 while (WebPRescalerHasPendingOutput(rescaler)) { | 144 while (WebPRescalerHasPendingOutput(rescaler)) { |
144 WebPRescalerExportRow(rescaler); | 145 WebPRescalerExportRow(rescaler); |
145 ++total_exported; | 146 ++total_exported; |
146 } | 147 } |
147 return total_exported; | 148 return total_exported; |
148 } | 149 } |
149 | 150 |
150 //------------------------------------------------------------------------------ | 151 //------------------------------------------------------------------------------ |
151 | 152 |
152 #if defined(__cplusplus) || defined(c_plusplus) | |
153 } // extern "C" | |
154 #endif | |
OLD | NEW |