當前位置: 首頁>>代碼示例>>Golang>>正文


Golang image.NewNRGBA64函數代碼示例

本文整理匯總了Golang中image.NewNRGBA64函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewNRGBA64函數的具體用法?Golang NewNRGBA64怎麽用?Golang NewNRGBA64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewNRGBA64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewDrawableSize

// NewDrawableSize returns a new draw.Image with the same type as p and the given bounds.
// If p is not a draw.Image, another type is used.
func NewDrawableSize(p image.Image, r image.Rectangle) draw.Image {
	switch p := p.(type) {
	case *image.RGBA:
		return image.NewRGBA(r)
	case *image.RGBA64:
		return image.NewRGBA64(r)
	case *image.NRGBA:
		return image.NewNRGBA(r)
	case *image.NRGBA64:
		return image.NewNRGBA64(r)
	case *image.Alpha:
		return image.NewAlpha(r)
	case *image.Alpha16:
		return image.NewAlpha16(r)
	case *image.Gray:
		return image.NewGray(r)
	case *image.Gray16:
		return image.NewGray16(r)
	case *image.Paletted:
		pl := make(color.Palette, len(p.Palette))
		copy(pl, p.Palette)
		return image.NewPaletted(r, pl)
	case *image.CMYK:
		return image.NewCMYK(r)
	default:
		return image.NewRGBA(r)
	}
}
開發者ID:cautio,項目名稱:imageserver,代碼行數:30,代碼來源:util.go

示例2: TestIsHighQuality

func TestIsHighQuality(t *testing.T) {
	r := image.Rect(0, 0, 1, 1)
	type TC struct {
		p        image.Image
		expected bool
	}
	for _, tc := range []TC{
		{
			p:        image.NewRGBA64(r),
			expected: true,
		},
		{
			p:        image.NewNRGBA64(r),
			expected: true,
		},
		{
			p:        image.NewRGBA(r),
			expected: false,
		},
	} {
		res := isHighQuality(tc.p)
		if res != tc.expected {
			t.Fatalf("unexpected result for %T: got %t, want %t", tc.p, res, tc.expected)
		}
	}
}
開發者ID:cautio,項目名稱:imageserver,代碼行數:26,代碼來源:gamma_test.go

示例3: Render

func Render(surfaces []Surface, camera Camera, width, height int) image.Image {

	view := View{camera, width, height}
	bounds := image.Rect(0, 0, width, height)
	img := image.NewNRGBA64(bounds)

	halfwidth := width / 2
	halfheight := height / 2

	// render
	for x := bounds.Min.X; x < bounds.Max.X; x++ {
		for y := bounds.Min.Y; y < bounds.Max.Y; y++ {

			// compensate for image y direction
			ray := view.Ray(x-halfwidth, -y+halfheight)

			hit, color := RayTraceRecursive(surfaces, ray, 1)

			if hit {
				img.Set(x, y, vecToNRGBA(color.Scale(0.7)))
			}
		}
	}

	return img
}
開發者ID:jpreiss,項目名稱:goray,代碼行數:26,代碼來源:renderer.go

示例4: TestIsHighQuality

func TestIsHighQuality(t *testing.T) {
	r := image.Rect(0, 0, 1, 1)
	for _, tc := range []struct {
		name     string
		p        image.Image
		expected bool
	}{
		{
			name:     "RGBA64",
			p:        image.NewRGBA64(r),
			expected: true,
		},
		{
			name:     "NRGBA64",
			p:        image.NewNRGBA64(r),
			expected: true,
		},
		{
			name:     "RGBA",
			p:        image.NewRGBA(r),
			expected: false,
		},
	} {
		t.Run(tc.name, func(t *testing.T) {
			res := isHighQuality(tc.p)
			if res != tc.expected {
				t.Fatalf("unexpected result for %T: got %t, want %t", tc.p, res, tc.expected)
			}
		})
	}
}
開發者ID:pierrre,項目名稱:imageserver,代碼行數:31,代碼來源:gamma_test.go

示例5: Process

func (self *AverageSmooth) Process(img image.Image) image.Image {
	ret := image.NewNRGBA64(img.Bounds())
	for x := 0; x < img.Bounds().Dx(); x++ {
		for y := 0; y < img.Bounds().Dy(); y++ {
			rs := 0
			gs := 0
			bs := 0
			as := 0
			n := 0
			for i := Max(0, x-1); i <= Min(img.Bounds().Dx()-1, x+1); i++ {
				for j := Max(0, y-1); j <= Min(img.Bounds().Dy()-1, y+1); j++ {
					c := 1
					if i == x && j == y {
						c = 8
					}
					r, g, b, a := img.At(i, j).RGBA()
					rs += int(r) * c
					gs += int(g) * c
					bs += int(b) * c
					as += int(a) * c
					n += c
				}
			}
			ret.Set(x, y, color.RGBA64{R: uint16(rs / n), G: uint16(gs / n), B: uint16(bs / n), A: uint16(as / n)})
		}
	}
	return ret
}
開發者ID:finallybiubiu,項目名稱:captcha,代碼行數:28,代碼來源:smooth.go

