diff --git a/waroot/src/image/color/color.wa b/waroot/src/image/color/color.wa index 4c532bcf..5dae280f 100644 --- a/waroot/src/image/color/color.wa +++ b/waroot/src/image/color/color.wa @@ -4,14 +4,6 @@ type Gray struct { Y: u8 } -type Gray16 struct { - Y: u16 -} - type RGBA struct { R, G, B, A: u8 } - -type RGBA64 struct { - R, G, B, A: u16 -} diff --git a/waroot/src/image/draw/draw.wa b/waroot/src/image/draw/draw.wa deleted file mode 100644 index 63c7a909..00000000 --- a/waroot/src/image/draw/draw.wa +++ /dev/null @@ -1,28 +0,0 @@ -// 版权 @2023 凹语言 作者。保留所有权利。 - -import ( - "image" - "image/color" -) - -type Image interface { - image.Image - Set(x, y: int, c: color.RGBA) -} - -type RGBA64Image interface { - image.RGBA64Image - Set(x, y: int, c: color.RGBA64) -} - -func Draw(dst: Image, r: image.Rectangle, src: image.Image, sp: image.Point) { - panic("todo") -} - -func DrawMask( - dst: Image, r: image.Rectangle, - src: image.Image, sp: image.Point, - mask: image.Image, mp: image.Point, -) { - panic("todo") -} diff --git a/waroot/src/image/geom.wa b/waroot/src/image/geom.wa index fcdcfa2c..feba9b12 100644 --- a/waroot/src/image/geom.wa +++ b/waroot/src/image/geom.wa @@ -2,10 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -import ( - "math/bits" -) - // 二维点 type Point struct { X, Y: int @@ -28,7 +24,7 @@ func Rect(x0, y0, x1, y1: int) => Rectangle { if y0 > y1 { y0, y1 = y1, y0 } - return Rectangle{ Min: Point{x0, y0}, Max: Point{x1, y1} } + return Rectangle{Min: Point{x0, y0}, Max: Point{x1, y1}} } func Rectangle.Dx => int { @@ -45,36 +41,8 @@ func Rectangle.Size => Point { this.Max.Y - this.Min.Y, } } -func Rectangle.Contain(x, y: int) => bool { + +func Rectangle.Contains(x, y: int) => bool { return this.Min.X <= x && x < this.Max.X && this.Min.Y <= y && y < this.Max.Y } - -func pixelBufferLength(bytesPerPixel: int, r: Rectangle, imageTypeName: string) => int { - totalLength := mul3NonNeg(bytesPerPixel, r.Dx(), r.Dy()) - if totalLength < 0 { - panic("image: New" + imageTypeName + " Rectangle has huge or negative dimensions") - } - return totalLength -} - -// mul3NonNeg returns (x * y * z), unless at least one argument is negative or -// if the computation overflows the int type, in which case it returns -1. -func mul3NonNeg(x: int, y: int, z: int) => int { - if (x < 0) || (y < 0) || (z < 0) { - return -1 - } - hi, lo := bits.Mul64(uint64(x), uint64(y)) - if hi != 0 { - return -1 - } - hi, lo = bits.Mul64(lo, uint64(z)) - if hi != 0 { - return -1 - } - a := int(lo) - if (a < 0) || (uint64(a) != lo) { - return -1 - } - return a -} diff --git a/waroot/src/image/image.wa b/waroot/src/image/image.wa index 87d2899f..4703fa6e 100644 --- a/waroot/src/image/image.wa +++ b/waroot/src/image/image.wa @@ -14,13 +14,6 @@ type Image interface { At(x, y: int) => color.RGBA } -// 图像接口(16bit) -type RGBA64Image interface { - Bounds() => Rectangle - PixOffset(x, y: int) => int - At(x, y: int) => color.RGBA64 -} - // 二维图像 Gray type Gray struct { Pix: []u8 @@ -28,13 +21,6 @@ type Gray struct { Rect: Rectangle } -// 二维图像 Gray16 -type Gray16 struct { - Pix: []u16 - Stride: int - Rect: Rectangle -} - // 二维图像 RGBA type RGBA struct { Pix: []u8 @@ -42,13 +28,6 @@ type RGBA struct { Rect: Rectangle } -// 二维图像 RGBA64 -type RGBA64 struct { - Pix: []u16 - Stride: int - Rect: Rectangle -} - // 调色板图像 type Paletted struct { Pix: []u8 diff --git a/waroot/src/image/image_impl.wa b/waroot/src/image/image_impl.wa index 8f7503ca..3838bd84 100644 --- a/waroot/src/image/image_impl.wa +++ b/waroot/src/image/image_impl.wa @@ -5,14 +5,11 @@ import "image/color" global ( _ :Image = (*Gray)(nil) _ :Image = (*RGBA)(nil) - - _ :RGBA64Image = (*Gray16)(nil) - _ :RGBA64Image = (*RGBA64)(nil) ) func NewGray(r: Rectangle) => *Gray { return &Gray{ - Pix: make([]u8, pixelBufferLength(1, r, "Gray")), + Pix: make([]u8, r.Dx()*r.Dy()), Stride: 1 * r.Dx(), Rect: r, } @@ -29,28 +26,9 @@ func Gray.At(x, y: int) => color.RGBA { return color.RGBA{v, v, v, 0xFF} } -func NewGray16(r: Rectangle) => *Gray16 { - return &Gray16{ - Pix: make([]u16, pixelBufferLength(2, r, "Gray16")), - Stride: 2 * r.Dx(), - Rect: r, - } -} -func Gray16.Bounds() => Rectangle { - return this.Rect -} -func Gray16.PixOffset(x, y: int) => int { - return (y-this.Rect.Min.Y)*this.Stride + (x-this.Rect.Min.X)*2 -} -func Gray16.At(x, y: int) => color.RGBA64 { - i := this.PixOffset(x, y) - v := this.Pix[i] - return color.RGBA64{v, v, v, 0xFFFF} -} - func NewRGBA(r: Rectangle) => *RGBA { return &RGBA{ - Pix: make([]u8, pixelBufferLength(4, r, "RGBA")), + Pix: make([]u8, 4*r.Dx()*r.Dy()), Stride: 4 * r.Dx(), Rect: r, } @@ -69,7 +47,7 @@ func RGBA.At(x, y: int) => color.RGBA { } func RGBA.SetRGBA(x, y: int, c: color.RGBA) { - if !this.Rect.Contain(x, y) { + if !this.Rect.Contains(x, y) { return } i := this.PixOffset(x, y) @@ -80,30 +58,9 @@ func RGBA.SetRGBA(x, y: int, c: color.RGBA) { s[3] = c.A } -func NewRGBA64(r: Rectangle) => *RGBA64 { - return &RGBA64{ - Pix: make([]u16, pixelBufferLength(8, r, "RGBA64")), - Stride: 8 * r.Dx(), - Rect: r, - } -} - -func RGBA64.Bounds() => Rectangle { - return this.Rect -} - -func RGBA64.PixOffset(x, y: int) => int { - return (y-this.Rect.Min.Y)*this.Stride + (x-this.Rect.Min.X)*8 -} -func RGBA64.At(x, y: int) => color.RGBA64 { - i := this.PixOffset(x, y) - s := this.Pix[i : i+4 : i+4] - return color.RGBA64{s[0], s[1], s[2], s[3]} -} - func NewPaletted(r: Rectangle, p: []color.RGBA) => *Paletted { return &Paletted{ - Pix: make([]u8, pixelBufferLength(1, r, "Paletted")), + Pix: make([]u8, r.Dx()*r.Dy()), Stride: 1 * r.Dx(), Rect: r, Palette: p,