@@ -144,7 +144,8 @@ pub fn build_transfer_fn(writer: &mut File) {
144
144
}
145
145
146
146
fn gen_into_linear_lut_u8 ( writer : & mut File , entries : & [ LutEntryU8 ] ) {
147
- use std:: io:: Write ;
147
+ use std:: fmt:: Write as _;
148
+ use std:: io:: Write as _;
148
149
149
150
for LutEntryU8 {
150
151
fn_type,
@@ -155,20 +156,24 @@ fn gen_into_linear_lut_u8(writer: &mut File, entries: &[LutEntryU8]) {
155
156
{
156
157
let table_size = 1 << 8 ;
157
158
let mut table = Vec :: new ( ) ;
158
- for i in 0 ..table_size {
159
+ // Handle integer floats printing without decimal
160
+ table. extend_from_slice ( b"\t 0.0,\n " ) ;
161
+
162
+ let mut float_string = String :: new ( ) ;
163
+
164
+ for i in 1 ..( table_size - 1 ) {
159
165
let encoded = ( i as f64 ) / ( ( table_size - 1 ) as f64 ) ;
160
166
let linear = into_linear ( encoded) ;
161
- // Handle integer floats printing without decimal
162
- let float_string = if linear <= 0.0 {
163
- "\t 0.0,\n " . to_owned ( )
164
- } else if linear >= 1.0 {
165
- "\t 1.0,\n " . to_owned ( )
166
- } else {
167
- format ! ( "\t {linear},\n " )
168
- } ;
167
+
168
+ writeln ! ( & mut float_string, "\t {linear}," ) . unwrap ( ) ;
169
169
table. extend_from_slice ( float_string. as_bytes ( ) ) ;
170
+
171
+ float_string. clear ( ) ;
170
172
}
171
173
174
+ // Handle integer floats printing without decimal
175
+ table. extend_from_slice ( b"\t 1.0,\n " ) ;
176
+
172
177
let table_name = format ! ( "{fn_type_uppercase}_U8_TO_F64" ) ;
173
178
writeln ! ( writer, "const {table_name}: [f64; {table_size}] = [" ) . unwrap ( ) ;
174
179
writer. write_all ( & table) . unwrap ( ) ;
@@ -200,7 +205,8 @@ fn gen_into_linear_lut_u8(writer: &mut File, entries: &[LutEntryU8]) {
200
205
201
206
#[ cfg( feature = "prophoto_lut" ) ]
202
207
fn gen_into_linear_lut_u16 ( writer : & mut File , entries : & [ LutEntryU16 ] ) {
203
- use std:: io:: Write ;
208
+ use std:: fmt:: Write as _;
209
+ use std:: io:: Write as _;
204
210
205
211
for LutEntryU16 {
206
212
fn_type,
@@ -211,20 +217,24 @@ fn gen_into_linear_lut_u16(writer: &mut File, entries: &[LutEntryU16]) {
211
217
{
212
218
let table_size = 1 << 16 ;
213
219
let mut table = Vec :: new ( ) ;
214
- for i in 0 ..table_size {
220
+ // Handle integer floats printing without decimal
221
+ table. extend_from_slice ( b"\t 0.0,\n " ) ;
222
+
223
+ let mut float_string = String :: new ( ) ;
224
+
225
+ for i in 1 ..( table_size - 1 ) {
215
226
let encoded = ( i as f64 ) / ( ( table_size - 1 ) as f64 ) ;
216
227
let linear = into_linear ( encoded) ;
217
- // Handle integer floats printing without decimal
218
- let float_string = if linear <= 0.0 {
219
- "\t 0.0,\n " . to_owned ( )
220
- } else if linear >= 1.0 {
221
- "\t 1.0,\n " . to_owned ( )
222
- } else {
223
- format ! ( "\t {linear},\n " )
224
- } ;
228
+
229
+ writeln ! ( & mut float_string, "\t {linear}," ) . unwrap ( ) ;
225
230
table. extend_from_slice ( float_string. as_bytes ( ) ) ;
231
+
232
+ float_string. clear ( ) ;
226
233
}
227
234
235
+ // Handle integer floats printing without decimal
236
+ table. extend_from_slice ( b"\t 1.0,\n " ) ;
237
+
228
238
let table_name = format ! ( "{fn_type_uppercase}_U16_TO_F64" ) ;
229
239
writeln ! ( writer, "static {table_name}: [f64; {table_size}] = [" ) . unwrap ( ) ;
230
240
writer. write_all ( & table) . unwrap ( ) ;
0 commit comments