mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
fix: remove extreme jpeg compression
This commit is contained in:
1 parent
4122ff5bf1
commit
5e0d0a3d6d
1 file changed
+8
-16
@@ -1,14 +1,9 @@
|
|||||||
import { DdsReadStream, PvrReadStream } from '@blitzkit/core';
|
import { DdsReadStream, PvrReadStream } from '@blitzkit/core';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import sharp, { JpegOptions } from 'sharp';
|
import sharp from 'sharp';
|
||||||
import { readDVPLFile } from '../readDVPLFile';
|
import { readDVPLFile } from '../readDVPLFile';
|
||||||
import { TextureMutation } from './constants';
|
import { TextureMutation } from './constants';
|
||||||
|
|
||||||
const jpegOptions: JpegOptions = {
|
|
||||||
quality: 20,
|
|
||||||
mozjpeg: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function readTexture(path: string, mutation?: TextureMutation) {
|
export async function readTexture(path: string, mutation?: TextureMutation) {
|
||||||
const ddsTexturePath = path.replace('.tex', '.dx11.dds.dvpl');
|
const ddsTexturePath = path.replace('.tex', '.dx11.dds.dvpl');
|
||||||
const isDds = existsSync(ddsTexturePath);
|
const isDds = existsSync(ddsTexturePath);
|
||||||
@@ -40,7 +35,7 @@ export async function readTexture(path: string, mutation?: TextureMutation) {
|
|||||||
raw.data[index + 3] = 255;
|
raw.data[index + 3] = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await sharp(raw.data, { raw }).jpeg(jpegOptions).toBuffer();
|
return await sharp(raw.data, { raw }).jpeg().toBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
case TextureMutation.RoughnessMetallicness: {
|
case TextureMutation.RoughnessMetallicness: {
|
||||||
@@ -49,16 +44,16 @@ export async function readTexture(path: string, mutation?: TextureMutation) {
|
|||||||
});
|
});
|
||||||
const metallicness = sharp(raw.data, { raw })
|
const metallicness = sharp(raw.data, { raw })
|
||||||
.extractChannel('green')
|
.extractChannel('green')
|
||||||
.jpeg(jpegOptions)
|
.jpeg()
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
const roughness = sharp(raw.data, { raw })
|
const roughness = sharp(raw.data, { raw })
|
||||||
.extractChannel('alpha')
|
.extractChannel('alpha')
|
||||||
.jpeg(jpegOptions)
|
.jpeg()
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
|
|
||||||
return await newImage
|
return await newImage
|
||||||
.joinChannel(await Promise.all([roughness, metallicness]))
|
.joinChannel(await Promise.all([roughness, metallicness]))
|
||||||
.jpeg(jpegOptions)
|
.jpeg()
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,18 +64,15 @@ export async function readTexture(path: string, mutation?: TextureMutation) {
|
|||||||
*/
|
*/
|
||||||
return await sharp(raw.data, { raw })
|
return await sharp(raw.data, { raw })
|
||||||
.extractChannel('alpha')
|
.extractChannel('alpha')
|
||||||
.jpeg(jpegOptions)
|
.jpeg()
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
case TextureMutation.Albedo: {
|
case TextureMutation.Albedo: {
|
||||||
return await sharp(raw.data, { raw })
|
return await sharp(raw.data, { raw }).removeAlpha().jpeg().toBuffer();
|
||||||
.removeAlpha()
|
|
||||||
.jpeg(jpegOptions)
|
|
||||||
.toBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return await sharp(raw.data, { raw }).jpeg(jpegOptions).toBuffer();
|
return await sharp(raw.data, { raw }).jpeg().toBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user