#include <avisynth.h>
#include <avs/win.h>
bool VideoInfo::HasVideo() const { return (width!=0); }
bool VideoInfo::HasAudio() const { return (audio_samples_per_second!=0); }
bool VideoInfo::IsRGB() const { return !!(pixel_type&CS_BGR); }
bool VideoInfo::IsRGB24() const { return ((pixel_type & CS_BGR24) == CS_BGR24) && ((pixel_type & CS_Sample_Bits_Mask) == CS_Sample_Bits_8); } bool VideoInfo::IsRGB32() const { return ((pixel_type & CS_BGR32) == CS_BGR32) && ((pixel_type & CS_Sample_Bits_Mask) == CS_Sample_Bits_8); }
bool VideoInfo::IsYUV() const { return !!(pixel_type&CS_YUV ); }
bool VideoInfo::IsYUY2() const { return (pixel_type & CS_YUY2) == CS_YUY2; }
bool VideoInfo::IsYV24() const { return (pixel_type & CS_PLANAR_MASK) == (CS_YV24 & CS_PLANAR_FILTER); }
bool VideoInfo::IsYV16() const { return (pixel_type & CS_PLANAR_MASK) == (CS_YV16 & CS_PLANAR_FILTER); }
bool VideoInfo::IsYV12() const { return (pixel_type & CS_PLANAR_MASK) == (CS_YV12 & CS_PLANAR_FILTER); }
bool VideoInfo::IsY8() const { return (pixel_type & CS_PLANAR_MASK) == (CS_Y8 & CS_PLANAR_FILTER); }
bool VideoInfo::IsYV411() const { return (pixel_type & CS_PLANAR_MASK) == (CS_YV411 & CS_PLANAR_FILTER); }
bool VideoInfo::IsColorSpace(int c_space) const {
return IsPlanar() ? ((pixel_type & CS_PLANAR_MASK) == (c_space & CS_PLANAR_FILTER)) :
( ((pixel_type & ~CS_Sample_Bits_Mask & c_space) == (c_space & ~CS_Sample_Bits_Mask)) && ((pixel_type & CS_Sample_Bits_Mask) == (c_space & CS_Sample_Bits_Mask)) );
}
bool VideoInfo::Is(int property) const { return ((image_type & property)==property ); }
bool VideoInfo::IsPlanar() const { return !!(pixel_type & CS_PLANAR); }
bool VideoInfo::IsFieldBased() const { return !!(image_type & IT_FIELDBASED); }
bool VideoInfo::IsParityKnown() const { return ((image_type & IT_FIELDBASED)&&(image_type & (IT_BFF|IT_TFF))); }
bool VideoInfo::IsBFF() const { return !!(image_type & IT_BFF); }
bool VideoInfo::IsTFF() const { return !!(image_type & IT_TFF); }
__int64 VideoInfo::AudioSamplesFromFrames(int frames) const { return (fps_numerator && HasVideo()) ? ((__int64)(frames) * audio_samples_per_second * fps_denominator / fps_numerator) : 0; }
int VideoInfo::FramesFromAudioSamples(__int64 samples) const { return (fps_denominator && HasAudio()) ? (int)((samples * fps_numerator)/((__int64)fps_denominator * audio_samples_per_second)) : 0; }
__int64 VideoInfo::AudioSamplesFromBytes(__int64 bytes) const { return HasAudio() ? bytes / BytesPerAudioSample() : 0; }
__int64 VideoInfo::BytesFromAudioSamples(__int64 samples) const { return samples * BytesPerAudioSample(); }
int VideoInfo::AudioChannels() const { return HasAudio() ? nchannels : 0; }
int VideoInfo::SampleType() const{ return sample_type;}
bool VideoInfo::IsSampleType(int testtype) const{ return !!(sample_type&testtype);}
int VideoInfo::SamplesPerSecond() const { return audio_samples_per_second; }
int VideoInfo::BytesPerAudioSample() const { return nchannels*BytesPerChannelSample();}
void VideoInfo::SetFieldBased(bool isfieldbased) { if (isfieldbased) image_type|=IT_FIELDBASED; else image_type&=~IT_FIELDBASED; }
void VideoInfo::Set(int property) { image_type|=property; }
void VideoInfo::Clear(int property) { image_type&=~property; }
int VideoInfo::BytesPerChannelSample() const {
switch (sample_type) {
case SAMPLE_INT8:
return sizeof(unsigned char);
case SAMPLE_INT16:
return sizeof(signed short);
case SAMPLE_INT24:
return 3;
case SAMPLE_INT32:
return sizeof(signed int);
case SAMPLE_FLOAT:
return sizeof(SFLOAT);
default:
_ASSERTE("Audio sample type not recognized!");
return 0;
}
}
bool VideoInfo::IsVPlaneFirst() const {
return (NumComponents() > 1) && IsPlanar() && (pixel_type & (CS_VPlaneFirst | CS_UPlaneFirst)) == CS_VPlaneFirst; }
int VideoInfo::BytesFromPixels(int pixels) const {
const int componentSizes[8] = {1,2,4,0,0,2,2,2};
return (NumComponents() > 1) && IsPlanar() ? pixels * componentSizes[(pixel_type>>CS_Shift_Sample_Bits) & 7] : pixels * (BitsPerPixel()>>3);
}
int VideoInfo::RowSize(int plane) const {
const int rowsize = BytesFromPixels(width);
switch (plane) {
case PLANAR_U: case PLANAR_V:
return ((NumComponents() > 1) && IsPlanar() && !IsPlanarRGB() && !IsPlanarRGBA()) ? rowsize>>GetPlaneWidthSubsampling(plane) : 0;
case PLANAR_U_ALIGNED: case PLANAR_V_ALIGNED:
return ((NumComponents() > 1) && IsPlanar() && !IsPlanarRGB() && !IsPlanarRGBA()) ? ((rowsize>>GetPlaneWidthSubsampling(plane))+FRAME_ALIGN-1)&(~(FRAME_ALIGN-1)) : 0;
case PLANAR_Y_ALIGNED:
return (rowsize+FRAME_ALIGN-1)&(~(FRAME_ALIGN-1));
case PLANAR_R: case PLANAR_G: case PLANAR_B:
return ((NumComponents() > 1) && (IsPlanarRGB() || IsPlanarRGBA())) ? rowsize : 0;
case PLANAR_R_ALIGNED: case PLANAR_G_ALIGNED: case PLANAR_B_ALIGNED:
return IsPlanarRGB() || IsPlanarRGBA() ? (rowsize+FRAME_ALIGN-1)&(~(FRAME_ALIGN-1)) : 0;
case PLANAR_A:
return ((NumComponents() == 4) && IsPlanar()) ? rowsize : 0;
case PLANAR_A_ALIGNED:
return ((NumComponents() == 4) && IsPlanar()) ? (rowsize+FRAME_ALIGN-1)&(~(FRAME_ALIGN-1)) : 0;
}
return rowsize;
}
int VideoInfo::BMPSize() const {
if ((NumComponents() > 1) && IsPlanar()) {
const int Ybytes = ((RowSize(PLANAR_Y)+3) & ~3) * height;
const int UVbytes = Ybytes >> (GetPlaneWidthSubsampling(PLANAR_U)+GetPlaneHeightSubsampling(PLANAR_U));
return Ybytes + UVbytes*2;
}
return height * ((RowSize()+3) & ~3);
}
int VideoInfo::GetPlaneWidthSubsampling(int plane) const { if (plane == PLANAR_Y || plane == PLANAR_R || plane == PLANAR_G || plane == PLANAR_B || plane == PLANAR_A) return 0;
if (NumComponents() == 1)
throw AvisynthError("Filter error: GetPlaneWidthSubsampling not available on greyscale pixel type.");
if (plane == PLANAR_U || plane == PLANAR_V) {
if (IsYUY2())
return 1;
else if (IsPlanar())
return ((pixel_type>>CS_Shift_Sub_Width)+1) & 3;
else
throw AvisynthError("Filter error: GetPlaneWidthSubsampling called with unsupported pixel type.");
}
throw AvisynthError("Filter error: GetPlaneWidthSubsampling called with unsupported plane.");
}
int VideoInfo::GetPlaneHeightSubsampling(int plane) const { if (plane == PLANAR_Y || plane == PLANAR_R || plane == PLANAR_G || plane == PLANAR_B || plane == PLANAR_A) return 0;
if (NumComponents() == 1)
throw AvisynthError("Filter error: GetPlaneHeightSubsampling not available on greyscale pixel type.");
if (plane == PLANAR_U || plane == PLANAR_V) {
if (IsYUY2())
return 0;
else if (IsPlanar())
return ((pixel_type>>CS_Shift_Sub_Height)+1) & 3;
else
throw AvisynthError("Filter error: GetPlaneHeightSubsampling called with unsupported pixel type.");
}
throw AvisynthError("Filter error: GetPlaneHeightSubsampling called with supported plane.");
}
int VideoInfo::BitsPerPixel() const {
switch (pixel_type) {
case CS_BGR24:
return 24;
case CS_BGR32:
return 32;
case CS_YUY2:
return 16;
case CS_Y8:
return 8;
case CS_Y10:
case CS_Y12:
case CS_Y14:
case CS_Y16: return 16;
case CS_Y32:
return 32;
case CS_BGR48:
return 48;
case CS_BGR64:
return 64;
}
if (IsPlanar()) {
const int componentSizes[8] = {1,2,4,0,0,2,2,2};
const int S = (IsYUV() || IsYUVA()) ? GetPlaneWidthSubsampling(PLANAR_U) + GetPlaneHeightSubsampling(PLANAR_U) : 0; const int fullSizePlaneCount = IsYUVA() || IsPlanarRGBA() ? 2 : 1; return (((fullSizePlaneCount << S) + 2) * (componentSizes[(pixel_type >> CS_Shift_Sample_Bits) & 7]) * 8) >> S;
}
return 0;
}
void VideoInfo::SetFPS(unsigned numerator, unsigned denominator) {
if ((numerator == 0) || (denominator == 0)) {
fps_numerator = 0;
fps_denominator = 1;
}
else {
unsigned x=numerator, y=denominator;
while (y) { unsigned t = x%y; x = y; y = t;
}
fps_numerator = numerator/x;
fps_denominator = denominator/x;
}
}
void VideoInfo::MulDivFPS(unsigned multiplier, unsigned divisor) {
unsigned __int64 numerator = UInt32x32To64(fps_numerator, multiplier);
unsigned __int64 denominator = UInt32x32To64(fps_denominator, divisor);
unsigned __int64 x=numerator, y=denominator;
while (y) { unsigned __int64 t = x%y; x = y; y = t;
}
numerator /= x; denominator /= x;
unsigned __int64 temp = numerator | denominator; unsigned u = 0;
while (temp & 0xffffffff80000000) { temp = Int64ShrlMod32(temp, 1);
u++;
}
if (u) { const unsigned round = 1 << (u-1);
SetFPS( (unsigned)Int64ShrlMod32(numerator + round, u),
(unsigned)Int64ShrlMod32(denominator + round, u) );
}
else {
fps_numerator = (unsigned)numerator;
fps_denominator = (unsigned)denominator;
}
}
bool VideoInfo::IsSameColorspace(const VideoInfo& vi) const {
if (vi.pixel_type == pixel_type) return TRUE;
if (IsYV12() && vi.IsYV12()) return TRUE;
return FALSE;
}
int VideoInfo::NumComponents() const {
switch (pixel_type) {
case CS_UNKNOWN:
return 0;
case CS_RAW32:
case CS_Y8:
case CS_Y10:
case CS_Y12:
case CS_Y14:
case CS_Y16:
case CS_Y32:
return 1;
case CS_BGR32:
case CS_BGR64:
return 4; default:
return (IsYUVA() || IsPlanarRGBA()) ? 4 : 3;
}
}
int VideoInfo::ComponentSize() const {
if(IsPlanar()) {
const int componentSizes[8] = {1,2,4,0,0,2,2,2};
return componentSizes[(pixel_type >> CS_Shift_Sample_Bits) & 7];
}
switch (pixel_type) {
case CS_UNKNOWN:
return 0;
case CS_RAW32:
return 4;
case CS_BGR48:
case CS_BGR64:
return 2;
default: return 1;
}
}
int VideoInfo::BitsPerComponent() const {
if (pixel_type == CS_YUY2)
return 8;
else if (pixel_type == CS_RAW32)
return 32;
const int componentBitSizes[8] = {8,16,32,0,0,10,12,14};
return componentBitSizes[(pixel_type >> CS_Shift_Sample_Bits) & 7];
}
bool VideoInfo::Is444() const { return ((pixel_type & CS_PLANAR_MASK & ~CS_Sample_Bits_Mask) == (CS_GENERIC_YUV444 & CS_PLANAR_FILTER)) ||
((pixel_type & CS_PLANAR_MASK & ~CS_Sample_Bits_Mask) == (CS_GENERIC_YUVA444 & CS_PLANAR_FILTER)) ; }
bool VideoInfo::Is422() const { return ((pixel_type & CS_PLANAR_MASK & ~CS_Sample_Bits_Mask) == (CS_GENERIC_YUV422 & CS_PLANAR_FILTER)) ||
((pixel_type & CS_PLANAR_MASK & ~CS_Sample_Bits_Mask) == (CS_GENERIC_YUVA422 & CS_PLANAR_FILTER)); }
bool VideoInfo::Is420() const { return ((pixel_type & CS_PLANAR_MASK & ~CS_Sample_Bits_Mask) == (CS_GENERIC_YUV420 & CS_PLANAR_FILTER)) ||
((pixel_type & CS_PLANAR_MASK & ~CS_Sample_Bits_Mask) == (CS_GENERIC_YUVA420 & CS_PLANAR_FILTER)); }
bool VideoInfo::IsY() const { return (pixel_type & CS_PLANAR_MASK & ~CS_Sample_Bits_Mask) == (CS_GENERIC_Y & CS_PLANAR_FILTER); }
bool VideoInfo::IsRGB48() const { return ((pixel_type & CS_BGR24) == CS_BGR24) && ((pixel_type & CS_Sample_Bits_Mask) == CS_Sample_Bits_16); } bool VideoInfo::IsRGB64() const { return ((pixel_type & CS_BGR32) == CS_BGR32) && ((pixel_type & CS_Sample_Bits_Mask) == CS_Sample_Bits_16); }
bool VideoInfo::IsYUVA() const { return !!(pixel_type&CS_YUVA ); }
bool VideoInfo::IsPlanarRGB() const { return !!(pixel_type&CS_PLANAR) && !!(pixel_type&CS_BGR) && !!(pixel_type&CS_RGB_TYPE); }
bool VideoInfo::IsPlanarRGBA() const { return !!(pixel_type&CS_PLANAR) && !!(pixel_type&CS_BGR) && !!(pixel_type&CS_RGBA_TYPE); }
const BYTE* VideoFrameBuffer::GetReadPtr() const { return data; }
BYTE* VideoFrameBuffer::GetWritePtr() { InterlockedIncrement(&sequence_number); return data; }
int VideoFrameBuffer::GetDataSize() const { return data_size; }
int VideoFrameBuffer::GetSequenceNumber() const { return sequence_number; }
int VideoFrameBuffer::GetRefcount() const { return refcount; }
void VideoFrame::AddRef() { InterlockedIncrement(&refcount); }
void VideoFrame::Release() {
VideoFrameBuffer* _vfb = vfb;
if (!InterlockedDecrement(&refcount))
InterlockedDecrement(&_vfb->refcount);
}
int VideoFrame::GetPitch(int plane) const { switch (plane) { case PLANAR_U: case PLANAR_V: return pitchUV; case PLANAR_A: return pitchA; } return pitch; }
int VideoFrame::GetRowSize(int plane) const {
switch (plane) {
case PLANAR_U: case PLANAR_V: if (pitchUV) return row_sizeUV; else return 0;
case PLANAR_U_ALIGNED: case PLANAR_V_ALIGNED:
if (pitchUV) {
const int r = (row_sizeUV+FRAME_ALIGN-1)&(~(FRAME_ALIGN-1)); if (r<=pitchUV)
return r;
return row_sizeUV;
}
else return 0;
case PLANAR_ALIGNED: case PLANAR_Y_ALIGNED:
case PLANAR_R_ALIGNED: case PLANAR_G_ALIGNED: case PLANAR_B_ALIGNED:
{
const int r = (row_size+FRAME_ALIGN-1)&(~(FRAME_ALIGN-1)); if (r<=pitch)
return r;
return row_size;
}
case PLANAR_A:
if (pitchA) return row_sizeA; else return 0;
case PLANAR_A_ALIGNED:
if(pitchA) {
const int r = (row_sizeA+FRAME_ALIGN-1)&(~(FRAME_ALIGN-1)); if (r<=pitchA)
return r;
return row_sizeA;
}
else return 0;
}
return row_size; }
int VideoFrame::GetHeight(int plane) const {
switch (plane) {
case PLANAR_U: case PLANAR_V: if (pitchUV) return heightUV; return 0;
case PLANAR_A: if (pitchA) return height; return 0;
}
return height;
}
VideoFrameBuffer* VideoFrame::GetFrameBuffer() const { return vfb; }
size_t VideoFrame::GetOffset(int plane) const {
switch (plane) {
case PLANAR_U: case PLANAR_B: return offsetU; case PLANAR_V: case PLANAR_R: return offsetV;
case PLANAR_A: return offsetA;
default: return offset; };
}
const BYTE* VideoFrame::GetReadPtr(int plane) const { return vfb->GetReadPtr() + GetOffset(plane); }
bool VideoFrame::IsWritable() const {
if (refcount == 1 && vfb->refcount == 1) {
vfb->GetWritePtr(); return true;
}
return false;
}
BYTE* VideoFrame::GetWritePtr(int plane) const {
if (!plane || plane == PLANAR_Y || plane == PLANAR_G) { if (vfb->GetRefcount()>1) {
_ASSERT(FALSE);
}
return (refcount == 1 && vfb->refcount == 1) ? vfb->GetWritePtr() + GetOffset(plane) : 0;
}
return vfb->data + GetOffset(plane);
}
VideoFrame::~VideoFrame() { DESTRUCTOR(); }
void VideoFrame::DESTRUCTOR() { Release(); }
void IClip::AddRef() { InterlockedIncrement(&refcnt); }
void IClip::Release() { if (!InterlockedDecrement(&refcnt)) delete this; }
IClip* PClip::GetPointerWithAddRef() const { if (p) p->AddRef(); return p; }
void PClip::Init(IClip* x) {
if (x) x->AddRef();
p=x;
}
void PClip::Set(IClip* x) {
if (x) x->AddRef();
if (p) p->Release();
p=x;
}
PClip::PClip() { CONSTRUCTOR0(); }
void PClip::CONSTRUCTOR0() { p = 0; }
PClip::PClip(const PClip& x) { CONSTRUCTOR1(x); }
void PClip::CONSTRUCTOR1(const PClip& x) { Init(x.p); }
PClip::PClip(IClip* x) { CONSTRUCTOR2(x); }
void PClip::CONSTRUCTOR2(IClip* x) { Init(x); }
void PClip::operator=(IClip* x) { OPERATOR_ASSIGN0(x); }
void PClip::OPERATOR_ASSIGN0(IClip* x) { Set(x); }
void PClip::operator=(const PClip& x) { OPERATOR_ASSIGN1(x); }
void PClip::OPERATOR_ASSIGN1(const PClip& x) { Set(x.p); }
PClip::~PClip() { DESTRUCTOR(); }
void PClip::DESTRUCTOR() { if (p) p->Release(); }
void PVideoFrame::Init(VideoFrame* x) {
if (x) x->AddRef();
p=x;
}
void PVideoFrame::Set(VideoFrame* x) {
if (x) x->AddRef();
if (p) p->Release();
p=x;
}
PVideoFrame::PVideoFrame() { CONSTRUCTOR0(); }
void PVideoFrame::CONSTRUCTOR0() { p = 0; }
PVideoFrame::PVideoFrame(const PVideoFrame& x) { CONSTRUCTOR1(x); }
void PVideoFrame::CONSTRUCTOR1(const PVideoFrame& x) { Init(x.p); }
PVideoFrame::PVideoFrame(VideoFrame* x) { CONSTRUCTOR2(x); }
void PVideoFrame::CONSTRUCTOR2(VideoFrame* x) { Init(x); }
void PVideoFrame::operator=(VideoFrame* x) { OPERATOR_ASSIGN0(x); }
void PVideoFrame::OPERATOR_ASSIGN0(VideoFrame* x) { Set(x); }
void PVideoFrame::operator=(const PVideoFrame& x) { OPERATOR_ASSIGN1(x); }
void PVideoFrame::OPERATOR_ASSIGN1(const PVideoFrame& x) { Set(x.p); }
PVideoFrame::~PVideoFrame() { DESTRUCTOR(); }
void PVideoFrame::DESTRUCTOR() { if (p) p->Release(); }
AVSValue::AVSValue() { CONSTRUCTOR0(); }
void AVSValue::CONSTRUCTOR0() { type = 'v'; array_size = 0; clip = NULL; }
AVSValue::AVSValue(IClip* c) { CONSTRUCTOR1(c); }
void AVSValue::CONSTRUCTOR1(IClip* c) { type = 'c'; array_size = 0; clip = c; if (c) c->AddRef(); }
AVSValue::AVSValue(const PClip& c) { CONSTRUCTOR2(c); }
void AVSValue::CONSTRUCTOR2(const PClip& c) { type = 'c'; array_size = 0; clip = c.GetPointerWithAddRef(); }
AVSValue::AVSValue(bool b) { CONSTRUCTOR3(b); }
void AVSValue::CONSTRUCTOR3(bool b) { type = 'b'; array_size = 0; clip = NULL; boolean = b; }
AVSValue::AVSValue(int i) { CONSTRUCTOR4(i); }
void AVSValue::CONSTRUCTOR4(int i) { type = 'i'; array_size = 0; clip = NULL; integer = i; }
AVSValue::AVSValue(float f) { CONSTRUCTOR5(f); }
void AVSValue::CONSTRUCTOR5(float f) { type = 'f'; array_size = 0; clip = NULL; floating_pt = f; }
AVSValue::AVSValue(double f) { CONSTRUCTOR6(f); }
void AVSValue::CONSTRUCTOR6(double f) { type = 'f'; array_size = 0; clip = NULL; floating_pt = float(f); }
AVSValue::AVSValue(const char* s) { CONSTRUCTOR7(s); }
void AVSValue::CONSTRUCTOR7(const char* s) { type = 's'; array_size = 0; string = s; }
AVSValue::AVSValue(const AVSValue& a, int size) { CONSTRUCTOR8(&a, size); }
AVSValue::AVSValue(const AVSValue* a, int size) { CONSTRUCTOR8(a, size); }
void AVSValue::CONSTRUCTOR8(const AVSValue* a, int size)
{
type = 'a';
array_size = (short)size;
#ifndef NEW_AVSVALUE
array = a;
#else
if (a == nullptr || size == 0) {
array = nullptr;
}
else {
array = new AVSValue[size];
for (int i = 0; i < size; i++) {
const_cast<AVSValue *>(array)[i].Assign(&a[i], true); }
}
#endif
}
AVSValue::AVSValue(const AVSValue& v) { CONSTRUCTOR9(v); }
void AVSValue::CONSTRUCTOR9(const AVSValue& v) { Assign(&v, true); }
#ifdef NEW_AVSVALUE
AVSValue::AVSValue(const AVSValue& v, bool c_arrays) { CONSTRUCTOR10(v, c_arrays); }
void AVSValue::CONSTRUCTOR10(const AVSValue& v, bool c_arrays) { Assign2(&v, true, c_arrays); }
#endif
#ifndef NEW_AVSVALUE
AVSValue::~AVSValue() { DESTRUCTOR(); }
void AVSValue::DESTRUCTOR()
{
if (IsClip() && clip)
clip->Release();
}
#else
AVSValue::~AVSValue() { DESTRUCTOR(); }
void AVSValue::DESTRUCTOR()
{
if (IsClip() && clip)
clip->Release();
if (IsArray() && array_size>0) {
delete[] array; array = nullptr;
}
}
void AVSValue::MarkArrayAsC()
{
if(array_size > 0)
array_size = -array_size;
}
#endif
AVSValue& AVSValue::operator=(const AVSValue& v) { return OPERATOR_ASSIGN(v); }
AVSValue& AVSValue::OPERATOR_ASSIGN(const AVSValue& v) { Assign(&v, false); return *this; }
bool AVSValue::Defined() const { return type != 'v'; }
bool AVSValue::IsClip() const { return type == 'c'; }
bool AVSValue::IsBool() const { return type == 'b'; }
bool AVSValue::IsInt() const { return type == 'i'; }
bool AVSValue::IsFloat() const { return type == 'f' || type == 'i'; }
bool AVSValue::IsString() const { return type == 's'; }
bool AVSValue::IsArray() const { return type == 'a'; }
PClip AVSValue::AsClip() const { _ASSERTE(IsClip()); return IsClip()?clip:0; }
bool AVSValue::AsBool1() const { _ASSERTE(IsBool()); return boolean; }
bool AVSValue::AsBool() const { return AsBool1(); }
int AVSValue::AsInt1() const { _ASSERTE(IsInt()); return integer; }
int AVSValue::AsInt() const { return AsInt1(); }
const char* AVSValue::AsString1() const { _ASSERTE(IsString()); return IsString()?string:0; }
const char* AVSValue::AsString() const { return AVSValue::AsString1(); }
double AVSValue::AsFloat1() const { _ASSERTE(IsFloat()); return IsInt()?integer:floating_pt; }
double AVSValue::AsFloat() const { return AsFloat1(); }
float AVSValue::AsFloatf() const { return float( AsFloat1() ); }
bool AVSValue::AsBool2(bool def) const { _ASSERTE(IsBool()||!Defined()); return IsBool() ? boolean : def; }
bool AVSValue::AsBool(bool def) const { return AsBool2(def); }
int AVSValue::AsInt2(int def) const { _ASSERTE(IsInt()||!Defined()); return IsInt() ? integer : def; }
int AVSValue::AsInt(int def) const { return AsInt2(def); }
double AVSValue::AsDblDef(double def) const { _ASSERTE(IsFloat()||!Defined()); return IsInt() ? integer : type=='f' ? floating_pt : def; }
double AVSValue::AsFloat2(float def) const { _ASSERTE(IsFloat()||!Defined()); return IsInt() ? integer : type=='f' ? floating_pt : def; }
double AVSValue::AsFloat(float def) const { return AsFloat2(def); }
float AVSValue::AsFloatf(float def) const { return float( AsFloat2(def) ); }
const char* AVSValue::AsString2(const char* def) const { _ASSERTE(IsString()||!Defined()); return IsString() ? string : def; }
const char* AVSValue::AsString(const char* def) const { return AVSValue::AsString2(def); }
int AVSValue::ArraySize() const { _ASSERTE(IsArray()) ; return IsArray() ? array_size : 1; }
const AVSValue& AVSValue::operator[](int index) const { return OPERATOR_INDEX(index); }
const AVSValue& AVSValue::OPERATOR_INDEX(int index) const {
_ASSERTE(IsArray() && index>=0 && index<array_size);
return (IsArray() && index>=0 && index<array_size) ? array[index] : *this;
}
#ifndef NEW_AVSVALUE
void AVSValue::Assign(const AVSValue* src, bool init) {
if (src->IsClip() && src->clip)
src->clip->AddRef();
if (!init && IsClip() && clip)
clip->Release();
this->type = src->type;
this->array_size = src->array_size;
this->clip = src->clip; }
#else
void AVSValue::Assign(const AVSValue* src, bool init) {
Assign2(src, init, false);
}
void AVSValue::Assign2(const AVSValue* src, bool init, bool c_arrays) {
if (src->IsClip() && src->clip)
src->clip->AddRef();
if (c_arrays) {
if (!init && IsClip() && clip)
clip->Release();
this->type = src->type;
this->array_size = src->array_size;
this->clip = src->clip; return;
}
bool shouldRelease = !init && IsClip() && clip;
IClip *prev_clip_pointer = (IClip*)((void*)clip);
bool prevIsArray = IsArray();
bool nextIsArray = src->IsArray();
AVSValue* tmp;
short tmp_type = src->type;
short tmp_array_size = src->array_size;
IClip *tmp_pointer = (IClip*)((void*)src->clip);
bool needtmpcopy = nextIsArray && tmp_array_size>0;
if (needtmpcopy)
{
tmp = new AVSValue[tmp_array_size];
for (int i = 0; i < tmp_array_size; i++) {
tmp[i].Assign(&src->array[i], true); }
}
if (prevIsArray && !init)
{
if (array_size>0) {
delete[] array; array = nullptr;
}
}
if (nextIsArray) {
if (needtmpcopy)
array = tmp; else
array = nullptr;
this->type = tmp_type;
this->array_size = tmp_array_size;
}
else {
this->clip = tmp_pointer; this->type = tmp_type;
this->array_size = tmp_array_size; }
if (shouldRelease)
prev_clip_pointer->Release();
}
#endif
static const AVS_Linkage avs_linkage = {
sizeof(AVS_Linkage),
&VideoInfo::HasVideo, &VideoInfo::HasAudio, &VideoInfo::IsRGB, &VideoInfo::IsRGB24, &VideoInfo::IsRGB32, &VideoInfo::IsYUV, &VideoInfo::IsYUY2, &VideoInfo::IsYV24, &VideoInfo::IsYV16, &VideoInfo::IsYV12, &VideoInfo::IsYV411, &VideoInfo::IsY8, &VideoInfo::IsColorSpace, &VideoInfo::Is, &VideoInfo::IsPlanar, &VideoInfo::IsFieldBased, &VideoInfo::IsParityKnown, &VideoInfo::IsBFF, &VideoInfo::IsTFF, &VideoInfo::IsVPlaneFirst, &VideoInfo::BytesFromPixels, &VideoInfo::RowSize, &VideoInfo::BMPSize, &VideoInfo::AudioSamplesFromFrames, &VideoInfo::FramesFromAudioSamples, &VideoInfo::AudioSamplesFromBytes, &VideoInfo::BytesFromAudioSamples, &VideoInfo::AudioChannels, &VideoInfo::SampleType, &VideoInfo::IsSampleType, &VideoInfo::SamplesPerSecond, &VideoInfo::BytesPerAudioSample, &VideoInfo::SetFieldBased, &VideoInfo::Set, &VideoInfo::Clear, &VideoInfo::GetPlaneWidthSubsampling, &VideoInfo::GetPlaneHeightSubsampling, &VideoInfo::BitsPerPixel, &VideoInfo::BytesPerChannelSample, &VideoInfo::SetFPS, &VideoInfo::MulDivFPS, &VideoInfo::IsSameColorspace,
&VideoFrameBuffer::GetReadPtr, &VideoFrameBuffer::GetWritePtr, &VideoFrameBuffer::GetDataSize, &VideoFrameBuffer::GetSequenceNumber, &VideoFrameBuffer::GetRefcount,
&VideoFrame::GetPitch, &VideoFrame::GetRowSize, &VideoFrame::GetHeight, &VideoFrame::GetFrameBuffer, &VideoFrame::GetOffset, &VideoFrame::GetReadPtr, &VideoFrame::IsWritable, &VideoFrame::GetWritePtr, &VideoFrame::DESTRUCTOR,
&PClip::CONSTRUCTOR0, &PClip::CONSTRUCTOR1, &PClip::CONSTRUCTOR2, &PClip::OPERATOR_ASSIGN0, &PClip::OPERATOR_ASSIGN1, &PClip::DESTRUCTOR,
&PVideoFrame::CONSTRUCTOR0, &PVideoFrame::CONSTRUCTOR1, &PVideoFrame::CONSTRUCTOR2, &PVideoFrame::OPERATOR_ASSIGN0, &PVideoFrame::OPERATOR_ASSIGN1, &PVideoFrame::DESTRUCTOR,
&AVSValue::CONSTRUCTOR0, &AVSValue::CONSTRUCTOR1, &AVSValue::CONSTRUCTOR2, &AVSValue::CONSTRUCTOR3, &AVSValue::CONSTRUCTOR4, &AVSValue::CONSTRUCTOR5, &AVSValue::CONSTRUCTOR6, &AVSValue::CONSTRUCTOR7, &AVSValue::CONSTRUCTOR8, &AVSValue::CONSTRUCTOR9, &AVSValue::DESTRUCTOR, &AVSValue::OPERATOR_ASSIGN, &AVSValue::OPERATOR_INDEX, &AVSValue::Defined, &AVSValue::IsClip, &AVSValue::IsBool, &AVSValue::IsInt, &AVSValue::IsFloat, &AVSValue::IsString, &AVSValue::IsArray, &AVSValue::AsClip, &AVSValue::AsBool1, &AVSValue::AsInt1, &AVSValue::AsString1, &AVSValue::AsFloat1, &AVSValue::AsBool2, &AVSValue::AsInt2, &AVSValue::AsDblDef, &AVSValue::AsFloat2, &AVSValue::AsString2, &AVSValue::ArraySize,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&VideoInfo::NumComponents, &VideoInfo::ComponentSize, &VideoInfo::BitsPerComponent, &VideoInfo::Is444, &VideoInfo::Is422, &VideoInfo::Is420, &VideoInfo::IsY, &VideoInfo::IsRGB48, &VideoInfo::IsRGB64, &VideoInfo::IsYUVA, &VideoInfo::IsPlanarRGB, &VideoInfo::IsPlanarRGBA,
};
extern __declspec(dllexport) const AVS_Linkage* const AVS_linkage = &avs_linkage;
#if 0#endif