diff --git a/image_test.go b/image_test.go index 7481bf249..08d0b3f9a 100644 --- a/image_test.go +++ b/image_test.go @@ -2199,3 +2199,31 @@ func TestImageReplacePixelsAndModifyPixels(t *testing.T) { } } } + +func TestImageCompositeModeMultiply(t *testing.T) { + const w, h = 16, 16 + dst, _ := NewImage(w, h, FilterDefault) + src, _ := NewImage(w, h, FilterDefault) + + dst.Fill(color.RGBA{0x01, 0x02, 0x03, 0x04}) + src.Fill(color.RGBA{0x05, 0x06, 0x07, 0x08}) + + op := &DrawImageOptions{} + op.CompositeMode = CompositeModeMultiply + dst.DrawImage(src, op) + + for j := 0; j < h; j++ { + for i := 0; i < w; i++ { + got := dst.At(i, j).(color.RGBA) + want := color.RGBA{ + R: byte(math.Floor((0x01 / 255.0) * (0x05 / 255.0) * 255)), + G: byte(math.Floor((0x02 / 255.0) * (0x06 / 255.0) * 255)), + B: byte(math.Floor((0x03 / 255.0) * (0x07 / 255.0) * 255)), + A: byte(math.Floor((0x04 / 255.0) * (0x08 / 255.0) * 255)), + } + if got != want { + t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want) + } + } + } +} diff --git a/internal/graphicsdriver/metal/graphics.go b/internal/graphicsdriver/metal/graphics.go index 71dde5bc5..ed102a28c 100644 --- a/internal/graphicsdriver/metal/graphics.go +++ b/internal/graphicsdriver/metal/graphics.go @@ -571,6 +571,8 @@ func (g *Graphics) Reset() error { return mtl.BlendFactorOneMinusSourceAlpha case driver.OneMinusDstAlpha: return mtl.BlendFactorOneMinusDestinationAlpha + case driver.DstColor: + return mtl.BlendFactorDestinationColor default: panic(fmt.Sprintf("metal: invalid operation: %d", c)) }