Validate story image PNG color modes
This commit is contained in:
@@ -9,6 +9,10 @@ const storyAssetsSourcePath = join('src', 'game', 'data', 'storyAssets.ts');
|
||||
|
||||
const expectedStorySize = { width: 1672, height: 941 };
|
||||
const expectedPortraitSize = { width: 1254, height: 1254 };
|
||||
const allowedPngColorTypes = new Map([
|
||||
[2, 'RGB'],
|
||||
[6, 'RGBA']
|
||||
]);
|
||||
|
||||
const server = await createServer({
|
||||
logLevel: 'error',
|
||||
@@ -138,11 +142,17 @@ function validatePngFile(errors, path, expectedSize, label) {
|
||||
|
||||
const width = bytes.readUInt32BE(16);
|
||||
const height = bytes.readUInt32BE(20);
|
||||
const bitDepth = bytes[24];
|
||||
const colorType = bytes[25];
|
||||
if (width !== expectedSize.width || height !== expectedSize.height) {
|
||||
errors.push(
|
||||
`${path}: ${label} should be ${expectedSize.width}x${expectedSize.height}, got ${width}x${height}`
|
||||
);
|
||||
}
|
||||
if (bitDepth !== 8 || !allowedPngColorTypes.has(colorType)) {
|
||||
const colorMode = allowedPngColorTypes.get(colorType) ?? `color type ${colorType}`;
|
||||
errors.push(`${path}: ${label} should be 8-bit RGB/RGBA PNG, got ${bitDepth}-bit ${colorMode}`);
|
||||
}
|
||||
}
|
||||
|
||||
function validateRuntimeUrl(errors, key, url, path) {
|
||||
|
||||
Reference in New Issue
Block a user