mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
21 lines
647 B
TypeScript
21 lines
647 B
TypeScript
import { existsSync } from 'fs';
|
|||
|
|
import { readDVPLFile } from '../blitz/readDVPLFile';
|
||
|
|
import { ToJpgOptions, toJpg } from './toJpg';
|
||
|
|
|
||
|
|
export async function readTexture(
|
||
|
|
path: string,
|
||
|
|
options?: Partial<Omit<ToJpgOptions, 'format'>>,
|
||
|
|
) {
|
||
|
|
const ddsTexturePath = path.replace('.tex', '.dx11.dds.dvpl');
|
||
|
|
const isDds = existsSync(ddsTexturePath);
|
||
|
|
const resolvedTexturePath = isDds
|
||
|
|
? ddsTexturePath
|
||
|
|
: ddsTexturePath.replace('.dds', '.pvr');
|
||
|
|
const decompressedTexture = await readDVPLFile(resolvedTexturePath);
|
||
|
|
const jpg = await toJpg(decompressedTexture, {
|
||
|
|
...options,
|
||
|
|
format: isDds ? 'dds' : 'pvr',
|
||
|
|
});
|
||
|
|
|
||
|
|
return jpg;
|
||
|
|
}
|