(c *Context)
| 5 | ) |
| 6 | |
| 7 | func (p *Processor) colorspaceToProcessing(c *Context) error { |
| 8 | if err := c.Img.Rad2Float(); err != nil { |
| 9 | return err |
| 10 | } |
| 11 | |
| 12 | supportsHDR := c.PO.Format().SupportsHDR() && c.PO.PreserveHDR() |
| 13 | cs := guessTargetColorspace(c.Img, supportsHDR) |
| 14 | |
| 15 | if c.Img.IsLinear() { |
| 16 | // If we keep its ICC, we'll get wrong colors after converting it to target |
| 17 | // colorspace (we never convert back to linear). |
| 18 | c.Img.RemoveColourProfile() |
| 19 | } else { |
| 20 | // vips 8.15+ tends to lose the colour profile during some color conversions. |
| 21 | // We need to backup the colour profile before the conversion and restore it later. |
| 22 | c.Img.BackupColourProfile() |
| 23 | |
| 24 | if shouldImportICC(c.Img) { |
| 25 | if err := c.Img.ImportColourProfile(); err != nil { |
| 26 | return err |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // Convert to processing colorspace |
| 32 | return c.Img.Colorspace(cs) |
| 33 | } |
| 34 | |
| 35 | // guessTargetColorspace returns the colorspace to which the image should be saved. |
| 36 | // If target format supports 16-bit colorspace, it will be preferred. |
no test coverage detected