整理代码
This commit is contained in:
commit
c7b4e178ec
364 changed files with 59691 additions and 0 deletions
119
video/core/SampleFormat.cpp
Normal file
119
video/core/SampleFormat.cpp
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* INCLUDE
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "SampleFormat.h"
|
||||
|
||||
namespace Video
|
||||
{
|
||||
namespace Core
|
||||
{
|
||||
/*
|
||||
*******************************************************************************
|
||||
* TYPEDEFS
|
||||
*******************************************************************************
|
||||
*/
|
||||
struct SampleFormatInfo
|
||||
{
|
||||
std::string name;
|
||||
int bits;
|
||||
bool isPlanar;
|
||||
SampleFormat altFormat;
|
||||
};
|
||||
|
||||
/*
|
||||
*******************************************************************************
|
||||
* LOCAL VARIABLES
|
||||
*******************************************************************************
|
||||
*/
|
||||
static const SampleFormatInfo sampleFormatInfo[(int)SampleFormat::NB] = {
|
||||
{"u8", 8, false, SampleFormat::U8P}, {"s16", 16, false, SampleFormat::S16P},
|
||||
{"s32", 32, false, SampleFormat::S32P}, {"s64", 64, false, SampleFormat::S64P},
|
||||
{"flt", 32, false, SampleFormat::FLTP}, {"dbl", 64, false, SampleFormat::DBLP},
|
||||
{"u8p", 8, true, SampleFormat::U8}, {"s16p", 16, true, SampleFormat::S16},
|
||||
{"s32p", 32, true, SampleFormat::S32}, {"s64p", 64, true, SampleFormat::S64},
|
||||
{"fltp", 32, true, SampleFormat::FLT}, {"dblp", 64, true, SampleFormat::DBL},
|
||||
};
|
||||
|
||||
static const std::string UNKNOWN = "UNKNOWN";
|
||||
|
||||
/*
|
||||
*******************************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*******************************************************************************
|
||||
*/
|
||||
static inline bool isSampleFormatValid(SampleFormat format)
|
||||
{
|
||||
return ((int)format >= 0 && format < SampleFormat::NB);
|
||||
}
|
||||
|
||||
/*
|
||||
*******************************************************************************
|
||||
* FUNCTIONS
|
||||
*******************************************************************************
|
||||
*/
|
||||
const std::string& sampleFormatName(SampleFormat format)
|
||||
{
|
||||
if (isSampleFormatValid(format))
|
||||
return sampleFormatInfo[(int)format].name;
|
||||
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
int sampleFormatBitWidth(SampleFormat format)
|
||||
{
|
||||
if (isSampleFormatValid(format))
|
||||
return sampleFormatInfo[(int)format].bits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sampleFormatBytesPerSample(SampleFormat format)
|
||||
{
|
||||
if (isSampleFormatValid(format))
|
||||
return sampleFormatInfo[(int)format].bits >> 3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool sampleFormatIsPlanar(SampleFormat format)
|
||||
{
|
||||
if (isSampleFormatValid(format))
|
||||
return sampleFormatInfo[(int)format].isPlanar;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int sampleFormatCalcLineSize(SampleFormat format, ChannelLayout layout, int samples)
|
||||
{
|
||||
int size = sampleFormatBytesPerSample(format) * samples;
|
||||
if (!sampleFormatIsPlanar(format))
|
||||
size *= channelLayoutChannels(layout);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
SampleFormat sampleFormatGetPackedFormat(SampleFormat format)
|
||||
{
|
||||
if (!isSampleFormatValid(format))
|
||||
return SampleFormat::NONE;
|
||||
|
||||
if (!sampleFormatIsPlanar(format))
|
||||
return format;
|
||||
|
||||
return sampleFormatInfo[(int)format].altFormat;
|
||||
}
|
||||
|
||||
SampleFormat sampleFormatGetPlanarFormat(SampleFormat format)
|
||||
{
|
||||
if (!isSampleFormatValid(format))
|
||||
return SampleFormat::NONE;
|
||||
|
||||
if (sampleFormatIsPlanar(format))
|
||||
return format;
|
||||
|
||||
return sampleFormatInfo[(int)format].altFormat;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue