@@ -21,7 +21,7 @@ use super::overlay::DecodedOverlay;
2121/// Rows are processed in parallel via `rayon` when the blit region is large
2222/// enough to benefit from multi-core dispatch.
2323#[ allow( clippy:: cast_possible_truncation, clippy:: cast_sign_loss, clippy:: too_many_arguments) ]
24- pub ( crate ) fn scale_blit_rgba (
24+ pub fn scale_blit_rgba (
2525 dst : & mut [ u8 ] ,
2626 dst_width : u32 ,
2727 dst_height : u32 ,
@@ -165,12 +165,12 @@ fn blit_row_opaque(
165165 row_slice[ dst_idx + 2 ] = sb;
166166 row_slice[ dst_idx + 3 ] = 255 ;
167167 } else if sa > 0 {
168- let a16 = sa as u16 ;
168+ let a16 = u16:: from ( sa ) ;
169169 row_slice[ dst_idx] = blend_u8 ( sr, row_slice[ dst_idx] , a16) ;
170170 row_slice[ dst_idx + 1 ] = blend_u8 ( sg, row_slice[ dst_idx + 1 ] , a16) ;
171171 row_slice[ dst_idx + 2 ] = blend_u8 ( sb, row_slice[ dst_idx + 2 ] , a16) ;
172172 // Composite alpha: a_out = a_src + a_dst * (1 - a_src)
173- let da = row_slice[ dst_idx + 3 ] as u16 ;
173+ let da = u16 :: from ( row_slice[ dst_idx + 3 ] ) ;
174174 row_slice[ dst_idx + 3 ] = ( a16 + ( ( da * ( 255 - a16) + 128 ) >> 8 ) ) . min ( 255 ) as u8 ;
175175 }
176176 }
@@ -221,7 +221,7 @@ fn blit_row_alpha(
221221 }
222222
223223 // Effective alpha: (sa * opacity) / 255, done in integer.
224- let sa_eff = ( ( sa as u16 * opacity_u16 + 128 ) >> 8 ) . min ( 255 ) as u16 ;
224+ let sa_eff = ( ( u16 :: from ( sa ) * opacity_u16 + 128 ) >> 8 ) . min ( 255 ) ;
225225 if sa_eff == 255 {
226226 row_slice[ dst_idx] = sr;
227227 row_slice[ dst_idx + 1 ] = sg;
@@ -231,20 +231,15 @@ fn blit_row_alpha(
231231 row_slice[ dst_idx] = blend_u8 ( sr, row_slice[ dst_idx] , sa_eff) ;
232232 row_slice[ dst_idx + 1 ] = blend_u8 ( sg, row_slice[ dst_idx + 1 ] , sa_eff) ;
233233 row_slice[ dst_idx + 2 ] = blend_u8 ( sb, row_slice[ dst_idx + 2 ] , sa_eff) ;
234- let da = row_slice[ dst_idx + 3 ] as u16 ;
234+ let da = u16 :: from ( row_slice[ dst_idx + 3 ] ) ;
235235 row_slice[ dst_idx + 3 ] = ( sa_eff + ( ( da * ( 255 - sa_eff) + 128 ) >> 8 ) ) . min ( 255 ) as u8 ;
236236 }
237237 }
238238}
239239
240240/// Blit a pre-decoded overlay onto the canvas (full alpha blend at the
241241/// overlay's configured opacity).
242- pub ( crate ) fn blit_overlay (
243- canvas : & mut [ u8 ] ,
244- canvas_w : u32 ,
245- canvas_h : u32 ,
246- overlay : & DecodedOverlay ,
247- ) {
242+ pub fn blit_overlay ( canvas : & mut [ u8 ] , canvas_w : u32 , canvas_h : u32 , overlay : & DecodedOverlay ) {
248243 scale_blit_rgba (
249244 canvas,
250245 canvas_w,
@@ -264,14 +259,14 @@ pub(crate) fn blit_overlay(
264259/// The caller must ensure `out` has length >= `width * height * 4`.
265260/// Rows are processed in parallel via `rayon`.
266261#[ allow( clippy:: cast_possible_truncation, clippy:: cast_sign_loss) ]
267- pub ( crate ) fn i420_to_rgba8_buf ( data : & [ u8 ] , width : u32 , height : u32 , out : & mut [ u8 ] ) {
262+ pub fn i420_to_rgba8_buf ( data : & [ u8 ] , width : u32 , height : u32 , out : & mut [ u8 ] ) {
268263 use rayon:: prelude:: * ;
269264
270265 let w = width as usize ;
271266 let h = height as usize ;
272267 let y_stride = w;
273- let chroma_w = ( w + 1 ) / 2 ;
274- let chroma_h = ( h + 1 ) / 2 ;
268+ let chroma_w = w . div_ceil ( 2 ) ;
269+ let chroma_h = h . div_ceil ( 2 ) ;
275270 let u_offset = y_stride * h;
276271 let v_offset = u_offset + chroma_w * chroma_h;
277272 let rgba_row_stride = w * 4 ;
@@ -287,9 +282,9 @@ pub(crate) fn i420_to_rgba8_buf(data: &[u8], width: u32, height: u32, out: &mut
287282 let v_base = v_offset + chroma_row * chroma_w;
288283
289284 for col in 0 ..w {
290- let y_val = data[ y_base + col] as i32 ;
291- let u_val = data[ u_base + col / 2 ] as i32 ;
292- let v_val = data[ v_base + col / 2 ] as i32 ;
285+ let y_val = i32 :: from ( data[ y_base + col] ) ;
286+ let u_val = i32 :: from ( data[ u_base + col / 2 ] ) ;
287+ let v_val = i32 :: from ( data[ v_base + col / 2 ] ) ;
293288
294289 let c = y_val - 16 ;
295290 let d = u_val - 128 ;
@@ -309,7 +304,7 @@ pub(crate) fn i420_to_rgba8_buf(data: &[u8], width: u32, height: u32, out: &mut
309304///
310305/// Prefer [`i420_to_rgba8_buf`] with a pooled buffer to avoid per-frame allocation.
311306#[ allow( dead_code, clippy:: cast_possible_truncation, clippy:: cast_sign_loss) ]
312- pub ( crate ) fn i420_to_rgba8 ( data : & [ u8 ] , width : u32 , height : u32 ) -> Vec < u8 > {
307+ pub fn i420_to_rgba8 ( data : & [ u8 ] , width : u32 , height : u32 ) -> Vec < u8 > {
313308 let mut rgba = vec ! [ 0u8 ; width as usize * height as usize * 4 ] ;
314309 i420_to_rgba8_buf ( data, width, height, & mut rgba) ;
315310 rgba
@@ -320,14 +315,14 @@ pub(crate) fn i420_to_rgba8(data: &[u8], width: u32, height: u32) -> Vec<u8> {
320315/// The caller must ensure `out` has length >= `w * h + 2 * ((w+1)/2) * ((h+1)/2)`.
321316/// Y, U and V planes are processed in parallel via `rayon`.
322317#[ allow( clippy:: cast_possible_truncation, clippy:: cast_sign_loss) ]
323- pub ( crate ) fn rgba8_to_i420_buf ( data : & [ u8 ] , width : u32 , height : u32 , out : & mut [ u8 ] ) {
318+ pub fn rgba8_to_i420_buf ( data : & [ u8 ] , width : u32 , height : u32 , out : & mut [ u8 ] ) {
324319 use rayon:: prelude:: * ;
325320
326321 let w = width as usize ;
327322 let h = height as usize ;
328323 let y_stride = w;
329- let chroma_w = ( w + 1 ) / 2 ;
330- let chroma_h = ( h + 1 ) / 2 ;
324+ let chroma_w = w . div_ceil ( 2 ) ;
325+ let chroma_h = h . div_ceil ( 2 ) ;
331326 let y_size = y_stride * h;
332327 let chroma_size = chroma_w * chroma_h;
333328
@@ -341,9 +336,9 @@ pub(crate) fn rgba8_to_i420_buf(data: &[u8], width: u32, height: u32, out: &mut
341336
342337 for col in 0 ..w {
343338 let off = rgba_base + col * 4 ;
344- let r = data[ off] as i32 ;
345- let g = data[ off + 1 ] as i32 ;
346- let b = data[ off + 2 ] as i32 ;
339+ let r = i32 :: from ( data[ off] ) ;
340+ let g = i32 :: from ( data[ off + 1 ] ) ;
341+ let b = i32 :: from ( data[ off + 2 ] ) ;
347342 let y = ( ( 66 * r + 129 * g + 25 * b + 128 ) >> 8 ) + 16 ;
348343 y_row[ col] = y. clamp ( 0 , 255 ) as u8 ;
349344 }
@@ -370,9 +365,9 @@ pub(crate) fn rgba8_to_i420_buf(data: &[u8], width: u32, height: u32, out: &mut
370365 let cc = c0 + dc;
371366 if cc < w {
372367 let off = ( rr * w + cc) * 4 ;
373- sr += data[ off] as i32 ;
374- sg += data[ off + 1 ] as i32 ;
375- sb += data[ off + 2 ] as i32 ;
368+ sr += i32 :: from ( data[ off] ) ;
369+ sg += i32 :: from ( data[ off + 1 ] ) ;
370+ sb += i32 :: from ( data[ off + 2 ] ) ;
376371 count += 1 ;
377372 }
378373 }
@@ -392,11 +387,11 @@ pub(crate) fn rgba8_to_i420_buf(data: &[u8], width: u32, height: u32, out: &mut
392387///
393388/// Prefer [`rgba8_to_i420_buf`] with a pooled buffer to avoid per-frame allocation.
394389#[ allow( dead_code, clippy:: cast_possible_truncation, clippy:: cast_sign_loss) ]
395- pub ( crate ) fn rgba8_to_i420 ( data : & [ u8 ] , width : u32 , height : u32 ) -> Vec < u8 > {
390+ pub fn rgba8_to_i420 ( data : & [ u8 ] , width : u32 , height : u32 ) -> Vec < u8 > {
396391 let w = width as usize ;
397392 let h = height as usize ;
398- let chroma_w = ( w + 1 ) / 2 ;
399- let chroma_h = ( h + 1 ) / 2 ;
393+ let chroma_w = w . div_ceil ( 2 ) ;
394+ let chroma_h = h . div_ceil ( 2 ) ;
400395 let total = w * h + 2 * chroma_w * chroma_h;
401396 let mut out = vec ! [ 0u8 ; total] ;
402397 rgba8_to_i420_buf ( data, width, height, & mut out) ;
0 commit comments