Skip to content

Commit

Permalink
Handle odd resolution
Browse files Browse the repository at this point in the history
This fixes #516

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
  • Loading branch information
xhaihao committed Aug 19, 2020
1 parent 567a22c commit d87db21
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
24 changes: 12 additions & 12 deletions src/gen8_post_processing.c
Expand Up @@ -1909,17 +1909,17 @@ gen8_pp_context_get_surface_conf(VADriverContextP ctx,
fourcc == VA_FOURCC_BGRA) {
/* nothing to do here */
} else if (fourcc == VA_FOURCC_P010 || fourcc == VA_FOURCC_NV12) {
width[1] = width[0] / 2;
height[1] = height[0] / 2;
width[1] = ALIGN(width[0], 2) / 2;
height[1] = ALIGN(height[0], 2) / 2;
pitch[1] = obj_surface->cb_cr_pitch;
bo_offset[1] = obj_surface->width * obj_surface->y_cb_offset;
} else {
width[1] = width[0] / 2;
height[1] = height[0] / 2;
width[1] = ALIGN(width[0], 2) / 2;
height[1] = ALIGN(height[0], 2) / 2;
pitch[1] = obj_surface->cb_cr_pitch;
bo_offset[1] = obj_surface->width * obj_surface->y_cb_offset;
width[2] = width[0] / 2;
height[2] = height[0] / 2;
width[2] = ALIGN(width[0], 2) / 2;
height[2] = ALIGN(height[0], 2) / 2;
pitch[2] = obj_surface->cb_cr_pitch;
bo_offset[2] = obj_surface->width * obj_surface->y_cr_offset;
}
Expand All @@ -1940,8 +1940,8 @@ gen8_pp_context_get_surface_conf(VADriverContextP ctx,
fourcc == VA_FOURCC_BGRA) {
/* nothing to do here */
} else if (fourcc == VA_FOURCC_P010 || fourcc == VA_FOURCC_NV12) {
width[1] = width[0] / 2;
height[1] = height[0] / 2;
width[1] = ALIGN(width[0], 2) / 2;
height[1] = ALIGN(height[0], 2) / 2;
pitch[1] = obj_image->image.pitches[1];
bo_offset[1] = obj_image->image.offsets[1];
} else {
Expand All @@ -1950,12 +1950,12 @@ gen8_pp_context_get_surface_conf(VADriverContextP ctx,
if (fourcc == VA_FOURCC_YV12 || fourcc == VA_FOURCC_IMC1)
u = 2, v = 1;

width[1] = width[0] / 2;
height[1] = height[0] / 2;
width[1] = ALIGN(width[0], 2) / 2;
height[1] = ALIGN(height[0], 2) / 2;
pitch[1] = obj_image->image.pitches[u];
bo_offset[1] = obj_image->image.offsets[u];
width[2] = width[0] / 2;
height[2] = height[0] / 2;
width[2] = ALIGN(width[0], 2) / 2;
height[2] = ALIGN(height[0], 2) / 2;
pitch[2] = obj_image->image.pitches[v];
bo_offset[2] = obj_image->image.offsets[v];
}
Expand Down
24 changes: 12 additions & 12 deletions src/gen9_post_processing.c
Expand Up @@ -731,19 +731,19 @@ gen9_pp_context_get_surface_conf(VADriverContextP ctx,
fourcc == VA_FOURCC_BGRA) {
/* nothing to do here */
} else if (fourcc == VA_FOURCC_P010 || fourcc == VA_FOURCC_NV12) {
width[1] = width[0] / 2;
height[1] = height[0] / 2;
width[1] = ALIGN(width[0], 2) / 2;
height[1] = ALIGN(height[0], 2) / 2;
pitch[1] = obj_surface->cb_cr_pitch;
bo_offset[1] = obj_surface->width * obj_surface->y_cb_offset;
} else if (fourcc == VA_FOURCC_YUY2 || fourcc == VA_FOURCC_UYVY) {
/* nothing to do here */
} else {
width[1] = width[0] / 2;
height[1] = height[0] / 2;
width[1] = ALIGN(width[0], 2) / 2;
height[1] = ALIGN(height[0], 2) / 2;
pitch[1] = obj_surface->cb_cr_pitch;
bo_offset[1] = obj_surface->width * obj_surface->y_cb_offset;
width[2] = width[0] / 2;
height[2] = height[0] / 2;
width[2] = ALIGN(width[0], 2) / 2;
height[2] = ALIGN(height[0], 2) / 2;
pitch[2] = obj_surface->cb_cr_pitch;
bo_offset[2] = obj_surface->width * obj_surface->y_cr_offset;
}
Expand All @@ -764,8 +764,8 @@ gen9_pp_context_get_surface_conf(VADriverContextP ctx,
fourcc == VA_FOURCC_BGRA) {
/* nothing to do here */
} else if (fourcc == VA_FOURCC_P010 || fourcc == VA_FOURCC_NV12) {
width[1] = width[0] / 2;
height[1] = height[0] / 2;
width[1] = ALIGN(width[0], 2) / 2;
height[1] = ALIGN(height[0], 2) / 2;
pitch[1] = obj_image->image.pitches[1];
bo_offset[1] = obj_image->image.offsets[1];
} else if (fourcc == VA_FOURCC_YUY2 || fourcc == VA_FOURCC_UYVY) {
Expand All @@ -776,12 +776,12 @@ gen9_pp_context_get_surface_conf(VADriverContextP ctx,
if (fourcc == VA_FOURCC_YV12 || fourcc == VA_FOURCC_IMC1)
u = 2, v = 1;

width[1] = width[0] / 2;
height[1] = height[0] / 2;
width[1] = ALIGN(width[0], 2) / 2;
height[1] = ALIGN(height[0], 2) / 2;
pitch[1] = obj_image->image.pitches[u];
bo_offset[1] = obj_image->image.offsets[u];
width[2] = width[0] / 2;
height[2] = height[0] / 2;
width[2] = ALIGN(width[0], 2) / 2;
height[2] = ALIGN(height[0], 2) / 2;
pitch[2] = obj_image->image.pitches[v];
bo_offset[2] = obj_image->image.offsets[v];
}
Expand Down
48 changes: 24 additions & 24 deletions src/i965_drv_video.c
Expand Up @@ -1725,8 +1725,8 @@ i965_suface_external_memory(VADriverContextP ctx,
obj_surface->subsampling = SUBSAMPLE_YUV420;
obj_surface->y_cb_offset = obj_surface->height;
obj_surface->y_cr_offset = obj_surface->height;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->cb_cr_height = ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
if (tiling)
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
Expand All @@ -1743,8 +1743,8 @@ i965_suface_external_memory(VADriverContextP ctx,
obj_surface->subsampling = SUBSAMPLE_YUV420;
obj_surface->y_cr_offset = obj_surface->height;
obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->cb_cr_height = ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];

if (tiling)
Expand All @@ -1764,8 +1764,8 @@ i965_suface_external_memory(VADriverContextP ctx,
obj_surface->subsampling = SUBSAMPLE_YUV420;
obj_surface->y_cb_offset = obj_surface->height;
obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->cb_cr_height = ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
if (tiling)
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
Expand Down Expand Up @@ -1837,7 +1837,7 @@ i965_suface_external_memory(VADriverContextP ctx,
obj_surface->subsampling = SUBSAMPLE_YUV422H;
obj_surface->y_cb_offset = obj_surface->height;
obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->cb_cr_height = obj_surface->orig_height;
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
if (tiling)
Expand All @@ -1854,7 +1854,7 @@ i965_suface_external_memory(VADriverContextP ctx,
obj_surface->subsampling = SUBSAMPLE_YUV422H;
obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->cb_cr_height = obj_surface->orig_height;
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
Expand All @@ -1869,7 +1869,7 @@ i965_suface_external_memory(VADriverContextP ctx,
obj_surface->y_cb_offset = obj_surface->height;
obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
obj_surface->cb_cr_width = obj_surface->orig_width;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_height = ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
if (tiling)
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
Expand Down Expand Up @@ -4526,8 +4526,8 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
case VA_FOURCC_P010:
assert(subsampling == SUBSAMPLE_YUV420);
obj_surface->cb_cr_pitch = obj_surface->width;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->cb_cr_height = ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->y_cb_offset = obj_surface->height;
obj_surface->y_cr_offset = obj_surface->height;
region_width = obj_surface->width;
Expand All @@ -4538,8 +4538,8 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
case VA_FOURCC_IMC1:
assert(subsampling == SUBSAMPLE_YUV420);
obj_surface->cb_cr_pitch = obj_surface->width;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->cb_cr_height = ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->y_cr_offset = obj_surface->height;
obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
region_width = obj_surface->width;
Expand All @@ -4550,8 +4550,8 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
case VA_FOURCC_IMC3:
assert(subsampling == SUBSAMPLE_YUV420);
obj_surface->cb_cr_pitch = obj_surface->width;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->cb_cr_height = ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->y_cb_offset = obj_surface->height;
obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
region_width = obj_surface->width;
Expand All @@ -4562,7 +4562,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
case VA_FOURCC_422H:
assert(subsampling == SUBSAMPLE_YUV422H);
obj_surface->cb_cr_pitch = obj_surface->width;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->cb_cr_height = obj_surface->orig_height;
obj_surface->y_cb_offset = obj_surface->height;
obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
Expand All @@ -4575,7 +4575,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
assert(subsampling == SUBSAMPLE_YUV422V);
obj_surface->cb_cr_pitch = obj_surface->width;
obj_surface->cb_cr_width = obj_surface->orig_width;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_height = ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->y_cb_offset = obj_surface->height;
obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
region_width = obj_surface->width;
Expand Down Expand Up @@ -4663,17 +4663,17 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
case VA_FOURCC_P010:
obj_surface->y_cb_offset = obj_surface->height;
obj_surface->y_cr_offset = obj_surface->height;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) *
bpp_1stplane;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_height = ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->cb_cr_pitch = obj_surface->width;
region_width = obj_surface->width;
region_height = obj_surface->height + obj_surface->height / 2;
break;

case VA_FOURCC_YV16:
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
obj_surface->cb_cr_height = obj_surface->orig_height;
obj_surface->y_cr_offset = obj_surface->height;
Expand All @@ -4694,9 +4694,9 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
}

obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_height = ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->cb_cr_pitch = obj_surface->width / 2;
region_width = obj_surface->width;
region_height = obj_surface->height + obj_surface->height / 2;
Expand All @@ -4705,9 +4705,9 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
case VA_FOURCC_I010:
obj_surface->y_cb_offset = obj_surface->height;
obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
obj_surface->cb_cr_width = ALIGN(obj_surface->orig_width, 2) / 2;
obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) * 2;
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
obj_surface->cb_cr_height =ALIGN(obj_surface->orig_height, 2) / 2;
obj_surface->cb_cr_pitch = obj_surface->width / 2;
region_width = obj_surface->width;
region_height = obj_surface->height + obj_surface->height / 2;
Expand Down

0 comments on commit d87db21

Please sign in to comment.