OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 * | 9 * |
10 * Based on code from the OggTheora software codec source code, | 10 * Based on code from the OggTheora software codec source code, |
11 * Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors. | 11 * Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors. |
12 */ | 12 */ |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 #include <string.h> | 14 #include <string.h> |
15 #include "y4minput.h" | 15 #include "y4minput.h" |
16 | 16 |
17 static int y4m_parse_tags(y4m_input *_y4m,char *_tags){ | 17 static int y4m_parse_tags(y4m_input *_y4m, char *_tags) { |
18 int got_w; | 18 int got_w; |
19 int got_h; | 19 int got_h; |
20 int got_fps; | 20 int got_fps; |
21 int got_interlace; | 21 int got_interlace; |
22 int got_par; | 22 int got_par; |
23 int got_chroma; | 23 int got_chroma; |
24 char *p; | 24 char *p; |
25 char *q; | 25 char *q; |
26 got_w=got_h=got_fps=got_interlace=got_par=got_chroma=0; | 26 got_w = got_h = got_fps = got_interlace = got_par = got_chroma = 0; |
27 for(p=_tags;;p=q){ | 27 for (p = _tags;; p = q) { |
28 /*Skip any leading spaces.*/ | 28 /*Skip any leading spaces.*/ |
29 while(*p==' ')p++; | 29 while (*p == ' ')p++; |
30 /*If that's all we have, stop.*/ | 30 /*If that's all we have, stop.*/ |
31 if(p[0]=='\0')break; | 31 if (p[0] == '\0')break; |
32 /*Find the end of this tag.*/ | 32 /*Find the end of this tag.*/ |
33 for(q=p+1;*q!='\0'&&*q!=' ';q++); | 33 for (q = p + 1; *q != '\0' && *q != ' '; q++); |
34 /*Process the tag.*/ | 34 /*Process the tag.*/ |
35 switch(p[0]){ | 35 switch (p[0]) { |
36 case 'W':{ | 36 case 'W': { |
37 if(sscanf(p+1,"%d",&_y4m->pic_w)!=1)return -1; | 37 if (sscanf(p + 1, "%d", &_y4m->pic_w) != 1)return -1; |
38 got_w=1; | 38 got_w = 1; |
39 }break; | 39 } |
40 case 'H':{ | 40 break; |
41 if(sscanf(p+1,"%d",&_y4m->pic_h)!=1)return -1; | 41 case 'H': { |
42 got_h=1; | 42 if (sscanf(p + 1, "%d", &_y4m->pic_h) != 1)return -1; |
43 }break; | 43 got_h = 1; |
44 case 'F':{ | 44 } |
45 if(sscanf(p+1,"%d:%d",&_y4m->fps_n,&_y4m->fps_d)!=2){ | 45 break; |
| 46 case 'F': { |
| 47 if (sscanf(p + 1, "%d:%d", &_y4m->fps_n, &_y4m->fps_d) != 2) { |
46 return -1; | 48 return -1; |
47 } | 49 } |
48 got_fps=1; | 50 got_fps = 1; |
49 }break; | 51 } |
50 case 'I':{ | 52 break; |
51 _y4m->interlace=p[1]; | 53 case 'I': { |
52 got_interlace=1; | 54 _y4m->interlace = p[1]; |
53 }break; | 55 got_interlace = 1; |
54 case 'A':{ | 56 } |
55 if(sscanf(p+1,"%d:%d",&_y4m->par_n,&_y4m->par_d)!=2){ | 57 break; |
| 58 case 'A': { |
| 59 if (sscanf(p + 1, "%d:%d", &_y4m->par_n, &_y4m->par_d) != 2) { |
56 return -1; | 60 return -1; |
57 } | 61 } |
58 got_par=1; | 62 got_par = 1; |
59 }break; | 63 } |
60 case 'C':{ | 64 break; |
61 if(q-p>16)return -1; | 65 case 'C': { |
62 memcpy(_y4m->chroma_type,p+1,q-p-1); | 66 if (q - p > 16)return -1; |
63 _y4m->chroma_type[q-p-1]='\0'; | 67 memcpy(_y4m->chroma_type, p + 1, q - p - 1); |
64 got_chroma=1; | 68 _y4m->chroma_type[q - p - 1] = '\0'; |
65 }break; | 69 got_chroma = 1; |
| 70 } |
| 71 break; |
66 /*Ignore unknown tags.*/ | 72 /*Ignore unknown tags.*/ |
67 } | 73 } |
68 } | 74 } |
69 if(!got_w||!got_h||!got_fps)return -1; | 75 if (!got_w || !got_h || !got_fps)return -1; |
70 if(!got_interlace)_y4m->interlace='?'; | 76 if (!got_interlace)_y4m->interlace = '?'; |
71 if(!got_par)_y4m->par_n=_y4m->par_d=0; | 77 if (!got_par)_y4m->par_n = _y4m->par_d = 0; |
72 /*Chroma-type is not specified in older files, e.g., those generated by | 78 /*Chroma-type is not specified in older files, e.g., those generated by |
73 mplayer.*/ | 79 mplayer.*/ |
74 if(!got_chroma)strcpy(_y4m->chroma_type,"420"); | 80 if (!got_chroma)strcpy(_y4m->chroma_type, "420"); |
75 return 0; | 81 return 0; |
76 } | 82 } |
77 | 83 |
78 | 84 |
79 | 85 |
80 /*All anti-aliasing filters in the following conversion functions are based on | 86 /*All anti-aliasing filters in the following conversion functions are based on |
81 one of two window functions: | 87 one of two window functions: |
82 The 6-tap Lanczos window (for down-sampling and shifts): | 88 The 6-tap Lanczos window (for down-sampling and shifts): |
83 sinc(\pi*t)*sinc(\pi*t/3), |t|<3 (sinc(t)==sin(t)/t) | 89 sinc(\pi*t)*sinc(\pi*t/3), |t|<3 (sinc(t)==sin(t)/t) |
84 0, |t|>=3 | 90 0, |t|>=3 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | | | | | 144 | | | | |
139 | | | | | 145 | | | | |
140 | | | | | 146 | | | | |
141 | 147 |
142 We use a resampling filter to shift the site locations one quarter pixel (at | 148 We use a resampling filter to shift the site locations one quarter pixel (at |
143 the chroma plane's resolution) to the right. | 149 the chroma plane's resolution) to the right. |
144 The 4:2:2 modes look exactly the same, except there are twice as many chroma | 150 The 4:2:2 modes look exactly the same, except there are twice as many chroma |
145 lines, and they are vertically co-sited with the luma samples in both the | 151 lines, and they are vertically co-sited with the luma samples in both the |
146 mpeg2 and jpeg cases (thus requiring no vertical resampling).*/ | 152 mpeg2 and jpeg cases (thus requiring no vertical resampling).*/ |
147 static void y4m_42xmpeg2_42xjpeg_helper(unsigned char *_dst, | 153 static void y4m_42xmpeg2_42xjpeg_helper(unsigned char *_dst, |
148 const unsigned char *_src,int _c_w,int _c_h){ | 154 const unsigned char *_src, int _c_w, int
_c_h) { |
149 int y; | 155 int y; |
150 int x; | 156 int x; |
151 for(y=0;y<_c_h;y++){ | 157 for (y = 0; y < _c_h; y++) { |
152 /*Filter: [4 -17 114 35 -9 1]/128, derived from a 6-tap Lanczos | 158 /*Filter: [4 -17 114 35 -9 1]/128, derived from a 6-tap Lanczos |
153 window.*/ | 159 window.*/ |
154 for(x=0;x<OC_MINI(_c_w,2);x++){ | 160 for (x = 0; x < OC_MINI(_c_w, 2); x++) { |
155 _dst[x]=(unsigned char)OC_CLAMPI(0,(4*_src[0]-17*_src[OC_MAXI(x-1,0)]+ | 161 _dst[x] = (unsigned char)OC_CLAMPI(0, (4 * _src[0] - 17 * _src[OC_MAXI(x -
1, 0)] + |
156 114*_src[x]+35*_src[OC_MINI(x+1,_c_w-1)]-9*_src[OC_MINI(x+2,_c_w-1)]+ | 162 114 * _src[x] + 35 * _src[OC_MINI(x
+ 1, _c_w - 1)] - 9 * _src[OC_MINI(x + 2, _c_w - 1)] + |
157 _src[OC_MINI(x+3,_c_w-1)]+64)>>7,255); | 163 _src[OC_MINI(x + 3, _c_w - 1)] + 64
) >> 7, 255); |
158 } | 164 } |
159 for(;x<_c_w-3;x++){ | 165 for (; x < _c_w - 3; x++) { |
160 _dst[x]=(unsigned char)OC_CLAMPI(0,(4*_src[x-2]-17*_src[x-1]+ | 166 _dst[x] = (unsigned char)OC_CLAMPI(0, (4 * _src[x - 2] - 17 * _src[x - 1]
+ |
161 114*_src[x]+35*_src[x+1]-9*_src[x+2]+_src[x+3]+64)>>7,255); | 167 114 * _src[x] + 35 * _src[x + 1] -
9 * _src[x + 2] + _src[x + 3] + 64) >> 7, 255); |
162 } | 168 } |
163 for(;x<_c_w;x++){ | 169 for (; x < _c_w; x++) { |
164 _dst[x]=(unsigned char)OC_CLAMPI(0,(4*_src[x-2]-17*_src[x-1]+ | 170 _dst[x] = (unsigned char)OC_CLAMPI(0, (4 * _src[x - 2] - 17 * _src[x - 1]
+ |
165 114*_src[x]+35*_src[OC_MINI(x+1,_c_w-1)]-9*_src[OC_MINI(x+2,_c_w-1)]+ | 171 114 * _src[x] + 35 * _src[OC_MINI(x
+ 1, _c_w - 1)] - 9 * _src[OC_MINI(x + 2, _c_w - 1)] + |
166 _src[_c_w-1]+64)>>7,255); | 172 _src[_c_w - 1] + 64) >> 7, 255); |
167 } | 173 } |
168 _dst+=_c_w; | 174 _dst += _c_w; |
169 _src+=_c_w; | 175 _src += _c_w; |
170 } | 176 } |
171 } | 177 } |
172 | 178 |
173 /*Handles both 422 and 420mpeg2 to 422jpeg and 420jpeg, respectively.*/ | 179 /*Handles both 422 and 420mpeg2 to 422jpeg and 420jpeg, respectively.*/ |
174 static void y4m_convert_42xmpeg2_42xjpeg(y4m_input *_y4m,unsigned char *_dst, | 180 static void y4m_convert_42xmpeg2_42xjpeg(y4m_input *_y4m, unsigned char *_dst, |
175 unsigned char *_aux){ | 181 unsigned char *_aux) { |
176 int c_w; | 182 int c_w; |
177 int c_h; | 183 int c_h; |
178 int c_sz; | 184 int c_sz; |
179 int pli; | 185 int pli; |
180 /*Skip past the luma data.*/ | 186 /*Skip past the luma data.*/ |
181 _dst+=_y4m->pic_w*_y4m->pic_h; | 187 _dst += _y4m->pic_w * _y4m->pic_h; |
182 /*Compute the size of each chroma plane.*/ | 188 /*Compute the size of each chroma plane.*/ |
183 c_w=(_y4m->pic_w+_y4m->dst_c_dec_h-1)/_y4m->dst_c_dec_h; | 189 c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
184 c_h=(_y4m->pic_h+_y4m->dst_c_dec_v-1)/_y4m->dst_c_dec_v; | 190 c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
185 c_sz=c_w*c_h; | 191 c_sz = c_w * c_h; |
186 for(pli=1;pli<3;pli++){ | 192 for (pli = 1; pli < 3; pli++) { |
187 y4m_42xmpeg2_42xjpeg_helper(_dst,_aux,c_w,c_h); | 193 y4m_42xmpeg2_42xjpeg_helper(_dst, _aux, c_w, c_h); |
188 _dst+=c_sz; | 194 _dst += c_sz; |
189 _aux+=c_sz; | 195 _aux += c_sz; |
190 } | 196 } |
191 } | 197 } |
192 | 198 |
193 /*This format is only used for interlaced content, but is included for | 199 /*This format is only used for interlaced content, but is included for |
194 completeness. | 200 completeness. |
195 | 201 |
196 420jpeg chroma samples are sited like: | 202 420jpeg chroma samples are sited like: |
197 Y-------Y-------Y-------Y------- | 203 Y-------Y-------Y-------Y------- |
198 | | | | | 204 | | | | |
199 | BR | | BR | | 205 | BR | | BR | |
(...skipping 26 matching lines...) Expand all Loading... |
226 | | | | | 232 | | | | |
227 YB------Y-------YB------Y------- | 233 YB------Y-------YB------Y------- |
228 | | | | | 234 | | | | |
229 | | | | | 235 | | | | |
230 | | | | | 236 | | | | |
231 | 237 |
232 We use a resampling filter to shift the site locations one quarter pixel (at | 238 We use a resampling filter to shift the site locations one quarter pixel (at |
233 the chroma plane's resolution) to the right. | 239 the chroma plane's resolution) to the right. |
234 Then we use another filter to move the C_r location down one quarter pixel, | 240 Then we use another filter to move the C_r location down one quarter pixel, |
235 and the C_b location up one quarter pixel.*/ | 241 and the C_b location up one quarter pixel.*/ |
236 static void y4m_convert_42xpaldv_42xjpeg(y4m_input *_y4m,unsigned char *_dst, | 242 static void y4m_convert_42xpaldv_42xjpeg(y4m_input *_y4m, unsigned char *_dst, |
237 unsigned char *_aux){ | 243 unsigned char *_aux) { |
238 unsigned char *tmp; | 244 unsigned char *tmp; |
239 int c_w; | 245 int c_w; |
240 int c_h; | 246 int c_h; |
241 int c_sz; | 247 int c_sz; |
242 int pli; | 248 int pli; |
243 int y; | 249 int y; |
244 int x; | 250 int x; |
245 /*Skip past the luma data.*/ | 251 /*Skip past the luma data.*/ |
246 _dst+=_y4m->pic_w*_y4m->pic_h; | 252 _dst += _y4m->pic_w * _y4m->pic_h; |
247 /*Compute the size of each chroma plane.*/ | 253 /*Compute the size of each chroma plane.*/ |
248 c_w=(_y4m->pic_w+1)/2; | 254 c_w = (_y4m->pic_w + 1) / 2; |
249 c_h=(_y4m->pic_h+_y4m->dst_c_dec_h-1)/_y4m->dst_c_dec_h; | 255 c_h = (_y4m->pic_h + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
250 c_sz=c_w*c_h; | 256 c_sz = c_w * c_h; |
251 tmp=_aux+2*c_sz; | 257 tmp = _aux + 2 * c_sz; |
252 for(pli=1;pli<3;pli++){ | 258 for (pli = 1; pli < 3; pli++) { |
253 /*First do the horizontal re-sampling. | 259 /*First do the horizontal re-sampling. |
254 This is the same as the mpeg2 case, except that after the horizontal | 260 This is the same as the mpeg2 case, except that after the horizontal |
255 case, we need to apply a second vertical filter.*/ | 261 case, we need to apply a second vertical filter.*/ |
256 y4m_42xmpeg2_42xjpeg_helper(tmp,_aux,c_w,c_h); | 262 y4m_42xmpeg2_42xjpeg_helper(tmp, _aux, c_w, c_h); |
257 _aux+=c_sz; | 263 _aux += c_sz; |
258 switch(pli){ | 264 switch (pli) { |
259 case 1:{ | 265 case 1: { |
260 /*Slide C_b up a quarter-pel. | 266 /*Slide C_b up a quarter-pel. |
261 This is the same filter used above, but in the other order.*/ | 267 This is the same filter used above, but in the other order.*/ |
262 for(x=0;x<c_w;x++){ | 268 for (x = 0; x < c_w; x++) { |
263 for(y=0;y<OC_MINI(c_h,3);y++){ | 269 for (y = 0; y < OC_MINI(c_h, 3); y++) { |
264 _dst[y*c_w]=(unsigned char)OC_CLAMPI(0,(tmp[0] | 270 _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (tmp[0] |
265 -9*tmp[OC_MAXI(y-2,0)*c_w]+35*tmp[OC_MAXI(y-1,0)*c_w] | 271 - 9 * tmp[OC_MAXI(y - 2
, 0) * c_w] + 35 * tmp[OC_MAXI(y - 1, 0) * c_w] |
266 +114*tmp[y*c_w]-17*tmp[OC_MINI(y+1,c_h-1)*c_w] | 272 + 114 * tmp[y * c_w] -
17 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] |
267 +4*tmp[OC_MINI(y+2,c_h-1)*c_w]+64)>>7,255); | 273 + 4 * tmp[OC_MINI(y + 2
, c_h - 1) * c_w] + 64) >> 7, 255); |
268 } | 274 } |
269 for(;y<c_h-2;y++){ | 275 for (; y < c_h - 2; y++) { |
270 _dst[y*c_w]=(unsigned char)OC_CLAMPI(0,(tmp[(y-3)*c_w] | 276 _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (tmp[(y - 3) * c_w] |
271 -9*tmp[(y-2)*c_w]+35*tmp[(y-1)*c_w]+114*tmp[y*c_w] | 277 - 9 * tmp[(y - 2) * c_w
] + 35 * tmp[(y - 1) * c_w] + 114 * tmp[y * c_w] |
272 -17*tmp[(y+1)*c_w]+4*tmp[(y+2)*c_w]+64)>>7,255); | 278 - 17 * tmp[(y + 1) * c_
w] + 4 * tmp[(y + 2) * c_w] + 64) >> 7, 255); |
273 } | 279 } |
274 for(;y<c_h;y++){ | 280 for (; y < c_h; y++) { |
275 _dst[y*c_w]=(unsigned char)OC_CLAMPI(0,(tmp[(y-3)*c_w] | 281 _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (tmp[(y - 3) * c_w] |
276 -9*tmp[(y-2)*c_w]+35*tmp[(y-1)*c_w]+114*tmp[y*c_w] | 282 - 9 * tmp[(y - 2) * c_w
] + 35 * tmp[(y - 1) * c_w] + 114 * tmp[y * c_w] |
277 -17*tmp[OC_MINI(y+1,c_h-1)*c_w]+4*tmp[(c_h-1)*c_w]+64)>>7,255); | 283 - 17 * tmp[OC_MINI(y +
1, c_h - 1) * c_w] + 4 * tmp[(c_h - 1) * c_w] + 64) >> 7, 255); |
278 } | 284 } |
279 _dst++; | 285 _dst++; |
280 tmp++; | 286 tmp++; |
281 } | 287 } |
282 _dst+=c_sz-c_w; | 288 _dst += c_sz - c_w; |
283 tmp-=c_w; | 289 tmp -= c_w; |
284 }break; | 290 } |
285 case 2:{ | 291 break; |
| 292 case 2: { |
286 /*Slide C_r down a quarter-pel. | 293 /*Slide C_r down a quarter-pel. |
287 This is the same as the horizontal filter.*/ | 294 This is the same as the horizontal filter.*/ |
288 for(x=0;x<c_w;x++){ | 295 for (x = 0; x < c_w; x++) { |
289 for(y=0;y<OC_MINI(c_h,2);y++){ | 296 for (y = 0; y < OC_MINI(c_h, 2); y++) { |
290 _dst[y*c_w]=(unsigned char)OC_CLAMPI(0,(4*tmp[0] | 297 _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (4 * tmp[0] |
291 -17*tmp[OC_MAXI(y-1,0)*c_w]+114*tmp[y*c_w] | 298 - 17 * tmp[OC_MAXI(y -
1, 0) * c_w] + 114 * tmp[y * c_w] |
292 +35*tmp[OC_MINI(y+1,c_h-1)*c_w]-9*tmp[OC_MINI(y+2,c_h-1)*c_w] | 299 + 35 * tmp[OC_MINI(y +
1, c_h - 1) * c_w] - 9 * tmp[OC_MINI(y + 2, c_h - 1) * c_w] |
293 +tmp[OC_MINI(y+3,c_h-1)*c_w]+64)>>7,255); | 300 + tmp[OC_MINI(y + 3, c_
h - 1) * c_w] + 64) >> 7, 255); |
294 } | 301 } |
295 for(;y<c_h-3;y++){ | 302 for (; y < c_h - 3; y++) { |
296 _dst[y*c_w]=(unsigned char)OC_CLAMPI(0,(4*tmp[(y-2)*c_w] | 303 _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (4 * tmp[(y - 2) * c_w] |
297 -17*tmp[(y-1)*c_w]+114*tmp[y*c_w]+35*tmp[(y+1)*c_w] | 304 - 17 * tmp[(y - 1) * c_
w] + 114 * tmp[y * c_w] + 35 * tmp[(y + 1) * c_w] |
298 -9*tmp[(y+2)*c_w]+tmp[(y+3)*c_w]+64)>>7,255); | 305 - 9 * tmp[(y + 2) * c_w
] + tmp[(y + 3) * c_w] + 64) >> 7, 255); |
299 } | 306 } |
300 for(;y<c_h;y++){ | 307 for (; y < c_h; y++) { |
301 _dst[y*c_w]=(unsigned char)OC_CLAMPI(0,(4*tmp[(y-2)*c_w] | 308 _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (4 * tmp[(y - 2) * c_w] |
302 -17*tmp[(y-1)*c_w]+114*tmp[y*c_w]+35*tmp[OC_MINI(y+1,c_h-1)*c_w] | 309 - 17 * tmp[(y - 1) * c_
w] + 114 * tmp[y * c_w] + 35 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] |
303 -9*tmp[OC_MINI(y+2,c_h-1)*c_w]+tmp[(c_h-1)*c_w]+64)>>7,255); | 310 - 9 * tmp[OC_MINI(y + 2
, c_h - 1) * c_w] + tmp[(c_h - 1) * c_w] + 64) >> 7, 255); |
304 } | 311 } |
305 _dst++; | 312 _dst++; |
306 tmp++; | 313 tmp++; |
307 } | 314 } |
308 }break; | 315 } |
| 316 break; |
309 } | 317 } |
310 /*For actual interlaced material, this would have to be done separately on | 318 /*For actual interlaced material, this would have to be done separately on |
311 each field, and the shift amounts would be different. | 319 each field, and the shift amounts would be different. |
312 C_r moves down 1/8, C_b up 3/8 in the top field, and C_r moves down 3/8, | 320 C_r moves down 1/8, C_b up 3/8 in the top field, and C_r moves down 3/8, |
313 C_b up 1/8 in the bottom field. | 321 C_b up 1/8 in the bottom field. |
314 The corresponding filters would be: | 322 The corresponding filters would be: |
315 Down 1/8 (reverse order for up): [3 -11 125 15 -4 0]/128 | 323 Down 1/8 (reverse order for up): [3 -11 125 15 -4 0]/128 |
316 Down 3/8 (reverse order for up): [4 -19 98 56 -13 2]/128*/ | 324 Down 3/8 (reverse order for up): [4 -19 98 56 -13 2]/128*/ |
317 } | 325 } |
318 } | 326 } |
319 | 327 |
320 /*Perform vertical filtering to reduce a single plane from 4:2:2 to 4:2:0. | 328 /*Perform vertical filtering to reduce a single plane from 4:2:2 to 4:2:0. |
321 This is used as a helper by several converation routines.*/ | 329 This is used as a helper by several converation routines.*/ |
322 static void y4m_422jpeg_420jpeg_helper(unsigned char *_dst, | 330 static void y4m_422jpeg_420jpeg_helper(unsigned char *_dst, |
323 const unsigned char *_src,int _c_w,int _c_h){ | 331 const unsigned char *_src, int _c_w, int
_c_h) { |
324 int y; | 332 int y; |
325 int x; | 333 int x; |
326 /*Filter: [3 -17 78 78 -17 3]/128, derived from a 6-tap Lanczos window.*/ | 334 /*Filter: [3 -17 78 78 -17 3]/128, derived from a 6-tap Lanczos window.*/ |
327 for(x=0;x<_c_w;x++){ | 335 for (x = 0; x < _c_w; x++) { |
328 for(y=0;y<OC_MINI(_c_h,2);y+=2){ | 336 for (y = 0; y < OC_MINI(_c_h, 2); y += 2) { |
329 _dst[(y>>1)*_c_w]=OC_CLAMPI(0,(64*_src[0] | 337 _dst[(y >> 1)*_c_w] = OC_CLAMPI(0, (64 * _src[0] |
330 +78*_src[OC_MINI(1,_c_h-1)*_c_w] | 338 + 78 * _src[OC_MINI(1, _c_h - 1) * _c_
w] |
331 -17*_src[OC_MINI(2,_c_h-1)*_c_w] | 339 - 17 * _src[OC_MINI(2, _c_h - 1) * _c_
w] |
332 +3*_src[OC_MINI(3,_c_h-1)*_c_w]+64)>>7,255); | 340 + 3 * _src[OC_MINI(3, _c_h - 1) * _c_w
] + 64) >> 7, 255); |
333 } | 341 } |
334 for(;y<_c_h-3;y+=2){ | 342 for (; y < _c_h - 3; y += 2) { |
335 _dst[(y>>1)*_c_w]=OC_CLAMPI(0,(3*(_src[(y-2)*_c_w]+_src[(y+3)*_c_w]) | 343 _dst[(y >> 1)*_c_w] = OC_CLAMPI(0, (3 * (_src[(y - 2) * _c_w] + _src[(y +
3) * _c_w]) |
336 -17*(_src[(y-1)*_c_w]+_src[(y+2)*_c_w]) | 344 - 17 * (_src[(y - 1) * _c_w] + _src[(y
+ 2) * _c_w]) |
337 +78*(_src[y*_c_w]+_src[(y+1)*_c_w])+64)>>7,255); | 345 + 78 * (_src[y * _c_w] + _src[(y + 1)
* _c_w]) + 64) >> 7, 255); |
338 } | 346 } |
339 for(;y<_c_h;y+=2){ | 347 for (; y < _c_h; y += 2) { |
340 _dst[(y>>1)*_c_w]=OC_CLAMPI(0,(3*(_src[(y-2)*_c_w] | 348 _dst[(y >> 1)*_c_w] = OC_CLAMPI(0, (3 * (_src[(y - 2) * _c_w] |
341 +_src[(_c_h-1)*_c_w])-17*(_src[(y-1)*_c_w] | 349 + _src[(_c_h - 1) * _c_w]) - 17 *
(_src[(y - 1) * _c_w] |
342 +_src[OC_MINI(y+2,_c_h-1)*_c_w]) | 350
+ _src[OC_MINI(y + 2, _c_h - 1) * _c_w]) |
343 +78*(_src[y*_c_w]+_src[OC_MINI(y+1,_c_h-1)*_c_w])+64)>>7,255); | 351 + 78 * (_src[y * _c_w] + _src[OC_MINI(
y + 1, _c_h - 1) * _c_w]) + 64) >> 7, 255); |
344 } | 352 } |
345 _src++; | 353 _src++; |
346 _dst++; | 354 _dst++; |
347 } | 355 } |
348 } | 356 } |
349 | 357 |
350 /*420jpeg chroma samples are sited like: | 358 /*420jpeg chroma samples are sited like: |
351 Y-------Y-------Y-------Y------- | 359 Y-------Y-------Y-------Y------- |
352 | | | | | 360 | | | | |
353 | BR | | BR | | 361 | BR | | BR | |
(...skipping 24 matching lines...) Expand all Loading... |
378 | | | | | 386 | | | | |
379 | | | | | 387 | | | | |
380 | | | | | 388 | | | | |
381 Y---BR--Y-------Y---BR--Y------- | 389 Y---BR--Y-------Y---BR--Y------- |
382 | | | | | 390 | | | | |
383 | | | | | 391 | | | | |
384 | | | | | 392 | | | | |
385 | 393 |
386 We use a resampling filter to decimate the chroma planes by two in the | 394 We use a resampling filter to decimate the chroma planes by two in the |
387 vertical direction.*/ | 395 vertical direction.*/ |
388 static void y4m_convert_422jpeg_420jpeg(y4m_input *_y4m,unsigned char *_dst, | 396 static void y4m_convert_422jpeg_420jpeg(y4m_input *_y4m, unsigned char *_dst, |
389 unsigned char *_aux){ | 397 unsigned char *_aux) { |
390 int c_w; | 398 int c_w; |
391 int c_h; | 399 int c_h; |
392 int c_sz; | 400 int c_sz; |
393 int dst_c_w; | 401 int dst_c_w; |
394 int dst_c_h; | 402 int dst_c_h; |
395 int dst_c_sz; | 403 int dst_c_sz; |
396 int pli; | 404 int pli; |
397 /*Skip past the luma data.*/ | 405 /*Skip past the luma data.*/ |
398 _dst+=_y4m->pic_w*_y4m->pic_h; | 406 _dst += _y4m->pic_w * _y4m->pic_h; |
399 /*Compute the size of each chroma plane.*/ | 407 /*Compute the size of each chroma plane.*/ |
400 c_w=(_y4m->pic_w+_y4m->src_c_dec_h-1)/_y4m->src_c_dec_h; | 408 c_w = (_y4m->pic_w + _y4m->src_c_dec_h - 1) / _y4m->src_c_dec_h; |
401 c_h=_y4m->pic_h; | 409 c_h = _y4m->pic_h; |
402 dst_c_w=(_y4m->pic_w+_y4m->dst_c_dec_h-1)/_y4m->dst_c_dec_h; | 410 dst_c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
403 dst_c_h=(_y4m->pic_h+_y4m->dst_c_dec_v-1)/_y4m->dst_c_dec_v; | 411 dst_c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
404 c_sz=c_w*c_h; | 412 c_sz = c_w * c_h; |
405 dst_c_sz=dst_c_w*dst_c_h; | 413 dst_c_sz = dst_c_w * dst_c_h; |
406 for(pli=1;pli<3;pli++){ | 414 for (pli = 1; pli < 3; pli++) { |
407 y4m_422jpeg_420jpeg_helper(_dst,_aux,c_w,c_h); | 415 y4m_422jpeg_420jpeg_helper(_dst, _aux, c_w, c_h); |
408 _aux+=c_sz; | 416 _aux += c_sz; |
409 _dst+=dst_c_sz; | 417 _dst += dst_c_sz; |
410 } | 418 } |
411 } | 419 } |
412 | 420 |
413 /*420jpeg chroma samples are sited like: | 421 /*420jpeg chroma samples are sited like: |
414 Y-------Y-------Y-------Y------- | 422 Y-------Y-------Y-------Y------- |
415 | | | | | 423 | | | | |
416 | BR | | BR | | 424 | BR | | BR | |
417 | | | | | 425 | | | | |
418 Y-------Y-------Y-------Y------- | 426 Y-------Y-------Y-------Y------- |
419 | | | | | 427 | | | | |
(...skipping 23 matching lines...) Expand all Loading... |
443 | | | | | 451 | | | | |
444 YBR-----Y-------YBR-----Y------- | 452 YBR-----Y-------YBR-----Y------- |
445 | | | | | 453 | | | | |
446 | | | | | 454 | | | | |
447 | | | | | 455 | | | | |
448 | 456 |
449 We use a resampling filter to shift the original site locations one quarter | 457 We use a resampling filter to shift the original site locations one quarter |
450 pixel (at the original chroma resolution) to the right. | 458 pixel (at the original chroma resolution) to the right. |
451 Then we use a second resampling filter to decimate the chroma planes by two | 459 Then we use a second resampling filter to decimate the chroma planes by two |
452 in the vertical direction.*/ | 460 in the vertical direction.*/ |
453 static void y4m_convert_422_420jpeg(y4m_input *_y4m,unsigned char *_dst, | 461 static void y4m_convert_422_420jpeg(y4m_input *_y4m, unsigned char *_dst, |
454 unsigned char *_aux){ | 462 unsigned char *_aux) { |
455 unsigned char *tmp; | 463 unsigned char *tmp; |
456 int c_w; | 464 int c_w; |
457 int c_h; | 465 int c_h; |
458 int c_sz; | 466 int c_sz; |
459 int dst_c_h; | 467 int dst_c_h; |
460 int dst_c_sz; | 468 int dst_c_sz; |
461 int pli; | 469 int pli; |
462 /*Skip past the luma data.*/ | 470 /*Skip past the luma data.*/ |
463 _dst+=_y4m->pic_w*_y4m->pic_h; | 471 _dst += _y4m->pic_w * _y4m->pic_h; |
464 /*Compute the size of each chroma plane.*/ | 472 /*Compute the size of each chroma plane.*/ |
465 c_w=(_y4m->pic_w+_y4m->src_c_dec_h-1)/_y4m->src_c_dec_h; | 473 c_w = (_y4m->pic_w + _y4m->src_c_dec_h - 1) / _y4m->src_c_dec_h; |
466 c_h=_y4m->pic_h; | 474 c_h = _y4m->pic_h; |
467 dst_c_h=(_y4m->pic_h+_y4m->dst_c_dec_v-1)/_y4m->dst_c_dec_v; | 475 dst_c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
468 c_sz=c_w*c_h; | 476 c_sz = c_w * c_h; |
469 dst_c_sz=c_w*dst_c_h; | 477 dst_c_sz = c_w * dst_c_h; |
470 tmp=_aux+2*c_sz; | 478 tmp = _aux + 2 * c_sz; |
471 for(pli=1;pli<3;pli++){ | 479 for (pli = 1; pli < 3; pli++) { |
472 /*In reality, the horizontal and vertical steps could be pipelined, for | 480 /*In reality, the horizontal and vertical steps could be pipelined, for |
473 less memory consumption and better cache performance, but we do them | 481 less memory consumption and better cache performance, but we do them |
474 separately for simplicity.*/ | 482 separately for simplicity.*/ |
475 /*First do horizontal filtering (convert to 422jpeg)*/ | 483 /*First do horizontal filtering (convert to 422jpeg)*/ |
476 y4m_42xmpeg2_42xjpeg_helper(tmp,_aux,c_w,c_h); | 484 y4m_42xmpeg2_42xjpeg_helper(tmp, _aux, c_w, c_h); |
477 /*Now do the vertical filtering.*/ | 485 /*Now do the vertical filtering.*/ |
478 y4m_422jpeg_420jpeg_helper(_dst,tmp,c_w,c_h); | 486 y4m_422jpeg_420jpeg_helper(_dst, tmp, c_w, c_h); |
479 _aux+=c_sz; | 487 _aux += c_sz; |
480 _dst+=dst_c_sz; | 488 _dst += dst_c_sz; |
481 } | 489 } |
482 } | 490 } |
483 | 491 |
484 /*420jpeg chroma samples are sited like: | 492 /*420jpeg chroma samples are sited like: |
485 Y-------Y-------Y-------Y------- | 493 Y-------Y-------Y-------Y------- |
486 | | | | | 494 | | | | |
487 | BR | | BR | | 495 | BR | | BR | |
488 | | | | | 496 | | | | |
489 Y-------Y-------Y-------Y------- | 497 Y-------Y-------Y-------Y------- |
490 | | | | | 498 | | | | |
(...skipping 24 matching lines...) Expand all Loading... |
515 YBR-----Y-------Y-------Y------- | 523 YBR-----Y-------Y-------Y------- |
516 | | | | | 524 | | | | |
517 | | | | | 525 | | | | |
518 | | | | | 526 | | | | |
519 | 527 |
520 We use a filter to resample at site locations one eighth pixel (at the source | 528 We use a filter to resample at site locations one eighth pixel (at the source |
521 chroma plane's horizontal resolution) and five eighths of a pixel to the | 529 chroma plane's horizontal resolution) and five eighths of a pixel to the |
522 right. | 530 right. |
523 Then we use another filter to decimate the planes by 2 in the vertical | 531 Then we use another filter to decimate the planes by 2 in the vertical |
524 direction.*/ | 532 direction.*/ |
525 static void y4m_convert_411_420jpeg(y4m_input *_y4m,unsigned char *_dst, | 533 static void y4m_convert_411_420jpeg(y4m_input *_y4m, unsigned char *_dst, |
526 unsigned char *_aux){ | 534 unsigned char *_aux) { |
527 unsigned char *tmp; | 535 unsigned char *tmp; |
528 int c_w; | 536 int c_w; |
529 int c_h; | 537 int c_h; |
530 int c_sz; | 538 int c_sz; |
531 int dst_c_w; | 539 int dst_c_w; |
532 int dst_c_h; | 540 int dst_c_h; |
533 int dst_c_sz; | 541 int dst_c_sz; |
534 int tmp_sz; | 542 int tmp_sz; |
535 int pli; | 543 int pli; |
536 int y; | 544 int y; |
537 int x; | 545 int x; |
538 /*Skip past the luma data.*/ | 546 /*Skip past the luma data.*/ |
539 _dst+=_y4m->pic_w*_y4m->pic_h; | 547 _dst += _y4m->pic_w * _y4m->pic_h; |
540 /*Compute the size of each chroma plane.*/ | 548 /*Compute the size of each chroma plane.*/ |
541 c_w=(_y4m->pic_w+_y4m->src_c_dec_h-1)/_y4m->src_c_dec_h; | 549 c_w = (_y4m->pic_w + _y4m->src_c_dec_h - 1) / _y4m->src_c_dec_h; |
542 c_h=_y4m->pic_h; | 550 c_h = _y4m->pic_h; |
543 dst_c_w=(_y4m->pic_w+_y4m->dst_c_dec_h-1)/_y4m->dst_c_dec_h; | 551 dst_c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
544 dst_c_h=(_y4m->pic_h+_y4m->dst_c_dec_v-1)/_y4m->dst_c_dec_v; | 552 dst_c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
545 c_sz=c_w*c_h; | 553 c_sz = c_w * c_h; |
546 dst_c_sz=dst_c_w*dst_c_h; | 554 dst_c_sz = dst_c_w * dst_c_h; |
547 tmp_sz=dst_c_w*c_h; | 555 tmp_sz = dst_c_w * c_h; |
548 tmp=_aux+2*c_sz; | 556 tmp = _aux + 2 * c_sz; |
549 for(pli=1;pli<3;pli++){ | 557 for (pli = 1; pli < 3; pli++) { |
550 /*In reality, the horizontal and vertical steps could be pipelined, for | 558 /*In reality, the horizontal and vertical steps could be pipelined, for |
551 less memory consumption and better cache performance, but we do them | 559 less memory consumption and better cache performance, but we do them |
552 separately for simplicity.*/ | 560 separately for simplicity.*/ |
553 /*First do horizontal filtering (convert to 422jpeg)*/ | 561 /*First do horizontal filtering (convert to 422jpeg)*/ |
554 for(y=0;y<c_h;y++){ | 562 for (y = 0; y < c_h; y++) { |
555 /*Filters: [1 110 18 -1]/128 and [-3 50 86 -5]/128, both derived from a | 563 /*Filters: [1 110 18 -1]/128 and [-3 50 86 -5]/128, both derived from a |
556 4-tap Mitchell window.*/ | 564 4-tap Mitchell window.*/ |
557 for(x=0;x<OC_MINI(c_w,1);x++){ | 565 for (x = 0; x < OC_MINI(c_w, 1); x++) { |
558 tmp[x<<1]=(unsigned char)OC_CLAMPI(0,(111*_aux[0] | 566 tmp[x << 1] = (unsigned char)OC_CLAMPI(0, (111 * _aux[0] |
559 +18*_aux[OC_MINI(1,c_w-1)]-_aux[OC_MINI(2,c_w-1)]+64)>>7,255); | 567 + 18 * _aux[OC_MINI(1, c_w -
1)] - _aux[OC_MINI(2, c_w - 1)] + 64) >> 7, 255); |
560 tmp[x<<1|1]=(unsigned char)OC_CLAMPI(0,(47*_aux[0] | 568 tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI(0, (47 * _aux[0] |
561 +86*_aux[OC_MINI(1,c_w-1)]-5*_aux[OC_MINI(2,c_w-1)]+64)>>7,255); | 569 + 86 * _aux[OC_MINI(1, c_
w - 1)] - 5 * _aux[OC_MINI(2, c_w - 1)] + 64) >> 7, 255); |
562 } | 570 } |
563 for(;x<c_w-2;x++){ | 571 for (; x < c_w - 2; x++) { |
564 tmp[x<<1]=(unsigned char)OC_CLAMPI(0,(_aux[x-1]+110*_aux[x] | 572 tmp[x << 1] = (unsigned char)OC_CLAMPI(0, (_aux[x - 1] + 110 * _aux[x] |
565 +18*_aux[x+1]-_aux[x+2]+64)>>7,255); | 573 + 18 * _aux[x + 1] - _aux[x +
2] + 64) >> 7, 255); |
566 tmp[x<<1|1]=(unsigned char)OC_CLAMPI(0,(-3*_aux[x-1]+50*_aux[x] | 574 tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI(0, (-3 * _aux[x - 1] + 50 * _
aux[x] |
567 +86*_aux[x+1]-5*_aux[x+2]+64)>>7,255); | 575 + 86 * _aux[x + 1] - 5 *
_aux[x + 2] + 64) >> 7, 255); |
568 } | 576 } |
569 for(;x<c_w;x++){ | 577 for (; x < c_w; x++) { |
570 tmp[x<<1]=(unsigned char)OC_CLAMPI(0,(_aux[x-1]+110*_aux[x] | 578 tmp[x << 1] = (unsigned char)OC_CLAMPI(0, (_aux[x - 1] + 110 * _aux[x] |
571 +18*_aux[OC_MINI(x+1,c_w-1)]-_aux[c_w-1]+64)>>7,255); | 579 + 18 * _aux[OC_MINI(x + 1, c_
w - 1)] - _aux[c_w - 1] + 64) >> 7, 255); |
572 if((x<<1|1)<dst_c_w){ | 580 if ((x << 1 | 1) < dst_c_w) { |
573 tmp[x<<1|1]=(unsigned char)OC_CLAMPI(0,(-3*_aux[x-1]+50*_aux[x] | 581 tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI(0, (-3 * _aux[x - 1] + 50 *
_aux[x] |
574 +86*_aux[OC_MINI(x+1,c_w-1)]-5*_aux[c_w-1]+64)>>7,255); | 582 + 86 * _aux[OC_MINI(x +
1, c_w - 1)] - 5 * _aux[c_w - 1] + 64) >> 7, 255); |
575 } | 583 } |
576 } | 584 } |
577 tmp+=dst_c_w; | 585 tmp += dst_c_w; |
578 _aux+=c_w; | 586 _aux += c_w; |
579 } | 587 } |
580 tmp-=tmp_sz; | 588 tmp -= tmp_sz; |
581 /*Now do the vertical filtering.*/ | 589 /*Now do the vertical filtering.*/ |
582 y4m_422jpeg_420jpeg_helper(_dst,tmp,dst_c_w,c_h); | 590 y4m_422jpeg_420jpeg_helper(_dst, tmp, dst_c_w, c_h); |
583 _dst+=dst_c_sz; | 591 _dst += dst_c_sz; |
584 } | 592 } |
585 } | 593 } |
586 | 594 |
587 /*Convert 444 to 420jpeg.*/ | 595 /*Convert 444 to 420jpeg.*/ |
588 static void y4m_convert_444_420jpeg(y4m_input *_y4m,unsigned char *_dst, | 596 static void y4m_convert_444_420jpeg(y4m_input *_y4m, unsigned char *_dst, |
589 unsigned char *_aux){ | 597 unsigned char *_aux) { |
590 unsigned char *tmp; | 598 unsigned char *tmp; |
591 int c_w; | 599 int c_w; |
592 int c_h; | 600 int c_h; |
593 int c_sz; | 601 int c_sz; |
594 int dst_c_w; | 602 int dst_c_w; |
595 int dst_c_h; | 603 int dst_c_h; |
596 int dst_c_sz; | 604 int dst_c_sz; |
597 int tmp_sz; | 605 int tmp_sz; |
598 int pli; | 606 int pli; |
599 int y; | 607 int y; |
600 int x; | 608 int x; |
601 /*Skip past the luma data.*/ | 609 /*Skip past the luma data.*/ |
602 _dst+=_y4m->pic_w*_y4m->pic_h; | 610 _dst += _y4m->pic_w * _y4m->pic_h; |
603 /*Compute the size of each chroma plane.*/ | 611 /*Compute the size of each chroma plane.*/ |
604 c_w=(_y4m->pic_w+_y4m->src_c_dec_h-1)/_y4m->src_c_dec_h; | 612 c_w = (_y4m->pic_w + _y4m->src_c_dec_h - 1) / _y4m->src_c_dec_h; |
605 c_h=_y4m->pic_h; | 613 c_h = _y4m->pic_h; |
606 dst_c_w=(_y4m->pic_w+_y4m->dst_c_dec_h-1)/_y4m->dst_c_dec_h; | 614 dst_c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
607 dst_c_h=(_y4m->pic_h+_y4m->dst_c_dec_v-1)/_y4m->dst_c_dec_v; | 615 dst_c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
608 c_sz=c_w*c_h; | 616 c_sz = c_w * c_h; |
609 dst_c_sz=dst_c_w*dst_c_h; | 617 dst_c_sz = dst_c_w * dst_c_h; |
610 tmp_sz=dst_c_w*c_h; | 618 tmp_sz = dst_c_w * c_h; |
611 tmp=_aux+2*c_sz; | 619 tmp = _aux + 2 * c_sz; |
612 for(pli=1;pli<3;pli++){ | 620 for (pli = 1; pli < 3; pli++) { |
613 /*Filter: [3 -17 78 78 -17 3]/128, derived from a 6-tap Lanczos window.*/ | 621 /*Filter: [3 -17 78 78 -17 3]/128, derived from a 6-tap Lanczos window.*/ |
614 for(y=0;y<c_h;y++){ | 622 for (y = 0; y < c_h; y++) { |
615 for(x=0;x<OC_MINI(c_w,2);x+=2){ | 623 for (x = 0; x < OC_MINI(c_w, 2); x += 2) { |
616 tmp[x>>1]=OC_CLAMPI(0,(64*_aux[0]+78*_aux[OC_MINI(1,c_w-1)] | 624 tmp[x >> 1] = OC_CLAMPI(0, (64 * _aux[0] + 78 * _aux[OC_MINI(1, c_w - 1)
] |
617 -17*_aux[OC_MINI(2,c_w-1)] | 625 - 17 * _aux[OC_MINI(2, c_w - 1)] |
618 +3*_aux[OC_MINI(3,c_w-1)]+64)>>7,255); | 626 + 3 * _aux[OC_MINI(3, c_w - 1)] + 64) >> 7,
255); |
619 } | 627 } |
620 for(;x<c_w-3;x+=2){ | 628 for (; x < c_w - 3; x += 2) { |
621 tmp[x>>1]=OC_CLAMPI(0,(3*(_aux[x-2]+_aux[x+3]) | 629 tmp[x >> 1] = OC_CLAMPI(0, (3 * (_aux[x - 2] + _aux[x + 3]) |
622 -17*(_aux[x-1]+_aux[x+2])+78*(_aux[x]+_aux[x+1])+64)>>7,255); | 630 - 17 * (_aux[x - 1] + _aux[x + 2]) + 78 * (_
aux[x] + _aux[x + 1]) + 64) >> 7, 255); |
623 } | 631 } |
624 for(;x<c_w;x+=2){ | 632 for (; x < c_w; x += 2) { |
625 tmp[x>>1]=OC_CLAMPI(0,(3*(_aux[x-2]+_aux[c_w-1])- | 633 tmp[x >> 1] = OC_CLAMPI(0, (3 * (_aux[x - 2] + _aux[c_w - 1]) - |
626 17*(_aux[x-1]+_aux[OC_MINI(x+2,c_w-1)])+ | 634 17 * (_aux[x - 1] + _aux[OC_MINI(x + 2, c_w
- 1)]) + |
627 78*(_aux[x]+_aux[OC_MINI(x+1,c_w-1)])+64)>>7,255); | 635 78 * (_aux[x] + _aux[OC_MINI(x + 1, c_w - 1)
]) + 64) >> 7, 255); |
628 } | 636 } |
629 tmp+=dst_c_w; | 637 tmp += dst_c_w; |
630 _aux+=c_w; | 638 _aux += c_w; |
631 } | 639 } |
632 tmp-=tmp_sz; | 640 tmp -= tmp_sz; |
633 /*Now do the vertical filtering.*/ | 641 /*Now do the vertical filtering.*/ |
634 y4m_422jpeg_420jpeg_helper(_dst,tmp,dst_c_w,c_h); | 642 y4m_422jpeg_420jpeg_helper(_dst, tmp, dst_c_w, c_h); |
635 _dst+=dst_c_sz; | 643 _dst += dst_c_sz; |
636 } | 644 } |
637 } | 645 } |
638 | 646 |
639 /*The image is padded with empty chroma components at 4:2:0.*/ | 647 /*The image is padded with empty chroma components at 4:2:0.*/ |
640 static void y4m_convert_mono_420jpeg(y4m_input *_y4m,unsigned char *_dst, | 648 static void y4m_convert_mono_420jpeg(y4m_input *_y4m, unsigned char *_dst, |
641 unsigned char *_aux){ | 649 unsigned char *_aux) { |
642 int c_sz; | 650 int c_sz; |
643 _dst+=_y4m->pic_w*_y4m->pic_h; | 651 _dst += _y4m->pic_w * _y4m->pic_h; |
644 c_sz=((_y4m->pic_w+_y4m->dst_c_dec_h-1)/_y4m->dst_c_dec_h)* | 652 c_sz = ((_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h) * |
645 ((_y4m->pic_h+_y4m->dst_c_dec_v-1)/_y4m->dst_c_dec_v); | 653 ((_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v); |
646 memset(_dst,128,c_sz*2); | 654 memset(_dst, 128, c_sz * 2); |
647 } | 655 } |
648 | 656 |
649 /*No conversion function needed.*/ | 657 /*No conversion function needed.*/ |
650 static void y4m_convert_null(y4m_input *_y4m,unsigned char *_dst, | 658 static void y4m_convert_null(y4m_input *_y4m, unsigned char *_dst, |
651 unsigned char *_aux){ | 659 unsigned char *_aux) { |
652 } | 660 } |
653 | 661 |
654 int y4m_input_open(y4m_input *_y4m,FILE *_fin,char *_skip,int _nskip){ | 662 int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip) { |
655 char buffer[80]; | 663 char buffer[80]; |
656 int ret; | 664 int ret; |
657 int i; | 665 int i; |
658 /*Read until newline, or 80 cols, whichever happens first.*/ | 666 /*Read until newline, or 80 cols, whichever happens first.*/ |
659 for(i=0;i<79;i++){ | 667 for (i = 0; i < 79; i++) { |
660 if(_nskip>0){ | 668 if (_nskip > 0) { |
661 buffer[i]=*_skip++; | 669 buffer[i] = *_skip++; |
662 _nskip--; | 670 _nskip--; |
| 671 } else { |
| 672 ret = (int)fread(buffer + i, 1, 1, _fin); |
| 673 if (ret < 1)return -1; |
663 } | 674 } |
664 else{ | 675 if (buffer[i] == '\n')break; |
665 ret=(int)fread(buffer+i,1,1,_fin); | |
666 if(ret<1)return -1; | |
667 } | |
668 if(buffer[i]=='\n')break; | |
669 } | 676 } |
670 /*We skipped too much header data.*/ | 677 /*We skipped too much header data.*/ |
671 if(_nskip>0)return -1; | 678 if (_nskip > 0)return -1; |
672 if(i==79){ | 679 if (i == 79) { |
673 fprintf(stderr,"Error parsing header; not a YUV2MPEG2 file?\n"); | 680 fprintf(stderr, "Error parsing header; not a YUV2MPEG2 file?\n"); |
674 return -1; | 681 return -1; |
675 } | 682 } |
676 buffer[i]='\0'; | 683 buffer[i] = '\0'; |
677 if(memcmp(buffer,"YUV4MPEG",8)){ | 684 if (memcmp(buffer, "YUV4MPEG", 8)) { |
678 fprintf(stderr,"Incomplete magic for YUV4MPEG file.\n"); | 685 fprintf(stderr, "Incomplete magic for YUV4MPEG file.\n"); |
679 return -1; | 686 return -1; |
680 } | 687 } |
681 if(buffer[8]!='2'){ | 688 if (buffer[8] != '2') { |
682 fprintf(stderr,"Incorrect YUV input file version; YUV4MPEG2 required.\n"); | 689 fprintf(stderr, "Incorrect YUV input file version; YUV4MPEG2 required.\n"); |
683 } | 690 } |
684 ret=y4m_parse_tags(_y4m,buffer+5); | 691 ret = y4m_parse_tags(_y4m, buffer + 5); |
685 if(ret<0){ | 692 if (ret < 0) { |
686 fprintf(stderr,"Error parsing YUV4MPEG2 header.\n"); | 693 fprintf(stderr, "Error parsing YUV4MPEG2 header.\n"); |
687 return ret; | 694 return ret; |
688 } | 695 } |
689 if(_y4m->interlace=='?'){ | 696 if (_y4m->interlace == '?') { |
690 fprintf(stderr,"Warning: Input video interlacing format unknown; " | 697 fprintf(stderr, "Warning: Input video interlacing format unknown; " |
691 "assuming progressive scan.\n"); | 698 "assuming progressive scan.\n"); |
692 } | 699 } else if (_y4m->interlace != 'p') { |
693 else if(_y4m->interlace!='p'){ | 700 fprintf(stderr, "Input video is interlaced; " |
694 fprintf(stderr,"Input video is interlaced; " | 701 "Only progressive scan handled.\n"); |
695 "Only progressive scan handled.\n"); | 702 return -1; |
696 return -1; | 703 } |
697 } | 704 if (strcmp(_y4m->chroma_type, "420") == 0 || |
698 if(strcmp(_y4m->chroma_type,"420")==0|| | 705 strcmp(_y4m->chroma_type, "420jpeg") == 0) { |
699 strcmp(_y4m->chroma_type,"420jpeg")==0){ | 706 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_
v = 2; |
700 _y4m->src_c_dec_h=_y4m->dst_c_dec_h=_y4m->src_c_dec_v=_y4m->dst_c_dec_v=2; | 707 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h |
701 _y4m->dst_buf_read_sz=_y4m->pic_w*_y4m->pic_h | 708 + 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) /
2); |
702 +2*((_y4m->pic_w+1)/2)*((_y4m->pic_h+1)/2); | |
703 /*Natively supported: no conversion required.*/ | 709 /*Natively supported: no conversion required.*/ |
704 _y4m->aux_buf_sz=_y4m->aux_buf_read_sz=0; | 710 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
705 _y4m->convert=y4m_convert_null; | 711 _y4m->convert = y4m_convert_null; |
706 } | 712 } else if (strcmp(_y4m->chroma_type, "420mpeg2") == 0) { |
707 else if(strcmp(_y4m->chroma_type,"420mpeg2")==0){ | 713 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_
v = 2; |
708 _y4m->src_c_dec_h=_y4m->dst_c_dec_h=_y4m->src_c_dec_v=_y4m->dst_c_dec_v=2; | 714 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
709 _y4m->dst_buf_read_sz=_y4m->pic_w*_y4m->pic_h; | |
710 /*Chroma filter required: read into the aux buf first.*/ | 715 /*Chroma filter required: read into the aux buf first.*/ |
711 _y4m->aux_buf_sz=_y4m->aux_buf_read_sz= | 716 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = |
712 2*((_y4m->pic_w+1)/2)*((_y4m->pic_h+1)/2); | 717 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); |
713 _y4m->convert=y4m_convert_42xmpeg2_42xjpeg; | 718 _y4m->convert = y4m_convert_42xmpeg2_42xjpeg; |
714 } | 719 } else if (strcmp(_y4m->chroma_type, "420paldv") == 0) { |
715 else if(strcmp(_y4m->chroma_type,"420paldv")==0){ | 720 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_
v = 2; |
716 _y4m->src_c_dec_h=_y4m->dst_c_dec_h=_y4m->src_c_dec_v=_y4m->dst_c_dec_v=2; | 721 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
717 _y4m->dst_buf_read_sz=_y4m->pic_w*_y4m->pic_h; | 722 /*Chroma filter required: read into the aux buf first. |
718 /*Chroma filter required: read into the aux buf first. | 723 We need to make two filter passes, so we need some extra space in the |
719 We need to make two filter passes, so we need some extra space in the | 724 aux buffer.*/ |
720 aux buffer.*/ | 725 _y4m->aux_buf_sz = 3 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); |
721 _y4m->aux_buf_sz=3*((_y4m->pic_w+1)/2)*((_y4m->pic_h+1)/2); | 726 _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2
); |
722 _y4m->aux_buf_read_sz=2*((_y4m->pic_w+1)/2)*((_y4m->pic_h+1)/2); | 727 _y4m->convert = y4m_convert_42xpaldv_42xjpeg; |
723 _y4m->convert=y4m_convert_42xpaldv_42xjpeg; | 728 } else if (strcmp(_y4m->chroma_type, "422jpeg") == 0) { |
724 } | 729 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = 2; |
725 else if(strcmp(_y4m->chroma_type,"422jpeg")==0){ | 730 _y4m->src_c_dec_v = 1; |
726 _y4m->src_c_dec_h=_y4m->dst_c_dec_h=2; | 731 _y4m->dst_c_dec_v = 2; |
727 _y4m->src_c_dec_v=1; | 732 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
728 _y4m->dst_c_dec_v=2; | |
729 _y4m->dst_buf_read_sz=_y4m->pic_w*_y4m->pic_h; | |
730 /*Chroma filter required: read into the aux buf first.*/ | 733 /*Chroma filter required: read into the aux buf first.*/ |
731 _y4m->aux_buf_sz=_y4m->aux_buf_read_sz=2*((_y4m->pic_w+1)/2)*_y4m->pic_h; | 734 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 1) / 2) * _y4
m->pic_h; |
732 _y4m->convert=y4m_convert_422jpeg_420jpeg; | 735 _y4m->convert = y4m_convert_422jpeg_420jpeg; |
733 } | 736 } else if (strcmp(_y4m->chroma_type, "422") == 0) { |
734 else if(strcmp(_y4m->chroma_type,"422")==0){ | 737 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = 2; |
735 _y4m->src_c_dec_h=_y4m->dst_c_dec_h=2; | 738 _y4m->src_c_dec_v = 1; |
736 _y4m->src_c_dec_v=1; | 739 _y4m->dst_c_dec_v = 2; |
737 _y4m->dst_c_dec_v=2; | 740 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
738 _y4m->dst_buf_read_sz=_y4m->pic_w*_y4m->pic_h; | 741 /*Chroma filter required: read into the aux buf first. |
739 /*Chroma filter required: read into the aux buf first. | 742 We need to make two filter passes, so we need some extra space in the |
740 We need to make two filter passes, so we need some extra space in the | 743 aux buffer.*/ |
741 aux buffer.*/ | 744 _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; |
742 _y4m->aux_buf_read_sz=2*((_y4m->pic_w+1)/2)*_y4m->pic_h; | 745 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->p
ic_h; |
743 _y4m->aux_buf_sz=_y4m->aux_buf_read_sz+((_y4m->pic_w+1)/2)*_y4m->pic_h; | 746 _y4m->convert = y4m_convert_422_420jpeg; |
744 _y4m->convert=y4m_convert_422_420jpeg; | 747 } else if (strcmp(_y4m->chroma_type, "411") == 0) { |
745 } | 748 _y4m->src_c_dec_h = 4; |
746 else if(strcmp(_y4m->chroma_type,"411")==0){ | 749 _y4m->dst_c_dec_h = 2; |
747 _y4m->src_c_dec_h=4; | 750 _y4m->src_c_dec_v = 1; |
748 _y4m->dst_c_dec_h=2; | 751 _y4m->dst_c_dec_v = 2; |
749 _y4m->src_c_dec_v=1; | 752 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
750 _y4m->dst_c_dec_v=2; | 753 /*Chroma filter required: read into the aux buf first. |
751 _y4m->dst_buf_read_sz=_y4m->pic_w*_y4m->pic_h; | 754 We need to make two filter passes, so we need some extra space in the |
752 /*Chroma filter required: read into the aux buf first. | 755 aux buffer.*/ |
753 We need to make two filter passes, so we need some extra space in the | 756 _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 3) / 4) * _y4m->pic_h; |
754 aux buffer.*/ | 757 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->p
ic_h; |
755 _y4m->aux_buf_read_sz=2*((_y4m->pic_w+3)/4)*_y4m->pic_h; | 758 _y4m->convert = y4m_convert_411_420jpeg; |
756 _y4m->aux_buf_sz=_y4m->aux_buf_read_sz+((_y4m->pic_w+1)/2)*_y4m->pic_h; | 759 } else if (strcmp(_y4m->chroma_type, "444") == 0) { |
757 _y4m->convert=y4m_convert_411_420jpeg; | 760 _y4m->src_c_dec_h = 1; |
758 } | 761 _y4m->dst_c_dec_h = 2; |
759 else if(strcmp(_y4m->chroma_type,"444")==0){ | 762 _y4m->src_c_dec_v = 1; |
760 _y4m->src_c_dec_h=1; | 763 _y4m->dst_c_dec_v = 2; |
761 _y4m->dst_c_dec_h=2; | 764 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
762 _y4m->src_c_dec_v=1; | 765 /*Chroma filter required: read into the aux buf first. |
763 _y4m->dst_c_dec_v=2; | 766 We need to make two filter passes, so we need some extra space in the |
764 _y4m->dst_buf_read_sz=_y4m->pic_w*_y4m->pic_h; | 767 aux buffer.*/ |
765 /*Chroma filter required: read into the aux buf first. | 768 _y4m->aux_buf_read_sz = 2 * _y4m->pic_w * _y4m->pic_h; |
766 We need to make two filter passes, so we need some extra space in the | 769 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->p
ic_h; |
767 aux buffer.*/ | 770 _y4m->convert = y4m_convert_444_420jpeg; |
768 _y4m->aux_buf_read_sz=2*_y4m->pic_w*_y4m->pic_h; | 771 } else if (strcmp(_y4m->chroma_type, "444alpha") == 0) { |
769 _y4m->aux_buf_sz=_y4m->aux_buf_read_sz+((_y4m->pic_w+1)/2)*_y4m->pic_h; | 772 _y4m->src_c_dec_h = 1; |
770 _y4m->convert=y4m_convert_444_420jpeg; | 773 _y4m->dst_c_dec_h = 2; |
771 } | 774 _y4m->src_c_dec_v = 1; |
772 else if(strcmp(_y4m->chroma_type,"444alpha")==0){ | 775 _y4m->dst_c_dec_v = 2; |
773 _y4m->src_c_dec_h=1; | 776 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
774 _y4m->dst_c_dec_h=2; | |
775 _y4m->src_c_dec_v=1; | |
776 _y4m->dst_c_dec_v=2; | |
777 _y4m->dst_buf_read_sz=_y4m->pic_w*_y4m->pic_h; | |
778 /*Chroma filter required: read into the aux buf first. | 777 /*Chroma filter required: read into the aux buf first. |
779 We need to make two filter passes, so we need some extra space in the | 778 We need to make two filter passes, so we need some extra space in the |
780 aux buffer. | 779 aux buffer. |
781 The extra plane also gets read into the aux buf. | 780 The extra plane also gets read into the aux buf. |
782 It will be discarded.*/ | 781 It will be discarded.*/ |
783 _y4m->aux_buf_sz=_y4m->aux_buf_read_sz=3*_y4m->pic_w*_y4m->pic_h; | 782 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 3 * _y4m->pic_w * _y4m->pic_h; |
784 _y4m->convert=y4m_convert_444_420jpeg; | 783 _y4m->convert = y4m_convert_444_420jpeg; |
785 } | 784 } else if (strcmp(_y4m->chroma_type, "mono") == 0) { |
786 else if(strcmp(_y4m->chroma_type,"mono")==0){ | 785 _y4m->src_c_dec_h = _y4m->src_c_dec_v = 0; |
787 _y4m->src_c_dec_h=_y4m->src_c_dec_v=0; | 786 _y4m->dst_c_dec_h = _y4m->dst_c_dec_v = 2; |
788 _y4m->dst_c_dec_h=_y4m->dst_c_dec_v=2; | 787 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; |
789 _y4m->dst_buf_read_sz=_y4m->pic_w*_y4m->pic_h; | |
790 /*No extra space required, but we need to clear the chroma planes.*/ | 788 /*No extra space required, but we need to clear the chroma planes.*/ |
791 _y4m->aux_buf_sz=_y4m->aux_buf_read_sz=0; | 789 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; |
792 _y4m->convert=y4m_convert_mono_420jpeg; | 790 _y4m->convert = y4m_convert_mono_420jpeg; |
793 } | 791 } else { |
794 else{ | 792 fprintf(stderr, "Unknown chroma sampling type: %s\n", _y4m->chroma_type); |
795 fprintf(stderr,"Unknown chroma sampling type: %s\n",_y4m->chroma_type); | |
796 return -1; | 793 return -1; |
797 } | 794 } |
798 /*The size of the final frame buffers is always computed from the | 795 /*The size of the final frame buffers is always computed from the |
799 destination chroma decimation type.*/ | 796 destination chroma decimation type.*/ |
800 _y4m->dst_buf_sz=_y4m->pic_w*_y4m->pic_h | 797 _y4m->dst_buf_sz = _y4m->pic_w * _y4m->pic_h |
801 +2*((_y4m->pic_w+_y4m->dst_c_dec_h-1)/_y4m->dst_c_dec_h)* | 798 + 2 * ((_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_
dec_h) * |
802 ((_y4m->pic_h+_y4m->dst_c_dec_v-1)/_y4m->dst_c_dec_v); | 799 ((_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v)
; |
803 _y4m->dst_buf=(unsigned char *)malloc(_y4m->dst_buf_sz); | 800 _y4m->dst_buf = (unsigned char *)malloc(_y4m->dst_buf_sz); |
804 _y4m->aux_buf=(unsigned char *)malloc(_y4m->aux_buf_sz); | 801 _y4m->aux_buf = (unsigned char *)malloc(_y4m->aux_buf_sz); |
805 return 0; | 802 return 0; |
806 } | 803 } |
807 | 804 |
808 void y4m_input_close(y4m_input *_y4m){ | 805 void y4m_input_close(y4m_input *_y4m) { |
809 free(_y4m->dst_buf); | 806 free(_y4m->dst_buf); |
810 free(_y4m->aux_buf); | 807 free(_y4m->aux_buf); |
811 } | 808 } |
812 | 809 |
813 int y4m_input_fetch_frame(y4m_input *_y4m,FILE *_fin,vpx_image_t *_img){ | 810 int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, vpx_image_t *_img) { |
814 char frame[6]; | 811 char frame[6]; |
815 int pic_sz; | 812 int pic_sz; |
816 int c_w; | 813 int c_w; |
817 int c_h; | 814 int c_h; |
818 int c_sz; | 815 int c_sz; |
819 int ret; | 816 int ret; |
820 /*Read and skip the frame header.*/ | 817 /*Read and skip the frame header.*/ |
821 ret=(int)fread(frame,1,6,_fin); | 818 ret = (int)fread(frame, 1, 6, _fin); |
822 if(ret<6)return 0; | 819 if (ret < 6)return 0; |
823 if(memcmp(frame,"FRAME",5)){ | 820 if (memcmp(frame, "FRAME", 5)) { |
824 fprintf(stderr,"Loss of framing in Y4M input data\n"); | 821 fprintf(stderr, "Loss of framing in Y4M input data\n"); |
825 return -1; | 822 return -1; |
826 } | 823 } |
827 if(frame[5]!='\n'){ | 824 if (frame[5] != '\n') { |
828 char c; | 825 char c; |
829 int j; | 826 int j; |
830 for(j=0;j<79&&fread(&c,1,1,_fin)&&c!='\n';j++); | 827 for (j = 0; j < 79 && fread(&c, 1, 1, _fin) && c != '\n'; j++); |
831 if(j==79){ | 828 if (j == 79) { |
832 fprintf(stderr,"Error parsing Y4M frame header\n"); | 829 fprintf(stderr, "Error parsing Y4M frame header\n"); |
833 return -1; | 830 return -1; |
834 } | 831 } |
835 } | 832 } |
836 /*Read the frame data that needs no conversion.*/ | 833 /*Read the frame data that needs no conversion.*/ |
837 if(fread(_y4m->dst_buf,1,_y4m->dst_buf_read_sz,_fin)!=_y4m->dst_buf_read_sz){ | 834 if (fread(_y4m->dst_buf, 1, _y4m->dst_buf_read_sz, _fin) != _y4m->dst_buf_read
_sz) { |
838 fprintf(stderr,"Error reading Y4M frame data.\n"); | 835 fprintf(stderr, "Error reading Y4M frame data.\n"); |
839 return -1; | 836 return -1; |
840 } | 837 } |
841 /*Read the frame data that does need conversion.*/ | 838 /*Read the frame data that does need conversion.*/ |
842 if(fread(_y4m->aux_buf,1,_y4m->aux_buf_read_sz,_fin)!=_y4m->aux_buf_read_sz){ | 839 if (fread(_y4m->aux_buf, 1, _y4m->aux_buf_read_sz, _fin) != _y4m->aux_buf_read
_sz) { |
843 fprintf(stderr,"Error reading Y4M frame data.\n"); | 840 fprintf(stderr, "Error reading Y4M frame data.\n"); |
844 return -1; | 841 return -1; |
845 } | 842 } |
846 /*Now convert the just read frame.*/ | 843 /*Now convert the just read frame.*/ |
847 (*_y4m->convert)(_y4m,_y4m->dst_buf,_y4m->aux_buf); | 844 (*_y4m->convert)(_y4m, _y4m->dst_buf, _y4m->aux_buf); |
848 /*Fill in the frame buffer pointers. | 845 /*Fill in the frame buffer pointers. |
849 We don't use vpx_img_wrap() because it forces padding for odd picture | 846 We don't use vpx_img_wrap() because it forces padding for odd picture |
850 sizes, which would require a separate fread call for every row.*/ | 847 sizes, which would require a separate fread call for every row.*/ |
851 memset(_img,0,sizeof(*_img)); | 848 memset(_img, 0, sizeof(*_img)); |
852 /*Y4M has the planes in Y'CbCr order, which libvpx calls Y, U, and V.*/ | 849 /*Y4M has the planes in Y'CbCr order, which libvpx calls Y, U, and V.*/ |
853 _img->fmt=IMG_FMT_I420; | 850 _img->fmt = IMG_FMT_I420; |
854 _img->w=_img->d_w=_y4m->pic_w; | 851 _img->w = _img->d_w = _y4m->pic_w; |
855 _img->h=_img->d_h=_y4m->pic_h; | 852 _img->h = _img->d_h = _y4m->pic_h; |
856 /*This is hard-coded to 4:2:0 for now, as that's all VP8 supports.*/ | 853 /*This is hard-coded to 4:2:0 for now, as that's all VP8 supports.*/ |
857 _img->x_chroma_shift=1; | 854 _img->x_chroma_shift = 1; |
858 _img->y_chroma_shift=1; | 855 _img->y_chroma_shift = 1; |
859 _img->bps=12; | 856 _img->bps = 12; |
860 /*Set up the buffer pointers.*/ | 857 /*Set up the buffer pointers.*/ |
861 pic_sz=_y4m->pic_w*_y4m->pic_h; | 858 pic_sz = _y4m->pic_w * _y4m->pic_h; |
862 c_w=(_y4m->pic_w+_y4m->dst_c_dec_h-1)/_y4m->dst_c_dec_h; | 859 c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; |
863 c_h=(_y4m->pic_h+_y4m->dst_c_dec_v-1)/_y4m->dst_c_dec_v; | 860 c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; |
864 c_sz=c_w*c_h; | 861 c_sz = c_w * c_h; |
865 _img->stride[PLANE_Y]=_y4m->pic_w; | 862 _img->stride[PLANE_Y] = _y4m->pic_w; |
866 _img->stride[PLANE_U]=_img->stride[PLANE_V]=c_w; | 863 _img->stride[PLANE_U] = _img->stride[PLANE_V] = c_w; |
867 _img->planes[PLANE_Y]=_y4m->dst_buf; | 864 _img->planes[PLANE_Y] = _y4m->dst_buf; |
868 _img->planes[PLANE_U]=_y4m->dst_buf+pic_sz; | 865 _img->planes[PLANE_U] = _y4m->dst_buf + pic_sz; |
869 _img->planes[PLANE_V]=_y4m->dst_buf+pic_sz+c_sz; | 866 _img->planes[PLANE_V] = _y4m->dst_buf + pic_sz + c_sz; |
870 return 1; | 867 return 1; |
871 } | 868 } |
OLD | NEW |