示例6: NewImageOfTypeRect

func NewImageOfTypeRect(src image.Image, bounds image.Rectangle) image.Image {
	switch i := src.(type) {
	case *image.Alpha:
		return image.NewAlpha(bounds)
	case *image.Alpha16:
		return image.NewAlpha16(bounds)
	case *image.Gray:
		return image.NewGray(bounds)
	case *image.Gray16:
		return image.NewGray16(bounds)
	case *image.NRGBA:
		return image.NewNRGBA(bounds)
	case *image.NRGBA64:
		return image.NewNRGBA64(bounds)
	case *image.Paletted:
		return image.NewPaletted(bounds, i.Palette)
	case *image.RGBA:
		return image.NewRGBA(bounds)
	case *image.RGBA64:
		return image.NewRGBA64(bounds)
	case *image.YCbCr:
		return image.NewYCbCr(bounds, i.SubsampleRatio)
	}
	panic("Unknown image type")
}
開發者ID:alexchipliev,項目名稱:go-start,代碼行數:25,代碼來源:functions.go

示例7: NewStegoImgWriter

/*
Create a new StegoImgWriter.
orig_img is a reader which should be the file of the image to encode the data into.
new_img is the file that the encoded image will be written to.
format can be one of "png", "jpeg", or "gif"

The orig_img reader need not remain open after the call returns. The writer must remain open until after the call to Close returns.
*/
func NewStegoImgWriter(orig_img io.Reader, new_img io.Writer) (img *StegoImgWriter, e error) {

	// create the image writer
	tmp_img := new(StegoImgWriter)

	// attempt to decode the original image
	tmp_img.orig_img, tmp_img.format, e = image.Decode(orig_img)

	// BUG(Andrew): only PNG format currently works
	tmp_img.format = "png"

	if e != nil {
		return
	}

	// create a new image
	tmp_img.new_img = image.NewNRGBA64(tmp_img.orig_img.Bounds())

	// make the data array to store all potential data
	size := (tmp_img.orig_img.Bounds().Max.X - 1) * (tmp_img.orig_img.Bounds().Max.Y - 1) * 3
	tmp_img.data = make([]byte, 0, size)

	// block out space for the size argument
	tmp_img.data = append(tmp_img.data, 0, 0, 0, 0)

	// save output
	tmp_img.output = new_img

	// mark image as open
	tmp_img.is_open = true

	// all was successful, return the new pointer
	img = tmp_img
	return
}
開發者ID:AndrewBurian,項目名稱:stegoimg,代碼行數:43,代碼來源:write_img.go

示例8: main

func main() {
	srcPath := os.Args[1]
	dstPath := os.Args[2]

	reader, err := os.Open(srcPath)
	check(err)
	src, srcFmt, err := image.Decode(reader)
	check(err)
	fmt.Println("Decoded source", srcPath, "as", srcFmt)

	scale := 8
	boundsMax := src.Bounds().Max
	smallMax := boundsMax.Div(scale)

	flat := image.NewNRGBA64(image.Rectangle{image.ZP, smallMax})

	samplePix := func(x, y int) (r, g, b []int) {
		var rs, gs, bs []int
		for i := x - 25; i <= x+25; i += 5 {
			if i < 0 || i >= boundsMax.X {
				continue
			}
			for j := y - 25; j <= y+25; j += 5 {
				if j < 0 || j >= boundsMax.Y {
					continue
				}
				r, g, b, _ := src.At(i, j).RGBA()
				rs = append(rs, int(r))
				gs = append(gs, int(g))
				bs = append(bs, int(b))
			}
		}
		return rs, gs, bs
	}

	var wg sync.WaitGroup
	for i := 0; i < smallMax.X; i++ {
		for j := 0; j < smallMax.Y; j++ {
			wg.Add(1)
			go func(x, y int) {
				defer wg.Done()
				r, g, b := samplePix(x*scale+scale/2, y*scale+scale/2)
				sort.Ints(r)
				sort.Ints(g)
				sort.Ints(b)
				idx := len(r) / 8
				flat.SetNRGBA64(x, y, color.NRGBA64{
					uint16(r[idx]), uint16(g[idx]), uint16(b[idx]),
					0xFFFF})
			}(i, j)
		}
	}
	wg.Wait()

	writer, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE, 0600)
	check(err)
	//jpeg.Encode(writer, proxy, nil)
	png.Encode(writer, flat)
}
開發者ID:nanotone,項目名稱:pictor,代碼行數:59,代碼來源:flat-init.go

