88#![ allow( clippy:: cast_possible_truncation) ]
99#![ allow( clippy:: cast_possible_wrap) ]
1010
11+ use core:: ffi:: { c_char, c_int, c_uint, c_void} ;
12+ use core:: mem:: { ManuallyDrop , MaybeUninit } ;
13+ use core:: { mem, ptr, slice} ;
1114use imagequant:: capi:: * ;
1215use imagequant:: Error :: LIQ_OK ;
1316use imagequant:: * ;
1417use std:: ffi:: CString ;
15- use std:: mem:: { ManuallyDrop , MaybeUninit } ;
16- use std:: os:: raw:: { c_char, c_int, c_uint, c_void} ;
17- use std:: ptr;
1818
1919pub use imagequant:: Error as liq_error;
2020
@@ -191,9 +191,9 @@ pub unsafe extern "C" fn liq_result_set_progress_callback(result: &mut liq_resul
191191
192192#[ allow( clippy:: cast_ptr_alignment) ]
193193unsafe fn attr_to_liq_attr_ptr ( ptr : & Attributes ) -> & liq_attr {
194- let liq_attr = std :: ptr:: NonNull :: < liq_attr > :: dangling ( ) ;
195- let outer_addr = std :: ptr:: addr_of!( * liq_attr. as_ptr( ) ) as isize ;
196- let inner_addr = std :: ptr:: addr_of!( ( * liq_attr. as_ptr( ) ) . inner) as isize ;
194+ let liq_attr = ptr:: NonNull :: < liq_attr > :: dangling ( ) ;
195+ let outer_addr = ptr:: addr_of!( * liq_attr. as_ptr( ) ) as isize ;
196+ let inner_addr = ptr:: addr_of!( ( * liq_attr. as_ptr( ) ) . inner) as isize ;
197197
198198 & * ( ptr as * const Attributes ) . cast :: < u8 > ( ) . offset ( outer_addr - inner_addr) . cast :: < liq_attr > ( )
199199}
@@ -304,7 +304,7 @@ pub unsafe extern "C" fn liq_write_remapped_image(result: &mut liq_result, input
304304
305305 let required_size = ( input_image. width ( ) ) * ( input_image. height ( ) ) ;
306306 if buffer_size < required_size { return Error :: BufferTooSmall ; }
307- let buffer_bytes = std :: slice:: from_raw_parts_mut ( buffer_bytes, required_size) ;
307+ let buffer_bytes = slice:: from_raw_parts_mut ( buffer_bytes, required_size) ;
308308 liq_write_remapped_image_impl ( result, input_image, buffer_bytes) . err ( ) . unwrap_or ( LIQ_OK )
309309}
310310
@@ -317,7 +317,7 @@ pub unsafe extern "C" fn liq_write_remapped_image_rows(result: &mut liq_result,
317317 let result = & mut result. inner ;
318318
319319 if liq_received_invalid_pointer ( row_pointers. cast ( ) ) { return Error :: InvalidPointer ; }
320- let rows = std :: slice:: from_raw_parts_mut ( row_pointers, input_image. height ( ) ) ;
320+ let rows = slice:: from_raw_parts_mut ( row_pointers, input_image. height ( ) ) ;
321321
322322 liq_write_remapped_image_rows_impl ( result, input_image, rows) . err ( ) . unwrap_or ( LIQ_OK )
323323}
@@ -378,7 +378,7 @@ pub unsafe extern "C" fn liq_image_set_importance_map(img: &mut liq_image, impor
378378 return Error :: BufferTooSmall ;
379379 }
380380
381- let importance_map_slice = std :: slice:: from_raw_parts ( importance_map, required_size) ;
381+ let importance_map_slice = slice:: from_raw_parts ( importance_map, required_size) ;
382382 if ownership == liq_ownership:: LIQ_COPY_PIXELS {
383383 img. set_importance_map ( importance_map_slice) . err ( ) . unwrap_or ( LIQ_OK )
384384 } else if ownership == liq_ownership:: LIQ_OWN_PIXELS {
@@ -430,7 +430,7 @@ pub extern "C" fn liq_attr_create_with_allocator(_unused: *mut c_void, free: uns
430430 inner : Attributes :: new ( ) ,
431431 c_api_free : free,
432432 } ) ;
433- debug_assert_eq ! ( std :: ptr:: addr_of!( * attr) , unsafe { attr_to_liq_attr_ptr( & attr. inner) } as * const liq_attr) ;
433+ debug_assert_eq ! ( ptr:: addr_of!( * attr) , unsafe { attr_to_liq_attr_ptr( & attr. inner) } as * const liq_attr) ;
434434 Some ( attr)
435435}
436436
@@ -561,7 +561,7 @@ pub unsafe extern "C" fn liq_result_from_palette(
561561 }
562562
563563 let attr = & attr. inner ;
564- let palette = std :: slice:: from_raw_parts ( palette, palette_size) ;
564+ let palette = slice:: from_raw_parts ( palette, palette_size) ;
565565
566566 let res = QuantizationResult :: from_palette ( attr, palette, gamma) . map ( |inner| liq_result {
567567 magic_header : LIQ_RESULT_MAGIC ,
@@ -585,9 +585,9 @@ pub(crate) fn check_image_size(attr: &liq_attr, width: u32, height: u32) -> bool
585585 return false ;
586586 }
587587
588- if width as usize > c_int:: MAX as usize / std :: mem:: size_of :: < liq_color > ( ) / height as usize ||
589- width as usize > c_int:: MAX as usize / 16 / std :: mem:: size_of :: < f32 > ( ) ||
590- height as usize > c_int:: MAX as usize / std :: mem:: size_of :: < usize > ( )
588+ if width as usize > c_int:: MAX as usize / mem:: size_of :: < liq_color > ( ) / height as usize ||
589+ width as usize > c_int:: MAX as usize / 16 / mem:: size_of :: < f32 > ( ) ||
590+ height as usize > c_int:: MAX as usize / mem:: size_of :: < usize > ( )
591591 {
592592 return false ;
593593 }
@@ -612,7 +612,7 @@ pub unsafe extern "C" fn liq_image_create_custom(attr: &liq_attr, row_callback:
612612pub unsafe extern "C" fn liq_image_create_rgba_rows < ' rows > ( attr : & liq_attr , rows : * const * const RGBA , width : c_uint , height : c_uint , gamma : f64 ) -> Option < Box < liq_image < ' rows > > > {
613613 if !check_image_size ( attr, width, height) { return None ; }
614614 if rows. is_null ( ) { return None ; }
615- let rows = std :: slice:: from_raw_parts ( rows, height as _ ) ;
615+ let rows = slice:: from_raw_parts ( rows, height as _ ) ;
616616 liq_image_create_rgba_rows_impl ( & attr. inner , rows, width as _ , height as _ , gamma)
617617 . map ( move |inner| Box :: new ( liq_image {
618618 magic_header : LIQ_IMAGE_MAGIC ,
@@ -651,7 +651,7 @@ pub unsafe extern "C" fn liq_histogram_add_colors(input_hist: &mut liq_histogram
651651
652652 if liq_received_invalid_pointer ( entries. cast ( ) ) { return Error :: InvalidPointer ; }
653653
654- let entries = std :: slice:: from_raw_parts ( entries, num_entries) ;
654+ let entries = slice:: from_raw_parts ( entries, num_entries) ;
655655
656656 input_hist. add_colors ( entries, gamma) . err ( ) . unwrap_or ( LIQ_OK )
657657}
@@ -678,7 +678,6 @@ pub unsafe extern "Rust" fn liq_executing_user_callback(callback: liq_image_get_
678678
679679#[ test]
680680fn links_and_runs ( ) {
681- use std:: ptr;
682681 unsafe {
683682 assert ! ( liq_version( ) >= 40000 ) ;
684683 let attr = liq_attr_create ( ) . unwrap ( ) ;
@@ -701,7 +700,6 @@ fn links_and_runs() {
701700#[ test]
702701#[ allow( deprecated) ]
703702fn link_every_symbol ( ) {
704- use std:: os:: raw:: c_void;
705703
706704 let x = liq_attr_create as * const c_void as usize
707705 + liq_attr_create_with_allocator as * const c_void as usize
@@ -757,8 +755,6 @@ fn link_every_symbol() {
757755
758756#[ test]
759757fn c_callback_test_c ( ) {
760- use std:: mem:: MaybeUninit ;
761-
762758 let mut called = 0 ;
763759 let mut res = unsafe {
764760 let mut a = liq_attr_create ( ) . unwrap ( ) ;
@@ -772,17 +768,15 @@ fn c_callback_test_c() {
772768 let user_data = user_data. 0 . cast :: < i32 > ( ) ;
773769 * user_data += 1 ;
774770 }
775- let mut img = liq_image_create_custom ( & a, get_row, AnySyncSendPtr ( std :: ptr:: addr_of_mut!( called) . cast :: < c_void > ( ) ) , 123 , 5 , 0. ) . unwrap ( ) ;
771+ let mut img = liq_image_create_custom ( & a, get_row, AnySyncSendPtr ( ptr:: addr_of_mut!( called) . cast :: < c_void > ( ) ) , 123 , 5 , 0. ) . unwrap ( ) ;
776772 liq_quantize_image ( & mut a, & mut img) . unwrap ( )
777773 } ;
778774 assert ! ( called > 5 && called < 50 ) ;
779775 let pal = liq_get_palette ( & mut res) . unwrap ( ) ;
780776 assert_eq ! ( 123 , pal. count) ;
781777}
782778
783-
784-
785779#[ test]
786780fn ownership_bitflags ( ) {
787- assert_eq ! ( 4 + 16 , ( liq_ownership:: LIQ_OWN_ROWS | liq_ownership:: LIQ_COPY_PIXELS ) . bits( ) ) ;
781+ assert_eq ! ( 4 + 16 , ( liq_ownership:: LIQ_OWN_ROWS | liq_ownership:: LIQ_COPY_PIXELS ) . bits( ) ) ;
788782}
0 commit comments