@@ -254,24 +254,33 @@ impl From<Rgb> for YCbCr {
254
254
// terms need to be scaled by << 5 we simply scale the final
255
255
// sum by >> 10
256
256
const DIVISOR : f32 = ( 1 << 15 ) as f32 ;
257
+ const Y_R : i32 = ( 0.299 * DIVISOR ) as i32 ;
258
+ const Y_G : i32 = ( 0.587 * DIVISOR ) as i32 ;
259
+ const Y_B : i32 = ( 0.114 * DIVISOR ) as i32 ;
260
+ const CB_R : i32 = ( 0.168_935 * DIVISOR ) as i32 ;
261
+ const CB_G : i32 = ( 0.331_665 * DIVISOR ) as i32 ;
262
+ const CB_B : i32 = ( 0.500_59 * DIVISOR ) as i32 ;
263
+ const CR_R : i32 = ( 0.499_813 * DIVISOR ) as i32 ;
264
+ const CR_G : i32 = ( 0.418_531 * DIVISOR ) as i32 ;
265
+ const CR_B : i32 = ( 0.081_282 * DIVISOR ) as i32 ;
257
266
258
267
let r = i32:: from ( r) ;
259
268
let g = i32:: from ( g) ;
260
269
let b = i32:: from ( b) ;
261
270
262
- let y_r = r. overflowing_mul ( ( 0.299 * DIVISOR ) as i32 ) . 0 ;
263
- let y_g = g. overflowing_mul ( ( 0.587 * DIVISOR ) as i32 ) . 0 ;
264
- let y_b = b. overflowing_mul ( ( 0.114 * DIVISOR ) as i32 ) . 0 ;
271
+ let y_r = r. overflowing_mul ( Y_R ) . 0 ;
272
+ let y_g = g. overflowing_mul ( Y_G ) . 0 ;
273
+ let y_b = b. overflowing_mul ( Y_B ) . 0 ;
265
274
let y = y_r. overflowing_add ( y_g) . 0 . overflowing_add ( y_b) . 0 >> 10 ;
266
275
267
- let cb_r = r. overflowing_mul ( ( 0.168_935 * DIVISOR ) as i32 ) . 0 ;
268
- let cb_g = g. overflowing_mul ( ( 0.331_665 * DIVISOR ) as i32 ) . 0 ;
269
- let cb_b = b. overflowing_mul ( ( 0.500_59 * DIVISOR ) as i32 ) . 0 ;
276
+ let cb_r = r. overflowing_mul ( CB_R ) . 0 ;
277
+ let cb_g = g. overflowing_mul ( CB_G ) . 0 ;
278
+ let cb_b = b. overflowing_mul ( CB_B ) . 0 ;
270
279
let cb = cb_b. overflowing_sub ( cb_g) . 0 . overflowing_sub ( cb_r) . 0 >> 10 ;
271
280
272
- let cr_r = r. overflowing_mul ( ( 0.499_813 * DIVISOR ) as i32 ) . 0 ;
273
- let cr_g = g. overflowing_mul ( ( 0.418_531 * DIVISOR ) as i32 ) . 0 ;
274
- let cr_b = b. overflowing_mul ( ( 0.081_282 * DIVISOR ) as i32 ) . 0 ;
281
+ let cr_r = r. overflowing_mul ( CR_R ) . 0 ;
282
+ let cr_g = g. overflowing_mul ( CR_G ) . 0 ;
283
+ let cr_b = b. overflowing_mul ( CR_B ) . 0 ;
275
284
let cr = cr_r. overflowing_sub ( cr_g) . 0 . overflowing_sub ( cr_b) . 0 >> 10 ;
276
285
277
286
Self {
0 commit comments