• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cshum / imagor / 21680984187

04 Feb 2026 05:11PM UTC coverage: 91.894% (-0.04%) from 91.931%
21680984187

push

github

web-flow
refactor: vips processor filter logic refacor (#727)

* cleanup logic

* sepapration of concern

178 of 200 new or added lines in 3 files covered. (89.0%)

1 existing line in 1 file now uncovered.

5714 of 6218 relevant lines covered (91.89%)

1.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.65
/processor/vipsprocessor/color.go
1
package vipsprocessor
2

3
import (
4
        "image/color"
5
        "strings"
6

7
        "github.com/cshum/vipsgen/vips"
8
        "golang.org/x/image/colornames"
9
)
10

11
// getColor parses a color string and returns RGB values as float64 slice
12
// Supports: color names (e.g., "red"), hex codes (e.g., "#ff0000" or "ff0000"),
13
// and "auto" which samples the image at top-left or bottom-right
14
func getColor(img *vips.Image, color string) []float64 {
1✔
15
        var vc = make([]float64, 3)
1✔
16
        args := strings.Split(strings.ToLower(color), ",")
1✔
17
        mode := ""
1✔
18
        name := strings.TrimPrefix(args[0], "#")
1✔
19
        if len(args) > 1 {
2✔
20
                mode = args[1]
1✔
21
        }
1✔
22
        if name == "auto" {
2✔
23
                if img != nil {
2✔
24
                        x := 0
1✔
25
                        y := 0
1✔
26
                        if mode == "bottom-right" {
2✔
27
                                x = img.Width() - 1
1✔
28
                                y = img.PageHeight() - 1
1✔
29
                        }
1✔
30
                        p, _ := img.Getpoint(x, y, nil)
1✔
31
                        if len(p) >= 3 {
2✔
32
                                vc[0] = p[0]
1✔
33
                                vc[1] = p[1]
1✔
34
                                vc[2] = p[2]
1✔
35
                        }
1✔
36
                }
37
        } else if c, ok := colornames.Map[name]; ok {
2✔
38
                vc[0] = float64(c.R)
1✔
39
                vc[1] = float64(c.G)
1✔
40
                vc[2] = float64(c.B)
1✔
41
        } else if c, ok := parseHexColor(name); ok {
3✔
42
                vc[0] = float64(c.R)
1✔
43
                vc[1] = float64(c.G)
1✔
44
                vc[2] = float64(c.B)
1✔
45
        }
1✔
46
        return vc
1✔
47
}
48

49
// parseHexColor parses a hex color string (3 or 6 characters) into RGBA
50
func parseHexColor(s string) (c color.RGBA, ok bool) {
1✔
51
        c.A = 0xff
1✔
52
        switch len(s) {
1✔
53
        case 6:
1✔
54
                c.R = hexToByte(s[0])<<4 + hexToByte(s[1])
1✔
55
                c.G = hexToByte(s[2])<<4 + hexToByte(s[3])
1✔
56
                c.B = hexToByte(s[4])<<4 + hexToByte(s[5])
1✔
57
                ok = true
1✔
58
        case 3:
1✔
59
                c.R = hexToByte(s[0]) * 17
1✔
60
                c.G = hexToByte(s[1]) * 17
1✔
61
                c.B = hexToByte(s[2]) * 17
1✔
62
                ok = true
1✔
63
        }
64
        return
1✔
65
}
66

67
// hexToByte converts a single hex character to its byte value
68
func hexToByte(b byte) byte {
1✔
69
        switch {
1✔
70
        case b >= '0' && b <= '9':
1✔
71
                return b - '0'
1✔
72
        case b >= 'a' && b <= 'f':
1✔
73
                return b - 'a' + 10
1✔
74
        }
75
        return 0
1✔
76
}
77

78
// isBlack checks if a color is pure black (0, 0, 0)
79
func isBlack(c []float64) bool {
1✔
80
        if len(c) < 3 {
1✔
NEW
81
                return false
×
NEW
82
        }
×
83
        return c[0] == 0x00 && c[1] == 0x00 && c[2] == 0x00
1✔
84
}
85

86
// isWhite checks if a color is pure white (255, 255, 255)
87
func isWhite(c []float64) bool {
1✔
88
        if len(c) < 3 {
1✔
NEW
89
                return false
×
NEW
90
        }
×
91
        return c[0] == 0xff && c[1] == 0xff && c[2] == 0xff
1✔
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc