WinGui: Fix another instance of the Caliburn vs Json.net sillyness where objects...
[HandBrake.git] / libhb / qsv_memory.c
bloba01b502c851f4b134953c98b5cbd9715b4464c73
1 /* ********************************************************************* *\
3 Copyright (C) 2013 Intel Corporation. All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 - Redistributions of source code must retain the above copyright notice,
8 this list of conditions and the following disclaimer.
9 - Redistributions in binary form must reproduce the above copyright notice,
10 this list of conditions and the following disclaimer in the documentation
11 and/or other materials provided with the distribution.
12 - Neither the name of Intel Corporation nor the names of its contributors
13 may be used to endorse or promote products derived from this software
14 without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 \* ********************************************************************* */
29 #ifdef USE_QSV
31 #include "hb.h"
32 #include "hbffmpeg.h"
33 #include "qsv_memory.h"
35 int qsv_nv12_to_yuv420(struct SwsContext* sws_context,hb_buffer_t* dst, mfxFrameSurface1* src, mfxCoreInterface *core){
36 int ret = 0;
37 int i,j;
39 int in_pitch = src->Data.Pitch;
40 int w = AV_QSV_ALIGN16(src->Info.Width);
41 int h = (MFX_PICSTRUCT_PROGRESSIVE == src->Info.PicStruct) ? AV_QSV_ALIGN16(src->Info.Height) : AV_QSV_ALIGN32(src->Info.Height);
42 uint8_t *in_luma = 0;
43 uint8_t *in_chroma = 0;
44 static int copyframe_in_use = 1;
47 mfxStatus sts = MFX_ERR_NONE;
48 mfxFrameSurface1 accel_dst;
50 if (copyframe_in_use)
52 accel_dst.Info.FourCC = src->Info.FourCC;
53 accel_dst.Info.CropH = src->Info.CropH;
54 accel_dst.Info.CropW = src->Info.CropW;
55 accel_dst.Info.CropY = src->Info.CropY;
56 accel_dst.Info.CropX = src->Info.CropX;
57 accel_dst.Info.Width = w;
58 accel_dst.Info.Height = h;
59 accel_dst.Data.Pitch = src->Data.Pitch;
60 accel_dst.Data.Y = calloc( 1, in_pitch*h );
61 accel_dst.Data.VU = calloc( 1, in_pitch*h/2 );
63 sts = core->CopyFrame(core->pthis, &accel_dst, src);
65 if (sts < MFX_ERR_NONE)
67 free(accel_dst.Data.Y);
68 free(accel_dst.Data.VU);
69 copyframe_in_use = 0;
71 else
73 in_luma = accel_dst.Data.Y + accel_dst.Info.CropY * in_pitch + accel_dst.Info.CropX;
74 in_chroma = accel_dst.Data.VU + accel_dst.Info.CropY / 2 * in_pitch + accel_dst.Info.CropX;
78 if (!copyframe_in_use)
80 in_luma = src->Data.Y + src->Info.CropY * in_pitch + src->Info.CropX;
81 in_chroma = src->Data.VU + src->Info.CropY / 2 * in_pitch + src->Info.CropX;
84 hb_video_buffer_realloc( dst, w, h );
86 uint8_t *srcs[] = { in_luma, in_chroma };
87 int srcs_stride[] = { in_pitch, in_pitch };
89 uint8_t *dsts[] = { dst->plane[0].data, dst->plane[1].data, dst->plane[2].data };
90 int dsts_stride[] = { dst->plane[0].stride, dst->plane[1].stride, dst->plane[2].stride };
92 ret = sws_scale(sws_context, srcs, srcs_stride, 0, h, dsts, dsts_stride );
94 if (copyframe_in_use)
96 free(accel_dst.Data.Y);
97 free(accel_dst.Data.VU);
100 return ret;
103 int qsv_yuv420_to_nv12(struct SwsContext* sws_context,mfxFrameSurface1* dst, hb_buffer_t* src){
104 int ret = 0;
106 int w = src->plane[0].width;
107 int h = src->plane[0].height;
109 int out_pitch = dst->Data.Pitch;
110 uint8_t *out_luma = dst->Data.Y;
111 uint8_t *out_chroma = dst->Data.VU;
113 uint8_t *srcs[] = { src->plane[0].data, src->plane[1].data, src->plane[2].data };
114 int srcs_stride[] = { src->plane[0].stride, src->plane[1].stride, src->plane[2].stride };
116 uint8_t *dsts[] = { out_luma, out_chroma };
117 int dsts_stride[] = { out_pitch, out_pitch };
119 ret = sws_scale(sws_context, srcs, srcs_stride, 0, h, dsts, dsts_stride );
121 return ret;
124 #endif // USE_QSV