Skip to content

Commit

Permalink
style: Clarification of decode information types for PNG, PNM and PVR…
Browse files Browse the repository at this point in the history
… formats
  • Loading branch information
yegor-pelykh committed May 17, 2024
1 parent a672ccf commit e80c656
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/formats/png-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export class PngDecoder implements Decoder {
* Start decoding the data as an animation sequence, but don't actually
* process the frames until they are requested with decodeFrame.
*/
public startDecode(bytes: Uint8Array): DecodeInfo | undefined {
public startDecode(bytes: Uint8Array): PngInfo | undefined {
if (!this.isValidFile(bytes) || this._input === undefined) {
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/formats/pnm-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class PnmDecoder implements Decoder {
);
}

public startDecode(bytes: Uint8Array): DecodeInfo | undefined {
public startDecode(bytes: Uint8Array): PnmInfo | undefined {
this._input = new InputBuffer({
buffer: bytes,
});
Expand Down
30 changes: 18 additions & 12 deletions src/formats/pvr-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class PvrDecoder implements Decoder {
return 1;
}

private decodePvr3Header(bytes: Uint8Array): DecodeInfo | undefined {
private decodePvr3Header(bytes: Uint8Array): Pvr3Info | undefined {
const input = new InputBuffer({
buffer: bytes,
});
Expand Down Expand Up @@ -76,7 +76,7 @@ export class PvrDecoder implements Decoder {
return info;
}

private decodePvr2Header(bytes: Uint8Array): DecodeInfo | undefined {
private decodePvr2Header(bytes: Uint8Array): Pvr2Info | undefined {
const input = new InputBuffer({
buffer: bytes,
});
Expand Down Expand Up @@ -122,7 +122,7 @@ export class PvrDecoder implements Decoder {
return info;
}

private decodeApplePvrtcHeader(bytes: Uint8Array): DecodeInfo | undefined {
private decodeApplePvrtcHeader(bytes: Uint8Array): PvrAppleInfo | undefined {
const fileSize = bytes.length;

const input = new InputBuffer({
Expand Down Expand Up @@ -737,7 +737,9 @@ export class PvrDecoder implements Decoder {
return this.startDecode(bytes) !== undefined;
}

public startDecode(bytes: Uint8Array): DecodeInfo | undefined {
public startDecode(
bytes: Uint8Array
): PvrAppleInfo | Pvr3Info | Pvr2Info | undefined {
// Use a heuristic to detect potential apple PVRTC formats
if (this.countBits(bytes.length) === 1) {
// very likely to be apple PVRTC
Expand All @@ -748,16 +750,20 @@ export class PvrDecoder implements Decoder {
}
}

let info = this.decodePvr3Header(bytes);
if (info !== undefined) {
this._data = bytes;
return (this._info = info);
{
const info = this.decodePvr3Header(bytes);
if (info !== undefined) {
this._data = bytes;
return (this._info = info);
}
}

info = this.decodePvr2Header(bytes);
if (info !== undefined) {
this._data = bytes;
return (this._info = info);
{
const info = this.decodePvr2Header(bytes);
if (info !== undefined) {
this._data = bytes;
return (this._info = info);
}
}

return undefined;
Expand Down

0 comments on commit e80c656

Please sign in to comment.