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

Method colorspaceToProcessing

processing/colorspace_to_processing.go:7–33  ·  view source on GitHub ↗
(c *Context)

Source from the content-addressed store, hash-verified

5)
6
7func (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.

Callers 1

trimMethod · 0.95

Calls 11

guessTargetColorspaceFunction · 0.85
shouldImportICCFunction · 0.85
Rad2FloatMethod · 0.80
SupportsHDRMethod · 0.80
PreserveHDRMethod · 0.80
IsLinearMethod · 0.80
RemoveColourProfileMethod · 0.80
BackupColourProfileMethod · 0.80
ImportColourProfileMethod · 0.80
ColorspaceMethod · 0.80
FormatMethod · 0.65

Tested by

no test coverage detected