Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | 4x 4x 4x 4x 4x 4x 2x 2x 4x 4x 2x 2x 2x 2x 2x | import { readFile } from "fs-extra";
import { readFileToIndexedImage } from "lib/tiles/readFileToTiles";
import { PNG } from "pngjs";
import { ColorCorrectionSetting } from "shared/lib/resources/types";
import {
AutoPaletteResult,
autoPalette,
autoPaletteUsingTiles,
} from "shared/lib/tiles/autoColor";
import { tileDataIndexFn } from "shared/lib/tiles/tileData";
type HexPalette = [string, string, string, string];
export const readFileToPalettes = async (
filename: string,
colorCorrection: ColorCorrectionSetting,
uiPalette: HexPalette | undefined,
): Promise<AutoPaletteResult> => {
const colorPNG = await readPNG(filename);
return autoPalette(
colorPNG.width,
colorPNG.height,
colorPNG.data,
colorCorrection,
uiPalette,
);
};
export const readFileToPalettesUsingTiles = async (
filename: string,
tilesFileName: string,
colorCorrection: ColorCorrectionSetting,
uiPalette: HexPalette | undefined,
): Promise<AutoPaletteResult> => {
const colorPNG = await readPNG(filename);
const indexedImage = await readFileToIndexedImage(
tilesFileName,
tileDataIndexFn,
);
return autoPaletteUsingTiles(
colorPNG.width,
colorPNG.height,
colorPNG.data,
indexedImage,
colorCorrection,
uiPalette,
);
};
const readPNG = async (filename: string): Promise<PNG> => {
const fileData = await readFile(filename);
return new Promise((resolve, reject) => {
new PNG().parse(fileData, (err, data) => {
Iif (err) {
return reject(err);
}
resolve(data);
});
});
};
|