-
Notifications
You must be signed in to change notification settings - Fork 1
/
interfaces.go
80 lines (68 loc) · 1.75 KB
/
interfaces.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
package pnm
import "fmt"
// Constants for image types
const (
PBMText int64 = iota + 1
PGMText
PPMText
PBMBinary
PGMBinary
PPMBinary
)
// Image represents all portable anytype format
type Image interface {
MagicNumber() int64
Width() int64
Height() int64
Buffer() []byte
SetBuffer(buffer []byte)
Value() byte
}
// PortableAnyMapImage implements a Portable anymap format. This
// struct will compose other.
type portableAnyMapImage struct {
magicNumber int64
width int64
height int64
maxValue byte
buffer []byte
}
// NewPBMImage creates a new pbm image
func newAnyMapImage(w, h int64, mv byte, t int64) *portableAnyMapImage {
image := &portableAnyMapImage{
magicNumber: t,
width: w,
height: h,
maxValue: mv,
buffer: make([]byte, w*h),
}
return image
}
// MagicNumber return the magic number information of image
func (p *portableAnyMapImage) MagicNumber() int64 {
return p.magicNumber
}
// Width returns the width of image
func (p *portableAnyMapImage) Width() int64 {
return p.width
}
// Height returns the height of image
func (p *portableAnyMapImage) Height() int64 {
return p.height
}
// Buffer returns the buffer of image
func (p *portableAnyMapImage) Buffer() []byte {
return p.buffer
}
// SetBuffer sets the buffer of image
func (p *portableAnyMapImage) SetBuffer(buffer []byte) {
p.buffer = buffer
}
// Value returns the max value of image
func (p *portableAnyMapImage) Value() byte {
return p.maxValue
}
// String implements interface Stringer
func (p *portableAnyMapImage) String() string {
return fmt.Sprintf("mn:%v mv: %v width:%v height:%v buffer:%v", p.magicNumber, p.Value(), p.width, p.height, p.buffer)
}