Skip to content

Commit 58ff0dc

Browse files
committed
refactor: separate file ios into fio package
1 parent eaa23de commit 58ff0dc

14 files changed

Lines changed: 105 additions & 71 deletions

context.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"strings"
1717
"unsafe"
1818

19+
"github.com/FloatTech/gg/fio"
1920
"github.com/golang/freetype/raster"
2021
"golang.org/x/image/draw"
2122
"golang.org/x/image/font"
@@ -270,14 +271,14 @@ func (dc *Context) H() int {
270271
//
271272
// 将图像编码为 PNG 并将其写入磁盘。
272273
func (dc *Context) SavePNG(path string) error {
273-
return SavePNG(path, dc.im)
274+
return fio.SavePNG(path, dc.im)
274275
}
275276

276277
// SaveJPG encodes the image as a JPG and writes it to disk.
277278
//
278279
// 将图像编码为 JPG 并将其写入磁盘。
279280
func (dc *Context) SaveJPG(path string, quality int) error {
280-
return SaveJPG(path, dc.im, quality)
281+
return fio.SaveJPG(path, dc.im, quality)
281282
}
282283

283284
// EncodePNG encodes the image as a PNG and writes it to the provided io.Writer.
@@ -921,7 +922,7 @@ func (dc *Context) DrawRegularPolygon(n int, x, y, r, rotation float64) {
921922

922923
// 加载指定路径的图像并设定像素坐标
923924
func (dc *Context) LoadImage(path string, x, y int) error {
924-
img, err := LoadImage(path) //添加图片
925+
img, err := fio.LoadImage(path) //添加图片
925926
if err != nil {
926927
return err
927928
}

context_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package gg
33
import (
44
"math/rand"
55
"testing"
6+
7+
"github.com/FloatTech/gg/fio"
68
)
79

810
func checkHash(t *testing.T, dc *Context, expected string) {
@@ -13,7 +15,7 @@ func checkHash(t *testing.T, dc *Context, expected string) {
1315
}
1416

1517
func saveImage(dc *Context, name string) error {
16-
return SavePNG(name+".png", dc.Image())
18+
return fio.SavePNG(name+".png", dc.Image())
1719
}
1820

1921
func TestBlank(t *testing.T) {

effects_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package gg
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
"github.com/FloatTech/gg/fio"
7+
)
48

59
func TestBrightness(t *testing.T) {
6-
im, err := LoadPNG("examples/gopher.png")
10+
im, err := fio.LoadPNG("examples/gopher.png")
711
if err != nil {
812
t.Fatal(err)
913
}
@@ -14,7 +18,7 @@ func TestBrightness(t *testing.T) {
1418
}
1519

1620
func TestContrast(t *testing.T) {
17-
im, err := LoadPNG("examples/gopher.png")
21+
im, err := fio.LoadPNG("examples/gopher.png")
1822
if err != nil {
1923
t.Fatal(err)
2024
}

examples/concat_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import (
55
"testing"
66

77
"github.com/FloatTech/gg"
8+
"github.com/FloatTech/gg/fio"
89
)
910

1011
func TestConcat(t *testing.T) {
11-
im1, err := gg.LoadPNG("james-webb.png")
12+
im1, err := fio.LoadPNG("james-webb.png")
1213
if err != nil {
1314
panic(err)
1415
}
1516

16-
im2, err := gg.LoadPNG("gopher.png")
17+
im2, err := fio.LoadPNG("gopher.png")
1718
if err != nil {
1819
panic(err)
1920
}

examples/ellipse_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"github.com/FloatTech/gg"
7+
"github.com/FloatTech/gg/fio"
78
)
89

910
func TestEllipse(t *testing.T) {
@@ -17,7 +18,7 @@ func TestEllipse(t *testing.T) {
1718
dc.Fill()
1819
dc.Pop()
1920
}
20-
if im, err := gg.LoadImage("gopher.png"); err == nil {
21+
if im, err := fio.LoadImage("gopher.png"); err == nil {
2122
dc.DrawImageAnchored(im, S/2, S/2, 0.5, 0.5)
2223
}
2324
dc.SavePNG(GetFileName() + ".png")

examples/mask_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"testing"
66

77
"github.com/FloatTech/gg"
8+
"github.com/FloatTech/gg/fio"
89
)
910

1011
func TestMask(t *testing.T) {
11-
im, err := gg.LoadImage("james-webb.png")
12+
im, err := fio.LoadImage("james-webb.png")
1213
if err != nil {
1314
log.Fatal(err)
1415
}

examples/pattern-fill_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"testing"
55

66
"github.com/FloatTech/gg"
7+
"github.com/FloatTech/gg/fio"
78
)
89

910
func TestPF(t *testing.T) {
10-
im, err := gg.LoadPNG("james-webb.png")
11+
im, err := fio.LoadPNG("james-webb.png")
1112
if err != nil {
1213
panic(err)
1314
}

examples/rotated-image_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"testing"
55

66
"github.com/FloatTech/gg"
7+
"github.com/FloatTech/gg/fio"
78
)
89

910
func TestRIM(t *testing.T) {
1011
const W = 400
1112
const H = 500
12-
im, err := gg.LoadPNG("gopher.png")
13+
im, err := fio.LoadPNG("gopher.png")
1314
if err != nil {
1415
panic(err)
1516
}

examples/tiling_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"testing"
55

66
"github.com/FloatTech/gg"
7+
"github.com/FloatTech/gg/fio"
78
)
89

910
func TestTiling(t *testing.T) {
1011
const NX = 4
1112
const NY = 3
12-
im, err := gg.LoadPNG("gopher.png")
13+
im, err := fio.LoadPNG("gopher.png")
1314
if err != nil {
1415
panic(err)
1516
}

factory/img.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414

1515
"github.com/FloatTech/gg"
16+
"github.com/FloatTech/gg/fio"
1617
"github.com/disintegration/imaging"
1718
)
1819

@@ -28,7 +29,7 @@ func Load(path string) (img image.Image, err error) {
2829
_ = res.Body.Close()
2930
return
3031
}
31-
return gg.LoadImage(path)
32+
return fio.LoadImage(path)
3233
}
3334

3435
// Parse 解析图片数据流

0 commit comments

Comments
 (0)