本文整理匯總了Golang中image.NRGBA64類的典型用法代碼示例。如果您正苦於以下問題:Golang NRGBA64類的具體用法?Golang NRGBA64怎麽用?Golang NRGBA64使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了NRGBA64類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AverageNRGBA64
func AverageNRGBA64(rect image.Rectangle, img *image.NRGBA64) color.NRGBA64 {
// Only use the area of the rectangle that overlaps with the image bounds.
rect = rect.Intersect(img.Bounds())
// Determine whether or not there's any area over which to determine an
// average.
d := uint64(rect.Dx() * rect.Dy())
if d == 0 {
return color.NRGBA64{}
}
var r, g, b, a uint64
AllPointsRP(
func(pt image.Point) {
c := img.NRGBA64At(pt.X, pt.Y)
r += uint64(c.R)
g += uint64(c.G)
b += uint64(c.B)
a += uint64(c.A)
},
)(rect)
return color.NRGBA64{
R: uint16(r / d),
G: uint16(g / d),
B: uint16(b / d),
A: uint16(a / d),
}
}
示例2: resizeNRGBA64
func resizeNRGBA64(in *image.NRGBA64, out *image.RGBA64, scale float64, coeffs []int32, offset []int, filterLength int) {
newBounds := out.Bounds()
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var rgba [4]int64
var sum int64
start := offset[y]
ci := y * filterLength
for i := 0; i < filterLength; i++ {
coeff := coeffs[ci+i]
if coeff != 0 {
xi := start + i
switch {
case uint(xi) < uint(maxX):
xi *= 8
case xi >= maxX:
xi = 8 * maxX
default:
xi = 0
}
// Forward alpha-premultiplication
a := int64(uint16(row[xi+6])<<8 | uint16(row[xi+7]))
r := int64(uint16(row[xi+0])<<8|uint16(row[xi+1])) * a
r /= 0xffff
g := int64(uint16(row[xi+2])<<8|uint16(row[xi+3])) * a
g /= 0xffff
b := int64(uint16(row[xi+4])<<8|uint16(row[xi+5])) * a
b /= 0xffff
rgba[0] += int64(coeff) * r
rgba[1] += int64(coeff) * g
rgba[2] += int64(coeff) * b
rgba[3] += int64(coeff) * a
sum += int64(coeff)
}
}
xo := (y-newBounds.Min.Y)*out.Stride + (x-newBounds.Min.X)*8
value := clampUint16(rgba[0] / sum)
out.Pix[xo+0] = uint8(value >> 8)
out.Pix[xo+1] = uint8(value)
value = clampUint16(rgba[1] / sum)
out.Pix[xo+2] = uint8(value >> 8)
out.Pix[xo+3] = uint8(value)
value = clampUint16(rgba[2] / sum)
out.Pix[xo+4] = uint8(value >> 8)
out.Pix[xo+5] = uint8(value)
value = clampUint16(rgba[3] / sum)
out.Pix[xo+6] = uint8(value >> 8)
out.Pix[xo+7] = uint8(value)
}
}
}
示例3: resizeGeneric
func resizeGeneric(in image.Image, out *image.NRGBA64, scale float64, coeffs []int32, offset []int, filterLength int) {
newBounds := out.Bounds()
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var rgba [4]int64
var sum int64
start := offset[y]
ci := y * filterLength
for i := 0; i < filterLength; i++ {
coeff := coeffs[ci+i]
if coeff != 0 {
xi := start + i
switch {
case xi < 0:
xi = 0
case xi >= maxX:
xi = maxX
}
r, g, b, a := in.At(xi+in.Bounds().Min.X, x+in.Bounds().Min.Y).RGBA()
// reverse alpha-premultiplication.
if a != 0 {
r *= 0xffff
r /= a
g *= 0xffff
g /= a
b *= 0xffff
b /= a
}
rgba[0] += int64(coeff) * int64(r)
rgba[1] += int64(coeff) * int64(g)
rgba[2] += int64(coeff) * int64(b)
rgba[3] += int64(coeff) * int64(a)
sum += int64(coeff)
}
}
offset := (y-newBounds.Min.Y)*out.Stride + (x-newBounds.Min.X)*8
value := clampUint16(rgba[0] / sum)
out.Pix[offset+0] = uint8(value >> 8)
out.Pix[offset+1] = uint8(value)
value = clampUint16(rgba[1] / sum)
out.Pix[offset+2] = uint8(value >> 8)
out.Pix[offset+3] = uint8(value)
value = clampUint16(rgba[2] / sum)
out.Pix[offset+4] = uint8(value >> 8)
out.Pix[offset+5] = uint8(value)
value = clampUint16(rgba[3] / sum)
out.Pix[offset+6] = uint8(value >> 8)
out.Pix[offset+7] = uint8(value)
}
}
}
示例4: interpolate1x64
// Interpolate uint64/pixel images.
func interpolate1x64(src *image.NRGBA64, dstW, dstH int) image.Image {
srcRect := src.Bounds()
srcW := srcRect.Dx()
srcH := srcRect.Dy()
ww, hh := uint64(dstW), uint64(dstH)
dx, dy := uint64(srcW), uint64(srcH)
n, sum := dx*dy, make([]uint64, dstW*dstH)
for y := 0; y < srcH; y++ {
pixOffset := src.PixOffset(0, y)
for x := 0; x < srcW; x++ {
// Get the source pixel.
val64 := binary.BigEndian.Uint64([]byte(src.Pix[pixOffset+0 : pixOffset+8]))
pixOffset += 8
// Spread the source pixel over 1 or more destination rows.
py := uint64(y) * hh
for remy := hh; remy > 0; {
qy := dy - (py % dy)
if qy > remy {
qy = remy
}
// Spread the source pixel over 1 or more destination columns.
px := uint64(x) * ww
index := (py/dy)*ww + (px / dx)
for remx := ww; remx > 0; {
qx := dx - (px % dx)
if qx > remx {
qx = remx
}
qxy := qx * qy
sum[index] += val64 * qxy
index++
px += qx
remx -= qx
}
py += qy
remy -= qy
}
}
}
dst := image.NewNRGBA64(image.Rect(0, 0, dstW, dstH))
index := 0
for y := 0; y < dstH; y++ {
pixOffset := dst.PixOffset(0, y)
for x := 0; x < dstW; x++ {
binary.BigEndian.PutUint64(dst.Pix[pixOffset+0:pixOffset+8], sum[index]/n)
pixOffset += 8
index++
}
}
return dst
}
示例5: newSetFuncNRGBA64
func newSetFuncNRGBA64(p *image.NRGBA64) SetFunc {
return func(x, y int, r, g, b, a uint32) {
r, g, b, a = RGBAToNRGBA(r, g, b, a)
i := p.PixOffset(x, y)
p.Pix[i+0] = uint8(r >> 8)
p.Pix[i+1] = uint8(r)
p.Pix[i+2] = uint8(g >> 8)
p.Pix[i+3] = uint8(g)
p.Pix[i+4] = uint8(b >> 8)
p.Pix[i+5] = uint8(b)
p.Pix[i+6] = uint8(a >> 8)
p.Pix[i+7] = uint8(a)
}
}
示例6: convertNRGBA64
func convertNRGBA64(dest *Image, src *image.NRGBA64) {
var x, y, i, si int
var a uint16
for x = dest.Rect.Min.X; x < dest.Rect.Max.X; x++ {
for y = dest.Rect.Min.Y; y < dest.Rect.Max.Y; y++ {
si = src.PixOffset(x, y)
i = dest.PixOffset(x, y)
a = uint16(src.Pix[si+6])
dest.Pix[i+0] = uint8((uint16(src.Pix[si+4]) * a) / 0xff)
dest.Pix[i+1] = uint8((uint16(src.Pix[si+2]) * a) / 0xff)
dest.Pix[i+2] = uint8((uint16(src.Pix[si+0]) * a) / 0xff)
dest.Pix[i+3] = src.Pix[si+6]
}
}
}
示例7: nearestNRGBA64
func nearestNRGBA64(in *image.NRGBA64, out *image.NRGBA64, scale float64, coeffs []bool, offset []int, filterLength int) {
newBounds := out.Bounds()
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var rgba [4]float32
var sum float32
start := offset[y]
ci := y * filterLength
for i := 0; i < filterLength; i++ {
if coeffs[ci+i] {
xi := start + i
switch {
case uint(xi) < uint(maxX):
xi *= 8
case xi >= maxX:
xi = 8 * maxX
default:
xi = 0
}
rgba[0] += float32(uint16(row[xi+0])<<8 | uint16(row[xi+1]))
rgba[1] += float32(uint16(row[xi+2])<<8 | uint16(row[xi+3]))
rgba[2] += float32(uint16(row[xi+4])<<8 | uint16(row[xi+5]))
rgba[3] += float32(uint16(row[xi+6])<<8 | uint16(row[xi+7]))
sum++
}
}
xo := (y-newBounds.Min.Y)*out.Stride + (x-newBounds.Min.X)*8
value := floatToUint16(rgba[0] / sum)
out.Pix[xo+0] = uint8(value >> 8)
out.Pix[xo+1] = uint8(value)
value = floatToUint16(rgba[1] / sum)
out.Pix[xo+2] = uint8(value >> 8)
out.Pix[xo+3] = uint8(value)
value = floatToUint16(rgba[2] / sum)
out.Pix[xo+4] = uint8(value >> 8)
out.Pix[xo+5] = uint8(value)
value = floatToUint16(rgba[3] / sum)
out.Pix[xo+6] = uint8(value >> 8)
out.Pix[xo+7] = uint8(value)
}
}
}
示例8: newAtFuncNRGBA64
func newAtFuncNRGBA64(p *image.NRGBA64) AtFunc {
return func(x, y int) (r, g, b, a uint32) {
i := p.PixOffset(x, y)
a = uint32(p.Pix[i+6])<<8 | uint32(p.Pix[i+7])
if a == 0 {
return
}
r = uint32(p.Pix[i+0])<<8 | uint32(p.Pix[i+1])
g = uint32(p.Pix[i+2])<<8 | uint32(p.Pix[i+3])
b = uint32(p.Pix[i+4])<<8 | uint32(p.Pix[i+5])
if a == 0xffff {
return
}
r = r * a / 0xffff
g = g * a / 0xffff
b = b * a / 0xffff
return
}
}
示例9: resize64
func resize64(src *image.NRGBA64, dstW, dstH int) image.Image {
srcRect := src.Bounds()
srcW := srcRect.Dx()
srcH := srcRect.Dy()
dstW64, dstH64 := uint64(dstW), uint64(dstH)
srcW64, srcH64 := uint64(srcW), uint64(srcH)
dst := image.NewNRGBA64(image.Rect(0, 0, dstW, dstH))
var x, y uint64
dstI := 0
for y = 0; y < dstH64; y++ {
srcY := int(y * srcH64 / dstH64)
for x = 0; x < dstW64; x++ {
srcX := int(x * srcW64 / dstW64)
srcI := 8 * (srcY*srcW + srcX)
copy(dst.Pix[dstI:dstI+8], src.Pix[srcI:srcI+8])
dstI += 8
}
}
return dst
}
示例10: NRGBA64ToChannels
// Channels decomposes a given NRGBA64 into red, green, blue, and alpha Channels.
func NRGBA64ToChannels(img *image.NRGBA64) (r, g, b, a Channel) {
r = channel{
bounds: img.Bounds,
gray16At: func(x, y int) color.Gray16 {
return color.Gray16{
Y: img.NRGBA64At(x, y).R,
}
},
}
g = channel{
bounds: img.Bounds,
gray16At: func(x, y int) color.Gray16 {
return color.Gray16{
Y: img.NRGBA64At(x, y).G,
}
},
}
b = channel{
bounds: img.Bounds,
gray16At: func(x, y int) color.Gray16 {
return color.Gray16{
Y: img.NRGBA64At(x, y).B,
}
},
}
a = channel{
bounds: img.Bounds,
gray16At: func(x, y int) color.Gray16 {
return color.Gray16{
Y: img.NRGBA64At(x, y).A,
}
},
}
return
}
示例11: putLineNRGBA64
func putLineNRGBA64(flipXY bool, column []f32RGBA, x int, dst *image.NRGBA64) {
dy := dst.Bounds().Min.Y
dx := dst.Bounds().Min.X
for y, dst_c := range column {
dst_nrgba := color.NRGBA64{
R: clampF32ToUint16(f32_to_uint16 * dst_c.R),
G: clampF32ToUint16(f32_to_uint16 * dst_c.G),
B: clampF32ToUint16(f32_to_uint16 * dst_c.B),
A: clampF32ToUint16(f32_to_uint16 * dst_c.A),
}
if flipXY {
dst.SetNRGBA64(y+dx, x+dy, dst_nrgba)
} else {
dst.SetNRGBA64(x+dx, y+dy, dst_nrgba)
}
}
}
示例12: fetchLineNRGBA64
func fetchLineNRGBA64(flipXY bool, column []f32RGBA, x int, src *image.NRGBA64) {
dy := src.Bounds().Min.Y
dx := src.Bounds().Min.X
pix := src.Pix
var idx int
for y := 0; y != len(column); y++ {
if flipXY {
idx = src.PixOffset(y+dx, x+dy)
} else {
idx = src.PixOffset(x+dx, y+dy)
}
column[y].R = uint16_to_f32 * float32(uint16(pix[idx+0])<<8|uint16(pix[idx+1]))
column[y].G = uint16_to_f32 * float32(uint16(pix[idx+2])<<8|uint16(pix[idx+3]))
column[y].B = uint16_to_f32 * float32(uint16(pix[idx+4])<<8|uint16(pix[idx+5]))
column[y].A = uint16_to_f32 * float32(uint16(pix[idx+6])<<8|uint16(pix[idx+7]))
}
}
示例13: readImagePass
// readImagePass reads a single image pass, sized according to the pass number.
func (d *decoder) readImagePass(r io.Reader, pass int, allocateOnly bool) (image.Image, error) {
var bitsPerPixel int = 0
pixOffset := 0
var (
gray *image.Gray
rgba *image.RGBA
paletted *image.Paletted
nrgba *image.NRGBA
gray16 *image.Gray16
rgba64 *image.RGBA64
nrgba64 *image.NRGBA64
img image.Image
)
width, height := d.width, d.height
if d.interlace == itAdam7 && !allocateOnly {
p := interlacing[pass]
// Add the multiplication factor and subtract one, effectively rounding up.
width = (width - p.xOffset + p.xFactor - 1) / p.xFactor
height = (height - p.yOffset + p.yFactor - 1) / p.yFactor
// A PNG image can't have zero width or height, but for an interlaced
// image, an individual pass might have zero width or height. If so, we
// shouldn't even read a per-row filter type byte, so return early.
if width == 0 || height == 0 {
return nil, nil
}
}
switch d.cb {
case cbG1, cbG2, cbG4, cbG8:
bitsPerPixel = d.depth
gray = image.NewGray(image.Rect(0, 0, width, height))
img = gray
case cbGA8:
bitsPerPixel = 16
nrgba = image.NewNRGBA(image.Rect(0, 0, width, height))
img = nrgba
case cbTC8:
bitsPerPixel = 24
rgba = image.NewRGBA(image.Rect(0, 0, width, height))
img = rgba
case cbP1, cbP2, cbP4, cbP8:
bitsPerPixel = d.depth
paletted = image.NewPaletted(image.Rect(0, 0, width, height), d.palette)
img = paletted
case cbTCA8:
bitsPerPixel = 32
nrgba = image.NewNRGBA(image.Rect(0, 0, width, height))
img = nrgba
case cbG16:
bitsPerPixel = 16
gray16 = image.NewGray16(image.Rect(0, 0, width, height))
img = gray16
case cbGA16:
bitsPerPixel = 32
nrgba64 = image.NewNRGBA64(image.Rect(0, 0, width, height))
img = nrgba64
case cbTC16:
bitsPerPixel = 48
rgba64 = image.NewRGBA64(image.Rect(0, 0, width, height))
img = rgba64
case cbTCA16:
bitsPerPixel = 64
nrgba64 = image.NewNRGBA64(image.Rect(0, 0, width, height))
img = nrgba64
}
if allocateOnly {
return img, nil
}
bytesPerPixel := (bitsPerPixel + 7) / 8
// The +1 is for the per-row filter type, which is at cr[0].
rowSize := 1 + (bitsPerPixel*width+7)/8
// cr and pr are the bytes for the current and previous row.
cr := make([]uint8, rowSize)
pr := make([]uint8, rowSize)
for y := 0; y < height; y++ {
// Read the decompressed bytes.
_, err := io.ReadFull(r, cr)
if err != nil {
if err == io.EOF || err == io.ErrUnexpectedEOF {
return nil, FormatError("not enough pixel data")
}
return nil, err
}
// Apply the filter.
cdat := cr[1:]
pdat := pr[1:]
switch cr[0] {
case ftNone:
// No-op.
case ftSub:
for i := bytesPerPixel; i < len(cdat); i++ {
cdat[i] += cdat[i-bytesPerPixel]
}
case ftUp:
for i, p := range pdat {
cdat[i] += p
}
//.........這裏部分代碼省略.........
示例14: idatReader
func (d *decoder) idatReader(idat io.Reader) (image.Image, os.Error) {
r, err := zlib.NewReader(idat)
if err != nil {
return nil, err
}
defer r.Close()
bpp := 0 // Bytes per pixel.
maxPalette := uint8(0)
var (
gray *image.Gray
rgba *image.RGBA
paletted *image.Paletted
nrgba *image.NRGBA
gray16 *image.Gray16
rgba64 *image.RGBA64
nrgba64 *image.NRGBA64
img image.Image
)
switch d.cb {
case cbG8:
bpp = 1
gray = image.NewGray(d.width, d.height)
img = gray
case cbTC8:
bpp = 3
rgba = image.NewRGBA(d.width, d.height)
img = rgba
case cbP8:
bpp = 1
paletted = image.NewPaletted(d.width, d.height, d.palette)
img = paletted
maxPalette = uint8(len(d.palette) - 1)
case cbTCA8:
bpp = 4
nrgba = image.NewNRGBA(d.width, d.height)
img = nrgba
case cbG16:
bpp = 2
gray16 = image.NewGray16(d.width, d.height)
img = gray16
case cbTC16:
bpp = 6
rgba64 = image.NewRGBA64(d.width, d.height)
img = rgba64
case cbTCA16:
bpp = 8
nrgba64 = image.NewNRGBA64(d.width, d.height)
img = nrgba64
}
// cr and pr are the bytes for the current and previous row.
// The +1 is for the per-row filter type, which is at cr[0].
cr := make([]uint8, 1+bpp*d.width)
pr := make([]uint8, 1+bpp*d.width)
for y := 0; y < d.height; y++ {
// Read the decompressed bytes.
_, err := io.ReadFull(r, cr)
if err != nil {
return nil, err
}
// Apply the filter.
cdat := cr[1:]
pdat := pr[1:]
switch cr[0] {
case ftNone:
// No-op.
case ftSub:
for i := bpp; i < len(cdat); i++ {
cdat[i] += cdat[i-bpp]
}
case ftUp:
for i := 0; i < len(cdat); i++ {
cdat[i] += pdat[i]
}
case ftAverage:
for i := 0; i < bpp; i++ {
cdat[i] += pdat[i] / 2
}
for i := bpp; i < len(cdat); i++ {
cdat[i] += uint8((int(cdat[i-bpp]) + int(pdat[i])) / 2)
}
case ftPaeth:
for i := 0; i < bpp; i++ {
cdat[i] += paeth(0, pdat[i], 0)
}
for i := bpp; i < len(cdat); i++ {
cdat[i] += paeth(cdat[i-bpp], pdat[i], pdat[i-bpp])
}
default:
return nil, FormatError("bad filter type")
}
// Convert from bytes to colors.
switch d.cb {
case cbG8:
for x := 0; x < d.width; x++ {
gray.Set(x, y, image.GrayColor{cdat[x]})
}
case cbTC8:
//.........這裏部分代碼省略.........
示例15: idatReader
func (d *decoder) idatReader(idat io.Reader) (image.Image, os.Error) {
r, err := zlib.NewReader(idat)
if err != nil {
return nil, err
}
defer r.Close()
bitsPerPixel := 0
maxPalette := uint8(0)
var (
gray *image.Gray
rgba *image.RGBA
paletted *image.Paletted
nrgba *image.NRGBA
gray16 *image.Gray16
rgba64 *image.RGBA64
nrgba64 *image.NRGBA64
img image.Image
)
switch d.cb {
case cbG1, cbG2, cbG4, cbG8:
bitsPerPixel = d.depth
gray = image.NewGray(d.width, d.height)
img = gray
case cbGA8:
bitsPerPixel = 16
nrgba = image.NewNRGBA(d.width, d.height)
img = nrgba
case cbTC8:
bitsPerPixel = 24
rgba = image.NewRGBA(d.width, d.height)
img = rgba
case cbP1, cbP2, cbP4, cbP8:
bitsPerPixel = d.depth
paletted = image.NewPaletted(d.width, d.height, d.palette)
img = paletted
maxPalette = uint8(len(d.palette) - 1)
case cbTCA8:
bitsPerPixel = 32
nrgba = image.NewNRGBA(d.width, d.height)
img = nrgba
case cbG16:
bitsPerPixel = 16
gray16 = image.NewGray16(d.width, d.height)
img = gray16
case cbGA16:
bitsPerPixel = 32
nrgba64 = image.NewNRGBA64(d.width, d.height)
img = nrgba64
case cbTC16:
bitsPerPixel = 48
rgba64 = image.NewRGBA64(d.width, d.height)
img = rgba64
case cbTCA16:
bitsPerPixel = 64
nrgba64 = image.NewNRGBA64(d.width, d.height)
img = nrgba64
}
bytesPerPixel := (bitsPerPixel + 7) / 8
// cr and pr are the bytes for the current and previous row.
// The +1 is for the per-row filter type, which is at cr[0].
cr := make([]uint8, 1+(bitsPerPixel*d.width+7)/8)
pr := make([]uint8, 1+(bitsPerPixel*d.width+7)/8)
for y := 0; y < d.height; y++ {
// Read the decompressed bytes.
_, err := io.ReadFull(r, cr)
if err != nil {
return nil, err
}
// Apply the filter.
cdat := cr[1:]
pdat := pr[1:]
switch cr[0] {
case ftNone:
// No-op.
case ftSub:
for i := bytesPerPixel; i < len(cdat); i++ {
cdat[i] += cdat[i-bytesPerPixel]
}
case ftUp:
for i := 0; i < len(cdat); i++ {
cdat[i] += pdat[i]
}
case ftAverage:
for i := 0; i < bytesPerPixel; i++ {
cdat[i] += pdat[i] / 2
}
for i := bytesPerPixel; i < len(cdat); i++ {
cdat[i] += uint8((int(cdat[i-bytesPerPixel]) + int(pdat[i])) / 2)
}
case ftPaeth:
for i := 0; i < bytesPerPixel; i++ {
cdat[i] += paeth(0, pdat[i], 0)
}
for i := bytesPerPixel; i < len(cdat); i++ {
cdat[i] += paeth(cdat[i-bytesPerPixel], pdat[i], pdat[i-bytesPerPixel])
}
default:
//.........這裏部分代碼省略.........