Skip to content

Commit 722e1cb

Browse files
committed
more godot support
1 parent a21ee7a commit 722e1cb

26 files changed

Lines changed: 704 additions & 85 deletions

css/sheet.png

4.07 KB
Loading

css/tree.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
background-position: -72px 0 !important;
2323
}
2424

25+
.icon-dir {
26+
background-image: url('/css/sheet.png') !important;
27+
background-size: 192px 192px;
28+
background-position: -96px 0 !important;
29+
}
30+
2531
.icon-object {
2632
background-image: url('/css/sheet.png') !important;
2733
background-size: 192px 192px;

encoders/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mod utils;
2-
mod pngenc;
3-
mod texdec;
4-
mod fp16;
5-
mod compress;
1+
pub mod utils;
2+
pub mod pngenc;
3+
pub mod texdec;
4+
pub mod fp16;
5+
pub mod compress;

encoders/src/texdec.rs

Lines changed: 99 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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]
269287
pub 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]
315346
pub 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]
412469
pub 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),

encoders/tests/web.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
//! Test suite for the Web and headless browsers.
21

3-
#![cfg(target_arch = "wasm32")]
4-
5-
extern crate wasm_bindgen_test;
62
use wasm_bindgen_test::*;
3+
use encoders::*;
74

8-
wasm_bindgen_test_configure!(run_in_browser);
5+
#[wasm_bindgen_test]
6+
fn test_swap() {
7+
let mut test_data = [0u8, 1, 2, 3, 4, 5, 6, 7];
8+
texdec::swap_bytes_xbox(&mut test_data);
9+
assert_eq!(test_data, [1u8, 0, 3, 2, 5, 4, 7, 6]);
10+
}
911

1012
#[wasm_bindgen_test]
11-
fn pass() {
12-
assert_eq!(1 + 1, 2);
13+
fn test_bgr2rgb() {
14+
let mut test_data = [128u8, 0, 64, 255, 64, 0, 128, 255, 32, 0, 32, 255];
15+
texdec::bgr2rgb(&mut test_data);
16+
assert_eq!(test_data, [64u8, 0, 128, 255, 128, 0, 64, 255, 32, 0, 32, 255]);
1317
}

js/encoders/encoders.d.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function decode_bgra4444(data: Uint8Array, width: number, height: number)
7575
* @param {number} height
7676
* @returns {Uint8Array}
7777
*/
78-
export function decode_normalizedbyte2(data: Uint8Array, width: number, height: number): Uint8Array;
78+
export function decode_rgba5551(data: Uint8Array, width: number, height: number): Uint8Array;
7979
/**
8080
* @param {Uint8Array} data
8181
* @param {number} width
@@ -117,6 +117,13 @@ export function decode_rghalf(data: Uint8Array, width: number, height: number):
117117
* @param {number} height
118118
* @returns {Uint8Array}
119119
*/
120+
export function decode_rgbhalf(data: Uint8Array, width: number, height: number): Uint8Array;
121+
/**
122+
* @param {Uint8Array} data
123+
* @param {number} width
124+
* @param {number} height
125+
* @returns {Uint8Array}
126+
*/
120127
export function decode_rgbahalf(data: Uint8Array, width: number, height: number): Uint8Array;
121128
/**
122129
* @param {Uint8Array} data
@@ -138,6 +145,13 @@ export function decode_rgfloat(data: Uint8Array, width: number, height: number):
138145
* @param {number} height
139146
* @returns {Uint8Array}
140147
*/
148+
export function decode_rgbfloat(data: Uint8Array, width: number, height: number): Uint8Array;
149+
/**
150+
* @param {Uint8Array} data
151+
* @param {number} width
152+
* @param {number} height
153+
* @returns {Uint8Array}
154+
*/
141155
export function decode_rgbafloat(data: Uint8Array, width: number, height: number): Uint8Array;
142156
/**
143157
* @param {Uint8Array} data
@@ -173,6 +187,20 @@ export function decode_r8(data: Uint8Array, width: number, height: number): Uint
173187
* @param {number} height
174188
* @returns {Uint8Array}
175189
*/
190+
export function decode_l8(data: Uint8Array, width: number, height: number): Uint8Array;
191+
/**
192+
* @param {Uint8Array} data
193+
* @param {number} width
194+
* @param {number} height
195+
* @returns {Uint8Array}
196+
*/
197+
export function decode_la16(data: Uint8Array, width: number, height: number): Uint8Array;
198+
/**
199+
* @param {Uint8Array} data
200+
* @param {number} width
201+
* @param {number} height
202+
* @returns {Uint8Array}
203+
*/
176204
export function decode_rg32(data: Uint8Array, width: number, height: number): Uint8Array;
177205
/**
178206
* @param {Uint8Array} data

0 commit comments

Comments
 (0)