video frame improvement
Originally committed to SVN as r904.
This commit is contained in:
parent
e07a71368b
commit
420ac447ee
3 changed files with 28 additions and 25 deletions
|
@ -45,8 +45,8 @@ AegiVideoFrame::AegiVideoFrame() {
|
||||||
for (int i=0;i<4;i++) {
|
for (int i=0;i<4;i++) {
|
||||||
data[i] = NULL;
|
data[i] = NULL;
|
||||||
pitch[i] = 0;
|
pitch[i] = 0;
|
||||||
memSize[i] = 0;
|
|
||||||
}
|
}
|
||||||
|
memSize = 0;
|
||||||
w = 0;
|
w = 0;
|
||||||
h = 0;
|
h = 0;
|
||||||
format = FORMAT_RGB24;
|
format = FORMAT_RGB24;
|
||||||
|
@ -78,18 +78,24 @@ AegiVideoFrame::AegiVideoFrame(int width,int height,VideoFrameFormat fmt) {
|
||||||
////////////
|
////////////
|
||||||
// Allocate
|
// Allocate
|
||||||
void AegiVideoFrame::Allocate() {
|
void AegiVideoFrame::Allocate() {
|
||||||
for (int i=0;i<4;i++) {
|
|
||||||
// Get size
|
// Get size
|
||||||
int height = h;
|
int height = h;
|
||||||
if (format == FORMAT_YV12 && i > 0) height/=2;
|
unsigned int size = pitch[0]*height;
|
||||||
unsigned int size = pitch[i]*height;
|
if (format == FORMAT_YV12) size = size * 3 / 2;
|
||||||
|
else size = size * GetBpp();
|
||||||
|
|
||||||
// Reallocate, if necessary
|
// Reallocate, if necessary
|
||||||
if (memSize[i] != size) {
|
if (memSize != size) {
|
||||||
if (cppAlloc) delete[] data[i];
|
if (cppAlloc) delete[] data[0];
|
||||||
else free(data[i]);
|
else free(data[0]);
|
||||||
data[i] = new unsigned char[size];
|
data[0] = new unsigned char[size];
|
||||||
memSize[i] = size;
|
for (int i=1;i<4;i++) data[i] = NULL;
|
||||||
|
memSize = size;
|
||||||
|
|
||||||
|
// Planar
|
||||||
|
if (format == FORMAT_YV12) {
|
||||||
|
data[1] = data[0] + (pitch[0]*height);
|
||||||
|
data[2] = data[0] + (pitch[0]*height*5/4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,14 +106,13 @@ void AegiVideoFrame::Allocate() {
|
||||||
/////////
|
/////////
|
||||||
// Clear
|
// Clear
|
||||||
void AegiVideoFrame::Clear() {
|
void AegiVideoFrame::Clear() {
|
||||||
|
if (cppAlloc) delete[] data[0];
|
||||||
|
else free(data[0]);
|
||||||
for (int i=0;i<4;i++) {
|
for (int i=0;i<4;i++) {
|
||||||
if (data[i]) {
|
|
||||||
if (cppAlloc) delete[] data[i];
|
|
||||||
else free(data[i]);
|
|
||||||
data[i] = NULL;
|
data[i] = NULL;
|
||||||
}
|
|
||||||
pitch[i] = 0;
|
pitch[i] = 0;
|
||||||
}
|
}
|
||||||
|
memSize = 0;
|
||||||
w = 0;
|
w = 0;
|
||||||
h = 0;
|
h = 0;
|
||||||
format = FORMAT_RGB24;
|
format = FORMAT_RGB24;
|
||||||
|
@ -125,9 +130,7 @@ void AegiVideoFrame::CopyFrom(const AegiVideoFrame &source) {
|
||||||
format = source.format;
|
format = source.format;
|
||||||
for (int i=0;i<4;i++) pitch[i] = source.pitch[i];
|
for (int i=0;i<4;i++) pitch[i] = source.pitch[i];
|
||||||
Allocate();
|
Allocate();
|
||||||
for (int i=0;i<4;i++) {
|
memcpy(data[0],source.data[0],memSize);
|
||||||
memcpy(data[i],source.data[i],memSize[i]);
|
|
||||||
}
|
|
||||||
flipped = source.flipped;
|
flipped = source.flipped;
|
||||||
invertChannels = source.invertChannels;
|
invertChannels = source.invertChannels;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ enum VideoFrameFormat {
|
||||||
// Video Frame class
|
// Video Frame class
|
||||||
class AegiVideoFrame {
|
class AegiVideoFrame {
|
||||||
private:
|
private:
|
||||||
unsigned int memSize[4];
|
unsigned int memSize;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
unsigned char *data[4]; // Pointers to the data planes. Interleaved formats only use data[0]
|
unsigned char *data[4]; // Pointers to the data planes. Interleaved formats only use data[0]
|
||||||
|
|
|
@ -429,14 +429,14 @@ void DirectShowVideoProvider::ReadFrame(long long timestamp, unsigned format, un
|
||||||
|
|
||||||
// Interleaved
|
// Interleaved
|
||||||
else {
|
else {
|
||||||
unsigned int datalen = stride*height;
|
|
||||||
df->frame.Allocate();
|
|
||||||
memcpy(df->frame.data[0],src,datalen);
|
|
||||||
|
|
||||||
// Set format
|
// Set format
|
||||||
if (format == IVS_RGB24) df->frame.format = FORMAT_RGB24;
|
if (format == IVS_RGB24) df->frame.format = FORMAT_RGB24;
|
||||||
else if (format == IVS_RGB32) df->frame.format = FORMAT_RGB32;
|
else if (format == IVS_RGB32) df->frame.format = FORMAT_RGB32;
|
||||||
else if (format == IVS_YV12) df->frame.format = FORMAT_YV12;
|
else if (format == IVS_YV12) df->frame.format = FORMAT_YV12;
|
||||||
|
|
||||||
|
unsigned int datalen = stride*height;
|
||||||
|
df->frame.Allocate();
|
||||||
|
memcpy(df->frame.data[0],src,datalen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue