comparison libvo/video_out.c @ 28511:db19e31a2c7c

Add a calc_src_dst_rects that calculates from window size, panscan etc. which part of the video source must be scaled onto which part of the window. Direct3D and (future) VDPAU need this, for XvMC it makes it easier to add cropping support and Xv is changed to keep the diff to XvMC small.
author reimar
date Thu, 12 Feb 2009 17:40:53 +0000
parents 7681eab10aea
children 4d64f83e2fac
comparison
equal deleted inserted replaced
28510:afcd1ee3d3f1 28511:db19e31a2c7c
353 int lookup_keymap_table(const struct keymap *map, int key) { 353 int lookup_keymap_table(const struct keymap *map, int key) {
354 while (map->from && map->from != key) map++; 354 while (map->from && map->from != key) map++;
355 return map->to; 355 return map->to;
356 } 356 }
357 357
358 /**
359 * \brief helper function for the kind of panscan-scaling that needs a source
360 * and destination rectangle like Direct3D and VDPAU
361 */
362 static void src_dst_split_scaling(int src_size, int dst_size, int scaled_src_size,
363 int *src_start, int *src_end, int *dst_start, int *dst_end) {
364 if (scaled_src_size > dst_size) {
365 int border = src_size * (scaled_src_size - dst_size) / scaled_src_size;
366 // round to a multiple of 2, this is at least needed for vo_direct3d and ATI cards
367 border = (border / 2 + 1) & ~1;
368 *src_start = border;
369 *src_end = src_size - border;
370 *dst_start = 0;
371 *dst_end = dst_size;
372 } else {
373 *src_start = 0;
374 *src_end = src_size;
375 *dst_start = (dst_size - scaled_src_size) / 2;
376 *dst_end = *dst_start + scaled_src_size;
377 }
378 }
379
380 /**
381 * Calculate the appropriate source and destination rectangle to
382 * get a correctly scaled picture, including pan-scan.
383 * Can be extended to take future cropping support into account.
384 *
385 * \param crop specifies the cropping border size in the left, right, top and bottom members, may be NULL
386 */
387 void calc_src_dst_rects(int src_width, int src_height, struct vo_rect *src, struct vo_rect *dst, struct vo_rect *crop) {
388 static const struct vo_rect no_crop = {0, 0, 0, 0, 0, 0};
389 int scaled_width = 0;
390 int scaled_height = 0;
391 if (!crop) crop = &no_crop;
392 src_width -= crop->left + crop->right;
393 src_height -= crop->top + crop->bottom;
394 if (src_width < 2) src_width = 2;
395 if (src_height < 2) src_height = 2;
396 dst->left = 0; dst->right = vo_dwidth;
397 dst->top = 0; dst->bottom = vo_dheight;
398 src->left = 0; src->right = src_width;
399 src->top = 0; src->bottom = src_height;
400 if (vo_fs) {
401 aspect(&scaled_width, &scaled_height, A_ZOOM);
402 panscan_calc();
403 scaled_width += vo_panscan_x;
404 scaled_height += vo_panscan_y;
405 src_dst_split_scaling(src_width, vo_dwidth, scaled_width,
406 &src->left, &src->right, &dst->left, &dst->right);
407 src_dst_split_scaling(src_height, vo_dheight, scaled_height,
408 &src->top, &src->bottom, &dst->top, &dst->bottom);
409 }
410 src->left += crop->left; src->right += crop->left;
411 src->top += crop->top; src->bottom += crop->top;
412 src->width = src->right - src->left;
413 src->height = src->bottom - src->top;
414 dst->width = dst->right - dst->left;
415 dst->height = dst->bottom - dst->top;
416 }
417
358 #if defined(CONFIG_FBDEV) || defined(CONFIG_VESA) 418 #if defined(CONFIG_FBDEV) || defined(CONFIG_VESA)
359 /* Borrowed from vo_fbdev.c 419 /* Borrowed from vo_fbdev.c
360 Monitor ranges related functions*/ 420 Monitor ranges related functions*/
361 421
362 char *monitor_hfreq_str = NULL; 422 char *monitor_hfreq_str = NULL;