package color const ( ChromaSamplePositionUnspecified ChromaSamplePosition = iota ChromaSamplePositionLeft ChromaSamplePositionCenter ChromaSamplePositionTopLeft ChromaSamplePositionTop ChromaSamplePositionBottomLeft ChromaSamplePositionBottom ChromaSamplePositionNB ) type ChromaSamplePosition byte // ChromaSampling The subsampling scheme is commonly expressed as a three-part ratio J : A : B (e.g. 4:2:2), that describe the number of luminance and chrominance samples in a conceptual region that is J pixels wide and 2 pixels high. type ChromaSampling struct { // J horizontal sampling reference (width of the conceptual region). Usually, 4. J byte // A number of chrominance samples (Cb, Cr) in the first row of J pixels. A byte // B number of changes of chrominance samples (Cb, Cr) between first and second row of J pixels. Note that B has to be either zero or equal to A B byte } // ElementPixels returns the number of pixels for a full element func (s ChromaSampling) ElementPixels() int { return int(s.J) * 2 } // ElementSamples returns the number of actual samples (total Y, Cb, Cr) for an encoded element func (s ChromaSampling) ElementSamples() int { return int(s.J)*2 + s.ElementChromaSamples() } func (s ChromaSampling) ElementChromaSamples() int { return int(s.A)*2 + int(s.B)*2 } func (s ChromaSampling) PlaneLumaSamples(width, height int) int { return width * height } func (s ChromaSampling) PlaneCrSamples(width, height int) int { return int((int64(width) * int64(height) * (int64(s.A) + int64(s.B))) / int64(s.ElementPixels())) } func (s ChromaSampling) PlaneCbSamples(width, height int) int { return int((int64(width) * int64(height) * (int64(s.A) + int64(s.B))) / int64(s.ElementPixels())) }