Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: the api image.NewYCbCr allow user input initial image data to init it #20926

Closed
acrazing opened this issue Jul 6, 2017 · 4 comments
Labels
FrozenDueToAge Proposal WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@acrazing
Copy link

acrazing commented Jul 6, 2017

Currently, this API init the image with an empty bytes slice, it is useless for handle a yuv stream for we need to init it with user defined data usually.

The souce code at:

go/src/image/ycbcr.go

Lines 169 to 184 in c478c48

func NewYCbCr(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *YCbCr {
w, h, cw, ch := yCbCrSize(r, subsampleRatio)
i0 := w*h + 0*cw*ch
i1 := w*h + 1*cw*ch
i2 := w*h + 2*cw*ch
b := make([]byte, i2)
return &YCbCr{
Y: b[:i0:i0],
Cb: b[i0:i1:i1],
Cr: b[i1:i2:i2],
SubsampleRatio: subsampleRatio,
YStride: w,
CStride: cw,
Rect: r,
}
}

as follow:

// NewYCbCr returns a new YCbCr image with the given bounds and subsample
// ratio.
func NewYCbCr(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *YCbCr {
    w, h, cw, ch := yCbCrSize(r, subsampleRatio)
    i0 := w*h + 0*cw*ch
    i1 := w*h + 1*cw*ch
    i2 := w*h + 2*cw*ch
    b := make([]byte, i2)
    return &YCbCr{
        Y:              b[:i0:i0],
        Cb:             b[i0:i1:i1],
        Cr:             b[i1:i2:i2],
        SubsampleRatio: subsampleRatio,
        YStride:        w,
        CStride:        cw,
        Rect:           r,
    }
}

Env: Go 1.8.3, x86-64, MacOS 10

@gopherbot gopherbot added this to the Proposal milestone Jul 6, 2017
@bradfitz
Copy link
Contributor

The image.New* functions return an empty image for drawing into.

I think this is working as intended.

If you have initial data, you can prepare the YCbCr struct yourself.

What is your proposal?

@bradfitz bradfitz added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 17, 2017
@acrazing
Copy link
Author

@bradfitz If I read a yuv frame from a file, there is a slice contains the data already. and the statement b := make([]byte, i2) is useless.

@bradfitz
Copy link
Contributor

@nigeltao, is there something here besides just "don't use NewYCbCr if it's not convenient for you"?

@nigeltao
Copy link
Contributor

Nothing besides "don't use NewYCbCr if it's not convenient for you".

Go isn't C++ and NewFoo isn't 'the' constructor for Foo, in that it's not mandatory to call NewFoo. Use a struct literal (or your own function that returns a struct literal) instead.

@golang golang locked and limited conversation to collaborators Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants