Help converting raw input with color-profile to srgb
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 32.7k
- Forks
- 1.4k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Description
Hi @lovell, I've tryed to all means to get this output image to work, but its getting out of my knowledge to fix it.
The goal is to import a psd layer0 pixel data as a raw input to sharp. Everything works fine if the psd is sRGB, but I have here an Adobe RGB psd file, that I can't get it right, the image gets desaturated.
I've tryed to export the image from photoshop with Adobe RGB icc embeded, and the jpg colors imports good, the issue is how to initialize the raw with the icc profile.
One of the problems, is that psd files uses xmp metadata, and I can use the "withMetadata" because I'm creating a raw, so I created a simple xmpParser to check for the color-profile tag.
I'm using ag-psd to read the psd and access the layer0 pixel-data buffer.
```
"sharp": "0.31.1",
"ag-psd": "20.2.0"
```
```typescript
const psdBuffer = fs.readFileSync(photo.localPath);
const psd = readPsd(psdBuffer, { useImageData: true, skipThumbnail: false });
const imageDataBuffer = psd.bitsPerChannel === 16 ? Buffer.from(psd.imageData.data) : psd.imageData.data;
let sharpInstance = sharp(imageDataBuffer, {
raw: {
width: psd.imageData.width,
height: psd.imageData.height,
channels: 4
}
});
// Extract XMP metadata
const xmpMetadata = psd.imageResources?.xmpMetadata ? psd.imageResources.xmpMetadata.toString() : null;
if (xmpMetadata) {
return from(this.extractIccFromPsdXmp(xmpMetadata)).pipe(
switchMap(iccProfilePath => {
if (iccProfilePath) {
return of(sharpInstance.withMetadata({
icc: iccProfilePath,
}));
}
return of(sharpInstance);
}),
catchError(err => of(sharpInstance)),
);
}
return of(sharpInstance);
}
```
I've also tried to add "toColorspace('srgb')" and the result is the same.
Files: https://www.pipebytes.com/zQnyxcio
Am I missing something?
Thank you, Rui
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 with the supplied PSD sample and the sharp(imageDataBuffer, { raw: ... }) entry point, then compare it with the embedded-ICC JPEG path. Inspect how withMetadata({ icc }) and toColorspace('srgb') behave for raw pixels in sharp 0.31.1. Done means establishing whether the Adobe RGB profile can be applied to this raw input and documenting the supported path or limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, typescript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100