hardware/intel/libva
Revisão | 558b07976c56ad73f3d6fb87aa925016edf4fa2b (tree) |
---|---|
Hora | 2010-07-13 16:29:16 |
Autor | Gwenole Beauchesne <gbeauchesne@spli...> |
Commiter | Xiang, Haihao |
Simplify vaGetImage().
@@ -1469,13 +1469,26 @@ i965_SetImagePalette(VADriverContextP ctx, | ||
1469 | 1469 | return VA_STATUS_SUCCESS; |
1470 | 1470 | } |
1471 | 1471 | |
1472 | +static inline void | |
1473 | +memcpy_pic(uint8_t *dst, unsigned int dst_stride, | |
1474 | + const uint8_t *src, unsigned int src_stride, | |
1475 | + unsigned int len, unsigned int height) | |
1476 | +{ | |
1477 | + unsigned int i; | |
1478 | + | |
1479 | + for (i = 0; i < height; i++) { | |
1480 | + memcpy(dst, src, len); | |
1481 | + dst += dst_stride; | |
1482 | + src += src_stride; | |
1483 | + } | |
1484 | +} | |
1485 | + | |
1472 | 1486 | static void |
1473 | -get_image_yv12(struct object_image *obj_image, uint8_t *image_data, | |
1487 | +get_image_i420(struct object_image *obj_image, uint8_t *image_data, | |
1474 | 1488 | struct object_surface *obj_surface, |
1475 | 1489 | const VARectangle *rect) |
1476 | 1490 | { |
1477 | 1491 | uint8_t *dst[3], *src[3]; |
1478 | - int i, x, y, w, h; | |
1479 | 1492 | |
1480 | 1493 | if (!obj_surface->bo) |
1481 | 1494 | return; |
@@ -1485,11 +1498,8 @@ get_image_yv12(struct object_image *obj_image, uint8_t *image_data, | ||
1485 | 1498 | if (!obj_surface->bo->virtual) |
1486 | 1499 | return; |
1487 | 1500 | |
1488 | - x = rect->x; | |
1489 | - y = rect->y; | |
1490 | - w = rect->width; | |
1491 | - h = rect->height; | |
1492 | - | |
1501 | + /* Dest VA image has either I420 or YV12 format. | |
1502 | + Source VA surface alway has I420 format */ | |
1493 | 1503 | dst[0] = image_data + obj_image->image.offsets[0]; |
1494 | 1504 | src[0] = (uint8_t *)obj_surface->bo->virtual; |
1495 | 1505 | dst[1] = image_data + obj_image->image.offsets[1]; |
@@ -1497,34 +1507,26 @@ get_image_yv12(struct object_image *obj_image, uint8_t *image_data, | ||
1497 | 1507 | dst[2] = image_data + obj_image->image.offsets[2]; |
1498 | 1508 | src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2); |
1499 | 1509 | |
1500 | - dst[0] += y * obj_image->image.pitches[0] + x; | |
1501 | - src[0] += y * obj_surface->width + x; | |
1502 | - for (i = 0; i < h; i++) { | |
1503 | - memcpy(dst[0], src[0], w); | |
1504 | - dst[0] += obj_image->image.pitches[0]; | |
1505 | - src[0] += obj_surface->width; | |
1506 | - } | |
1507 | - | |
1508 | - x /= 2; | |
1509 | - y /= 2; | |
1510 | - w /= 2; | |
1511 | - h /= 2; | |
1512 | - | |
1513 | - dst[1] += y * obj_image->image.pitches[1] + x; | |
1514 | - src[1] += y * obj_surface->width / 2 + x; | |
1515 | - for (i = 0; i < h; i++) { | |
1516 | - memcpy(dst[1], src[1], w); | |
1517 | - dst[1] += obj_image->image.pitches[1]; | |
1518 | - src[1] += obj_surface->width / 2; | |
1519 | - } | |
1520 | - | |
1521 | - dst[2] += y * obj_image->image.pitches[2] + y; | |
1522 | - src[2] += y * obj_surface->width / 2 + x; | |
1523 | - for (i = 0; i < h; i++) { | |
1524 | - memcpy(dst[2], src[2], w); | |
1525 | - dst[2] += obj_image->image.pitches[2]; | |
1526 | - src[2] += obj_surface->width / 2; | |
1527 | - } | |
1510 | + /* Y plane */ | |
1511 | + dst[0] += rect->y * obj_image->image.pitches[0] + rect->x; | |
1512 | + src[0] += rect->y * obj_surface->width + rect->x; | |
1513 | + memcpy_pic(dst[0], obj_image->image.pitches[0], | |
1514 | + src[0], obj_surface->width, | |
1515 | + rect->width, rect->height); | |
1516 | + | |
1517 | + /* U plane */ | |
1518 | + dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + rect->x / 2; | |
1519 | + src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2; | |
1520 | + memcpy_pic(dst[1], obj_image->image.pitches[1], | |
1521 | + src[1], obj_surface->width / 2, | |
1522 | + rect->width / 2, rect->height / 2); | |
1523 | + | |
1524 | + /* V plane */ | |
1525 | + dst[2] += (rect->y / 2) * obj_image->image.pitches[2] + rect->x / 2; | |
1526 | + src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2; | |
1527 | + memcpy_pic(dst[2], obj_image->image.pitches[2], | |
1528 | + src[2], obj_surface->width / 2, | |
1529 | + rect->width / 2, rect->height / 2); | |
1528 | 1530 | |
1529 | 1531 | dri_bo_unmap(obj_surface->bo); |
1530 | 1532 | } |
@@ -1534,8 +1536,7 @@ get_image_nv12(struct object_image *obj_image, uint8_t *image_data, | ||
1534 | 1536 | struct object_surface *obj_surface, |
1535 | 1537 | const VARectangle *rect) |
1536 | 1538 | { |
1537 | - uint8_t *dst, *src; | |
1538 | - int i, x, y, w, h; | |
1539 | + uint8_t *dst[2], *src[2]; | |
1539 | 1540 | |
1540 | 1541 | if (!obj_surface->bo) |
1541 | 1542 | return; |
@@ -1545,30 +1546,25 @@ get_image_nv12(struct object_image *obj_image, uint8_t *image_data, | ||
1545 | 1546 | if (!obj_surface->bo->virtual) |
1546 | 1547 | return; |
1547 | 1548 | |
1548 | - x = rect->x; | |
1549 | - y = rect->y; | |
1550 | - w = rect->width; | |
1551 | - h = rect->height; | |
1552 | - | |
1553 | - dst = image_data + obj_image->image.offsets[0] + y * obj_image->image.pitches[0] + x; | |
1554 | - src = (uint8_t *)obj_surface->bo->virtual + y * obj_surface->width + x; | |
1555 | - for (i = 0; i < h; i++) { | |
1556 | - memcpy(dst, src, w); | |
1557 | - dst += obj_image->image.pitches[0]; | |
1558 | - src += obj_surface->width; | |
1559 | - } | |
1549 | + /* Both dest VA image and source surface have NV12 format */ | |
1550 | + dst[0] = image_data + obj_image->image.offsets[0]; | |
1551 | + src[0] = (uint8_t *)obj_surface->bo->virtual; | |
1552 | + dst[1] = image_data + obj_image->image.offsets[1]; | |
1553 | + src[1] = src[0] + obj_surface->width * obj_surface->height; | |
1560 | 1554 | |
1561 | - x /= 2; | |
1562 | - y /= 2; | |
1563 | - h /= 2; | |
1555 | + /* Y plane */ | |
1556 | + dst[0] += rect->y * obj_image->image.pitches[0] + rect->x; | |
1557 | + src[0] += rect->y * obj_surface->width + rect->x; | |
1558 | + memcpy_pic(dst[0], obj_image->image.pitches[0], | |
1559 | + src[0], obj_surface->width, | |
1560 | + rect->width, rect->height); | |
1564 | 1561 | |
1565 | - dst = image_data + obj_image->image.offsets[1] + y * obj_image->image.pitches[1] + x * 2; | |
1566 | - src = (uint8_t *)obj_surface->bo->virtual + obj_surface->width * obj_surface->height + y * obj_surface->width + x * 2; | |
1567 | - for (i = 0; i < h; i++) { | |
1568 | - memcpy(dst, src, w); | |
1569 | - dst += obj_image->image.pitches[1]; | |
1570 | - src += obj_surface->width; | |
1571 | - } | |
1562 | + /* UV plane */ | |
1563 | + dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2); | |
1564 | + src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2); | |
1565 | + memcpy_pic(dst[1], obj_image->image.pitches[1], | |
1566 | + src[1], obj_surface->width, | |
1567 | + rect->width, rect->height / 2); | |
1572 | 1568 | |
1573 | 1569 | dri_bo_unmap(obj_surface->bo); |
1574 | 1570 | } |
@@ -1624,7 +1620,7 @@ i965_GetImage(VADriverContextP ctx, | ||
1624 | 1620 | /* I420 is native format for MPEG-2 decoded surfaces */ |
1625 | 1621 | if (render_state->interleaved_uv) |
1626 | 1622 | goto operation_failed; |
1627 | - get_image_yv12(obj_image, image_data, obj_surface, &rect); | |
1623 | + get_image_i420(obj_image, image_data, obj_surface, &rect); | |
1628 | 1624 | break; |
1629 | 1625 | case VA_FOURCC('N','V','1','2'): |
1630 | 1626 | /* NV12 is native format for H.264 decoded surfaces */ |