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


Golang image.NewYCbCr函數代碼示例

本文整理匯總了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)
	}
}
開發者ID:donlzx,項目名稱:rez,代碼行數:12,代碼來源:bench_test.go

示例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),
	}
}
開發者ID:sfrdmn,項目名稱:camlistore,代碼行數:15,代碼來源:resize_test.go

示例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")
}
開發者ID:alexchipliev,項目名稱:go-start,代碼行數:25,代碼來源:functions.go

示例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 {
	}
}
開發者ID:oscarleung,項目名稱:golang-image,代碼行數:28,代碼來源:scan.go

示例5: BenchmarkHalveYCrCb

func BenchmarkHalveYCrCb(b *testing.B) {
	m := image.NewYCbCr(orig, image.YCbCrSubsampleRatio422)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		halve(m)
	}
}
開發者ID:rfistman,項目名稱:camlistore,代碼行數:7,代碼來源:bench_test.go

示例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
}
開發者ID:donlzx,項目名稱:rez,代碼行數:46,代碼來源:resize_test.go

示例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)
	}
}
開發者ID:rayleyva,項目名稱:camlistore,代碼行數:9,代碼來源:bench_test.go

示例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())
}
開發者ID:donlzx,項目名稱:rez,代碼行數:10,代碼來源:resize_test.go

示例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)
}
開發者ID:jordanshoebox,項目名稱:resize,代碼行數:11,代碼來源:resize_test.go

示例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)
}
開發者ID:xushiwei,項目名稱:vp8-go,代碼行數:12,代碼來源:decode.go

示例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
}
開發者ID:yoya,項目名稱:go-qcms,代碼行數:53,代碼來源:image.go

示例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
}
開發者ID:donlzx,項目名稱:rez,代碼行數:12,代碼來源:resize_test.go

示例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)
	}
}
開發者ID:camarox53,項目名稱:coreos-baremetal,代碼行數:13,代碼來源:bench_test.go

示例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)")
	}
}
開發者ID:kaiinui,項目名稱:gift,代碼行數:49,代碼來源:pixels_test.go

示例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)
}
開發者ID:nolenroyalty,項目名稱:bangarang,代碼行數:18,代碼來源:image_test.go


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