diff options
Diffstat (limited to 'src/image/draw/draw.go')
-rw-r--r-- | src/image/draw/draw.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/image/draw/draw.go b/src/image/draw/draw.go index cffdcbc0d7..7f9127168e 100644 --- a/src/image/draw/draw.go +++ b/src/image/draw/draw.go @@ -127,6 +127,9 @@ func DrawMask(dst Image, r image.Rectangle, src image.Image, sp image.Point, mas if drawYCbCr(dst0, r, src0, sp) { return } + case *image.CMYK: + drawCMYK(dst0, r, src0, sp) + return } } else if mask0, ok := mask.(*image.Alpha); ok { switch src0 := src.(type) { @@ -151,6 +154,9 @@ func DrawMask(dst Image, r image.Rectangle, src image.Image, sp image.Point, mas if drawYCbCr(dst0, r, src0, sp) { return } + case *image.CMYK: + drawCMYK(dst0, r, src0, sp) + return } } } @@ -392,6 +398,8 @@ func drawNRGBASrc(dst *image.RGBA, r image.Rectangle, src *image.NRGBA, sp image } } +// TODO(nigeltao): this function is copy/pasted to image/jpeg/reader.go. We +// should un-copy/paste it. func drawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Point) (ok bool) { // An image.YCbCr is always fully opaque, and so if the mask is implicitly nil // (i.e. fully opaque) then the op is effectively always Src. @@ -460,6 +468,28 @@ func drawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po return true } +func drawCMYK(dst *image.RGBA, r image.Rectangle, src *image.CMYK, sp image.Point) { + // An image.CMYK is always fully opaque, and so if the mask is implicitly nil + // (i.e. fully opaque) then the op is effectively always Src. + i0 := (r.Min.X - dst.Rect.Min.X) * 4 + i1 := (r.Max.X - dst.Rect.Min.X) * 4 + si0 := (sp.X - src.Rect.Min.X) * 4 + yMax := r.Max.Y - dst.Rect.Min.Y + + y := r.Min.Y - dst.Rect.Min.Y + sy := sp.Y - src.Rect.Min.Y + for ; y != yMax; y, sy = y+1, sy+1 { + dpix := dst.Pix[y*dst.Stride:] + spix := src.Pix[sy*src.Stride:] + + for i, si := i0, si0; i < i1; i, si = i+4, si+4 { + dpix[i+0], dpix[i+1], dpix[i+2] = + color.CMYKToRGB(spix[si+0], spix[si+1], spix[si+2], spix[si+3]) + dpix[i+3] = 255 + } + } +} + func drawGlyphOver(dst *image.RGBA, r image.Rectangle, src *image.Uniform, mask *image.Alpha, mp image.Point) { i0 := dst.PixOffset(r.Min.X, r.Min.Y) i1 := i0 + r.Dx()*4 |