8am cleanup

felt lime it
This commit is contained in:
yellows111 2023-10-18 08:25:42 +01:00
parent 0569aa7b0b
commit 3ee8d20894
3 changed files with 12 additions and 14 deletions

View File

@ -15,6 +15,7 @@ A JavaScript library (sorta) to read PS2 icons, and their related formats.
* Read and parse an EMS MA export file. * Read and parse an EMS MA export file.
* Export the icon model, with all seperate shapes included to a JavaScript Object. * Export the icon model, with all seperate shapes included to a JavaScript Object.
* Node.js compatible (CommonJS) exporting while still being compatible with other JavaScript implementations. * Node.js compatible (CommonJS) exporting while still being compatible with other JavaScript implementations.
* Convert a 128x128x16 BGR5A1 bitmap to a RGB5A1 format.
## What it doesn't do ## What it doesn't do
* (Re)build save files. * (Re)build save files.

19
icon.js
View File

@ -1,7 +1,7 @@
//todo: Make this a module/mjs file. C6 compatibility can stay, if needed. //todo: Make this a module/mjs file. C6 compatibility can stay, if needed.
ICONJS_DEBUG = false; ICONJS_DEBUG = false;
ICONJS_STRICT = true; ICONJS_STRICT = true;
ICONJS_VERSION = "0.4.0"; ICONJS_VERSION = "0.4.1";
function setDebug(value) { function setDebug(value) {
ICONJS_DEBUG = !!value; ICONJS_DEBUG = !!value;
@ -27,7 +27,7 @@ function getTextureFormat(i) {
} }
function uncompressTexture(texData) { function uncompressTexture(texData) {
// for texture formats 8-14 (and maybe 15 but that's being weird) // for texture formats 8-15
if (texData.length & 1) { if (texData.length & 1) {
throw "Texture size isn't a multiple of 2 (was ${texData.length})"; throw "Texture size isn't a multiple of 2 (was ${texData.length})";
} }
@ -35,7 +35,7 @@ function uncompressTexture(texData) {
const u16le = function(i){return view.getUint16(i, 1)} const u16le = function(i){return view.getUint16(i, 1)}
let uncompressed = new Uint16Array(16384); let uncompressed = new Uint16Array(16384);
let offset = 0; let offset = 0;
for (let index = 0; index < 16384; index++) { for (let index = 0; index < 16384;) {
currentValue = u16le(offset); currentValue = u16le(offset);
if(currentValue === 0) { if(currentValue === 0) {
// if this is specifically a katamari 1 or 2 icon, skip this byte // if this is specifically a katamari 1 or 2 icon, skip this byte
@ -45,7 +45,7 @@ function uncompressTexture(texData) {
} }
offset += 2; offset += 2;
if (currentValue >= 0xff00) { if (currentValue >= 0xff00) {
//do a raw copy //do a raw copy of the next currentValue bytes
let length = ((0x10000 - currentValue)); let length = ((0x10000 - currentValue));
for (let enumerator = 0; enumerator < length; enumerator++) { for (let enumerator = 0; enumerator < length; enumerator++) {
uncompressed[index] = u16le(offset); uncompressed[index] = u16le(offset);
@ -53,7 +53,7 @@ function uncompressTexture(texData) {
index++; index++;
} }
} else { } else {
//repeat next byte rleType times //repeat next byte currentValue times
uncompressed[index] = u16le(offset); uncompressed[index] = u16le(offset);
for (let indey = 0; indey < currentValue; indey++) { for (let indey = 0; indey < currentValue; indey++) {
uncompressed[index] = u16le(offset); uncompressed[index] = u16le(offset);
@ -61,7 +61,6 @@ function uncompressTexture(texData) {
} }
offset += 2; offset += 2;
} }
index--;
} }
return uncompressed; return uncompressed;
} }
@ -71,13 +70,11 @@ function convertBGR5A1toRGB5A1(bgrData) {
throw `Not a 128x128x16 texture. (length was ${bgrData.length})`; throw `Not a 128x128x16 texture. (length was ${bgrData.length})`;
} }
// converts 5-bit blue, green, red (in that order) with one alpha bit to GL-compatible RGB5A1 // converts 5-bit blue, green, red (in that order) with one alpha bit to GL-compatible RGB5A1
const view = new DataView(bgrData);
const u16le = function(i){return view.getUint16(i, 1)}
let converted = new Uint16Array(16384); let converted = new Uint16Array(16384);
for (let index = 0; index < 16384; index++) { for (let index = 0; index < 16384; index++) {
let b = ( u16le(index*2) & 0b11111); let b = ( bgrData[index] & 0b11111);
let g = (((u16le(index*2)) >> 5) & 0b11111); let g = ((bgrData[index] >> 5) & 0b11111);
let r = (((u16le(index*2)) >> 10) & 0b11111); let r = ((bgrData[index] >> 10) & 0b11111);
// rrrrrgggggbbbbba (a = 1 because 0 is 127 which is 1.0f opacity for the GS) // rrrrrgggggbbbbba (a = 1 because 0 is 127 which is 1.0f opacity for the GS)
let newValue = 0b0000000000000001; let newValue = 0b0000000000000001;
newValue |= (r << 1); newValue |= (r << 1);

View File

@ -173,9 +173,9 @@
let rgb5a1_converted; let rgb5a1_converted;
if (iconData.textureFormat === "C") { if (iconData.textureFormat === "C") {
let uncompressed = uncompressTexture(iconData.texture.data); let uncompressed = uncompressTexture(iconData.texture.data);
rgb5a1_converted = convertBGR5A1toRGB5A1(uncompressed.buffer); rgb5a1_converted = convertBGR5A1toRGB5A1(uncompressed);
} else { } else {
rgb5a1_converted = convertBGR5A1toRGB5A1(iconData.texture.buffer); rgb5a1_converted = convertBGR5A1toRGB5A1(iconData.texture);
} }
glFgContext.texImage2D(glFgContext.TEXTURE_2D, 0, glFgContext.RGBA, 128, 128, 0, glFgContext.RGBA, glFgContext.UNSIGNED_SHORT_5_5_5_1, rgb5a1_converted); glFgContext.texImage2D(glFgContext.TEXTURE_2D, 0, glFgContext.RGBA, 128, 128, 0, glFgContext.RGBA, glFgContext.UNSIGNED_SHORT_5_5_5_1, rgb5a1_converted);
glFgContext.generateMipmap(glFgContext.TEXTURE_2D); glFgContext.generateMipmap(glFgContext.TEXTURE_2D);
@ -454,6 +454,6 @@
</script> </script>
<span id="version">icondumper2 <span id="iconjsVersion">(unknown icon.js version)</span> [C: <span id="clientVersion">Loading...</span>] - &copy; 2023 yellows111</span> <span id="version">icondumper2 <span id="iconjsVersion">(unknown icon.js version)</span> [C: <span id="clientVersion">Loading...</span>] - &copy; 2023 yellows111</span>
<script>document.getElementById("iconjsVersion").textContent = ICONJS_VERSION;</script> <script>document.getElementById("iconjsVersion").textContent = ICONJS_VERSION;</script>
<script>document.getElementById("clientVersion").textContent = "0.5.1";</script> <script>document.getElementById("clientVersion").textContent = "0.5.2";</script>
</body> </body>
</html> </html>