image-js / image-js-typescript

Temporary repository to work on the migration of image-js to TypeScript
https://image-js.github.io/image-js-typescript/
MIT License
5 stars 5 forks source link

Exporting 16-bits images as png doesn't work #444

Closed moonayyur closed 4 months ago

moonayyur commented 4 months ago

In the function encodePng that uses fast-png library :

encode(image.getRawImage(), options);

We have :

Image.getRawImage(): {
    width: number;
    height: number;
    data: ImageDataArray;
    channels: number;
    bitDepth: BitDepth;
}

While :

export interface ImageData {
    width: number;
    height: number;
    data: PngDataArray;
    depth?: BitDepth;
    channels?: number;
}

bitDepth in getRawImage has to be changed to depth So here since we don't pass a value to depth it uses the default value in fast-png which is 8 bits

stropitek commented 4 months ago

Probably introduced by https://github.com/image-js/image-js-typescript/pull/298

Can you make a PR with a fix?

moonayyur commented 4 months ago

@stropitek was there a reason why bitDepth was choosen over depth to start with ?

stropitek commented 4 months ago

Maybe better to ask @targos since he worked on it but I think it was just for clarity. depth does not specify the unit so it could as well could have been expressed in bytes, not bits.

targos commented 4 months ago

There were three different names for the same thing (depth, bit depth, color depth) and we had to choose one for consistency.