(c *Context)
| 1 | package processing |
| 2 | |
| 3 | func (p *Processor) colorspaceToResult(c *Context) error { |
| 4 | keepProfile := !c.PO.StripColorProfile() && c.PO.Format().SupportsColourProfile() |
| 5 | profileImported := c.Img.ColourProfileImported() |
| 6 | |
| 7 | // vips 8.15+ tends to lose the colour profile during some color conversions. |
| 8 | // We probably have a backup of the colour profile, so we need to restore it. |
| 9 | c.Img.RestoreColourProfile() |
| 10 | |
| 11 | // NOTE: |
| 12 | // If we imported ICC but don't want to keep it, we can just remove it without transforming, |
| 13 | // because the image is already in a standard color space. |
| 14 | // If we didn't import ICC but want to keep it, we can just keep it without exporting, |
| 15 | // because the image is still in the ICC's color space. |
| 16 | |
| 17 | switch { |
| 18 | case keepProfile && profileImported: |
| 19 | // We imported ICC profile and want to keep it, |
| 20 | // so we need to export it |
| 21 | if err := c.Img.ExportColourProfile(); err != nil { |
| 22 | return err |
| 23 | } |
| 24 | case !keepProfile && !profileImported: |
| 25 | // We didn't import ICC profile and don't want to keep it, |
| 26 | // so we need to transform it to sRGB/sGray for maximum compatibility |
| 27 | if err := c.Img.TransformColourProfileToStandard(); err != nil { |
| 28 | return err |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | if !keepProfile { |
| 33 | return c.Img.RemoveColourProfile() |
| 34 | } |
| 35 | |
| 36 | return nil |
| 37 | } |
nothing calls this directly
no test coverage detected