当前位置: 首页>>代码示例>>Golang>>正文


Golang Surface.Pixels方法代码示例

本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Surface.Pixels方法的典型用法代码示例。如果您正苦于以下问题:Golang Surface.Pixels方法的具体用法?Golang Surface.Pixels怎么用?Golang Surface.Pixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/veandco/go-sdl2/sdl.Surface的用法示例。


在下文中一共展示了Surface.Pixels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: surfaceManipulate

// surfaceManipulate is an internal function that creates a new surface, gets
// metadata, and then calls a passed-in function to actually do something to it,
// e.g. horizontally flip all the pixels.
//
// Note: this only supports manipulations that leave the Surface the same
// dimensions. It could potentially be generalized to handle manipulations that
// leave the Surface with the same number of pixels.
func surfaceManipulate(src *sdl.Surface, f func(src *sdl.Surface, srcWBytes, bytesPerPixel int32, srcPx, destPx []byte)) (*sdl.Surface, error) {
	pf := src.Format

	pixels := src.Pixels()
	bytesPP := int32(pf.BytesPerPixel)
	bitsPP := int32(pf.BitsPerPixel)

	newSurface, err := sdl.CreateRGBSurface(0, src.W, src.H, bitsPP, pf.Rmask, pf.Gmask, pf.Bmask, pf.Amask)

	if err != nil {
		return nil, err
	}

	pixelsDest := newSurface.Pixels()

	srcWBytes := int32(src.W * bytesPP)

	// Perform the manipulation
	f(src, srcWBytes, bytesPP, pixels, pixelsDest)

	return newSurface, nil
}
开发者ID:beejjorgensen,项目名称:eggdrop,代码行数:29,代码来源:util.go

示例2: SurfaceConvertToImage

func SurfaceConvertToImage(s *sdl.Surface) (img image.Image, err error) {
	switch s.Format.Format {
	case sdl.PIXELFORMAT_RGBA8888, sdl.PIXELFORMAT_RGBX8888:
		i := &image.RGBA{Rect: image.Rect(0, 0, int(s.W), int(s.H))}
		i.Pix = s.Pixels()
		img = i
	case sdl.PIXELFORMAT_INDEX8:
		i := image.NewRGBA(image.Rect(0, 0, int(s.W), int(s.H)))
		key, err := s.GetColorKey()
		if err != nil {
			return nil, err
		}
		//		fmt.Println(s.PixelNum(), len(s.Pixels()), len(i.Pix), s.W, s.H, s.Pitch, s.Format.BitsPerPixel, s.Format.BytesPerPixel, key)
		l := len(s.Pixels())
		var r, g, b, a uint8
		for n := 0; n < l; n += 1 {
			pixel := s.Pixels()[n]
			if pixel == uint8(key) {
				r, g, b, a = 0, 0, 0, 0
			} else {
				r, g, b, a = sdl.GetRGBA(uint32(pixel), s.Format)
			}

			p := i.PixOffset(n%int(s.Pitch), n/int(s.Pitch))
			i.Pix[p], i.Pix[p+1], i.Pix[p+2], i.Pix[p+3] = r, g, b, a
		}
		img = i
	default:
		sx, err := s.ConvertFormat(sdl.PIXELFORMAT_RGBX8888, 0)
		if err != nil {
			return nil, err
		}
		i := &image.RGBA{Rect: image.Rect(0, 0, int(s.W), int(s.H))}
		i.Pix = sx.Pixels()
		img = i
	}
	return
}
开发者ID:FieldSoft-HelloClyde,项目名称:bbvm,代码行数:38,代码来源:sdl.go


注:本文中的github.com/veandco/go-sdl2/sdl.Surface.Pixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。