Skip to content

Commit 8264ed1

Browse files
committed
Update fximg.helper.ts, test.ts
1 parent 6ee9bd0 commit 8264ed1

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

fximg.helper.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ signture mismatch:
199199
}
200200

201201
function fximgHeaderCheck(fximg: Fximg) {
202+
if (!fximgValidate) return;
202203
if (fximgIsValidHeader(fximg)) return;
203204
const hash = fximgMakeHeaderHash(fximg)
204205
fximgHashAlert((fximg as Buffer)[0], hash)
@@ -287,23 +288,21 @@ signture mismatch:
287288
if (idxType < 0x0 || idxType > 0x3) return { idx: -1, b2: -1 }
288289
header &= 0xff;
289290
let idx = 3, b2 = 0;
290-
if (idxType >= 0x0) {
291-
b2 = (header >> 4);
292-
b2 &= 0x3;
293-
if (idxType > 0x0) idx += (1 << b2);
294-
}
295-
if (idxType >= 0x1) {
296-
b2 = (header >> 2);
291+
for (let i = 0; i <= idxType; i++) {
292+
if (i >= 0x3) break;
293+
b2 = (header >> (i * 2));
297294
b2 &= 0x3;
298-
if (idxType > 0x1) idx += (1 << b2);
299-
}
300-
if (idxType >= 0x2) {
301-
b2 = (header);
302-
b2 &= 0x3;
303-
if (idxType > 0x2) idx += (1 << b2);
295+
if (i < idxType) idx += (1 << b2)
304296
}
305297
return { idx: idx, b2: b2 }
306298
}
299+
export function fximgGetHeaderData(header: number, idxType: FximgDataIdx) {
300+
header &= 0xff;
301+
if (idxType >= 3) return -1;
302+
let b2 = (header >> ((2 - idxType) * 2));
303+
b2 &= 0x3
304+
return b2;
305+
}
307306
export function fximgGetIndex(fximg: Fximg, idxType: FximgDataIdx) {
308307
return fximgGetOffsetUtils((fximg as Buffer)[1], (fximg as Buffer)[0], idxType);
309308
}
@@ -319,7 +318,8 @@ signture mismatch:
319318
return;
320319
}
321320
if (dataType >= 0x3) return;
322-
const { idx, b2 } = fximgGetOffsetUtils((fximg as Buffer)[1], (fximg as Buffer)[0], dataType);
321+
const idx = fximgGetOffset(fximg, dataType);
322+
const b2 = fximgGetHeaderData((fximg as Buffer)[1], dataType)
323323
if (idx < 0 || b2 < 0) return;
324324
if (b2 === 0x2) {
325325
if (v > 0xffffffff) v = 0xffffffff;
@@ -335,7 +335,8 @@ signture mismatch:
335335
}
336336
export function fximgGetData(fximg: Fximg, dataType: FximgDataIdx) {
337337
fximgValidation(fximg);
338-
const { idx, b2 } = fximgGetOffsetUtils((fximg as Buffer)[1], (fximg as Buffer)[0], dataType);
338+
const idx = fximgGetOffset(fximg, dataType);
339+
const b2 = fximgGetHeaderData((fximg as Buffer)[1], dataType);
339340
if (idx < 0 || b2 < 0) return -1;
340341
if (dataType >= 0x3) return idx;
341342
if (b2 >= 0x3) return -1;

test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ game.onUpdate(() => {
4444
randint(0, w - 1), randint(10, h - 1),
4545
randint(0x0, 0xf)
4646
);
47-
if (0) fximg.drawTransDistortedImage(imgfxb, imgfxa,
47+
if (1) fximg.drawTransDistortedImage(imgfxb, imgfxa,
4848
randint(0, w - 1), randint(10, h - 1),
4949
randint(0, w - 1), randint(10, h - 1),
5050
randint(0, w - 1), randint(10, h - 1),
5151
randint(0, w - 1), randint(10, h - 1),
5252
);
53-
if (1) fximg.fillTriangle(imgfxb,
53+
if (0) fximg.fillTriangle(imgfxb,
5454
randint(0, w - 1), randint(10, h - 1),
5555
randint(0, w - 1), randint(10, h - 1),
5656
randint(0, w - 1), randint(10, h - 1),

0 commit comments

Comments
 (0)