Skip to content

Commit

Permalink
chore: update dependencies (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
targos authored Feb 10, 2024
1 parent e2113f5 commit fdb2289
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 39 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@
},
"homepage": "https://github.com/image-js/fast-png#readme",
"devDependencies": {
"@types/jest": "^29.5.3",
"@types/node": "^20.4.2",
"eslint": "^8.45.0",
"eslint-config-cheminfo-typescript": "^11.3.1",
"jest": "^29.6.1",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.17",
"eslint": "^8.56.0",
"eslint-config-cheminfo-typescript": "^12.1.0",
"jest": "^29.7.0",
"pngjs": "^7.0.0",
"prettier": "^3.0.0",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
},
"dependencies": {
"@types/pako": "^2.0.0",
"@types/pako": "^2.0.3",
"iobuffer": "^5.3.2",
"pako": "^2.1.0"
}
Expand Down
8 changes: 4 additions & 4 deletions src/PngDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class PngDecoder extends IOBuffer {
image.height = this.readUint32();
image.depth = checkBitDepth(this.readUint8());

const colorType: ColorType = this.readUint8();
const colorType = this.readUint8() as ColorType;
this._colorType = colorType;
let channels: number;
switch (colorType) {
Expand All @@ -176,15 +176,15 @@ export default class PngDecoder extends IOBuffer {
}
this._png.channels = channels;

this._compressionMethod = this.readUint8();
this._compressionMethod = this.readUint8() as CompressionMethod;
if (this._compressionMethod !== CompressionMethod.DEFLATE) {
throw new Error(
`Unsupported compression method: ${this._compressionMethod}`,
);
}

this._filterMethod = this.readUint8();
this._interlaceMethod = this.readUint8();
this._filterMethod = this.readUint8() as FilterMethod;
this._interlaceMethod = this.readUint8() as InterlaceMethod;
}

// https://www.w3.org/TR/PNG/#11PLTE
Expand Down
12 changes: 9 additions & 3 deletions src/PngEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ function checkInteger(value: number, name: string): number {
throw new TypeError(`${name} must be a positive integer`);
}

function getColorType(data: ImageData): {
interface GetColorTypeReturn {
channels: number;
depth: BitDepth;
colorType: ColorType;
} {
}

function getColorType(data: ImageData): GetColorTypeReturn {
const { channels = 4, depth = 8 } = data;
if (channels !== 4 && channels !== 3 && channels !== 2 && channels !== 1) {
throw new RangeError(`unsupported number of channels: ${channels}`);
Expand All @@ -159,7 +161,11 @@ function getColorType(data: ImageData): {
throw new RangeError(`unsupported bit depth: ${depth}`);
}

const returnValue = { channels, depth, colorType: ColorType.UNKNOWN };
const returnValue: GetColorTypeReturn = {
channels,
depth,
colorType: ColorType.UNKNOWN,
};
switch (channels) {
case 4:
returnValue.colorType = ColorType.TRUECOLOUR_ALPHA;
Expand Down
52 changes: 31 additions & 21 deletions src/internalTypes.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
export enum ColorType {
UNKNOWN = -1,
GREYSCALE = 0,
TRUECOLOUR = 2,
INDEXED_COLOUR = 3,
GREYSCALE_ALPHA = 4,
TRUECOLOUR_ALPHA = 6,
}
export const ColorType = {
UNKNOWN: -1,
GREYSCALE: 0,
TRUECOLOUR: 2,
INDEXED_COLOUR: 3,
GREYSCALE_ALPHA: 4,
TRUECOLOUR_ALPHA: 6,
} as const;
// eslint-disable-next-line @typescript-eslint/no-redeclare
export type ColorType = (typeof ColorType)[keyof typeof ColorType];

export enum CompressionMethod {
UNKNOWN = -1,
DEFLATE = 0,
}
export const CompressionMethod = {
UNKNOWN: -1,
DEFLATE: 0,
} as const;
// eslint-disable-next-line @typescript-eslint/no-redeclare
export type CompressionMethod =
(typeof CompressionMethod)[keyof typeof CompressionMethod];

export enum FilterMethod {
UNKNOWN = -1,
ADAPTIVE = 0,
}
export const FilterMethod = {
UNKNOWN: -1,
ADAPTIVE: 0,
} as const;
// eslint-disable-next-line @typescript-eslint/no-redeclare
export type FilterMethod = (typeof FilterMethod)[keyof typeof FilterMethod];

export enum InterlaceMethod {
UNKNOWN = -1,
NO_INTERLACE = 0,
ADAM7 = 1,
}
export const InterlaceMethod = {
UNKNOWN: -1,
NO_INTERLACE: 0,
ADAM7: 1,
} as const;
// eslint-disable-next-line @typescript-eslint/no-redeclare
export type InterlaceMethod =
(typeof InterlaceMethod)[keyof typeof InterlaceMethod];
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface DecodedPng {
data: PngDataArray;
depth: BitDepth;
channels: number;
text: { [key: string]: string };
text: Record<string, string>;
resolution?: PngResolution;
palette?: IndexedColors;
transparency?: Uint16Array;
Expand Down

0 comments on commit fdb2289

Please sign in to comment.