image-js / fast-png

PNG image decoder and encoder written entirely in JavaScript
MIT License
329 stars 17 forks source link

Convert indexed data into RGB data #23

Open microshine opened 2 years ago

microshine commented 2 years ago

Hi.

I added rgb method to index.js file. It allows converting indexed data into RGB data

Example of usage

const imgFile = fs.readFileSync(path.join(__dirname, "../../img/palette.png"));
const img = fastPng.decode(imgFile);

const data = fastPng.rgb(img.data, img.depth, img.palette)
const newImg = fastPng.encode({
  width: img.width,
  height: img.height,
  channels: 3,
  depth: 8,
  data,
});
targos commented 2 years ago

Thanks for the PR! Can you please remove the second commit? Our repositories expect npm7+ to be present (peer dependencies are installed automatically with it).

targos commented 2 years ago

I'll have a closer look at the code in a few days, as the implementation is quite different than the one I did in image-js: https://github.com/image-js/image-js/blob/5811f5b7e7677cdda1d8ac124a5c963812e5cd59/src/image/core/load.js#L99-L124

microshine commented 2 years ago

@targos Thanks. Waiting for your review.

microshine commented 2 years ago

Can you please remove the second commit?

Done

But in my case, it breaks lint tests

https://github.com/microshine/fast-png/runs/4118047939?check_suite_focus=true

codecov-commenter commented 2 years ago

Codecov Report

Merging #23 (0ae308d) into master (bdb81f9) will increase coverage by 0.11%. The diff coverage is 92.10%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #23      +/-   ##
==========================================
+ Coverage   90.57%   90.68%   +0.11%     
==========================================
  Files           6        6              
  Lines         403      440      +37     
  Branches       79       86       +7     
==========================================
+ Hits          365      399      +34     
- Misses         38       41       +3     
Impacted Files Coverage Δ
src/types.ts 100.00% <ø> (ø)
src/index.ts 93.61% <92.10%> (-6.39%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bdb81f9...0ae308d. Read the comment docs.

targos commented 2 years ago

Can you please remove the second commit?

Done

But in my case, it breaks lint tests

https://github.com/microshine/fast-png/runs/4118047939?check_suite_focus=true

The Prettier errors can be fixed with npm run prettier-write

microshine commented 2 years ago

@targos Thank you for the advice. I fixed it