Parent Directory
|
Revision Log
Revision 681 - (view) (download)
1 : | albeu | 315 | /************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * image stuff | ||
5 : | * | ||
6 : | chl | 530 | * This program is an implementation of a part of one or more MPEG-4 |
7 : | * Video tools as specified in ISO/IEC 14496-2 standard. Those intending | ||
8 : | * to use this software module in hardware or software products are | ||
9 : | * advised that its use may infringe existing patents or copyrights, and | ||
10 : | * any such use would be at such party's own risk. The original | ||
11 : | * developer of this software module and his/her company, and subsequent | ||
12 : | * editors and their companies, will have no liability for use of this | ||
13 : | * software or modifications or derivatives thereof. | ||
14 : | * | ||
15 : | albeu | 315 | * This program is free software; you can redistribute it and/or modify |
16 : | * it under the terms of the GNU General Public License as published by | ||
17 : | * the Free Software Foundation; either version 2 of the License, or | ||
18 : | * (at your option) any later version. | ||
19 : | * | ||
20 : | * This program is distributed in the hope that it will be useful, | ||
21 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
22 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
23 : | * GNU General Public License for more details. | ||
24 : | * | ||
25 : | * You should have received a copy of the GNU General Public License | ||
26 : | * along with this program; if not, write to the Free Software | ||
27 : | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
28 : | * | ||
29 : | *************************************************************************/ | ||
30 : | |||
31 : | /************************************************************************** | ||
32 : | * | ||
33 : | * History: | ||
34 : | * | ||
35 : | Isibaar | 579 | * 05.10.2002 support for interpolated images in qpel mode - Isibaar |
36 : | albeu | 315 | * 01.05.2002 BFRAME image-based u,v interpolation |
37 : | * 22.04.2002 added some B-frame support | ||
38 : | * 14.04.2002 added image_dump_yuvpgm(), added image_mad() | ||
39 : | * XVID_CSP_USER input support | ||
40 : | Isibaar | 579 | * 09.04.2002 PSNR calculations - Isibaar |
41 : | albeu | 315 | * 06.04.2002 removed interlaced edging from U,V blocks (as per spec) |
42 : | * 26.03.2002 interlacing support (field-based edging in set_edges) | ||
43 : | * 26.01.2002 rgb555, rgb565 | ||
44 : | * 07.01.2001 commented u,v interpolation (not required for uv-block-based) | ||
45 : | * 23.12.2001 removed #ifdefs, added function pointers + init_common() | ||
46 : | * 22.12.2001 cpu #ifdefs | ||
47 : | * 19.12.2001 image_dump(); useful for debugging | ||
48 : | * 6.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> | ||
49 : | * | ||
50 : | *************************************************************************/ | ||
51 : | |||
52 : | #include <stdlib.h> | ||
53 : | #include <string.h> // memcpy, memset | ||
54 : | #include <math.h> | ||
55 : | |||
56 : | #include "../portab.h" | ||
57 : | suxen_drol | 631 | #include "../global.h" |
58 : | albeu | 315 | #include "../xvid.h" |
59 : | #include "image.h" | ||
60 : | #include "colorspace.h" | ||
61 : | #include "interpolate8x8.h" | ||
62 : | #include "../divx4.h" | ||
63 : | #include "../utils/mem_align.h" | ||
64 : | |||
65 : | suxen_drol | 631 | #include "font.h" |
66 : | |||
67 : | albeu | 315 | #define SAFETY 64 |
68 : | #define EDGE_SIZE2 (EDGE_SIZE/2) | ||
69 : | |||
70 : | |||
71 : | int32_t | ||
72 : | image_create(IMAGE * image, | ||
73 : | uint32_t edged_width, | ||
74 : | uint32_t edged_height) | ||
75 : | { | ||
76 : | const uint32_t edged_width2 = edged_width / 2; | ||
77 : | const uint32_t edged_height2 = edged_height / 2; | ||
78 : | uint32_t i; | ||
79 : | |||
80 : | image->y = | ||
81 : | xvid_malloc(edged_width * (edged_height + 1) + SAFETY, CACHE_LINE); | ||
82 : | if (image->y == NULL) { | ||
83 : | return -1; | ||
84 : | } | ||
85 : | |||
86 : | for (i = 0; i < edged_width * edged_height + SAFETY; i++) { | ||
87 : | image->y[i] = 0; | ||
88 : | } | ||
89 : | |||
90 : | image->u = xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE); | ||
91 : | if (image->u == NULL) { | ||
92 : | xvid_free(image->y); | ||
93 : | return -1; | ||
94 : | } | ||
95 : | image->v = xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE); | ||
96 : | if (image->v == NULL) { | ||
97 : | xvid_free(image->u); | ||
98 : | xvid_free(image->y); | ||
99 : | return -1; | ||
100 : | } | ||
101 : | |||
102 : | image->y += EDGE_SIZE * edged_width + EDGE_SIZE; | ||
103 : | image->u += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2; | ||
104 : | image->v += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2; | ||
105 : | |||
106 : | return 0; | ||
107 : | } | ||
108 : | |||
109 : | |||
110 : | |||
111 : | void | ||
112 : | image_destroy(IMAGE * image, | ||
113 : | uint32_t edged_width, | ||
114 : | uint32_t edged_height) | ||
115 : | { | ||
116 : | const uint32_t edged_width2 = edged_width / 2; | ||
117 : | |||
118 : | if (image->y) { | ||
119 : | xvid_free(image->y - (EDGE_SIZE * edged_width + EDGE_SIZE)); | ||
120 : | } | ||
121 : | if (image->u) { | ||
122 : | xvid_free(image->u - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2)); | ||
123 : | } | ||
124 : | if (image->v) { | ||
125 : | xvid_free(image->v - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2)); | ||
126 : | } | ||
127 : | } | ||
128 : | |||
129 : | |||
130 : | void | ||
131 : | image_swap(IMAGE * image1, | ||
132 : | IMAGE * image2) | ||
133 : | { | ||
134 : | uint8_t *tmp; | ||
135 : | |||
136 : | tmp = image1->y; | ||
137 : | image1->y = image2->y; | ||
138 : | image2->y = tmp; | ||
139 : | |||
140 : | tmp = image1->u; | ||
141 : | image1->u = image2->u; | ||
142 : | image2->u = tmp; | ||
143 : | |||
144 : | tmp = image1->v; | ||
145 : | image1->v = image2->v; | ||
146 : | image2->v = tmp; | ||
147 : | } | ||
148 : | |||
149 : | |||
150 : | void | ||
151 : | image_copy(IMAGE * image1, | ||
152 : | IMAGE * image2, | ||
153 : | uint32_t edged_width, | ||
154 : | uint32_t height) | ||
155 : | { | ||
156 : | memcpy(image1->y, image2->y, edged_width * height); | ||
157 : | memcpy(image1->u, image2->u, edged_width * height / 4); | ||
158 : | memcpy(image1->v, image2->v, edged_width * height / 4); | ||
159 : | } | ||
160 : | |||
161 : | |||
162 : | void | ||
163 : | image_setedges(IMAGE * image, | ||
164 : | uint32_t edged_width, | ||
165 : | uint32_t edged_height, | ||
166 : | uint32_t width, | ||
167 : | h | 543 | uint32_t height) |
168 : | albeu | 315 | { |
169 : | const uint32_t edged_width2 = edged_width / 2; | ||
170 : | const uint32_t width2 = width / 2; | ||
171 : | uint32_t i; | ||
172 : | uint8_t *dst; | ||
173 : | uint8_t *src; | ||
174 : | |||
175 : | |||
176 : | dst = image->y - (EDGE_SIZE + EDGE_SIZE * edged_width); | ||
177 : | src = image->y; | ||
178 : | |||
179 : | for (i = 0; i < EDGE_SIZE; i++) { | ||
180 : | h | 543 | memset(dst, *src, EDGE_SIZE); |
181 : | memcpy(dst + EDGE_SIZE, src, width); | ||
182 : | memset(dst + edged_width - EDGE_SIZE, *(src + width - 1), | ||
183 : | EDGE_SIZE); | ||
184 : | albeu | 315 | dst += edged_width; |
185 : | } | ||
186 : | |||
187 : | for (i = 0; i < height; i++) { | ||
188 : | memset(dst, *src, EDGE_SIZE); | ||
189 : | memset(dst + edged_width - EDGE_SIZE, src[width - 1], EDGE_SIZE); | ||
190 : | dst += edged_width; | ||
191 : | src += edged_width; | ||
192 : | } | ||
193 : | |||
194 : | src -= edged_width; | ||
195 : | for (i = 0; i < EDGE_SIZE; i++) { | ||
196 : | h | 543 | memset(dst, *src, EDGE_SIZE); |
197 : | memcpy(dst + EDGE_SIZE, src, width); | ||
198 : | memset(dst + edged_width - EDGE_SIZE, *(src + width - 1), | ||
199 : | albeu | 315 | EDGE_SIZE); |
200 : | dst += edged_width; | ||
201 : | } | ||
202 : | |||
203 : | |||
204 : | //U | ||
205 : | dst = image->u - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2); | ||
206 : | src = image->u; | ||
207 : | |||
208 : | for (i = 0; i < EDGE_SIZE2; i++) { | ||
209 : | memset(dst, *src, EDGE_SIZE2); | ||
210 : | memcpy(dst + EDGE_SIZE2, src, width2); | ||
211 : | memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), | ||
212 : | EDGE_SIZE2); | ||
213 : | dst += edged_width2; | ||
214 : | } | ||
215 : | |||
216 : | for (i = 0; i < height / 2; i++) { | ||
217 : | memset(dst, *src, EDGE_SIZE2); | ||
218 : | memset(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1], EDGE_SIZE2); | ||
219 : | dst += edged_width2; | ||
220 : | src += edged_width2; | ||
221 : | } | ||
222 : | src -= edged_width2; | ||
223 : | for (i = 0; i < EDGE_SIZE2; i++) { | ||
224 : | memset(dst, *src, EDGE_SIZE2); | ||
225 : | memcpy(dst + EDGE_SIZE2, src, width2); | ||
226 : | memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), | ||
227 : | EDGE_SIZE2); | ||
228 : | dst += edged_width2; | ||
229 : | } | ||
230 : | |||
231 : | |||
232 : | // V | ||
233 : | dst = image->v - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2); | ||
234 : | src = image->v; | ||
235 : | |||
236 : | for (i = 0; i < EDGE_SIZE2; i++) { | ||
237 : | memset(dst, *src, EDGE_SIZE2); | ||
238 : | memcpy(dst + EDGE_SIZE2, src, width2); | ||
239 : | memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), | ||
240 : | EDGE_SIZE2); | ||
241 : | dst += edged_width2; | ||
242 : | } | ||
243 : | |||
244 : | for (i = 0; i < height / 2; i++) { | ||
245 : | memset(dst, *src, EDGE_SIZE2); | ||
246 : | memset(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1], EDGE_SIZE2); | ||
247 : | dst += edged_width2; | ||
248 : | src += edged_width2; | ||
249 : | } | ||
250 : | src -= edged_width2; | ||
251 : | for (i = 0; i < EDGE_SIZE2; i++) { | ||
252 : | memset(dst, *src, EDGE_SIZE2); | ||
253 : | memcpy(dst + EDGE_SIZE2, src, width2); | ||
254 : | memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), | ||
255 : | EDGE_SIZE2); | ||
256 : | dst += edged_width2; | ||
257 : | } | ||
258 : | } | ||
259 : | |||
260 : | chl | 530 | // bframe encoding requires image-based u,v interpolation |
261 : | albeu | 315 | void |
262 : | image_interpolate(const IMAGE * refn, | ||
263 : | IMAGE * refh, | ||
264 : | IMAGE * refv, | ||
265 : | IMAGE * refhv, | ||
266 : | uint32_t edged_width, | ||
267 : | uint32_t edged_height, | ||
268 : | Isibaar | 579 | uint32_t quarterpel, |
269 : | albeu | 315 | uint32_t rounding) |
270 : | { | ||
271 : | Isibaar | 586 | const uint32_t offset = EDGE_SIZE2 * (edged_width + 1); // we only interpolate half of the edge area |
272 : | albeu | 315 | const uint32_t stride_add = 7 * edged_width; |
273 : | Isibaar | 586 | /* |
274 : | chl | 530 | #ifdef BFRAMES |
275 : | albeu | 315 | const uint32_t edged_width2 = edged_width / 2; |
276 : | const uint32_t edged_height2 = edged_height / 2; | ||
277 : | const uint32_t offset2 = EDGE_SIZE2 * (edged_width2 + 1); | ||
278 : | const uint32_t stride_add2 = 7 * edged_width2; | ||
279 : | chl | 530 | #endif |
280 : | Isibaar | 586 | */ |
281 : | albeu | 315 | uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr; |
282 : | uint32_t x, y; | ||
283 : | |||
284 : | |||
285 : | n_ptr = refn->y; | ||
286 : | h_ptr = refh->y; | ||
287 : | v_ptr = refv->y; | ||
288 : | hv_ptr = refhv->y; | ||
289 : | |||
290 : | n_ptr -= offset; | ||
291 : | h_ptr -= offset; | ||
292 : | v_ptr -= offset; | ||
293 : | hv_ptr -= offset; | ||
294 : | |||
295 : | Isibaar | 579 | if(quarterpel) { |
296 : | |||
297 : | Isibaar | 586 | for (y = 0; y < (edged_height - EDGE_SIZE); y += 8) { |
298 : | for (x = 0; x < (edged_width - EDGE_SIZE); x += 8) { | ||
299 : | Isibaar | 579 | interpolate8x8_6tap_lowpass_h(h_ptr, n_ptr, edged_width, rounding); |
300 : | interpolate8x8_6tap_lowpass_v(v_ptr, n_ptr, edged_width, rounding); | ||
301 : | albeu | 315 | |
302 : | Isibaar | 579 | n_ptr += 8; |
303 : | h_ptr += 8; | ||
304 : | v_ptr += 8; | ||
305 : | } | ||
306 : | |||
307 : | Isibaar | 586 | n_ptr += EDGE_SIZE; |
308 : | h_ptr += EDGE_SIZE; | ||
309 : | v_ptr += EDGE_SIZE; | ||
310 : | |||
311 : | Isibaar | 579 | h_ptr += stride_add; |
312 : | v_ptr += stride_add; | ||
313 : | n_ptr += stride_add; | ||
314 : | albeu | 315 | } |
315 : | Isibaar | 579 | |
316 : | h_ptr = refh->y; | ||
317 : | h_ptr -= offset; | ||
318 : | |||
319 : | Isibaar | 586 | for (y = 0; y < (edged_height - EDGE_SIZE); y = y + 8) { |
320 : | for (x = 0; x < (edged_width - EDGE_SIZE); x = x + 8) { | ||
321 : | Isibaar | 579 | interpolate8x8_6tap_lowpass_v(hv_ptr, h_ptr, edged_width, rounding); |
322 : | hv_ptr += 8; | ||
323 : | h_ptr += 8; | ||
324 : | } | ||
325 : | Isibaar | 586 | |
326 : | syskin | 681 | hv_ptr += EDGE_SIZE; |
327 : | h_ptr += EDGE_SIZE; | ||
328 : | Isibaar | 586 | |
329 : | Isibaar | 579 | hv_ptr += stride_add; |
330 : | h_ptr += stride_add; | ||
331 : | } | ||
332 : | albeu | 315 | } |
333 : | Isibaar | 579 | else { |
334 : | |||
335 : | Isibaar | 586 | for (y = 0; y < (edged_height - EDGE_SIZE); y += 8) { |
336 : | for (x = 0; x < (edged_width - EDGE_SIZE); x += 8) { | ||
337 : | Isibaar | 579 | interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width, rounding); |
338 : | interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width, rounding); | ||
339 : | interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width, rounding); | ||
340 : | |||
341 : | n_ptr += 8; | ||
342 : | h_ptr += 8; | ||
343 : | v_ptr += 8; | ||
344 : | hv_ptr += 8; | ||
345 : | } | ||
346 : | |||
347 : | Isibaar | 586 | h_ptr += EDGE_SIZE; |
348 : | v_ptr += EDGE_SIZE; | ||
349 : | hv_ptr += EDGE_SIZE; | ||
350 : | n_ptr += EDGE_SIZE; | ||
351 : | |||
352 : | Isibaar | 579 | h_ptr += stride_add; |
353 : | v_ptr += stride_add; | ||
354 : | hv_ptr += stride_add; | ||
355 : | n_ptr += stride_add; | ||
356 : | } | ||
357 : | } | ||
358 : | chl | 530 | /* |
359 : | #ifdef BFRAMES | ||
360 : | albeu | 315 | n_ptr = refn->u; |
361 : | h_ptr = refh->u; | ||
362 : | v_ptr = refv->u; | ||
363 : | hv_ptr = refhv->u; | ||
364 : | |||
365 : | n_ptr -= offset2; | ||
366 : | h_ptr -= offset2; | ||
367 : | v_ptr -= offset2; | ||
368 : | hv_ptr -= offset2; | ||
369 : | |||
370 : | chl | 530 | for (y = 0; y < edged_height2; y += 8) { |
371 : | for (x = 0; x < edged_width2; x += 8) { | ||
372 : | albeu | 315 | interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding); |
373 : | interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding); | ||
374 : | interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding); | ||
375 : | |||
376 : | n_ptr += 8; | ||
377 : | h_ptr += 8; | ||
378 : | v_ptr += 8; | ||
379 : | hv_ptr += 8; | ||
380 : | } | ||
381 : | h_ptr += stride_add2; | ||
382 : | v_ptr += stride_add2; | ||
383 : | hv_ptr += stride_add2; | ||
384 : | n_ptr += stride_add2; | ||
385 : | } | ||
386 : | |||
387 : | n_ptr = refn->v; | ||
388 : | h_ptr = refh->v; | ||
389 : | v_ptr = refv->v; | ||
390 : | hv_ptr = refhv->v; | ||
391 : | |||
392 : | n_ptr -= offset2; | ||
393 : | h_ptr -= offset2; | ||
394 : | v_ptr -= offset2; | ||
395 : | hv_ptr -= offset2; | ||
396 : | |||
397 : | for (y = 0; y < edged_height2; y = y + 8) { | ||
398 : | for (x = 0; x < edged_width2; x = x + 8) { | ||
399 : | interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding); | ||
400 : | interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding); | ||
401 : | interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding); | ||
402 : | |||
403 : | n_ptr += 8; | ||
404 : | h_ptr += 8; | ||
405 : | v_ptr += 8; | ||
406 : | hv_ptr += 8; | ||
407 : | } | ||
408 : | h_ptr += stride_add2; | ||
409 : | v_ptr += stride_add2; | ||
410 : | hv_ptr += stride_add2; | ||
411 : | n_ptr += stride_add2; | ||
412 : | } | ||
413 : | chl | 530 | #endif |
414 : | suxen_drol | 449 | */ |
415 : | chl | 530 | /* |
416 : | interpolate_halfpel_h( | ||
417 : | refh->y - offset, | ||
418 : | refn->y - offset, | ||
419 : | edged_width, edged_height, | ||
420 : | rounding); | ||
421 : | |||
422 : | interpolate_halfpel_v( | ||
423 : | refv->y - offset, | ||
424 : | refn->y - offset, | ||
425 : | edged_width, edged_height, | ||
426 : | rounding); | ||
427 : | |||
428 : | interpolate_halfpel_hv( | ||
429 : | refhv->y - offset, | ||
430 : | refn->y - offset, | ||
431 : | edged_width, edged_height, | ||
432 : | rounding); | ||
433 : | */ | ||
434 : | |||
435 : | /* uv-image-based compensation | ||
436 : | offset = EDGE_SIZE2 * (edged_width / 2 + 1); | ||
437 : | |||
438 : | interpolate_halfpel_h( | ||
439 : | refh->u - offset, | ||
440 : | refn->u - offset, | ||
441 : | edged_width / 2, edged_height / 2, | ||
442 : | rounding); | ||
443 : | |||
444 : | interpolate_halfpel_v( | ||
445 : | refv->u - offset, | ||
446 : | refn->u - offset, | ||
447 : | edged_width / 2, edged_height / 2, | ||
448 : | rounding); | ||
449 : | |||
450 : | interpolate_halfpel_hv( | ||
451 : | refhv->u - offset, | ||
452 : | refn->u - offset, | ||
453 : | edged_width / 2, edged_height / 2, | ||
454 : | rounding); | ||
455 : | |||
456 : | |||
457 : | interpolate_halfpel_h( | ||
458 : | refh->v - offset, | ||
459 : | refn->v - offset, | ||
460 : | edged_width / 2, edged_height / 2, | ||
461 : | rounding); | ||
462 : | |||
463 : | interpolate_halfpel_v( | ||
464 : | refv->v - offset, | ||
465 : | refn->v - offset, | ||
466 : | edged_width / 2, edged_height / 2, | ||
467 : | rounding); | ||
468 : | |||
469 : | interpolate_halfpel_hv( | ||
470 : | refhv->v - offset, | ||
471 : | refn->v - offset, | ||
472 : | edged_width / 2, edged_height / 2, | ||
473 : | rounding); | ||
474 : | */ | ||
475 : | albeu | 315 | } |
476 : | |||
477 : | |||
478 : | suxen_drol | 631 | |
479 : | /* | ||
480 : | perform safe packed colorspace conversion, by splitting | ||
481 : | the image up into an optimized area (pixel width divisible by 16), | ||
482 : | and two unoptimized/plain-c areas (pixel width divisible by 2) | ||
483 : | */ | ||
484 : | |||
485 : | static void | ||
486 : | safe_packed_conv(uint8_t * x_ptr, int x_stride, | ||
487 : | uint8_t * y_ptr, uint8_t * u_ptr, uint8_t * v_ptr, | ||
488 : | int y_stride, int uv_stride, | ||
489 : | int width, int height, int vflip, | ||
490 : | packedFunc * func_opt, packedFunc func_c, int size) | ||
491 : | { | ||
492 : | int width_opt, width_c; | ||
493 : | |||
494 : | if (func_opt != func_c && x_stride < size*((width+15)/16)*16) | ||
495 : | { | ||
496 : | width_opt = width & (~15); | ||
497 : | width_c = width - width_opt; | ||
498 : | } | ||
499 : | else | ||
500 : | { | ||
501 : | width_opt = width; | ||
502 : | width_c = 0; | ||
503 : | } | ||
504 : | |||
505 : | func_opt(x_ptr, x_stride, | ||
506 : | y_ptr, u_ptr, v_ptr, y_stride, uv_stride, | ||
507 : | width_opt, height, vflip); | ||
508 : | |||
509 : | if (width_c) | ||
510 : | { | ||
511 : | func_c(x_ptr + size*width_opt, x_stride, | ||
512 : | y_ptr + width_opt, u_ptr + width_opt/2, v_ptr + width_opt/2, | ||
513 : | y_stride, uv_stride, width_c, height, vflip); | ||
514 : | } | ||
515 : | } | ||
516 : | |||
517 : | |||
518 : | |||
519 : | albeu | 315 | int |
520 : | image_input(IMAGE * image, | ||
521 : | uint32_t width, | ||
522 : | int height, | ||
523 : | uint32_t edged_width, | ||
524 : | uint8_t * src, | ||
525 : | suxen_drol | 631 | int src_stride, |
526 : | int csp, | ||
527 : | int interlacing) | ||
528 : | albeu | 315 | { |
529 : | suxen_drol | 631 | const int edged_width2 = edged_width/2; |
530 : | const int width2 = width/2; | ||
531 : | const int height2 = height/2; | ||
532 : | //const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height; | ||
533 : | albeu | 315 | |
534 : | suxen_drol | 631 | |
535 : | // int src_stride = width; | ||
536 : | |||
537 : | // --- xvid 2.1 compatiblity patch --- | ||
538 : | // --- remove when xvid_dec_frame->stride equals real stride | ||
539 : | /* | ||
540 : | if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB555 || | ||
541 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB565 || | ||
542 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YUY2 || | ||
543 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YVYU || | ||
544 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_UYVY) | ||
545 : | albeu | 315 | { |
546 : | suxen_drol | 631 | src_stride *= 2; |
547 : | } | ||
548 : | else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB24) | ||
549 : | { | ||
550 : | src_stride *= 3; | ||
551 : | albeu | 315 | } |
552 : | suxen_drol | 631 | else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB32 || |
553 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_ABGR || | ||
554 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGBA) | ||
555 : | { | ||
556 : | src_stride *= 4; | ||
557 : | } | ||
558 : | */ | ||
559 : | // ^--- xvid 2.1 compatiblity fix ---^ | ||
560 : | albeu | 315 | |
561 : | switch (csp & ~XVID_CSP_VFLIP) { | ||
562 : | case XVID_CSP_RGB555: | ||
563 : | suxen_drol | 631 | safe_packed_conv( |
564 : | src, src_stride, image->y, image->u, image->v, | ||
565 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
566 : | interlacing?rgb555i_to_yv12 :rgb555_to_yv12, | ||
567 : | interlacing?rgb555i_to_yv12_c:rgb555_to_yv12_c, 2); | ||
568 : | break; | ||
569 : | albeu | 315 | |
570 : | case XVID_CSP_RGB565: | ||
571 : | suxen_drol | 631 | safe_packed_conv( |
572 : | src, src_stride, image->y, image->u, image->v, | ||
573 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
574 : | interlacing?rgb565i_to_yv12 :rgb565_to_yv12, | ||
575 : | interlacing?rgb565i_to_yv12_c:rgb565_to_yv12_c, 2); | ||
576 : | break; | ||
577 : | albeu | 315 | |
578 : | |||
579 : | case XVID_CSP_RGB24: | ||
580 : | suxen_drol | 631 | safe_packed_conv( |
581 : | src, src_stride, image->y, image->u, image->v, | ||
582 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
583 : | interlacing?bgri_to_yv12 :bgr_to_yv12, | ||
584 : | interlacing?bgri_to_yv12_c:bgr_to_yv12_c, 3); | ||
585 : | break; | ||
586 : | albeu | 315 | |
587 : | case XVID_CSP_RGB32: | ||
588 : | suxen_drol | 631 | safe_packed_conv( |
589 : | src, src_stride, image->y, image->u, image->v, | ||
590 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
591 : | interlacing?bgrai_to_yv12 :bgra_to_yv12, | ||
592 : | interlacing?bgrai_to_yv12_c:bgra_to_yv12_c, 4); | ||
593 : | break; | ||
594 : | albeu | 315 | |
595 : | suxen_drol | 631 | case XVID_CSP_ABGR : |
596 : | safe_packed_conv( | ||
597 : | src, src_stride, image->y, image->u, image->v, | ||
598 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
599 : | interlacing?abgri_to_yv12 :abgr_to_yv12, | ||
600 : | interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4); | ||
601 : | break; | ||
602 : | albeu | 315 | |
603 : | suxen_drol | 631 | case XVID_CSP_RGBA : |
604 : | safe_packed_conv( | ||
605 : | src, src_stride, image->y, image->u, image->v, | ||
606 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
607 : | interlacing?rgbai_to_yv12 :rgba_to_yv12, | ||
608 : | interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4); | ||
609 : | break; | ||
610 : | albeu | 315 | |
611 : | case XVID_CSP_YUY2: | ||
612 : | suxen_drol | 631 | safe_packed_conv( |
613 : | src, src_stride, image->y, image->u, image->v, | ||
614 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
615 : | interlacing?yuyvi_to_yv12 :yuyv_to_yv12, | ||
616 : | interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); | ||
617 : | break; | ||
618 : | albeu | 315 | |
619 : | case XVID_CSP_YVYU: /* u/v swapped */ | ||
620 : | suxen_drol | 631 | safe_packed_conv( |
621 : | src, src_stride, image->y, image->v, image->y, | ||
622 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
623 : | interlacing?yuyvi_to_yv12 :yuyv_to_yv12, | ||
624 : | interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); | ||
625 : | break; | ||
626 : | albeu | 315 | |
627 : | case XVID_CSP_UYVY: | ||
628 : | suxen_drol | 631 | safe_packed_conv( |
629 : | src, src_stride, image->y, image->u, image->v, | ||
630 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
631 : | interlacing?uyvyi_to_yv12 :uyvy_to_yv12, | ||
632 : | interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2); | ||
633 : | break; | ||
634 : | albeu | 315 | |
635 : | suxen_drol | 631 | case XVID_CSP_I420: |
636 : | yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2, | ||
637 : | src, src + width*height, src + width*height + width2*height2, | ||
638 : | width, width2, width, height, (csp & XVID_CSP_VFLIP)); | ||
639 : | break | ||
640 : | ; | ||
641 : | case XVID_CSP_YV12: /* u/v swapped */ | ||
642 : | yv12_to_yv12(image->y, image->v, image->u, edged_width, edged_width2, | ||
643 : | src, src + width*height, src + width*height + width2*height2, | ||
644 : | width, width2, width, height, (csp & XVID_CSP_VFLIP)); | ||
645 : | break; | ||
646 : | |||
647 : | albeu | 315 | case XVID_CSP_USER: |
648 : | suxen_drol | 631 | { |
649 : | DEC_PICTURE * pic = (DEC_PICTURE*)src; | ||
650 : | yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2, | ||
651 : | pic->y, pic->u, pic->v, pic->stride_y, pic->stride_y, | ||
652 : | width, height, (csp & XVID_CSP_VFLIP)); | ||
653 : | } | ||
654 : | break; | ||
655 : | albeu | 315 | |
656 : | case XVID_CSP_NULL: | ||
657 : | break; | ||
658 : | |||
659 : | suxen_drol | 631 | default : |
660 : | return -1; | ||
661 : | albeu | 315 | } |
662 : | |||
663 : | suxen_drol | 631 | |
664 : | /* pad out image when the width and/or height is not a multiple of 16 */ | ||
665 : | |||
666 : | if (width & 15) | ||
667 : | { | ||
668 : | int i; | ||
669 : | int pad_width = 16 - (width&15); | ||
670 : | for (i = 0; i < height; i++) | ||
671 : | { | ||
672 : | memset(image->y + i*edged_width + width, | ||
673 : | *(image->y + i*edged_width + width - 1), pad_width); | ||
674 : | } | ||
675 : | for (i = 0; i < height/2; i++) | ||
676 : | { | ||
677 : | memset(image->u + i*edged_width2 + width2, | ||
678 : | *(image->u + i*edged_width2 + width2 - 1),pad_width/2); | ||
679 : | memset(image->v + i*edged_width2 + width2, | ||
680 : | *(image->v + i*edged_width2 + width2 - 1),pad_width/2); | ||
681 : | } | ||
682 : | } | ||
683 : | |||
684 : | if (height & 15) | ||
685 : | { | ||
686 : | int pad_height = 16 - (height&15); | ||
687 : | int length = ((width+15)/16)*16; | ||
688 : | int i; | ||
689 : | for (i = 0; i < pad_height; i++) | ||
690 : | { | ||
691 : | memcpy(image->y + (height+i)*edged_width, | ||
692 : | image->y + (height-1)*edged_width,length); | ||
693 : | } | ||
694 : | |||
695 : | for (i = 0; i < pad_height/2; i++) | ||
696 : | { | ||
697 : | memcpy(image->u + (height2+i)*edged_width2, | ||
698 : | image->u + (height2-1)*edged_width2,length/2); | ||
699 : | memcpy(image->v + (height2+i)*edged_width2, | ||
700 : | image->v + (height2-1)*edged_width2,length/2); | ||
701 : | } | ||
702 : | } | ||
703 : | |||
704 : | /* | ||
705 : | if (interlacing) | ||
706 : | image_printf(image, edged_width, height, 5,5, "[i]"); | ||
707 : | image_dump_yuvpgm(image, edged_width, ((width+15)/16)*16, ((height+15)/16)*16, "\\encode.pgm"); | ||
708 : | */ | ||
709 : | return 0; | ||
710 : | albeu | 315 | } |
711 : | |||
712 : | |||
713 : | |||
714 : | int | ||
715 : | image_output(IMAGE * image, | ||
716 : | uint32_t width, | ||
717 : | int height, | ||
718 : | uint32_t edged_width, | ||
719 : | uint8_t * dst, | ||
720 : | uint32_t dst_stride, | ||
721 : | suxen_drol | 631 | int csp, |
722 : | int interlacing) | ||
723 : | albeu | 315 | { |
724 : | suxen_drol | 631 | const int edged_width2 = edged_width/2; |
725 : | int width2 = width/2; | ||
726 : | int height2 = height/2; | ||
727 : | albeu | 315 | |
728 : | suxen_drol | 631 | /* |
729 : | if (interlacing) | ||
730 : | image_printf(image, edged_width, height, 5,100, "[i]=%i,%i",width,height); | ||
731 : | image_dump_yuvpgm(image, edged_width, width, height, "\\decode.pgm"); | ||
732 : | */ | ||
733 : | |||
734 : | |||
735 : | suxen_drol | 582 | // --- xvid 2.1 compatiblity patch --- |
736 : | // --- remove when xvid_dec_frame->stride equals real stride | ||
737 : | suxen_drol | 631 | /* |
738 : | suxen_drol | 582 | if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB555 || |
739 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB565 || | ||
740 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YUY2 || | ||
741 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YVYU || | ||
742 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_UYVY) | ||
743 : | { | ||
744 : | dst_stride *= 2; | ||
745 : | } | ||
746 : | else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB24) | ||
747 : | { | ||
748 : | dst_stride *= 3; | ||
749 : | } | ||
750 : | else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB32 || | ||
751 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_ABGR || | ||
752 : | (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGBA) | ||
753 : | { | ||
754 : | dst_stride *= 4; | ||
755 : | } | ||
756 : | suxen_drol | 631 | */ |
757 : | suxen_drol | 582 | // ^--- xvid 2.1 compatiblity fix ---^ |
758 : | |||
759 : | |||
760 : | albeu | 315 | switch (csp & ~XVID_CSP_VFLIP) { |
761 : | case XVID_CSP_RGB555: | ||
762 : | suxen_drol | 631 | safe_packed_conv( |
763 : | dst, dst_stride, image->y, image->u, image->v, | ||
764 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
765 : | interlacing?yv12_to_rgb555i :yv12_to_rgb555, | ||
766 : | interlacing?yv12_to_rgb555i_c:yv12_to_rgb555_c, 2); | ||
767 : | albeu | 315 | return 0; |
768 : | |||
769 : | case XVID_CSP_RGB565: | ||
770 : | suxen_drol | 631 | safe_packed_conv( |
771 : | dst, dst_stride, image->y, image->u, image->v, | ||
772 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
773 : | interlacing?yv12_to_rgb565i :yv12_to_rgb565, | ||
774 : | interlacing?yv12_to_rgb565i_c:yv12_to_rgb565_c, 2); | ||
775 : | albeu | 315 | return 0; |
776 : | |||
777 : | case XVID_CSP_RGB24: | ||
778 : | suxen_drol | 631 | safe_packed_conv( |
779 : | dst, dst_stride, image->y, image->u, image->v, | ||
780 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
781 : | interlacing?yv12_to_bgri :yv12_to_bgr, | ||
782 : | interlacing?yv12_to_bgri_c:yv12_to_bgr_c, 3); | ||
783 : | albeu | 315 | return 0; |
784 : | |||
785 : | case XVID_CSP_RGB32: | ||
786 : | suxen_drol | 631 | safe_packed_conv( |
787 : | dst, dst_stride, image->y, image->u, image->v, | ||
788 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
789 : | interlacing?yv12_to_bgrai :yv12_to_bgra, | ||
790 : | interlacing?yv12_to_bgrai_c:yv12_to_bgra_c, 4); | ||
791 : | albeu | 315 | return 0; |
792 : | |||
793 : | suxen_drol | 582 | case XVID_CSP_ABGR: |
794 : | suxen_drol | 631 | safe_packed_conv( |
795 : | dst, dst_stride, image->y, image->u, image->v, | ||
796 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
797 : | interlacing?yv12_to_abgri :yv12_to_abgr, | ||
798 : | interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4); | ||
799 : | suxen_drol | 582 | return 0; |
800 : | |||
801 : | case XVID_CSP_RGBA: | ||
802 : | suxen_drol | 631 | safe_packed_conv( |
803 : | dst, dst_stride, image->y, image->u, image->v, | ||
804 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
805 : | interlacing?yv12_to_rgbai :yv12_to_rgba, | ||
806 : | interlacing?yv12_to_rgbai_c:yv12_to_rgba_c, 4); | ||
807 : | suxen_drol | 582 | return 0; |
808 : | |||
809 : | suxen_drol | 631 | case XVID_CSP_YUY2: |
810 : | safe_packed_conv( | ||
811 : | dst, dst_stride, image->y, image->u, image->v, | ||
812 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
813 : | interlacing?yv12_to_yuyvi :yv12_to_yuyv, | ||
814 : | interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); | ||
815 : | albeu | 315 | return 0; |
816 : | |||
817 : | suxen_drol | 631 | case XVID_CSP_YVYU: // u,v swapped |
818 : | safe_packed_conv( | ||
819 : | dst, dst_stride, image->y, image->v, image->u, | ||
820 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
821 : | interlacing?yv12_to_yuyvi :yv12_to_yuyv, | ||
822 : | interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); | ||
823 : | albeu | 315 | return 0; |
824 : | |||
825 : | suxen_drol | 631 | case XVID_CSP_UYVY: |
826 : | safe_packed_conv( | ||
827 : | dst, dst_stride, image->y, image->u, image->v, | ||
828 : | edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), | ||
829 : | interlacing?yv12_to_uyvyi :yv12_to_uyvy, | ||
830 : | interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2); | ||
831 : | albeu | 315 | return 0; |
832 : | |||
833 : | suxen_drol | 631 | case XVID_CSP_I420: |
834 : | yv12_to_yv12(dst, dst + width*height, dst + width*height + width2*height2, | ||
835 : | width, width2, | ||
836 : | image->y, image->u, image->v, edged_width, edged_width2, | ||
837 : | width, height, (csp & XVID_CSP_VFLIP)); | ||
838 : | albeu | 315 | return 0; |
839 : | |||
840 : | suxen_drol | 631 | case XVID_CSP_YV12: // u,v swapped |
841 : | yv12_to_yv12(dst, dst + width*height, dst + width*height + width2*height2, | ||
842 : | width, width2, | ||
843 : | image->y, image->v, image->u, edged_width, edged_width2, | ||
844 : | width, height, (csp & XVID_CSP_VFLIP)); | ||
845 : | albeu | 315 | return 0; |
846 : | |||
847 : | case XVID_CSP_USER: | ||
848 : | suxen_drol | 631 | { |
849 : | DEC_PICTURE * pic = (DEC_PICTURE*)dst; | ||
850 : | pic->y = image->y; | ||
851 : | pic->u = image->u; | ||
852 : | pic->v = image->v; | ||
853 : | pic->stride_y = edged_width; | ||
854 : | pic->stride_uv = edged_width / 2; | ||
855 : | } | ||
856 : | albeu | 315 | return 0; |
857 : | |||
858 : | case XVID_CSP_NULL: | ||
859 : | case XVID_CSP_EXTERN: | ||
860 : | return 0; | ||
861 : | |||
862 : | } | ||
863 : | |||
864 : | return -1; | ||
865 : | } | ||
866 : | |||
867 : | float | ||
868 : | image_psnr(IMAGE * orig_image, | ||
869 : | IMAGE * recon_image, | ||
870 : | uint16_t stride, | ||
871 : | uint16_t width, | ||
872 : | uint16_t height) | ||
873 : | { | ||
874 : | int32_t diff, x, y, quad = 0; | ||
875 : | uint8_t *orig = orig_image->y; | ||
876 : | uint8_t *recon = recon_image->y; | ||
877 : | float psnr_y; | ||
878 : | |||
879 : | for (y = 0; y < height; y++) { | ||
880 : | for (x = 0; x < width; x++) { | ||
881 : | diff = *(orig + x) - *(recon + x); | ||
882 : | quad += diff * diff; | ||
883 : | } | ||
884 : | orig += stride; | ||
885 : | recon += stride; | ||
886 : | } | ||
887 : | |||
888 : | psnr_y = (float) quad / (float) (width * height); | ||
889 : | |||
890 : | if (psnr_y) { | ||
891 : | psnr_y = (float) (255 * 255) / psnr_y; | ||
892 : | psnr_y = 10 * (float) log10(psnr_y); | ||
893 : | } else | ||
894 : | psnr_y = (float) 99.99; | ||
895 : | |||
896 : | return psnr_y; | ||
897 : | } | ||
898 : | |||
899 : | /* | ||
900 : | |||
901 : | #include <stdio.h> | ||
902 : | #include <string.h> | ||
903 : | |||
904 : | int image_dump_pgm(uint8_t * bmp, uint32_t width, uint32_t height, char * filename) | ||
905 : | { | ||
906 : | FILE * f; | ||
907 : | char hdr[1024]; | ||
908 : | |||
909 : | f = fopen(filename, "wb"); | ||
910 : | if ( f == NULL) | ||
911 : | { | ||
912 : | return -1; | ||
913 : | } | ||
914 : | sprintf(hdr, "P5\n#xvid\n%i %i\n255\n", width, height); | ||
915 : | fwrite(hdr, strlen(hdr), 1, f); | ||
916 : | fwrite(bmp, width, height, f); | ||
917 : | fclose(f); | ||
918 : | |||
919 : | return 0; | ||
920 : | } | ||
921 : | |||
922 : | |||
923 : | // dump image+edges to yuv pgm files | ||
924 : | |||
925 : | int image_dump(IMAGE * image, uint32_t edged_width, uint32_t edged_height, char * path, int number) | ||
926 : | { | ||
927 : | char filename[1024]; | ||
928 : | |||
929 : | sprintf(filename, "%s_%i_%c.pgm", path, number, 'y'); | ||
930 : | image_dump_pgm( | ||
931 : | image->y - (EDGE_SIZE * edged_width + EDGE_SIZE), | ||
932 : | edged_width, edged_height, filename); | ||
933 : | |||
934 : | sprintf(filename, "%s_%i_%c.pgm", path, number, 'u'); | ||
935 : | image_dump_pgm( | ||
936 : | image->u - (EDGE_SIZE2 * edged_width / 2 + EDGE_SIZE2), | ||
937 : | edged_width / 2, edged_height / 2, filename); | ||
938 : | |||
939 : | sprintf(filename, "%s_%i_%c.pgm", path, number, 'v'); | ||
940 : | image_dump_pgm( | ||
941 : | image->v - (EDGE_SIZE2 * edged_width / 2 + EDGE_SIZE2), | ||
942 : | edged_width / 2, edged_height / 2, filename); | ||
943 : | |||
944 : | return 0; | ||
945 : | } | ||
946 : | */ | ||
947 : | |||
948 : | |||
949 : | |||
950 : | /* dump image to yuvpgm file */ | ||
951 : | |||
952 : | #include <stdio.h> | ||
953 : | |||
954 : | int | ||
955 : | image_dump_yuvpgm(const IMAGE * image, | ||
956 : | const uint32_t edged_width, | ||
957 : | const uint32_t width, | ||
958 : | const uint32_t height, | ||
959 : | char *filename) | ||
960 : | { | ||
961 : | FILE *f; | ||
962 : | char hdr[1024]; | ||
963 : | uint32_t i; | ||
964 : | uint8_t *bmp1; | ||
965 : | uint8_t *bmp2; | ||
966 : | |||
967 : | |||
968 : | f = fopen(filename, "wb"); | ||
969 : | if (f == NULL) { | ||
970 : | return -1; | ||
971 : | } | ||
972 : | sprintf(hdr, "P5\n#xvid\n%i %i\n255\n", width, (3 * height) / 2); | ||
973 : | fwrite(hdr, strlen(hdr), 1, f); | ||
974 : | |||
975 : | bmp1 = image->y; | ||
976 : | for (i = 0; i < height; i++) { | ||
977 : | fwrite(bmp1, width, 1, f); | ||
978 : | bmp1 += edged_width; | ||
979 : | } | ||
980 : | |||
981 : | bmp1 = image->u; | ||
982 : | bmp2 = image->v; | ||
983 : | for (i = 0; i < height / 2; i++) { | ||
984 : | fwrite(bmp1, width / 2, 1, f); | ||
985 : | fwrite(bmp2, width / 2, 1, f); | ||
986 : | bmp1 += edged_width / 2; | ||
987 : | bmp2 += edged_width / 2; | ||
988 : | } | ||
989 : | |||
990 : | fclose(f); | ||
991 : | return 0; | ||
992 : | } | ||
993 : | |||
994 : | |||
995 : | #define ABS(X) (((X)>0)?(X):-(X)) | ||
996 : | float | ||
997 : | image_mad(const IMAGE * img1, | ||
998 : | const IMAGE * img2, | ||
999 : | uint32_t stride, | ||
1000 : | uint32_t width, | ||
1001 : | uint32_t height) | ||
1002 : | { | ||
1003 : | const uint32_t stride2 = stride / 2; | ||
1004 : | const uint32_t width2 = width / 2; | ||
1005 : | const uint32_t height2 = height / 2; | ||
1006 : | |||
1007 : | uint32_t x, y; | ||
1008 : | uint32_t sum = 0; | ||
1009 : | |||
1010 : | for (y = 0; y < height; y++) | ||
1011 : | for (x = 0; x < width; x++) | ||
1012 : | sum += ABS(img1->y[x + y * stride] - img2->y[x + y * stride]); | ||
1013 : | |||
1014 : | for (y = 0; y < height2; y++) | ||
1015 : | for (x = 0; x < width2; x++) | ||
1016 : | sum += ABS(img1->u[x + y * stride2] - img2->u[x + y * stride2]); | ||
1017 : | |||
1018 : | for (y = 0; y < height2; y++) | ||
1019 : | for (x = 0; x < width2; x++) | ||
1020 : | sum += ABS(img1->v[x + y * stride2] - img2->v[x + y * stride2]); | ||
1021 : | |||
1022 : | return (float) sum / (width * height * 3 / 2); | ||
1023 : | } | ||
1024 : | |||
1025 : | void | ||
1026 : | output_slice(IMAGE * cur, int std, int width, XVID_DEC_PICTURE* out_frm, int mbx, int mby,int mbl) { | ||
1027 : | uint8_t *dY,*dU,*dV,*sY,*sU,*sV; | ||
1028 : | int std2 = std >> 1; | ||
1029 : | int w = mbl << 4, w2,i; | ||
1030 : | |||
1031 : | if(w > width) | ||
1032 : | w = width; | ||
1033 : | w2 = w >> 1; | ||
1034 : | suxen_drol | 323 | |
1035 : | albeu | 315 | dY = (uint8_t*)out_frm->y + (mby << 4) * out_frm->stride_y + (mbx << 4); |
1036 : | dU = (uint8_t*)out_frm->u + (mby << 3) * out_frm->stride_u + (mbx << 3); | ||
1037 : | dV = (uint8_t*)out_frm->v + (mby << 3) * out_frm->stride_v + (mbx << 3); | ||
1038 : | sY = cur->y + (mby << 4) * std + (mbx << 4); | ||
1039 : | sU = cur->u + (mby << 3) * std2 + (mbx << 3); | ||
1040 : | sV = cur->v + (mby << 3) * std2 + (mbx << 3); | ||
1041 : | |||
1042 : | for(i = 0 ; i < 16 ; i++) { | ||
1043 : | memcpy(dY,sY,w); | ||
1044 : | suxen_drol | 323 | dY += out_frm->stride_y; |
1045 : | sY += std; | ||
1046 : | } | ||
1047 : | albeu | 315 | for(i = 0 ; i < 8 ; i++) { |
1048 : | memcpy(dU,sU,w2); | ||
1049 : | dU += out_frm->stride_u; | ||
1050 : | sU += std2; | ||
1051 : | } | ||
1052 : | for(i = 0 ; i < 8 ; i++) { | ||
1053 : | memcpy(dV,sV,w2); | ||
1054 : | dV += out_frm->stride_v; | ||
1055 : | sV += std2; | ||
1056 : | } | ||
1057 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |