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