MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / colorspaceToResult

Method colorspaceToResult

processing/colorspace_to_result.go:3–37  ·  view source on GitHub ↗
(c *Context)

Source from the content-addressed store, hash-verified

1package processing
2
3func (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}

Callers

nothing calls this directly

Calls 8

StripColorProfileMethod · 0.80
SupportsColourProfileMethod · 0.80
ColourProfileImportedMethod · 0.80
RestoreColourProfileMethod · 0.80
ExportColourProfileMethod · 0.80
RemoveColourProfileMethod · 0.80
FormatMethod · 0.65

Tested by

no test coverage detected