-
Notifications
You must be signed in to change notification settings - Fork 23
/
bitmap.go
40 lines (33 loc) · 927 Bytes
/
bitmap.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
// Copyright 2012 The go-gl Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gltext
import (
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"io"
)
// LoadBitmap loads a bitmap (raster) font from the given
// sprite sheet and config files. It is optionally scaled by
// the given scale factor.
//
// A scale factor of 1 retains the original size. A factor of 2 doubles the
// font size, etc. A scale factor of 0 is not valid and will default to 1.
//
// Supported image formats are 32-bit RGBA as PNG, JPEG and GIF.
func LoadBitmap(img, config io.Reader, scale int) (*Font, error) {
pix, _, err := image.Decode(img)
if err != nil {
return nil, err
}
rgba := toRGBA(pix, scale)
var fc FontConfig
err = fc.Load(config)
if err != nil {
return nil, err
}
fc.Glyphs.Scale(scale)
return loadFont(rgba, &fc)
}