Channel excluded from image manipulations, if the channel was `join`ed at later time
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 32.7k
- Forks
- 1.4k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Description
I'm not quite sure if the title is accurate to Sharp's internal algorithm, but [`joinChannel`](https://sharp.pixelplumbing.com/api-channel#joinchannel) *does* appear to exhibit an unusual behavior *at least* somewhere.
As a very simple example to reproduce, I'm extracting all `4` channels as `raw` from a colorful PNG, then joining those channels into a new instance of image. The expected result should be 1:1 duplicate of the original.
```js
import sharp from 'sharp';
const orig = sharp('./colors.png');
// decompose into individual RGBA channel values
// concept taken from https://github.com/lovell/sharp/issues/1757#issuecomment-503653509
const channels = ['red', 'green', 'blue', 'alpha'];
const decompose = channels.map(
channel => orig.extractChannel(channel).raw().toBuffer()
);
const [r, g, b, a] = await Promise.all(decompose);
// copy dimensions from original
const { info } = await orig.toBuffer({ resolveWithObject: true });
const metadata = { raw: {
...info,
channels: 1,
background: 'transparent'
}};
// join/compose all 4 decomposed channels to create an original-alike
const dupe = sharp(r, metadata).joinChannel([g, b, a], metadata);
// export
dupe.toFile('./colors-dupe.png');
```
Things seem to appear nice and fine until this point - the export is still 1:1 with the original. However, any further manipulation on the `dupe` from here on, will result in only the `red` channel being affected. As an example, rotating by 90 degrees:
```js
// export
dupe.rotate(90).toFile('./colors-dupe.png');
```
This is my exact concern, as one would normally expect all 4 channels being manipulated as a whole.
*In order to verify it's only the `red` channel being manipulated:*
1. Open `colors-dupe.png` in GIMP.
2. Go to `Channels` panel (next to `Layers` panel).
3. Hide all 3 channels excluding the `red`.
4. **Result:** Only the `red` channel appears rotated by 90 degrees.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied raw RGBA example with joinChannel, then compare each channel before and after applying rotate(90). Read the joinChannel and rotate API entry points and trace how the joined image is represented; done means all four channels are transformed together rather than only the red channel.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100