1 // generated by "go run gen.go". DO NOT EDIT.
9 // DrawYCbCr draws the YCbCr source image on the RGBA destination image with
10 // r.Min in dst aligned with sp in src. It reports whether the draw was
11 // successful. If it returns false, no dst pixels were changed.
13 // This function assumes that r is entirely within dst's bounds and the
14 // translation of r from dst coordinate space to src coordinate space is
15 // entirely within src's bounds.
16 func DrawYCbCr(dst
*image
.RGBA
, r image
.Rectangle
, src
*image
.YCbCr
, sp image
.Point
) (ok
bool) {
17 // This function exists in the image/internal/imageutil package because it
18 // is needed by both the image/draw and image/jpeg packages, but it doesn't
19 // seem right for one of those two to depend on the other.
21 // Another option is to have this code be exported in the image package,
22 // but we'd need to make sure we're totally happy with the API (for the
23 // rest of Go 1 compatibility), and decide if we want to have a more
24 // general purpose DrawToRGBA method for other image types. One possibility
27 // func (src *YCbCr) CopyToRGBA(dst *RGBA, dr, sr Rectangle) (effectiveDr, effectiveSr Rectangle)
29 // in the spirit of the built-in copy function for 1-dimensional slices,
30 // that also allowed a CopyFromRGBA method if needed.
32 x0
:= (r
.Min
.X
- dst
.Rect
.Min
.X
) * 4
33 x1
:= (r
.Max
.X
- dst
.Rect
.Min
.X
) * 4
34 y0
:= r
.Min
.Y
- dst
.Rect
.Min
.Y
35 y1
:= r
.Max
.Y
- dst
.Rect
.Min
.Y
36 switch src
.SubsampleRatio
{
38 case image
.YCbCrSubsampleRatio444
:
39 for y
, sy
:= y0
, sp
.Y
; y
!= y1
; y
, sy
= y
+1, sy
+1 {
40 dpix
:= dst
.Pix
[y
*dst
.Stride
:]
41 yi
:= (sy
-src
.Rect
.Min
.Y
)*src
.YStride
+ (sp
.X
- src
.Rect
.Min
.X
)
43 ci
:= (sy
-src
.Rect
.Min
.Y
)*src
.CStride
+ (sp
.X
- src
.Rect
.Min
.X
)
44 for x
:= x0
; x
!= x1
; x
, yi
, ci
= x
+4, yi
+1, ci
+1 {
46 // This is an inline version of image/color/ycbcr.go's func YCbCrToRGB.
47 yy1
:= int32(src
.Y
[yi
]) * 0x10101
48 cb1
:= int32(src
.Cb
[ci
]) - 128
49 cr1
:= int32(src
.Cr
[ci
]) - 128
51 // The bit twiddling below is equivalent to
53 // r := (yy1 + 91881*cr1) >> 16
56 // } else if r > 0xff {
60 // but uses fewer branches and is faster.
61 // Note that the uint8 type conversion in the return
62 // statement will convert ^int32(0) to 0xff.
63 // The code below to compute g and b uses a similar pattern.
65 if uint32(r
)&0xff000000 == 0 {
71 g
:= yy1
- 22554*cb1
- 46802*cr1
72 if uint32(g
)&0xff000000 == 0 {
79 if uint32(b
)&0xff000000 == 0 {
85 // use a temp slice to hint to the compiler that a single bounds check suffices
86 rgba
:= dpix
[x
: x
+4 : len(dpix
)]
94 case image
.YCbCrSubsampleRatio422
:
95 for y
, sy
:= y0
, sp
.Y
; y
!= y1
; y
, sy
= y
+1, sy
+1 {
96 dpix
:= dst
.Pix
[y
*dst
.Stride
:]
97 yi
:= (sy
-src
.Rect
.Min
.Y
)*src
.YStride
+ (sp
.X
- src
.Rect
.Min
.X
)
99 ciBase
:= (sy
-src
.Rect
.Min
.Y
)*src
.CStride
- src
.Rect
.Min
.X
/2
100 for x
, sx
:= x0
, sp
.X
; x
!= x1
; x
, sx
, yi
= x
+4, sx
+1, yi
+1 {
103 // This is an inline version of image/color/ycbcr.go's func YCbCrToRGB.
104 yy1
:= int32(src
.Y
[yi
]) * 0x10101
105 cb1
:= int32(src
.Cb
[ci
]) - 128
106 cr1
:= int32(src
.Cr
[ci
]) - 128
108 // The bit twiddling below is equivalent to
110 // r := (yy1 + 91881*cr1) >> 16
113 // } else if r > 0xff {
117 // but uses fewer branches and is faster.
118 // Note that the uint8 type conversion in the return
119 // statement will convert ^int32(0) to 0xff.
120 // The code below to compute g and b uses a similar pattern.
122 if uint32(r
)&0xff000000 == 0 {
128 g
:= yy1
- 22554*cb1
- 46802*cr1
129 if uint32(g
)&0xff000000 == 0 {
135 b
:= yy1
+ 116130*cb1
136 if uint32(b
)&0xff000000 == 0 {
142 // use a temp slice to hint to the compiler that a single bounds check suffices
143 rgba
:= dpix
[x
: x
+4 : len(dpix
)]
151 case image
.YCbCrSubsampleRatio420
:
152 for y
, sy
:= y0
, sp
.Y
; y
!= y1
; y
, sy
= y
+1, sy
+1 {
153 dpix
:= dst
.Pix
[y
*dst
.Stride
:]
154 yi
:= (sy
-src
.Rect
.Min
.Y
)*src
.YStride
+ (sp
.X
- src
.Rect
.Min
.X
)
156 ciBase
:= (sy
/2-src
.Rect
.Min
.Y
/2)*src
.CStride
- src
.Rect
.Min
.X
/2
157 for x
, sx
:= x0
, sp
.X
; x
!= x1
; x
, sx
, yi
= x
+4, sx
+1, yi
+1 {
160 // This is an inline version of image/color/ycbcr.go's func YCbCrToRGB.
161 yy1
:= int32(src
.Y
[yi
]) * 0x10101
162 cb1
:= int32(src
.Cb
[ci
]) - 128
163 cr1
:= int32(src
.Cr
[ci
]) - 128
165 // The bit twiddling below is equivalent to
167 // r := (yy1 + 91881*cr1) >> 16
170 // } else if r > 0xff {
174 // but uses fewer branches and is faster.
175 // Note that the uint8 type conversion in the return
176 // statement will convert ^int32(0) to 0xff.
177 // The code below to compute g and b uses a similar pattern.
179 if uint32(r
)&0xff000000 == 0 {
185 g
:= yy1
- 22554*cb1
- 46802*cr1
186 if uint32(g
)&0xff000000 == 0 {
192 b
:= yy1
+ 116130*cb1
193 if uint32(b
)&0xff000000 == 0 {
199 // use a temp slice to hint to the compiler that a single bounds check suffices
200 rgba
:= dpix
[x
: x
+4 : len(dpix
)]
208 case image
.YCbCrSubsampleRatio440
:
209 for y
, sy
:= y0
, sp
.Y
; y
!= y1
; y
, sy
= y
+1, sy
+1 {
210 dpix
:= dst
.Pix
[y
*dst
.Stride
:]
211 yi
:= (sy
-src
.Rect
.Min
.Y
)*src
.YStride
+ (sp
.X
- src
.Rect
.Min
.X
)
213 ci
:= (sy
/2-src
.Rect
.Min
.Y
/2)*src
.CStride
+ (sp
.X
- src
.Rect
.Min
.X
)
214 for x
:= x0
; x
!= x1
; x
, yi
, ci
= x
+4, yi
+1, ci
+1 {
216 // This is an inline version of image/color/ycbcr.go's func YCbCrToRGB.
217 yy1
:= int32(src
.Y
[yi
]) * 0x10101
218 cb1
:= int32(src
.Cb
[ci
]) - 128
219 cr1
:= int32(src
.Cr
[ci
]) - 128
221 // The bit twiddling below is equivalent to
223 // r := (yy1 + 91881*cr1) >> 16
226 // } else if r > 0xff {
230 // but uses fewer branches and is faster.
231 // Note that the uint8 type conversion in the return
232 // statement will convert ^int32(0) to 0xff.
233 // The code below to compute g and b uses a similar pattern.
235 if uint32(r
)&0xff000000 == 0 {
241 g
:= yy1
- 22554*cb1
- 46802*cr1
242 if uint32(g
)&0xff000000 == 0 {
248 b
:= yy1
+ 116130*cb1
249 if uint32(b
)&0xff000000 == 0 {
255 // use a temp slice to hint to the compiler that a single bounds check suffices
256 rgba
:= dpix
[x
: x
+4 : len(dpix
)]