From e95f320dd030e9def8174e8b173e3631f11dba25 Mon Sep 17 00:00:00 2001 From: tobigun Date: Fri, 18 Jan 2008 16:30:06 +0000 Subject: added blindy's swscale support. It can be enabled with {$DEFINE UseSWScale}. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@795 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVideo.pas | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'Game/Code') diff --git a/Game/Code/Classes/UVideo.pas b/Game/Code/Classes/UVideo.pas index bbd03d84..c30b271e 100644 --- a/Game/Code/Classes/UVideo.pas +++ b/Game/Code/Classes/UVideo.pas @@ -37,6 +37,9 @@ uses SDL, avcodec, avformat, avutil, + {$IFDEF UseSWScale} + swscale, + {$ENDIF} math, OpenGL12, SysUtils, @@ -77,6 +80,10 @@ type AVFrameRGB: PAVFrame; myBuffer: pByte; + {$IFDEF UseSWScale} + SoftwareScaleContext: PSwsContext; + {$ENDIF} + TexX, TexY, dataX, dataY: Cardinal; ScaledVideoWidth, ScaledVideoHeight: Real; @@ -312,10 +319,18 @@ begin if Framefinished=0 then begin Exit; end; + // otherwise we convert the pixeldata from YUV to RGB + {$IFDEF UseSWScale} + errnum:=sws_scale(SoftwareScaleContext,@(AVFrame.data),@(AVFrame.linesize), + 0,VideoCodecContext^.Height, + @(AVFrameRGB.data),@(AVFrameRGB.linesize)); + {$ELSE} errnum:=img_convert(PAVPicture(AVFrameRGB), PIX_FMT_RGB24, PAVPicture(AVFrame), VideoCodecContext^.pix_fmt, VideoCodecContext^.width, VideoCodecContext^.height); + {$ENDIF} + if errnum >=0 then begin glBindTexture(GL_TEXTURE_2D, fVideoTex); @@ -568,6 +583,23 @@ begin av_close_input_file(VideoFormatContext); Exit; end; + + {$IFDEF UseSWScale} + SoftwareScaleContext:=sws_getContext(VideoCodecContext^.width,VideoCodecContext^.height,integer(VideoCodecContext^.pix_fmt), + dataX, dataY, integer(PIX_FMT_RGB24), + SWS_FAST_BILINEAR, 0, 0, 0); + if SoftwareScaleContext <> Nil then + writeln('got swscale context') + else begin + writeln('ERROR: didnīt get swscale context'); + av_free(AVFrameRGB); + av_free(AVFrame); + avcodec_close(VideoCodecContext); + av_close_input_file(VideoFormatContext); + Exit; + end; + {$ENDIF} + // this is the errnum from avpicture_fill if errnum >=0 then begin -- cgit v1.2.3