@@ -574,17 +574,22 @@ mod swizzle {
574574 // https://github.com/tge-was-taken/GFD-Studio/blob/dad6c2183a6ec0716c3943b71991733bfbd4649d/GFDLibrary/Textures/Swizzle/PS4SwizzleAlgorithm.cs#L20
575575 fn do_swizzle (
576576 source : & [ u8 ] ,
577- destination : & mut Vec < u8 > ,
577+ destination : & mut [ u8 ] ,
578578 width : usize ,
579579 height : usize ,
580580 block_size : usize ,
581581 pixel_block_size : usize ,
582582 unswizzle : bool ,
583583 ) {
584- destination. resize ( source. len ( ) , 0 ) ;
585- let width_texels = width / pixel_block_size;
584+ let width_pow2 = width. next_power_of_two ( ) ;
585+ let height_pow2 = height. next_power_of_two ( ) ;
586+
587+ let width_texels_dest = width / pixel_block_size;
588+ let height_texels_dest = height / pixel_block_size;
589+
590+ let width_texels = width_pow2 / pixel_block_size;
586591 let width_texels_aligned = ( width_texels + 7 ) / 8 ;
587- let height_texels = height / pixel_block_size;
592+ let height_texels = height_pow2 / pixel_block_size;
588593 let height_texels_aligned = ( height_texels + 7 ) / 8 ;
589594 let mut data_index = 0 ;
590595
@@ -597,8 +602,8 @@ mod swizzle {
597602 let x_offset = ( x * 8 ) + rem;
598603 let y_offset = ( y * 8 ) + div;
599604
600- if x_offset < width_texels && y_offset < height_texels {
601- let dest_pixel_index = y_offset * width_texels + x_offset;
605+ if x_offset < width_texels_dest && y_offset < height_texels_dest {
606+ let dest_pixel_index = y_offset * width_texels_dest + x_offset;
602607 let dest_index = block_size * dest_pixel_index;
603608 let ( src, dst) = if unswizzle {
604609 ( data_index, dest_index)
@@ -624,6 +629,7 @@ mod swizzle {
624629 block_size : usize ,
625630 pixel_block_size : usize ,
626631 ) {
632+ destination. resize ( source. len ( ) , 0 ) ;
627633 do_swizzle (
628634 source,
629635 destination,
0 commit comments