1
/***************************************************************************
2
copyright : (C) 2007 by mean
3
email : fixounet@free.fr
6
***************************************************************************/
8
/***************************************************************************
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
15
***************************************************************************/
22
#include "ADM_utilities/default.h"
23
#include <ADM_assert.h>
25
#include "colorspace.h"
27
#include "ADM_osSupport/ADM_cpuCap.h"
28
#if (defined( ARCH_X86) || defined(ARCH_X86_64))
30
#include "ADM_lavcodec/avcodec.h"
34
#include "../ADM_lavutil/avutil.h"
35
#include "../ADM_libswscale/swscale.h"
37
#include "ADM_colorspace.h"
39
#if (defined( ARCH_X86) || defined(ARCH_X86_64))
40
#define ADD(x,y) if( CpuCaps::has##x()) flags|=SWS_CPU_CAPS_##y;
41
#define FLAGS() ADD(MMX,MMX); ADD(3DNOW,3DNOW); ADD(MMXEXT,MMX2);
44
#define FLAGS() flags|=SWS_CPU_CAPS_ALTIVEC;
50
#define CONTEXT (SwsContext *)context
54
\brief Convert ADM colorspace type swscale/lavcodec colorspace name
57
static PixelFormat ADMColor2LAVColor(ADM_colorspace fromColor)
61
case ADM_COLOR_YV12: return PIX_FMT_YUV420P;
62
case ADM_COLOR_YUV422P: return PIX_FMT_YUV422P;
63
default : ADM_assert(0);
65
return PIX_FMT_YUV420P;
68
\fn getStrideAndPointers
69
\brief Fill in strides etc.. needed by libswscale
71
uint8_t ADMColorspace::getStrideAndPointers(uint8_t *from,ADM_colorspace fromColor,uint8_t **srcData,int *srcStride)
77
srcData[1]=from+width*height;
78
srcData[2]=from+((5*width*height)>>2);
80
srcStride[1]=width>>1;
81
srcStride[2]=width>>1;
83
case ADM_COLOR_YUV422P:
85
srcData[1]=from+width*height;
86
srcData[2]=from+((3*width*height)>>1);
88
srcStride[1]=width>>1;
89
srcStride[2]=width>>1;
99
\brief Do the color conversion
100
@param from Source image
101
@param to Target image
104
uint8_t ADMColorspace::convert(uint8_t *from, uint8_t *to)
111
getStrideAndPointers(from,fromColor,srcData,srcStride);
112
getStrideAndPointers(to,toColor,dstData,dstStride);
113
sws_scale(CONTEXT,srcData,srcStride,0,height,dstData,dstStride);
123
@param from colorspace to convert from
124
@param to colorspace to concert to
127
ADMColorspace::ADMColorspace(uint32_t w, uint32_t h, ADM_colorspace from,ADM_colorspace to)
129
int flags=SWS_BICUBLIN;
136
PixelFormat lavFrom=ADMColor2LAVColor(fromColor);
137
PixelFormat lavTo=ADMColor2LAVColor(toColor);
139
context=(void *)sws_getContext(
144
flags, NULL, NULL,NULL);
151
ADMColorspace::~ADMColorspace()
155
sws_freeContext(CONTEXT);