示例9: createRandomImage

func createRandomImage(maxPaletteSize int) image.Image {
	r := image.Rectangle{Min: image.Point{0, 0}, Max: image.Point{gen.Rand(32) + 1, gen.Rand(32) + 1}}
	var img Image
	switch gen.Rand(10) {
	case 0:
		img = image.NewAlpha(r)
	case 1:
		img = image.NewAlpha16(r)
	case 2:
		img = image.NewCMYK(r)
	case 3:
		img = image.NewGray(r)
	case 4:
		img = image.NewGray16(r)
	case 5:
		img = image.NewNRGBA(r)
	case 6:
		img = image.NewNRGBA64(r)
	case 7:
		img = image.NewPaletted(r, randPalette(maxPaletteSize))
	case 8:
		img = image.NewRGBA(r)
	case 9:
		img = image.NewRGBA64(r)
	default:
		panic("bad")
	}
	fill := gen.Rand(19)
	var palette []color.Color
	if fill == 17 {
		palette = randPalette(maxPaletteSize)
	}
	for y := 0; y < r.Max.Y; y++ {
		for x := 0; x < r.Max.X; x++ {
			switch {
			case fill <= 15:
				img.Set(x, y, color.RGBA64{
					^uint16(0) * uint16((fill>>0)&1),
					^uint16(0) * uint16((fill>>1)&1),
					^uint16(0) * uint16((fill>>2)&1),
					^uint16(0) * uint16((fill>>3)&1),
				})
			case fill == 16:
				img.Set(x, y, randColor())
			case fill == 17:
				img.Set(x, y, palette[gen.Rand(len(palette))])
			case fill == 18:
				if gen.Rand(3) != 0 {
					img.Set(x, y, color.RGBA64{})
				} else {
					img.Set(x, y, randColor())
				}
			default:
				panic("bad")
			}
		}
	}
	return img.(image.Image)
}
開發者ID:sjn1978,項目名稱:go-fuzz,代碼行數:59,代碼來源:main.go

示例10: ConvertToNRGBA64

// ConvertToNRGBA64 returns an *image.NRGBA64 instance by asserting the given
// ImageReader has that type or, if it does not, using Copy to concurrently
// set the color.Color values of a new *image.NRGBA64 instance with the same
// bounds.
func ConvertToNRGBA64(src ImageReader) *image.NRGBA64 {
	if dst, ok := src.(*image.NRGBA64); ok {
		return dst
	}
	dst := image.NewNRGBA64(src.Bounds())
	Copy(dst, src)
	return dst
}
開發者ID:buth,項目名稱:imageutil,代碼行數:12,代碼來源:imageutil.go

示例11: BenchmarkEncodeNRGBA64

func BenchmarkEncodeNRGBA64(b *testing.B) {
	img := image.NewNRGBA64(image.Rect(0, 0, 1<<10, 1<<10))
	io.ReadFull(rand.Reader, img.Pix)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		Encode(ioutil.Discard, img)
	}
}
開發者ID:juggle-tux,項目名稱:farbfeld,代碼行數:8,代碼來源:farbfeld_test.go

示例12: TestSubImage

func TestSubImage(t *testing.T) {
	testData := []struct {
		desc string
		img  draw.Image
		ok   bool
	}{
		{
			"sub image (Gray)",
			image.NewGray(image.Rect(0, 0, 10, 10)),
			true,
		},
		{
			"sub image (Gray16)",
			image.NewGray16(image.Rect(0, 0, 10, 10)),
			true,
		},
		{
			"sub image (RGBA)",
			image.NewRGBA(image.Rect(0, 0, 10, 10)),
			true,
		},
		{
			"sub image (RGBA64)",
			image.NewRGBA64(image.Rect(0, 0, 10, 10)),
			true,
		},
		{
			"sub image (NRGBA)",
			image.NewNRGBA(image.Rect(0, 0, 10, 10)),
			true,
		},
		{
			"sub image (NRGBA64)",
			image.NewNRGBA64(image.Rect(0, 0, 10, 10)),
			true,
		},
		{
			"sub image (fake)",
			fakeDrawImage{image.Rect(0, 0, 10, 10)},
			false,
		},
	}

	for _, d := range testData {
		simg, ok := getSubImage(d.img, image.Pt(3, 3))
		if ok != d.ok {
			t.Errorf("test [%s] failed: expected %#v, got %#v", d.desc, d.ok, ok)
		} else if ok {
			simg.Set(5, 5, color.NRGBA{255, 255, 255, 255})
			r, g, b, a := d.img.At(5, 5).RGBA()
			if r != 0xffff || g != 0xffff || b != 0xffff || a != 0xffff {
				t.Errorf("test [%s] failed: expected (0xffff, 0xffff, 0xffff, 0xffff), got (%d, %d, %d, %d)", d.desc, r, g, b, a)
			}
		}
	}

}
開發者ID:eliquious,項目名稱:gift,代碼行數:57,代碼來源:gift_test.go

