-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathimage_type_parser.go
31 lines (24 loc) · 947 Bytes
/
image_type_parser.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
package fastimage
// ImageTypeParser is the interface each image type needs to implement to be
// able to detect images on a buffer stream.
type ImageTypeParser interface {
// Type returns the type of the image
Type() ImageType
// Returns true if the image type can be detected on the byte slice
Detect([]byte) bool
// Returns the image size by inspecting the byte slice, or error if it
// can't be detected (more data needed?)
GetSize([]byte) (*ImageSize, error)
}
var imageTypeParsers = make(map[string]ImageTypeParser)
func register(imageTypeParser ImageTypeParser) {
if imageTypeParser == nil {
panic("ImageTypeParser: Register image type is nil")
}
name := imageTypeParser.Type().String()
if _, dup := imageTypeParsers[name]; dup {
panic("ImageTypeParser: Register called twice for type " + name)
}
logger.Printf("ImageTypeParser: Registering %s %v", name, imageTypeParser)
imageTypeParsers[name] = imageTypeParser
}