-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.go
86 lines (72 loc) · 2.26 KB
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package script
import (
color2 "github.com/peter-mount/go-anim/graph/color"
"github.com/peter-mount/go-anim/renderer"
"github.com/peter-mount/go-anim/util/goexr/exr"
"image"
"image/color"
)
type Image struct {
Width4K int
Height4K int
}
const (
Width4K = 3840 // 4K resolution, 2160p
Height4K = 2160 // 4K resolution, 2160p
Width1080p = 1920 // FHD 1080p resolution
Height1080p = 1080 // FHD 1080p resolution
Width720p = 1280 // HD 720p resolution
Height720p = 720
)
func newImage() *Image {
return &Image{
Width4K: 3840,
Height4K: 2160,
}
}
// New4K creates a new RGBA image at 4K resolution
func (_ Image) New4K() *image.RGBA {
return image.NewRGBA(image.Rect(0, 0, Width4K, Height4K))
}
// New2160p creates a new RGBA image at 2160p.
// This is the same as New4K.
func (g Image) New2160p() *image.RGBA {
return g.New4K()
}
// New1080p creates a new RGBA image at 1080p resolution,
// also known as FHD or Full HD.
func (_ Image) New1080p() *image.RGBA {
return image.NewRGBA(image.Rect(0, 0, Width1080p, Height1080p))
}
// New720p creates a new RGBA image at 720p resolution,
// also known has HD or HD Ready.
func (_ Image) New720p() *image.RGBA {
return image.NewRGBA(image.Rect(0, 0, Width720p, Height720p))
}
// NewRGBA creates an RGBA image with the specified dimensions
func (_ Image) NewRGBA(w, h int) *image.RGBA {
return image.NewRGBA(image.Rect(0, 0, w, h))
}
// NewRGBA64 creates an RGBA64 image with the specified dimensions
func (_ Image) NewRGBA64(w, h int) *image.RGBA64 {
return image.NewRGBA64(image.Rect(0, 0, w, h))
}
// NewFloat16 returns a RGBAImage using float16 for each colour component
func (_ Image) NewFloat16(w, h int) *exr.RGBAImage {
return exr.NewFloat16(image.Rect(0, 0, w, h))
}
// NewFloat32 returns a RGBAImage using float32 for each colour component
func (_ Image) NewFloat32(w, h int) *exr.RGBAImage {
return exr.NewFloat32(image.Rect(0, 0, w, h))
}
// Fill fills the image in the context with a specific colour
func (_ Image) Fill(ctx renderer.Context, background color.Color) {
gc := ctx.Gc()
gc.Save()
defer gc.Restore()
gc.SetFillColor(background)
gc.ClearRect(0, 0, ctx.Width(), ctx.Height())
}
func (_ Image) Histogram(src image.Image) *color2.Histogram {
return color2.NewHistogram().AnalyzeImage(src)
}