Statistics
| Branch: | Revision:

ffmpeg / libswscale / swscale_internal.h @ 9990e426

History | View | Annotate | Download (9.13 KB)

1
/*
2
 * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg 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 GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20

    
21
#ifndef SWSCALE_SWSCALE_INTERNAL_H
22
#define SWSCALE_SWSCALE_INTERNAL_H
23

    
24
#include "config.h"
25

    
26
#ifdef HAVE_ALTIVEC_H
27
#include <altivec.h>
28
#endif
29

    
30
#include "libavutil/avutil.h"
31

    
32
#define MAX_FILTER_SIZE 256
33

    
34
#define VOFW 2048
35
#define VOF  (VOFW*2)
36

    
37
#ifdef WORDS_BIGENDIAN
38
#define ALT32_CORR (-1)
39
#else
40
#define ALT32_CORR   1
41
#endif
42

    
43
typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
44
             int srcSliceH, uint8_t* dst[], int dstStride[]);
45

    
46
/* This struct should be aligned on at least a 32-byte boundary. */
47
typedef struct SwsContext{
48
    /**
49
     * info on struct for av_log
50
     */
51
    const AVClass *av_class;
52

    
53
    /**
54
     * Note that src, dst, srcStride, dstStride will be copied in the
55
     * sws_scale() wrapper so they can be freely modified here.
56
     */
57
    SwsFunc swScale;
58
    int srcW, srcH, dstH;
59
    int chrSrcW, chrSrcH, chrDstW, chrDstH;
60
    int lumXInc, chrXInc;
61
    int lumYInc, chrYInc;
62
    int dstFormat, srcFormat;               ///< format 4:2:0 type is always YV12
63
    int origDstFormat, origSrcFormat;       ///< format
64
    int chrSrcHSubSample, chrSrcVSubSample;
65
    int chrIntHSubSample, chrIntVSubSample;
66
    int chrDstHSubSample, chrDstVSubSample;
67
    int vChrDrop;
68
    int sliceDir;
69
    double param[2];
70

    
71
    int16_t **lumPixBuf;
72
    int16_t **chrPixBuf;
73
    int16_t *hLumFilter;
74
    int16_t *hLumFilterPos;
75
    int16_t *hChrFilter;
76
    int16_t *hChrFilterPos;
77
    int16_t *vLumFilter;
78
    int16_t *vLumFilterPos;
79
    int16_t *vChrFilter;
80
    int16_t *vChrFilterPos;
81

    
82
    uint8_t formatConvBuffer[VOF]; //FIXME dynamic allocation, but we have to change a lot of code for this to be useful
83

    
84
    int hLumFilterSize;
85
    int hChrFilterSize;
86
    int vLumFilterSize;
87
    int vChrFilterSize;
88
    int vLumBufSize;
89
    int vChrBufSize;
90

    
91
    uint8_t *funnyYCode;
92
    uint8_t *funnyUVCode;
93
    int32_t *lumMmx2FilterPos;
94
    int32_t *chrMmx2FilterPos;
95
    int16_t *lumMmx2Filter;
96
    int16_t *chrMmx2Filter;
97

    
98
    int canMMX2BeUsed;
99

    
100
    int lastInLumBuf;
101
    int lastInChrBuf;
102
    int lumBufIndex;
103
    int chrBufIndex;
104
    int dstY;
105
    int flags;
106
    void * yuvTable;            // pointer to the yuv->rgb table start so it can be freed()
107
    uint8_t * table_rV[256];
108
    uint8_t * table_gU[256];
109
    int    table_gV[256];
110
    uint8_t * table_bU[256];
111

    
112
    //Colorspace stuff
113
    int contrast, brightness, saturation;    // for sws_getColorspaceDetails
114
    int srcColorspaceTable[4];
115
    int dstColorspaceTable[4];
116
    int srcRange, dstRange;
117

    
118
#define RED_DITHER            "0*8"
119
#define GREEN_DITHER          "1*8"
120
#define BLUE_DITHER           "2*8"
121
#define Y_COEFF               "3*8"
122
#define VR_COEFF              "4*8"
123
#define UB_COEFF              "5*8"
124
#define VG_COEFF              "6*8"
125
#define UG_COEFF              "7*8"
126
#define Y_OFFSET              "8*8"
127
#define U_OFFSET              "9*8"
128
#define V_OFFSET              "10*8"
129
#define LUM_MMX_FILTER_OFFSET "11*8"
130
#define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
131
#define DSTW_OFFSET           "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
132
#define ESP_OFFSET            "11*8+4*4*256*2+8"
133
#define VROUNDER_OFFSET       "11*8+4*4*256*2+16"
134
#define U_TEMP                "11*8+4*4*256*2+24"
135
#define V_TEMP                "11*8+4*4*256*2+32"
136

    
137
    uint64_t redDither   __attribute__((aligned(8)));
138
    uint64_t greenDither __attribute__((aligned(8)));
139
    uint64_t blueDither  __attribute__((aligned(8)));
140

    
141
    uint64_t yCoeff      __attribute__((aligned(8)));
142
    uint64_t vrCoeff     __attribute__((aligned(8)));
143
    uint64_t ubCoeff     __attribute__((aligned(8)));
144
    uint64_t vgCoeff     __attribute__((aligned(8)));
145
    uint64_t ugCoeff     __attribute__((aligned(8)));
146
    uint64_t yOffset     __attribute__((aligned(8)));
147
    uint64_t uOffset     __attribute__((aligned(8)));
148
    uint64_t vOffset     __attribute__((aligned(8)));
149
    int32_t  lumMmxFilter[4*MAX_FILTER_SIZE];
150
    int32_t  chrMmxFilter[4*MAX_FILTER_SIZE];
151
    int dstW;
152
    uint64_t esp          __attribute__((aligned(8)));
153
    uint64_t vRounder     __attribute__((aligned(8)));
154
    uint64_t u_temp       __attribute__((aligned(8)));
155
    uint64_t v_temp       __attribute__((aligned(8)));
156

    
157
#ifdef HAVE_ALTIVEC
158

    
159
  vector signed short   CY;
160
  vector signed short   CRV;
161
  vector signed short   CBU;
162
  vector signed short   CGU;
163
  vector signed short   CGV;
164
  vector signed short   OY;
165
  vector unsigned short CSHIFT;
166
  vector signed short   *vYCoeffsBank, *vCCoeffsBank;
167

    
168
#endif
169

    
170

    
171
#ifdef ARCH_BFIN
172
    uint32_t oy           __attribute__((aligned(4)));
173
    uint32_t oc           __attribute__((aligned(4)));
174
    uint32_t zero         __attribute__((aligned(4)));
175
    uint32_t cy           __attribute__((aligned(4)));
176
    uint32_t crv          __attribute__((aligned(4)));
177
    uint32_t rmask        __attribute__((aligned(4)));
178
    uint32_t cbu          __attribute__((aligned(4)));
179
    uint32_t bmask        __attribute__((aligned(4)));
180
    uint32_t cgu          __attribute__((aligned(4)));
181
    uint32_t cgv          __attribute__((aligned(4)));
182
    uint32_t gmask        __attribute__((aligned(4)));
183
#endif
184

    
185
#ifdef HAVE_VIS
186
    uint64_t sparc_coeffs[10] __attribute__((aligned(8)));
187
#endif
188

    
189
} SwsContext;
190
//FIXME check init (where 0)
191

    
192
SwsFunc yuv2rgb_get_func_ptr (SwsContext *c);
193
int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation);
194

    
195
void yuv2rgb_altivec_init_tables (SwsContext *c, const int inv_table[4],int brightness,int contrast, int saturation);
196
SwsFunc yuv2rgb_init_altivec (SwsContext *c);
197
void altivec_yuv2packedX (SwsContext *c,
198
                          int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
199
                          int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
200
                          uint8_t *dest, int dstW, int dstY);
201

    
202
const char *sws_format_name(int format);
203

    
204
//FIXME replace this with something faster
205
#define isPlanarYUV(x)  (           \
206
           (x)==PIX_FMT_YUV410P     \
207
        || (x)==PIX_FMT_YUV420P     \
208
        || (x)==PIX_FMT_YUV411P     \
209
        || (x)==PIX_FMT_YUV422P     \
210
        || (x)==PIX_FMT_YUV444P     \
211
        || (x)==PIX_FMT_YUV440P     \
212
        || (x)==PIX_FMT_NV12        \
213
        || (x)==PIX_FMT_NV21        \
214
    )
215
#define isYUV(x)        (           \
216
           (x)==PIX_FMT_UYVY422     \
217
        || (x)==PIX_FMT_YUYV422     \
218
        || isPlanarYUV(x)           \
219
    )
220
#define isGray(x)       (           \
221
           (x)==PIX_FMT_GRAY8       \
222
        || (x)==PIX_FMT_GRAY16BE    \
223
        || (x)==PIX_FMT_GRAY16LE    \
224
    )
225
#define isGray16(x)     (           \
226
           (x)==PIX_FMT_GRAY16BE    \
227
        || (x)==PIX_FMT_GRAY16LE    \
228
    )
229
#define isRGB(x)        (           \
230
           (x)==PIX_FMT_RGB32       \
