sharp() constructor for raw pixel input has no colorspace parameter — blocks CMYK raw roundtrip
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 32.7k
- Forks
- 1.4k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Description
## Feature request
When constructing a Sharp instance from a raw pixel buffer, there is no way to declare the colorspace of those bytes. The `raw` input option only accepts `{ width, height, channels, depth? }`. Four-channel raw input is always interpreted as RGBA, making it impossible to feed modified CMYK raw bytes back into Sharp for re-encoding as a CMYK JPEG.
### What are you trying to achieve?
This blocks any workflow that needs to: decode a CMYK image → manipulate individual channel values in JS → re-encode as CMYK JPEG, without a lossy sRGB round-trip.
### When you searched for similar feature requests, what did you find that might be related?
Issue #3620 fixed the `pipelineColorspace` CMYK roundtrip in v0.32.1, which is related but does not address raw input colorspace declaration.
Also saw https://github.com/lovell/sharp/issues/3789
### What would you expect the API to look like?
```js
sharp(rawCmykBuffer, {
raw: {
width: 400,
height: 300,
channels: 4,
colorspace: 'cmyk' // <-- missing option
}
})
.toColorspace('cmyk')
.jpeg({ quality: 95 })
.toBuffer()
```
Alternatively, a `pipelineColorspace` hint on the constructor that applies to raw input would achieve the same result.
### What alternatives have you considered?
converting to RGB, but want to avoid conversion potential loss. Output image is embedded in .pdf for CMYK printing.
### Please provide sample image(s) that help explain this feature
Any image.
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 at the sharp() constructor's raw input option and trace how raw four-channel buffers are interpreted before toColorspace('cmyk') and jpeg() encoding. Review the related behavior described in issues #3620 and #3789. Done means a raw input can declare CMYK colorspace and preserve the requested CMYK roundtrip without requiring RGB conversion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- computer-graphics
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100