@@ -176,14 +176,16 @@ pub fn decode_bgra4444(data: &mut [u8], width: usize, height: usize) -> Box<[u8]
176176}
177177
178178#[ wasm_bindgen]
179- pub fn decode_normalizedbyte2 ( data : & mut [ u8 ] , width : usize , height : usize ) -> Box < [ u8 ] > {
179+ pub fn decode_rgba5551 ( data : & mut [ u8 ] , width : usize , height : usize ) -> Box < [ u8 ] > {
180180 let mut out = Vec :: new ( ) ;
181- out. resize ( width * height * 4 , 0 ) ;
182181 for i in 0 ..( width * height) {
183- out[ i * 4 ] = data[ i * 2 ] ;
184- out[ i * 4 + 1 ] = data[ i * 2 ] ;
185- out[ i * 4 + 2 ] = data[ i * 2 ] ;
186- out[ i * 4 + 3 ] = data[ i * 2 + 1 ] ;
182+ let color = u16:: from_le_bytes ( [ data[ i * 2 ] , data[ i * 2 + 1 ] ] ) ;
183+ out. write_all ( & [
184+ ( ( color & 0x001F ) << 3 ) as u8 ,
185+ ( ( color & 0x03E0 ) >> 2 ) as u8 ,
186+ ( ( color & 0x7C00 ) >> 7 ) as u8 ,
187+ ( if ( color & 0x8000 ) == 0x8000 { 0xff } else { 0x00 } ) as u8
188+ ] ) . expect ( "rgba5551" ) ;
187189 }
188190 out. into ( )
189191}
@@ -265,6 +267,22 @@ pub fn decode_rghalf(data: &mut [u8], width: usize, height: usize) -> Box<[u8]>
265267 out. into ( )
266268}
267269
270+ #[ wasm_bindgen]
271+ pub fn decode_rgbhalf ( data : & mut [ u8 ] , width : usize , height : usize ) -> Box < [ u8 ] > {
272+ let mut out = Vec :: new ( ) ;
273+ for i in 0 ..( width * height) {
274+ let r = ( ( data[ i * 6 + 1 ] as u16 ) << 8 ) | ( data[ i * 6 ] as u16 ) ;
275+ let g = ( ( data[ i * 6 + 3 ] as u16 ) << 8 ) | ( data[ i * 6 + 2 ] as u16 ) ;
276+ let b = ( ( data[ i * 6 + 5 ] as u16 ) << 8 ) | ( data[ i * 6 + 4 ] as u16 ) ;
277+ out. write_all ( & [
278+ ( fp16_ieee_to_fp32_value ( r) * 255.0 ) as u8 ,
279+ ( fp16_ieee_to_fp32_value ( g) * 255.0 ) as u8 ,
280+ ( fp16_ieee_to_fp32_value ( b) * 255.0 ) as u8 ,
281+ ] ) . expect ( "rgbhalf" ) ;
282+ }
283+ out. into ( )
284+ }
285+
268286#[ wasm_bindgen]
269287pub fn decode_rgbahalf ( data : & mut [ u8 ] , width : usize , height : usize ) -> Box < [ u8 ] > {
270288 let mut out = Vec :: new ( ) ;
@@ -278,7 +296,7 @@ pub fn decode_rgbahalf(data: &mut [u8], width: usize, height: usize) -> Box<[u8]
278296 ( fp16_ieee_to_fp32_value ( g) * 255.0 ) as u8 ,
279297 ( fp16_ieee_to_fp32_value ( b) * 255.0 ) as u8 ,
280298 ( fp16_ieee_to_fp32_value ( a) * 255.0 ) as u8 ,
281- ] ) . expect ( "rghalf " ) ;
299+ ] ) . expect ( "rgbahalf " ) ;
282300 }
283301 out. into ( )
284302}
@@ -311,6 +329,19 @@ pub fn decode_rgfloat(data: &mut [u8], width: usize, height: usize) -> Box<[u8]>
311329 out. into ( )
312330}
313331
332+ #[ wasm_bindgen]
333+ pub fn decode_rgbfloat ( data : & mut [ u8 ] , width : usize , height : usize ) -> Box < [ u8 ] > {
334+ let mut out = Vec :: new ( ) ;
335+ for i in 0 ..( width * height) {
336+ out. write_all ( & [
337+ f32:: from_le_bytes ( [ data[ i * 12 ] , data[ i * 12 + 1 ] , data[ i * 12 + 2 ] , data[ i * 12 + 3 ] ] ) as u8 ,
338+ f32:: from_le_bytes ( [ data[ i * 12 + 4 ] , data[ i * 12 + 5 ] , data[ i * 12 + 6 ] , data[ i * 12 + 7 ] ] ) as u8 ,
339+ f32:: from_le_bytes ( [ data[ i * 12 + 8 ] , data[ i * 12 + 9 ] , data[ i * 12 + 10 ] , data[ i * 12 + 11 ] ] ) as u8 ,
340+ ] ) . expect ( "rgbfloat" ) ;
341+ }
342+ out. into ( )
343+ }
344+
314345#[ wasm_bindgen]
315346pub fn decode_rgbafloat ( data : & mut [ u8 ] , width : usize , height : usize ) -> Box < [ u8 ] > {
316347 let mut out = Vec :: new ( ) ;
@@ -408,6 +439,32 @@ pub fn decode_r8(data: &mut [u8], width: usize, height: usize) -> Box<[u8]> {
408439 out. into ( )
409440}
410441
442+ #[ wasm_bindgen]
443+ pub fn decode_l8 ( data : & mut [ u8 ] , width : usize , height : usize ) -> Box < [ u8 ] > {
444+ let mut out = Vec :: new ( ) ;
445+ out. resize ( width * height * 4 , 0 ) ;
446+ for i in 0 ..( width * height) {
447+ out[ i * 4 ] = data[ i] ;
448+ out[ i * 4 + 1 ] = data[ i] ;
449+ out[ i * 4 + 2 ] = data[ i] ;
450+ out[ i * 4 + 3 ] = 0xff ;
451+ }
452+ out. into ( )
453+ }
454+
455+ #[ wasm_bindgen]
456+ pub fn decode_la16 ( data : & mut [ u8 ] , width : usize , height : usize ) -> Box < [ u8 ] > {
457+ let mut out = Vec :: new ( ) ;
458+ out. resize ( width * height * 4 , 0 ) ;
459+ for i in 0 ..( width * height) {
460+ out[ i * 4 ] = data[ i * 2 ] ;
461+ out[ i * 4 + 1 ] = data[ i * 2 ] ;
462+ out[ i * 4 + 2 ] = data[ i * 2 ] ;
463+ out[ i * 4 + 3 ] = data[ i * 2 + 1 ] ;
464+ }
465+ out. into ( )
466+ }
467+
411468#[ wasm_bindgen]
412469pub fn decode_rg32 ( data : & mut [ u8 ] , width : usize , height : usize ) -> Box < [ u8 ] > {
413470 let mut out = Vec :: new ( ) ;
@@ -617,58 +674,74 @@ pub fn decode(format: &str, data: &mut [u8], width: usize, height: usize, is_xbo
617674 if is_xbox { swap_bytes_xbox ( data) } ;
618675 decode_rgb565 ( data, width, height)
619676 } ,
620- "R16" => decode_r16 ( data, width, height) ,
621- "DXT1" => {
622- if is_xbox { swap_bytes_xbox ( data) } ;
623- decode_dxt1 ( data, width, height)
624- } ,
625- "DXT3" => {
626- decode_dxt3 ( data, width, height)
627- } ,
628- "DXT5" => {
629- if is_xbox { swap_bytes_xbox ( data) } ;
630- decode_dxt5 ( data, width, height)
631- } ,
632- "RGBA4444" => {
633- decode_rgba4444 ( data, width, height)
634- } ,
677+ "RGBA4444" => decode_rgba4444 ( data, width, height) ,
678+ "RGBA5551" => decode_rgba5551 ( data, width, height) ,
635679 "BGRA32" => decode_bgra32 ( data, width, height) ,
680+
636681 "RHalf" => decode_rhalf ( data, width, height) ,
637682 "RGHalf" => decode_rghalf ( data, width, height) ,
683+ "RGBHalf" => decode_rgbhalf ( data, width, height) ,
638684 "RGBAHalf" => decode_rgbahalf ( data, width, height) ,
685+
639686 "RFloat" => decode_rfloat ( data, width, height) ,
640687 "RGFloat" => decode_rgfloat ( data, width, height) ,
688+ "RGBFloat" => decode_rgbfloat ( data, width, height) ,
641689 "RGBAFloat" => decode_rgbafloat ( data, width, height) ,
690+
642691 "YUY2" => decode_yuy2 ( data, width, height) ,
692+
643693 "RGB9e5Float" => decode_rgb9e5float ( data, width, height) ,
694+
644695 "BC6H" => decode_bc6h ( data, width, height) ,
645696 "BC7" => decode_bc7 ( data, width, height) ,
646697 "BC4" => decode_bc4 ( data, width, height) ,
647698 "BC5" => decode_bc5 ( data, width, height) ,
699+
700+ "DXT1" => {
701+ if is_xbox { swap_bytes_xbox ( data) } ;
702+ decode_dxt1 ( data, width, height)
703+ } ,
704+ "DXT3" => {
705+ decode_dxt3 ( data, width, height)
706+ } ,
707+ "DXT5" => {
708+ if is_xbox { swap_bytes_xbox ( data) } ;
709+ decode_dxt5 ( data, width, height)
710+ } ,
648711 "DXT1Crunched" => decode_dxt1 ( data, width, height) ,
649712 "DXT5Crunched" => decode_dxt5 ( data, width, height) ,
713+
650714 "PVRTC_RGB2" | "PVRTC_RGBA2" => decode_pvrtc ( data, width, height, true ) ,
651715 "PVRTC_RGB4" | "PVRTC_RGBA4" => decode_pvrtc ( data, width, height, false ) ,
652- "ETC_RGB4" | "ETC_RGB4_3DS" => decode_etc1 ( data , width , height ) ,
716+
653717 "ATC_RGB4" => decode_atc_rgb4 ( data, width, height) ,
654718 "ATC_RGBA8" => decode_atc_rgba8 ( data, width, height) ,
719+
655720 "EAC_R" => decode_eacr ( data, width, height) ,
656721 "EAC_R_SIGNED" => decode_eacr_signed ( data, width, height) ,
657722 "EAC_RG" => decode_eacrg ( data, width, height) ,
658723 "EAC_RG_SIGNED" => decode_eacrg_signed ( data, width, height) ,
724+
725+ "ETC_RGB4" | "ETC_RGB4_3DS" => decode_etc1 ( data, width, height) ,
659726 "ETC2_RGB" => decode_etc2 ( data, width, height) ,
660727 "ETC2_RGBA1" => decode_etc2_a1 ( data, width, height) ,
661728 "ETC2_RGBA8" | "ETC2_RGBA8_3DS" => decode_etc2_a8 ( data, width, height) ,
729+ "ETC_RGB4Crunched" => decode_etc1 ( data, width, height) ,
730+ "ETC_RGBA8Crunched" => decode_etc2_a8 ( data, width, height) ,
731+
662732 "ASTC_RGB_4x4" | "ASTC_RGBA_4x4" | "ASTC_HDR_4x4" => decode_astc ( data, width, height, 4 , 4 ) ,
663733 "ASTC_RGB_5x5" | "ASTC_RGBA_5x5" | "ASTC_HDR_5x5" => decode_astc ( data, width, height, 5 , 5 ) ,
664734 "ASTC_RGB_6x6" | "ASTC_RGBA_6x6" | "ASTC_HDR_6x6" => decode_astc ( data, width, height, 6 , 6 ) ,
665735 "ASTC_RGB_8x8" | "ASTC_RGBA_8x8" | "ASTC_HDR_8x8" => decode_astc ( data, width, height, 8 , 8 ) ,
666736 "ASTC_RGB_10x10" | "ASTC_RGBA_10x10" | "ASTC_HDR_10x10" => decode_astc ( data, width, height, 10 , 10 ) ,
667737 "ASTC_RGB_12x12" | "ASTC_RGBA_12x12" | "ASTC_HDR_12x12" => decode_astc ( data, width, height, 12 , 12 ) ,
668- "RG16" => decode_rg16 ( data, width, height) ,
738+
739+ "L8" => decode_l8 ( data, width, height) ,
740+ "LA16" => decode_la16 ( data, width, height) ,
741+
669742 "R8" => decode_r8 ( data, width, height) ,
670- "ETC_RGB4Crunched " => decode_etc1 ( data, width, height) ,
671- "ETC_RGBA8Crunched " => decode_etc2_a8 ( data, width, height) ,
743+ "R16 " => decode_r16 ( data, width, height) ,
744+ "RG16 " => decode_rg16 ( data, width, height) ,
672745 "RG32" => decode_rg32 ( data, width, height) ,
673746 "RGB48" => decode_rgb48 ( data, width, height) ,
674747 "RGBA64" => decode_rgba64 ( data, width, height) ,
0 commit comments