feat: add mosaic screenshot annotations
This commit is contained in:
@@ -171,3 +171,61 @@ func TestApplyAnnotationsUsesStrokeWidth(t *testing.T) {
|
||||
t.Fatalf("expected thick rectangle stroke to cover y=24, got %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyAnnotationsPixelatesMosaicRectangle(t *testing.T) {
|
||||
src := image.NewRGBA(image.Rect(0, 0, 40, 30))
|
||||
for y := 0; y < 30; y++ {
|
||||
for x := 0; x < 40; x++ {
|
||||
src.SetRGBA(x, y, color.RGBA{R: uint8(x * 6), G: uint8(y * 8), B: uint8((x + y) * 3), A: 255})
|
||||
}
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if err := png.Encode(&buf, src); err != nil {
|
||||
t.Fatalf("encode source: %v", err)
|
||||
}
|
||||
out, err := ApplyAnnotations(buf.Bytes(), []Annotation{{
|
||||
Tool: "mosaic-rect", Points: []Point{{X: 10, Y: 5}, {X: 30, Y: 25}},
|
||||
}}, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("apply annotations: %v", err)
|
||||
}
|
||||
img, err := png.Decode(bytes.NewReader(out))
|
||||
if err != nil {
|
||||
t.Fatalf("decode output: %v", err)
|
||||
}
|
||||
if img.At(12, 7) != img.At(18, 13) {
|
||||
t.Fatalf("expected pixels in one mosaic block to share a color")
|
||||
}
|
||||
if img.At(5, 5) != src.At(5, 5) {
|
||||
t.Fatalf("expected pixels outside mosaic rectangle to remain unchanged")
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyAnnotationsPixelatesOnlyMosaicBrushStroke(t *testing.T) {
|
||||
src := image.NewRGBA(image.Rect(0, 0, 50, 30))
|
||||
for y := 0; y < 30; y++ {
|
||||
for x := 0; x < 50; x++ {
|
||||
src.SetRGBA(x, y, color.RGBA{R: uint8(x * 5), G: uint8(y * 8), A: 255})
|
||||
}
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if err := png.Encode(&buf, src); err != nil {
|
||||
t.Fatalf("encode source: %v", err)
|
||||
}
|
||||
out, err := ApplyAnnotations(buf.Bytes(), []Annotation{{
|
||||
Tool: "mosaic-brush", StrokeWidth: 12, Points: []Point{{X: 5, Y: 15}, {X: 45, Y: 15}},
|
||||
}}, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("apply annotations: %v", err)
|
||||
}
|
||||
img, err := png.Decode(bytes.NewReader(out))
|
||||
if err != nil {
|
||||
t.Fatalf("decode output: %v", err)
|
||||
}
|
||||
if img.At(12, 15) == src.At(12, 15) {
|
||||
t.Fatalf("expected brush path to be pixelated")
|
||||
}
|
||||
if img.At(12, 2) != src.At(12, 2) {
|
||||
t.Fatalf("expected pixels outside brush path to remain unchanged")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user