draw

package
v1.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

drawパッケージは、画像合成関数を提供します。

このパッケージの紹介については、「Go image/drawパッケージ」を参照してください: https://golang.org/doc/articles/image_draw.html

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Draw

func Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point, op Op)

Drawは、nilマスクで DrawMask を呼び出します。

func DrawMask

func DrawMask(dst Image, r image.Rectangle, src image.Image, sp image.Point, mask image.Image, mp image.Point, op Op)

DrawMaskは、dstのr.Minをsrcのspとmaskのmpに揃え、その後dstの矩形rを ポーター-ダフ合成の結果で置き換えます。nilのマスクは不透明として扱われます。

Types

type Drawer added in v1.2.0

type Drawer interface {
	Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point)
}

Drawerは Draw メソッドを含みます。

Example (FloydSteinberg)
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/image"
	"github.com/shogo82148/std/image/color"
	"github.com/shogo82148/std/image/draw"
	"github.com/shogo82148/std/math"
)

func main() {
	const width = 130
	const height = 50

	im := image.NewGray(image.Rectangle{Max: image.Point{X: width, Y: height}})
	for x := 0; x < width; x++ {
		for y := 0; y < height; y++ {
			dist := math.Sqrt(math.Pow(float64(x-width/2), 2)/3+math.Pow(float64(y-height/2), 2)) / (height / 1.5) * 255
			var gray uint8
			if dist > 255 {
				gray = 255
			} else {
				gray = uint8(dist)
			}
			im.SetGray(x, y, color.Gray{Y: 255 - gray})
		}
	}
	pi := image.NewPaletted(im.Bounds(), []color.Color{
		color.Gray{Y: 255},
		color.Gray{Y: 160},
		color.Gray{Y: 70},
		color.Gray{Y: 35},
		color.Gray{Y: 0},
	})

	draw.FloydSteinberg.Draw(pi, im.Bounds(), im, image.Point{})
	shade := []string{" ", "░", "▒", "▓", "█"}
	for i, p := range pi.Pix {
		fmt.Print(shade[p])
		if (i+1)%width == 0 {
			fmt.Print("\n")
		}
	}
}
Output:

var FloydSteinberg Drawer = floydSteinberg{}

FloydSteinbergは、Floyd-Steinberg誤差拡散を持つ Src OpDrawer です。

type Image

type Image interface {
	image.Image
	Set(x, y int, c color.Color)
}

Imageは、単一のピクセルを変更するSetメソッドを持つimage.Imageです。

type Op

type Op int

Opは、ポーター-ダフ合成演算子です。

const (
	// Overは “(src in mask) over dst” を指定します。
	Over Op = iota
	// Srcは “src in mask” を指定します。
	Src
)

func (Op) Draw added in v1.2.0

func (op Op) Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point)

Drawは、この Op とともにDraw関数を呼び出すことで Drawer インターフェースを実装します。

type Quantizer added in v1.2.0

type Quantizer interface {
	Quantize(p color.Palette, m image.Image) color.Palette
}

Quantizerは、画像のパレットを生成します。

type RGBA64Image added in v1.17.0

type RGBA64Image interface {
	image.RGBA64Image
	Set(x, y int, c color.Color)
	SetRGBA64(x, y int, c color.RGBA64)
}

RGBA64Imageは、単一のピクセルを変更するSetRGBA64メソッドで、Imageimage.RGBA64Image の インターフェースを拡張します。SetRGBA64はSetを呼び出すのと同等ですが、具体的な色の タイプを color.Color インターフェースタイプに変換する際の割り当てを避けることができます。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL