backport 569648f2a3b8e094c33d102edd41397ca04b07be into dharma 10.1 (because git maste...
[vuplus_xbmc] / xbmc / cores / dvdplayer / Codecs / DllSwScale.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2010 Team XBMC
4  *      http://www.xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, write to
18  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19  *  http://www.gnu.org/copyleft/gpl.html
20  *
21  */
22
23 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
24   #include "config.h"
25 #endif
26 #include "DynamicDll.h"
27 #include "utils/log.h"
28
29 extern "C" {
30 #ifndef HAVE_MMX
31 #define HAVE_MMX
32 #endif
33
34 #ifndef __STDC_CONSTANT_MACROS
35 #define __STDC_CONSTANT_MACROS
36 #endif
37
38 #ifndef __STDC_LIMIT_MACROS
39 #define __STDC_LIMIT_MACROS
40 #endif
41
42 #ifndef __GNUC__
43 #pragma warning(disable:4244)
44 #endif
45
46 #if (defined USE_EXTERNAL_FFMPEG)
47   #if (defined HAVE_LIBAVUTIL_AVUTIL_H)
48     #include <libavutil/avutil.h>
49   #elif (defined HAVE_FFMPEG_AVUTIL_H)
50     #include <ffmpeg/avutil.h>
51   #endif
52   #if (defined HAVE_LIBSWSCALE_SWSCALE_H)
53     #include <libswscale/swscale.h>
54   #elif (defined HAVE_FFMPEG_SWSCALE_H)
55     #include <ffmpeg/swscale.h>
56   #endif
57   #if (defined HAVE_LIBSWSCALE_RGB2RGB_H)
58     #include <libswscale/rgb2rgb.h>
59   #elif (defined HAVE_FFMPEG_RGB2RGB_H)
60     #include <ffmpeg/rgb2rgb.h>
61   #endif
62 #else
63   #include "libavutil/avutil.h"
64   #include "libswscale/swscale.h"
65   #include "libswscale/rgb2rgb.h"
66 #endif
67 }
68
69 inline int SwScaleCPUFlags()
70 {
71 #if !defined(__powerpc__) && !defined(__ppc__) && !defined(__arm__)
72   return SWS_CPU_CAPS_MMX;
73 #elif defined(__powerpc__) || defined(__ppc__)
74   return SWS_CPU_CAPS_ALTIVEC;
75 #else
76   return 0;
77 #endif
78 }
79
80 class DllSwScaleInterface
81 {
82 public:
83    virtual ~DllSwScaleInterface() {}
84
85    virtual struct SwsContext *sws_getCachedContext(struct SwsContext *context,
86                                              int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
87                                   SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)=0;
88
89    virtual struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
90                                   SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)=0;
91
92    virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
93                          int srcSliceH, uint8_t* dst[], int dstStride[])=0;
94     #if (! defined USE_EXTERNAL_FFMPEG)
95       virtual void sws_rgb2rgb_init(int flags)=0;
96     #elif (defined HAVE_LIBSWSCALE_RGB2RGB_H) || (defined HAVE_FFMPEG_RGB2RGB_H)
97       virtual void sws_rgb2rgb_init(int flags)=0;
98     #endif
99
100    virtual void sws_freeContext(struct SwsContext *context)=0;
101 };
102
103 #if (defined USE_EXTERNAL_FFMPEG)
104
105 // We call into this library directly.
106 class DllSwScale : public DllDynamic, public DllSwScaleInterface
107 {
108 public:
109   virtual ~DllSwScale() {}
110   virtual struct SwsContext *sws_getCachedContext(struct SwsContext *context,
111                                             int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
112                                SwsFilter *srcFilter, SwsFilter *dstFilter, double *param) 
113     { return ::sws_getCachedContext(context, srcW, srcH, (enum PixelFormat)srcFormat, dstW, dstH, (enum PixelFormat)dstFormat, flags, srcFilter, dstFilter, param); }
114
115   virtual struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
116                                SwsFilter *srcFilter, SwsFilter *dstFilter, double *param) 
117     { return ::sws_getContext(srcW, srcH, (enum PixelFormat)srcFormat, dstW, dstH, (enum PixelFormat)dstFormat, flags, srcFilter, dstFilter, param); }
118
119   virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
120                 int srcSliceH, uint8_t* dst[], int dstStride[])  
121     { return ::sws_scale(context, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); }
122   #if (! defined USE_EXTERNAL_FFMPEG)
123     virtual void sws_rgb2rgb_init(int flags) { ::sws_rgb2rgb_init(flags); }
124   #elif (defined HAVE_LIBSWSCALE_RGB2RGB_H) || (defined HAVE_FFMPEG_RGB2RGB_H)
125     virtual void sws_rgb2rgb_init(int flags) { ::sws_rgb2rgb_init(flags); }
126   #endif
127   virtual void sws_freeContext(struct SwsContext *context) { ::sws_freeContext(context); }
128   
129   // DLL faking.
130   virtual bool ResolveExports() { return true; }
131   virtual bool Load() {
132     CLog::Log(LOGDEBUG, "DllSwScale: Using libswscale system library");
133     return true;
134   }
135   virtual void Unload() {}
136 };
137
138 #else
139
140 class DllSwScale : public DllDynamic, public DllSwScaleInterface
141 {
142   DECLARE_DLL_WRAPPER(DllSwScale, DLL_PATH_LIBSWSCALE)
143   DEFINE_METHOD11(struct SwsContext *, sws_getCachedContext, ( struct SwsContext *p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8,
144                                                          SwsFilter * p9, SwsFilter * p10, double * p11))
145   DEFINE_METHOD10(struct SwsContext *, sws_getContext, ( int p1, int p2, int p3, int p4, int p5, int p6, int p7, 
146                                                          SwsFilter * p8, SwsFilter * p9, double * p10))
147   DEFINE_METHOD7(int, sws_scale, (struct SwsContext *p1, uint8_t** p2, int *p3, int p4, int p5, uint8_t **p6, int *p7))
148   DEFINE_METHOD1(void, sws_rgb2rgb_init, (int p1))
149   DEFINE_METHOD1(void, sws_freeContext, (struct SwsContext *p1))
150
151   BEGIN_METHOD_RESOLVE()
152     RESOLVE_METHOD(sws_getCachedContext)
153     RESOLVE_METHOD(sws_getContext)
154     RESOLVE_METHOD(sws_scale)
155     RESOLVE_METHOD(sws_rgb2rgb_init)
156     RESOLVE_METHOD(sws_freeContext)
157   END_METHOD_RESOLVE()
158 };
159
160 #endif