本文整理匯總了Golang中image.NewYCbCr函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewYCbCr函數的具體用法?Golang NewYCbCr怎麽用?Golang NewYCbCr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewYCbCr函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: benchSpeed
func benchSpeed(b *testing.B, bt BenchType, asm bool) {
raw := readImage(b, "testdata/lenna.jpg")
src := image.NewYCbCr(image.Rect(0, 0, bt.win, bt.hin), image.YCbCrSubsampleRatio420)
convert(b, src, raw, asm, bt.interlaced, bt.filter)
dst := image.NewYCbCr(image.Rect(0, 0, bt.wout, bt.hout), image.YCbCrSubsampleRatio420)
converter := prepare(b, dst, src, asm, bt.interlaced, bt.filter, 0)
b.SetBytes(int64(bt.wout*bt.hout*3) >> 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
converter.Convert(dst, src)
}
}
示例2: makeImages
func makeImages(r image.Rectangle) []image.Image {
return []image.Image{
image.NewGray(r),
image.NewGray16(r),
image.NewNRGBA(r),
image.NewNRGBA64(r),
image.NewPaletted(r, somePalette),
image.NewRGBA(r),
image.NewRGBA64(r),
image.NewYCbCr(r, image.YCbCrSubsampleRatio444),
image.NewYCbCr(r, image.YCbCrSubsampleRatio422),
image.NewYCbCr(r, image.YCbCrSubsampleRatio420),
image.NewYCbCr(r, image.YCbCrSubsampleRatio440),
}
}
示例3: 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")
}
示例4: makeImg
// makeImg allocates and initializes the destination image.
func (d *decoder) makeImg(h0, v0, mxx, myy int) {
if d.jpegColorSpace == Grayscale {
m := image.NewGray(image.Rect(0, 0, 8*mxx, 8*myy))
d.img1 = m.SubImage(image.Rect(0, 0, d.width, d.height)).(*image.Gray)
return
} else if d.jpegColorSpace == YCbCr {
var subsampleRatio image.YCbCrSubsampleRatio
switch {
case h0 == 1 && v0 == 1:
subsampleRatio = image.YCbCrSubsampleRatio444
case h0 == 1 && v0 == 2:
subsampleRatio = image.YCbCrSubsampleRatio440
case h0 == 2 && v0 == 1:
subsampleRatio = image.YCbCrSubsampleRatio422
case h0 == 2 && v0 == 2:
subsampleRatio = image.YCbCrSubsampleRatio420
default:
panic("unreachable")
}
m := image.NewYCbCr(image.Rect(0, 0, 8*h0*mxx, 8*v0*myy), subsampleRatio)
d.img3 = m.SubImage(image.Rect(0, 0, d.width, d.height)).(*image.YCbCr)
} else if d.jpegColorSpace == RGBA {
m := image.NewRGBA(image.Rect(0, 0, 8*h0*mxx, 8*v0*myy))
d.img4 = m.SubImage(image.Rect(0, 0, d.width, d.height)).(*image.RGBA)
} else {
}
}
示例5: BenchmarkHalveYCrCb
func BenchmarkHalveYCrCb(b *testing.B) {
m := image.NewYCbCr(orig, image.YCbCrSubsampleRatio422)
b.ResetTimer()
for i := 0; i < b.N; i++ {
halve(m)
}
}
示例6: runTestCaseWith
func runTestCaseWith(t *testing.T, tc *TestCase, asm bool, cycles int) image.Image {
srcRaw := readImage(t, "testdata/"+tc.file).(*image.YCbCr)
dstRaw := image.NewYCbCr(image.Rect(0, 0, tc.dst.Max.X*2, tc.dst.Max.Y*2), srcRaw.SubsampleRatio)
var src, dst, ref image.Image
if tc.src.Empty() {
tc.src = srcRaw.Bounds()
}
suffix := "yuv"
if tc.rgb {
suffix = "rgb"
src = toRgb(srcRaw).SubImage(tc.src)
ref = toRgb(srcRaw).SubImage(tc.src)
dst = toRgb(dstRaw).SubImage(tc.dst)
} else {
src = srcRaw.SubImage(tc.src)
refRaw := image.NewYCbCr(src.Bounds(), srcRaw.SubsampleRatio)
err := Convert(refRaw, src, nil)
expect(t, err, nil)
ref = refRaw.SubImage(tc.src)
dst = dstRaw.SubImage(tc.dst)
}
fwd := prepare(t, dst, src, asm, tc.interlaced, tc.filter, tc.threads)
bwd := prepare(t, src, dst, asm, tc.interlaced, tc.filter, tc.threads)
for i := 0; i < cycles; i++ {
err := fwd.Convert(dst, src)
expect(t, err, nil)
err = bwd.Convert(src, dst)
expect(t, err, nil)
}
if len(tc.psnrs) > 0 {
checkPsnrs(t, ref, src, tc.psnrRect, tc.psnrs)
}
if len(tc.dump) > 0 {
sb := src.Bounds()
db := dst.Bounds()
asmSuffix := "go"
if asm {
asmSuffix = "asm"
}
name := fmt.Sprintf("testdata/%v-%vx%v-%vx%v-%v-%v-%v-%v.png",
tc.dump, sb.Dx(), sb.Dy(), db.Dx(), db.Dy(), suffix,
toInterlacedString(tc.interlaced), asmSuffix, tc.filter.Name())
writeImage(t, name, src)
}
return src
}
示例7: benchRescale
func benchRescale(b *testing.B, w, h, thumbW, thumbH int) {
// Most JPEGs are YCbCr, so bench with that.
im := image.NewYCbCr(image.Rect(0, 0, w, h), image.YCbCrSubsampleRatio422)
o := &DecodeOpts{MaxWidth: thumbW, MaxHeight: thumbH}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = rescale(im, o, false)
}
}
示例8: testInterlacedFailWith
func testInterlacedFailWith(t *testing.T, rgb bool) {
src := readImage(t, "testdata/lenna.jpg")
dst := image.Image(image.NewYCbCr(image.Rect(0, 0, 640, 480), image.YCbCrSubsampleRatio420))
if rgb {
src = toRgb(src)
dst = toRgb(dst)
}
convert(t, dst, src, false, true, NewBicubicFilter())
convert(t, dst, src, true, true, NewBicubicFilter())
}
示例9: jpegThumb
// Benchmark resize of 16 MPix jpeg image to 800px width.
func jpegThumb(b *testing.B, interp InterpolationFunction) {
input := image.NewYCbCr(image.Rect(0, 0, 4896, 3264), image.YCbCrSubsampleRatio422)
var output image.Image
for i := 0; i < b.N; i++ {
output = Resize(800, 0, input, interp)
}
output.At(0, 0)
}
示例10: ensureImg
// ensureImg ensures that d.img is large enough to hold the decoded frame.
func (d *Decoder) ensureImg() {
if d.img != nil {
p0, p1 := d.img.Rect.Min, d.img.Rect.Max
if p0.X == 0 && p0.Y == 0 && p1.X >= 16*d.mbw && p1.Y >= 16*d.mbh {
return
}
}
m := image.NewYCbCr(image.Rect(0, 0, 16*d.mbw, 16*d.mbh), image.YCbCrSubsampleRatio420)
d.img = m.SubImage(image.Rect(0, 0, d.frameHeader.Width, d.frameHeader.Height)).(*image.YCbCr)
d.upMB = make([]mb, d.mbw)
}
示例11: ImageTransformByProfile
func ImageTransformByProfile(src_image image.Image, src_prof, dst_prof *Profile) (image.Image, error) {
var dst_image image.Image
rect := src_image.Bounds()
width := rect.Dx()
height := rect.Dy()
colorModel := src_image.ColorModel()
// 今のところ RGBA, YCbCr のみ対応
if (colorModel != color.YCbCrModel) && (colorModel != color.RGBAModel) {
return nil, fmt.Errorf("ImageTransformByProfile: Unsupported ColorModel(%d)", colorModel)
}
var src_rgba *image.RGBA
var src_ycbcr *image.YCbCr
if colorModel == color.YCbCrModel {
// YCbCr の場合は RGB に変換する
src_ycbcr = src_image.(*image.YCbCr)
src_rgba = image.NewRGBA(rect)
DrawYCbCr(src_rgba, rect, src_ycbcr, image.Pt(0, 0))
} else {
src_rgba = src_image.(*image.RGBA) // type assertions
}
transform := CreateTransform(src_prof, DATA_RGBA_8, dst_prof, DATA_RGBA_8)
defer transform.DeleteTransform()
if transform == nil {
return nil, fmt.Errorf("ImageTransformByProfile: CreateTransform Failedl(%d)", colorModel)
}
dst_rgba := image.NewRGBA(rect)
src_pix := src_rgba.Pix
dst_pix := dst_rgba.Pix
len_pix := len(src_pix)
transform.DoTransform(src_pix, dst_pix, len_pix)
// YCbCr の場合は RGB から戻す
if colorModel == color.YCbCrModel {
dst_ycbcr := image.NewYCbCr(rect, src_ycbcr.SubsampleRatio)
var x int
var y int
for y = 0; y < height; y++ {
for x = 0; x < width; x++ {
r, g, b, _ := dst_rgba.At(x, y).RGBA()
yy, cb, cr := color.RGBToYCbCr(uint8(r), uint8(g), uint8(b))
yi := dst_ycbcr.YOffset(x, y)
ci := dst_ycbcr.COffset(x, y)
dst_ycbcr.Y[yi] = yy
dst_ycbcr.Cb[ci] = cb
dst_ycbcr.Cr[ci] = cr
}
}
dst_image = image.Image(dst_ycbcr)
} else {
dst_image = image.Image(dst_rgba)
}
return dst_image, nil
}
示例12: convertFiles
func convertFiles(t Tester, w, h int, input string, filter Filter, rgb bool) (image.Image, image.Image) {
src := readImage(t, input)
raw := image.NewYCbCr(image.Rect(0, 0, w*2, h*2), image.YCbCrSubsampleRatio420)
dst := raw.SubImage(image.Rect(7, 7, 7+w, 7+h))
if rgb {
src = toRgb(src)
dst = toRgb(dst)
}
err := Convert(dst, src, filter)
expect(t, err, nil)
return src, dst
}
示例13: benchRescale
func benchRescale(b *testing.B, w, h, thumbW, thumbH int) {
// Most JPEGs are YCbCr, so bench with that.
im := image.NewYCbCr(image.Rect(0, 0, w, h), image.YCbCrSubsampleRatio422)
o := &DecodeOpts{MaxWidth: thumbW, MaxHeight: thumbH}
sw, sh, needRescale := o.rescaleDimensions(im.Bounds(), false)
if !needRescale {
b.Fatal("opts.rescaleDimensions failed to indicate image needs rescale")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = rescale(im, sw, sh)
}
}
示例14: TestNewPixelGetter
func TestNewPixelGetter(t *testing.T) {
var img image.Image
var pg *pixelGetter
img = image.NewNRGBA(image.Rect(0, 0, 1, 1))
pg = newPixelGetter(img)
if pg.imgType != itNRGBA || pg.imgNRGBA == nil || !img.Bounds().Eq(pg.imgBounds) {
t.Error("newPixelGetter NRGBA")
}
img = image.NewNRGBA64(image.Rect(0, 0, 1, 1))
pg = newPixelGetter(img)
if pg.imgType != itNRGBA64 || pg.imgNRGBA64 == nil || !img.Bounds().Eq(pg.imgBounds) {
t.Error("newPixelGetter NRGBA64")
}
img = image.NewRGBA(image.Rect(0, 0, 1, 1))
pg = newPixelGetter(img)
if pg.imgType != itRGBA || pg.imgRGBA == nil || !img.Bounds().Eq(pg.imgBounds) {
t.Error("newPixelGetter RGBA")
}
img = image.NewRGBA64(image.Rect(0, 0, 1, 1))
pg = newPixelGetter(img)
if pg.imgType != itRGBA64 || pg.imgRGBA64 == nil || !img.Bounds().Eq(pg.imgBounds) {
t.Error("newPixelGetter RGBA64")
}
img = image.NewGray(image.Rect(0, 0, 1, 1))
pg = newPixelGetter(img)
if pg.imgType != itGray || pg.imgGray == nil || !img.Bounds().Eq(pg.imgBounds) {
t.Error("newPixelGetter Gray")
}
img = image.NewGray16(image.Rect(0, 0, 1, 1))
pg = newPixelGetter(img)
if pg.imgType != itGray16 || pg.imgGray16 == nil || !img.Bounds().Eq(pg.imgBounds) {
t.Error("newPixelGetter Gray16")
}
img = image.NewYCbCr(image.Rect(0, 0, 1, 1), image.YCbCrSubsampleRatio422)
pg = newPixelGetter(img)
if pg.imgType != itYCbCr || pg.imgYCbCr == nil || !img.Bounds().Eq(pg.imgBounds) {
t.Error("newPixelGetter YCbCr")
}
img = image.NewUniform(color.NRGBA64{0, 0, 0, 0})
pg = newPixelGetter(img)
if pg.imgType != itGeneric || pg.imgGeneric == nil || !img.Bounds().Eq(pg.imgBounds) {
t.Error("newPixelGetter Generic(Uniform)")
}
img = image.NewAlpha(image.Rect(0, 0, 1, 1))
pg = newPixelGetter(img)
if pg.imgType != itGeneric || pg.imgGeneric == nil || !img.Bounds().Eq(pg.imgBounds) {
t.Error("newPixelGetter Generic(Alpha)")
}
}
示例15: TestEncodeYCbCrStreamGeneric
func TestEncodeYCbCrStreamGeneric(t *testing.T) {
r := image.Rect(0, 0, 16, 16)
img := image.NewYCbCr(r, image.YCbCrSubsampleRatio444)
c := color.YCbCr{Y: 70, Cb: 146, Cr: 164}
for i := range img.Y {
img.Y[i] = c.Y
}
for i := range img.Cb {
img.Cb[i] = c.Cb
}
for i := range img.Cr {
img.Cr[i] = c.Cr
}
var buf bytes.Buffer
encodeImageStream(&buf, img)
expectImageBuffer(buf.Bytes(), r, c, t)
}