示例13: Decode

// Decode reads a farbfeld from r and returns it as image.NRGBA64.
func Decode(r io.Reader) (image.Image, error) {
	cfg, err := DecodeConfig(r)
	if err != nil {
		return nil, err
	}
	img := image.NewNRGBA64(image.Rect(0, 0, cfg.Width, cfg.Height))
	// image.NRGBA64 is big endian, so is farbfeld → just copy bytes
	_, err = io.ReadFull(r, img.Pix)
	return img, err
}
開發者ID:hullerob,項目名稱:go.farbfeld,代碼行數:11,代碼來源:farbfeld.go

示例14: Decode

// Decode reads a Farbfeld image from r and returns it as an image.Image.
func Decode(r io.Reader) (image.Image, error) {
	cfg, err := DecodeConfig(r)
	if err != nil {
		return nil, err
	}

	img := image.NewNRGBA64(image.Rect(0, 0, cfg.Width, cfg.Height))
	_, err = io.ReadFull(r, img.Pix)
	return img, err
}
開發者ID:juggle-tux,項目名稱:farbfeld,代碼行數:11,代碼來源:farbfeld.go

示例15: TestIsOpaque

func TestIsOpaque(t *testing.T) {
	type opqt struct {
		img    image.Image
		opaque bool
	}
	var testData []opqt

	testData = append(testData, opqt{image.NewNRGBA(image.Rect(0, 0, 1, 1)), false})
	testData = append(testData, opqt{image.NewNRGBA64(image.Rect(0, 0, 1, 1)), false})
	testData = append(testData, opqt{image.NewRGBA(image.Rect(0, 0, 1, 1)), false})
	testData = append(testData, opqt{image.NewRGBA64(image.Rect(0, 0, 1, 1)), false})
	testData = append(testData, opqt{image.NewGray(image.Rect(0, 0, 1, 1)), true})
	testData = append(testData, opqt{image.NewGray16(image.Rect(0, 0, 1, 1)), true})
	testData = append(testData, opqt{image.NewYCbCr(image.Rect(0, 0, 1, 1), image.YCbCrSubsampleRatio444), true})
	testData = append(testData, opqt{image.NewAlpha(image.Rect(0, 0, 1, 1)), false})

	img1 := image.NewNRGBA(image.Rect(0, 0, 1, 1))
	img1.Set(0, 0, color.NRGBA{0x00, 0x00, 0x00, 0xff})
	testData = append(testData, opqt{img1, true})
	img2 := image.NewNRGBA64(image.Rect(0, 0, 1, 1))
	img2.Set(0, 0, color.NRGBA{0x00, 0x00, 0x00, 0xff})
	testData = append(testData, opqt{img2, true})
	img3 := image.NewRGBA(image.Rect(0, 0, 1, 1))
	img3.Set(0, 0, color.NRGBA{0x00, 0x00, 0x00, 0xff})
	testData = append(testData, opqt{img3, true})
	img4 := image.NewRGBA64(image.Rect(0, 0, 1, 1))
	img4.Set(0, 0, color.NRGBA{0x00, 0x00, 0x00, 0xff})
	testData = append(testData, opqt{img4, true})
	imgp1 := image.NewPaletted(image.Rect(0, 0, 1, 1), []color.Color{color.NRGBA{0x00, 0x00, 0x00, 0xff}})
	imgp1.SetColorIndex(0, 0, 0)
	testData = append(testData, opqt{imgp1, true})
	imgp2 := image.NewPaletted(image.Rect(0, 0, 1, 1), []color.Color{color.NRGBA{0x00, 0x00, 0x00, 0xfe}})
	imgp2.SetColorIndex(0, 0, 0)
	testData = append(testData, opqt{imgp2, false})

	for _, d := range testData {
		isop := isOpaque(d.img)
		if isop != d.opaque {
			t.Errorf("isOpaque failed %#v, %v", d.img, isop)
		}
	}
}
開發者ID:eliquious,項目名稱:gift,代碼行數:42,代碼來源:utils_test.go


注:本文中的image.NewNRGBA64函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。