diff options
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/cropscale.c | 29 | ||||
-rw-r--r-- | libhb/decavcodec.c | 8 | ||||
-rw-r--r-- | libhb/hb.c | 52 | ||||
-rw-r--r-- | libhb/hbffmpeg.h | 1 | ||||
-rw-r--r-- | libhb/internal.h | 3 | ||||
-rw-r--r-- | libhb/oclnv12toyuv.c | 32 | ||||
-rw-r--r-- | libhb/rendersub.c | 14 |
7 files changed, 84 insertions, 55 deletions
diff --git a/libhb/cropscale.c b/libhb/cropscale.c index 733602457..fc4950bf0 100644 --- a/libhb/cropscale.c +++ b/libhb/cropscale.c @@ -158,19 +158,16 @@ static void hb_crop_scale_close( hb_filter_object_t * filter ) /* OpenCL */ static hb_buffer_t* crop_scale( hb_filter_private_t * pv, hb_buffer_t * in ) { - AVPicture pic_in; - AVPicture pic_out; - AVPicture pic_crop; hb_buffer_t * out; - out = hb_video_buffer_init( pv->width_out, pv->height_out ); + uint8_t * crop_data[4], * out_data[4]; + int crop_stride[4], out_stride[4]; - hb_avpicture_fill( &pic_in, in ); - hb_avpicture_fill( &pic_out, out ); + out = hb_video_buffer_init( pv->width_out, pv->height_out ); + hb_picture_fill(out_data, out_stride, out); // Crop; this alters the pointer to the data to point to the // correct place for cropped frame - av_picture_crop( &pic_crop, &pic_in, in->f.fmt, - pv->crop[0], pv->crop[2] ); + hb_picture_crop(crop_data, crop_stride, in, pv->crop[0], pv->crop[2]); // Use bicubic OpenCL scaling when selected and when downsampling < 4:1; if ((pv->job->use_opencl && pv->job->title->opencl_support) && @@ -193,10 +190,11 @@ static hb_buffer_t* crop_scale( hb_filter_private_t * pv, hb_buffer_t * in ) sws_freeContext(pv->context); } - pv->context = hb_sws_get_context(in->f.width - (pv->crop[2] + pv->crop[3]), - in->f.height - (pv->crop[0] + pv->crop[1]), - in->f.fmt, out->f.width, out->f.height, - out->f.fmt, SWS_LANCZOS|SWS_ACCURATE_RND); + pv->context = hb_sws_get_context( + in->f.width - (pv->crop[2] + pv->crop[3]), + in->f.height - (pv->crop[0] + pv->crop[1]), + in->f.fmt, out->f.width, out->f.height, + out->f.fmt, SWS_LANCZOS|SWS_ACCURATE_RND); pv->width_in = in->f.width; pv->height_in = in->f.height; pv->pix_fmt = in->f.fmt; @@ -208,12 +206,11 @@ static hb_buffer_t* crop_scale( hb_filter_private_t * pv, hb_buffer_t * in ) return NULL; } - // Scale pic_crop into pic_render according to the - // context set up above + // Scale crop into out according to the context set up above sws_scale(pv->context, - (const uint8_t* const*)pic_crop.data, pic_crop.linesize, + (const uint8_t* const*)crop_data, crop_stride, 0, in->f.height - (pv->crop[0] + pv->crop[1]), - pic_out.data, pic_out.linesize); + out_data, out_stride); } out->s = in->s; diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index 474d672d2..bcfea83a8 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -920,8 +920,9 @@ static hb_buffer_t *copy_frame( hb_work_private_t *pv ) h != context->height) { // have to convert to our internal color space and/or rescale - AVPicture dstpic; - hb_avpicture_fill(&dstpic, buf); + uint8_t * data[4]; + int stride[4]; + hb_picture_fill(data, stride, buf); if (pv->sws_context == NULL || pv->sws_width != context->width || @@ -941,8 +942,7 @@ static hb_buffer_t *copy_frame( hb_work_private_t *pv ) } sws_scale(pv->sws_context, (const uint8_t* const *)pv->frame->data, - pv->frame->linesize, - 0, context->height, dstpic.data, dstpic.linesize); + pv->frame->linesize, 0, context->height, data, stride); } else { diff --git a/libhb/hb.c b/libhb/hb.c index 2a90726ce..0364a5a15 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -172,24 +172,49 @@ int hb_avcodec_close(AVCodecContext *avctx) } -int hb_avpicture_fill(AVPicture *pic, hb_buffer_t *buf) +int hb_picture_fill(uint8_t *data[], int stride[], hb_buffer_t *buf) { int ret, ii; for (ii = 0; ii < 4; ii++) - pic->linesize[ii] = buf->plane[ii].stride; + stride[ii] = buf->plane[ii].stride; - ret = av_image_fill_pointers(pic->data, buf->f.fmt, + ret = av_image_fill_pointers(data, buf->f.fmt, buf->plane[0].height_stride, - buf->data, pic->linesize); + buf->data, stride); if (ret != buf->size) { - hb_error("Internal error hb_avpicture_fill expected %d, got %d", + hb_error("Internal error hb_picture_fill expected %d, got %d", buf->size, ret); } return ret; } +int hb_picture_crop(uint8_t *data[], int stride[], hb_buffer_t *buf, + int top, int left) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(buf->f.fmt); + int x_shift, y_shift; + + if (desc == NULL) + return -1; + + x_shift = desc->log2_chroma_w; + y_shift = desc->log2_chroma_h; + + data[0] = buf->plane[0].data + top * buf->plane[0].stride + left; + data[1] = buf->plane[1].data + (top >> y_shift) * buf->plane[1].stride + + (left >> x_shift); + data[2] = buf->plane[2].data + (top >> y_shift) * buf->plane[2].stride + + (left >> x_shift); + + stride[0] = buf->plane[0].stride; + stride[1] = buf->plane[1].stride; + stride[2] = buf->plane[2].stride; + + return 0; +} + static int handle_jpeg(enum AVPixelFormat *format) { switch (*format) @@ -761,7 +786,8 @@ hb_image_t* hb_get_preview2(hb_handle_t * h, int title_idx, int picture, hb_buffer_t * in_buf = NULL, * deint_buf = NULL; hb_buffer_t * preview_buf = NULL; uint32_t swsflags; - AVPicture pic_in, pic_preview, pic_deint, pic_crop; + uint8_t * preview_data[4], * crop_data[4]; + int preview_stride[4], crop_stride[4]; struct SwsContext * context; int width = geo->geometry.width * @@ -781,7 +807,7 @@ hb_image_t* hb_get_preview2(hb_handle_t * h, int title_idx, int picture, preview_buf = hb_frame_buffer_init(AV_PIX_FMT_RGB32, width, height); // fill in AVPicture - hb_avpicture_fill( &pic_preview, preview_buf ); + hb_picture_fill( preview_data, preview_stride, preview_buf ); memset( filename, 0, 1024 ); @@ -800,23 +826,19 @@ hb_image_t* hb_get_preview2(hb_handle_t * h, int title_idx, int picture, goto fail; } - hb_avpicture_fill( &pic_in, in_buf ); - if (deinterlace) { // Deinterlace and crop deint_buf = hb_frame_buffer_init( AV_PIX_FMT_YUV420P, title->geometry.width, title->geometry.height ); hb_deinterlace(deint_buf, in_buf); - hb_avpicture_fill( &pic_deint, deint_buf ); - - av_picture_crop(&pic_crop, &pic_deint, AV_PIX_FMT_YUV420P, + hb_picture_crop(crop_data, crop_stride, deint_buf, geo->crop[0], geo->crop[2] ); } else { // Crop - av_picture_crop(&pic_crop, &pic_in, AV_PIX_FMT_YUV420P, + hb_picture_crop(crop_data, crop_stride, in_buf, geo->crop[0], geo->crop[2] ); } @@ -834,9 +856,9 @@ hb_image_t* hb_get_preview2(hb_handle_t * h, int title_idx, int picture, // Scale sws_scale(context, - (const uint8_t* const *)pic_crop.data, pic_crop.linesize, + (const uint8_t * const *)crop_data, crop_stride, 0, title->geometry.height - (geo->crop[0] + geo->crop[1]), - pic_preview.data, pic_preview.linesize); + preview_data, preview_stride); // Free context sws_freeContext( context ); diff --git a/libhb/hbffmpeg.h b/libhb/hbffmpeg.h index ff65bd6cc..30d5455c2 100644 --- a/libhb/hbffmpeg.h +++ b/libhb/hbffmpeg.h @@ -32,4 +32,3 @@ struct SwsContext* hb_sws_get_context(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags); -int hb_avpicture_fill(AVPicture *pic, hb_buffer_t *buf); diff --git a/libhb/internal.h b/libhb/internal.h index e66783bb4..6401f7b4b 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -183,6 +183,9 @@ int hb_buffer_copy( hb_buffer_t * dst, const hb_buffer_t * src ); void hb_buffer_swap_copy( hb_buffer_t *src, hb_buffer_t *dst ); hb_image_t * hb_image_init(int pix_fmt, int width, int height); hb_image_t * hb_buffer_to_image(hb_buffer_t *buf); +int hb_picture_fill(uint8_t *data[], int stride[], hb_buffer_t *b); +int hb_picture_crop(uint8_t *data[], int stride[], hb_buffer_t *b, + int top, int left); hb_fifo_t * hb_fifo_init( int capacity, int thresh ); void hb_fifo_register_full_cond( hb_fifo_t * f, hb_cond_t * c ); diff --git a/libhb/oclnv12toyuv.c b/libhb/oclnv12toyuv.c index 6f2cf66e5..cb739e8a9 100644 --- a/libhb/oclnv12toyuv.c +++ b/libhb/oclnv12toyuv.c @@ -228,10 +228,12 @@ static int hb_nv12toyuv( void **userdata, KernelEnv *kenv ) HB_OCL_CHECK(hb_ocl->clEnqueueNDRangeKernel, kenv->command_queue, kenv->kernel, 2, NULL, gdim, NULL, 0, NULL, NULL ); - if( (crop[0] || crop[1] || crop[2] || crop[3]) && (decomb == 0) && (detelecine == 0) ) + if ((crop[0] || crop[1] || crop[2] || crop[3]) && + (decomb == 0) && (detelecine == 0)) { - AVPicture pic_in; - AVPicture pic_crop; + uint8_t * crop_data[4]; + int crop_stride[4]; + hb_ocl->clEnqueueReadBuffer(kenv->command_queue, dxva2->cl_mem_yuv, CL_TRUE, 0, in_bytes, dxva2->nv12toyuv_tmp_out, 0, NULL, NULL); @@ -239,23 +241,29 @@ static int hb_nv12toyuv( void **userdata, KernelEnv *kenv ) int wmp = in->plane[0].stride; int hmp = in->plane[0].height; - copy_plane( in->plane[0].data, dxva2->nv12toyuv_tmp_out, wmp, w, hmp ); + copy_plane(in->plane[0].data, dxva2->nv12toyuv_tmp_out, wmp, w, hmp); wmp = in->plane[1].stride; hmp = in->plane[1].height; - copy_plane( in->plane[1].data, dxva2->nv12toyuv_tmp_out + w * h, wmp, w>>1, hmp ); + copy_plane(in->plane[1].data, dxva2->nv12toyuv_tmp_out + w * h, + wmp, w >> 1, hmp); wmp = in->plane[2].stride; hmp = in->plane[2].height; - copy_plane( in->plane[2].data, dxva2->nv12toyuv_tmp_out + w * h +( ( w * h )>>2 ), wmp, w>>1, hmp ); + copy_plane(in->plane[2].data, dxva2->nv12toyuv_tmp_out + w * h + + ((w * h) >> 2), wmp, w>>1, hmp); - hb_avpicture_fill( &pic_in, in ); - av_picture_crop( &pic_crop, &pic_in, in->f.fmt, crop[0], crop[2] ); + hb_picture_crop(crop_data, crop_stride, in, crop[0], crop[2]); int i, ww = w - ( crop[2] + crop[3] ), hh = h - ( crop[0] + crop[1] ); for( i = 0; i< hh >> 1; i++ ) { - memcpy( dxva2->nv12toyuv_tmp_in + ( ( i << 1 ) + 0 ) * ww, pic_crop.data[0]+ ( ( i << 1 ) + 0 ) * pic_crop.linesize[0], ww ); - memcpy( dxva2->nv12toyuv_tmp_in + ( ( i << 1 ) + 1 ) * ww, pic_crop.data[0]+ ( ( i << 1 ) + 1 ) * pic_crop.linesize[0], ww ); - memcpy( dxva2->nv12toyuv_tmp_in + ( ww * hh ) + i * ( ww >> 1 ), pic_crop.data[1] + i * pic_crop.linesize[1], ww >> 1 ); - memcpy( dxva2->nv12toyuv_tmp_in + ( ww * hh ) + ( ( ww * hh )>>2 ) + i * ( ww >> 1 ), pic_crop.data[2] + i * pic_crop.linesize[2], ww >> 1 ); + memcpy( dxva2->nv12toyuv_tmp_in + ((i << 1) + 0) * ww, + crop_data[0]+ ((i << 1) + 0) * crop_stride[0], ww ); + memcpy( dxva2->nv12toyuv_tmp_in + ((i << 1) + 1) * ww, + crop_data[0]+ ((i << 1) + 1) * crop_stride[0], ww ); + memcpy( dxva2->nv12toyuv_tmp_in + (ww * hh) + i * (ww >> 1), + crop_data[1] + i * crop_stride[1], ww >> 1 ); + memcpy( dxva2->nv12toyuv_tmp_in + (ww * hh) + ((ww * hh) >> 2) + + i * (ww >> 1), + crop_data[2] + i * crop_stride[2], ww >> 1 ); } if( kenv->isAMD ) diff --git a/libhb/rendersub.c b/libhb/rendersub.c index ab0fbcf76..f24eec632 100644 --- a/libhb/rendersub.c +++ b/libhb/rendersub.c @@ -218,8 +218,9 @@ static hb_buffer_t * ScaleSubtitle(hb_filter_private_t *pv, } if (ABS(xfactor - 1) > 0.01 || ABS(yfactor - 1) > 0.01) { - AVPicture pic_in, pic_out; - int width, height; + uint8_t * in_data[4], * out_data[4]; + int in_stride[4], out_stride[4]; + int width, height; width = sub->f.width * xfactor; height = sub->f.height * yfactor; @@ -227,8 +228,8 @@ static hb_buffer_t * ScaleSubtitle(hb_filter_private_t *pv, scaled->f.x = sub->f.x * xfactor; scaled->f.y = sub->f.y * yfactor; - hb_avpicture_fill(&pic_in, sub); - hb_avpicture_fill(&pic_out, scaled); + hb_picture_fill(in_data, in_stride, sub); + hb_picture_fill(out_data, out_stride, scaled); if (pv->sws == NULL || pv->sws_width != width || @@ -243,9 +244,8 @@ static hb_buffer_t * ScaleSubtitle(hb_filter_private_t *pv, pv->sws_width = width; pv->sws_height = height; } - sws_scale(pv->sws, - (const uint8_t* const *)pic_in.data, pic_in.linesize, - 0, sub->f.height, pic_out.data, pic_out.linesize); + sws_scale(pv->sws, (const uint8_t* const *)in_data, in_stride, + 0, sub->f.height, out_data, out_stride); } else { |