-
Notifications
You must be signed in to change notification settings - Fork 0
/
gray32i.go
114 lines (97 loc) · 2.88 KB
/
gray32i.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Auto Generated By 'go generate', DONOT EDIT!!!
package image
import (
"image"
"image/color"
"reflect"
colorExt "github.com/chai2010/image/color"
)
type Gray32i struct {
M struct {
Pix []uint8
Stride int
Rect image.Rectangle
}
}
// NewGray32i returns a new Gray32i with the given bounds.
func NewGray32i(r image.Rectangle) *Gray32i {
return new(Gray32i).Init(make([]uint8, 4*r.Dx()*r.Dy()), 4*r.Dx(), r)
}
func (p *Gray32i) Init(pix []uint8, stride int, rect image.Rectangle) *Gray32i {
*p = Gray32i{
M: struct {
Pix []uint8
Stride int
Rect image.Rectangle
}{
Pix: pix,
Stride: stride,
Rect: rect,
},
}
return p
}
func (p *Gray32i) BaseType() image.Image { return asBaseType(p) }
func (p *Gray32i) Pix() []byte { return p.M.Pix }
func (p *Gray32i) Stride() int { return p.M.Stride }
func (p *Gray32i) Rect() image.Rectangle { return p.M.Rect }
func (p *Gray32i) Channels() int { return 1 }
func (p *Gray32i) Depth() reflect.Kind { return reflect.Int32 }
func (p *Gray32i) ColorModel() color.Model { return colorExt.Gray32iModel }
func (p *Gray32i) Bounds() image.Rectangle { return p.M.Rect }
func (p *Gray32i) At(x, y int) color.Color {
return p.Gray32iAt(x, y)
}
func (p *Gray32i) Gray32iAt(x, y int) colorExt.Gray32i {
if !(image.Point{x, y}.In(p.M.Rect)) {
return colorExt.Gray32i{}
}
i := p.PixOffset(x, y)
return pGray32iAt(p.M.Pix[i:])
}
// PixOffset returns the index of the first element of Pix that corresponds to
// the pixel at (x, y).
func (p *Gray32i) PixOffset(x, y int) int {
return (y-p.M.Rect.Min.Y)*p.M.Stride + (x-p.M.Rect.Min.X)*4
}
func (p *Gray32i) Set(x, y int, c color.Color) {
if !(image.Point{x, y}.In(p.M.Rect)) {
return
}
i := p.PixOffset(x, y)
c1 := colorExt.Gray32iModel.Convert(c).(colorExt.Gray32i)
pSetGray32i(p.M.Pix[i:], c1)
return
}
func (p *Gray32i) SetGray32i(x, y int, c colorExt.Gray32i) {
if !(image.Point{x, y}.In(p.M.Rect)) {
return
}
i := p.PixOffset(x, y)
pSetGray32i(p.M.Pix[i:], c)
return
}
// SubImage returns an image representing the portion of the image p visible
// through r. The returned value shares pixels with the original image.
func (p *Gray32i) SubImage(r image.Rectangle) image.Image {
r = r.Intersect(p.M.Rect)
// If r1 and r2 are Rectangles, r1.Intersect(r2) is not guaranteed to be inside
// either r1 or r2 if the intersection is empty. Without explicitly checking for
// this, the Pix[i:] expression below can panic.
if r.Empty() {
return &Gray32i{}
}
i := p.PixOffset(r.Min.X, r.Min.Y)
return new(Gray32i).Init(
p.M.Pix[i:],
p.M.Stride,
r,
)
}
// Opaque scans the entire image and reports whether it is fully opaque.
func (p *Gray32i) Opaque() bool {
return true
}