231
        || (x)==PIX_FMT_RGB32_1     \
232
        || (x)==PIX_FMT_RGB24       \
233
        || (x)==PIX_FMT_RGB565      \
234
        || (x)==PIX_FMT_RGB555      \
235
        || (x)==PIX_FMT_RGB8        \
236
        || (x)==PIX_FMT_RGB4        \
237
        || (x)==PIX_FMT_RGB4_BYTE   \
238
        || (x)==PIX_FMT_MONOBLACK   \
239
    )
240
#define isBGR(x)        (           \
241
           (x)==PIX_FMT_BGR32       \
242
        || (x)==PIX_FMT_BGR32_1     \
243
        || (x)==PIX_FMT_BGR24       \
244
        || (x)==PIX_FMT_BGR565      \
245
        || (x)==PIX_FMT_BGR555      \
246
        || (x)==PIX_FMT_BGR8        \
247
        || (x)==PIX_FMT_BGR4        \
248
        || (x)==PIX_FMT_BGR4_BYTE   \
249
        || (x)==PIX_FMT_MONOBLACK   \
250
    )
251

    
252
static inline int fmt_depth(int fmt)
253
{
254
    switch(fmt) {
255
        case PIX_FMT_BGRA:
256
        case PIX_FMT_ABGR:
257
        case PIX_FMT_RGBA:
258
        case PIX_FMT_ARGB:
259
            return 32;
260
        case PIX_FMT_BGR24:
261
        case PIX_FMT_RGB24:
262
            return 24;
263
        case PIX_FMT_BGR565:
264
        case PIX_FMT_RGB565:
265
        case PIX_FMT_GRAY16BE:
266
        case PIX_FMT_GRAY16LE:
267
            return 16;
268
        case PIX_FMT_BGR555:
269
        case PIX_FMT_RGB555:
270
            return 15;
271
        case PIX_FMT_BGR8:
272
        case PIX_FMT_RGB8:
273
            return 8;
274
        case PIX_FMT_BGR4:
275
        case PIX_FMT_RGB4:
276
        case PIX_FMT_BGR4_BYTE:
277
        case PIX_FMT_RGB4_BYTE:
278
            return 4;
279
        case PIX_FMT_MONOBLACK:
280
            return 1;
281
        default:
282
            return 0;
283
    }
284
}
285

    
286
extern const DECLARE_ALIGNED(8, uint64_t, ff_dither4[2]);
287
extern const DECLARE_ALIGNED(8, uint64_t, ff_dither8[2]);
288

    
289
extern const AVClass sws_context_class;
290

    
291
#endif /* SWSCALE_SWSCALE_INTERNAL_H */