mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
op/paint: remove unnecessary check in ImageOp
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
@@ -229,8 +229,9 @@ func flipImageY(stride, height int, pixels []byte) {
|
|||||||
func UploadImage(t Texture, offset image.Point, img *image.RGBA) {
|
func UploadImage(t Texture, offset image.Point, img *image.RGBA) {
|
||||||
var pixels []byte
|
var pixels []byte
|
||||||
size := img.Bounds().Size()
|
size := img.Bounds().Size()
|
||||||
start := img.PixOffset(0, 0)
|
min := img.Rect.Min
|
||||||
end := img.PixOffset(size.X, size.Y-1)
|
start := img.PixOffset(min.X, min.Y)
|
||||||
|
end := img.PixOffset(min.X+size.X, min.Y+size.Y-1)
|
||||||
pixels = img.Pix[start:end]
|
pixels = img.Pix[start:end]
|
||||||
t.Upload(offset, size, pixels, img.Stride)
|
t.Upload(offset, size, pixels, img.Stride)
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 394 B |
@@ -334,6 +334,29 @@ func TestZeroImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImageRGBA(t *testing.T) {
|
||||||
|
run(t, func(o *op.Ops) {
|
||||||
|
w := newWindow(t, 10, 10)
|
||||||
|
|
||||||
|
im := image.NewRGBA(image.Rect(0, 0, 5, 5))
|
||||||
|
im.Set(3, 3, colornames.Black)
|
||||||
|
im.Set(4, 3, colornames.Black)
|
||||||
|
im.Set(3, 4, colornames.Black)
|
||||||
|
im.Set(4, 4, colornames.Black)
|
||||||
|
im = im.SubImage(image.Rect(2, 2, 5, 5)).(*image.RGBA)
|
||||||
|
paint.NewImageOp(im).Add(o)
|
||||||
|
paint.PaintOp{}.Add(o)
|
||||||
|
if err := w.Frame(o); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}, func(r result) {
|
||||||
|
r.expect(1, 1, colornames.Black)
|
||||||
|
r.expect(2, 1, colornames.Black)
|
||||||
|
r.expect(1, 2, colornames.Black)
|
||||||
|
r.expect(2, 2, colornames.Black)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// lerp calculates linear interpolation with color b and p.
|
// lerp calculates linear interpolation with color b and p.
|
||||||
func lerp(a, b f32color.RGBA, p float32) f32color.RGBA {
|
func lerp(a, b f32color.RGBA, p float32) f32color.RGBA {
|
||||||
return f32color.RGBA{
|
return f32color.RGBA{
|
||||||
|
|||||||
@@ -145,6 +145,10 @@ func verifyRef(t *testing.T, img *image.RGBA, frame int) (ok bool) {
|
|||||||
if frame != 0 {
|
if frame != 0 {
|
||||||
path = filepath.Join("refs", t.Name()+"_"+strconv.Itoa(frame)+".png")
|
path = filepath.Join("refs", t.Name()+"_"+strconv.Itoa(frame)+".png")
|
||||||
}
|
}
|
||||||
|
if *dumpImages {
|
||||||
|
saveImage(t, path, img)
|
||||||
|
return true
|
||||||
|
}
|
||||||
b, err := ioutil.ReadFile(path)
|
b, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("could not open ref:", err)
|
t.Error("could not open ref:", err)
|
||||||
|
|||||||
+3
-6
@@ -59,12 +59,9 @@ func NewImageOp(src image.Image) ImageOp {
|
|||||||
color: col,
|
color: col,
|
||||||
}
|
}
|
||||||
case *image.RGBA:
|
case *image.RGBA:
|
||||||
bounds := src.Bounds()
|
return ImageOp{
|
||||||
if bounds.Min == (image.Point{}) && src.Stride == bounds.Dx()*4 {
|
src: src,
|
||||||
return ImageOp{
|
handle: new(int),
|
||||||
src: src,
|
|
||||||
handle: new(int),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user