Avisynth filter is complete, but untested, which probably means that it will crash imediately.

Originally committed to SVN as r276.
This commit is contained in:
Rodrigo Braz Monteiro 2006-04-01 12:08:45 +00:00
parent edec701f82
commit b1f6012762
3 changed files with 65 additions and 3 deletions

View file

@ -258,7 +258,7 @@ void PRSFile::DrawFrame(int n,PRSVideoFrame *frame) {
PRSVideoFrame *overFrame = image->GetDecodedFrame();
// Draw image on frame
// TODO
if (overFrame) overFrame->Overlay(frame,display->x,display->y,display->alpha,display->blend);
// Clean up
delete overFrame;

View file

@ -39,6 +39,21 @@
#include "prs_video_frame.h"
//////////
// Macros
#ifndef MIN
#define MIN(a,b) ((a)<(b))?(a):(b)
#endif
#ifndef MAX
#define MAX(a,b) ((a)>(b))?(a):(b)
#endif
#ifndef MID
#define MID(a,b,c) MAX(a,MIN(b,c))
#endif
///////////////
// Constructor
PRSVideoFrame::PRSVideoFrame () {
@ -60,5 +75,52 @@ PRSVideoFrame::~PRSVideoFrame () {
///////////////////////////////////
// Overlay frame on top of another
void PRSVideoFrame::Overlay(PRSVideoFrame *dst,int x,int y,unsigned char alpha) {
void PRSVideoFrame::Overlay(PRSVideoFrame *dstFrame,int x,int y,unsigned char alpha,unsigned char blend) {
// TODO: Colorspace conversion, for now, the function assumes RGB32 on RGB32!
// Get pointers
const unsigned char *src;
unsigned char *dst;
// Get boundaries
int srcBpp = 4;
int dstBpp = 4;
int srcRowLen = w * srcBpp;
int dstRowLen = dstFrame->w * dstBpp;
int dstStarty = MAX(0,y);
int dstEndy = MIN(y+h,dstFrame->h);
int height = dstEndy - dstStarty;
int rowLen = MID(0,w,dstFrame->w - x);
// Values
char sc1,sc2,sc3,a,ia;
char dc1,dc2,dc3,da;
// Draw each row
for (int j=0;j<height;j++) {
src = (const unsigned char *) data[0] + j*srcRowLen;
dst = (unsigned char *) dstFrame->data[0] + (j+dstStarty)*dstRowLen + x*dstBpp;
// Draw the row
for (int i=0;i<rowLen;i++) {
// Read alpha
a = *src++;
da = *dst;
ia = 255-a;
// Read colors
sc1 = *src++;
dc1 = *(dst+1);
sc2 = *src++;
dc2 = *(dst+2);
sc3 = *src++;
dc3 = *(dst+3);
// Write colors
*dst++ = da;
*dst++ = (sc1*a + dc1*ia)/255;
*dst++ = (sc2*a + dc2*ia)/255;
*dst++ = (sc3*a + dc3*ia)/255;
}
}
}

View file

@ -60,5 +60,5 @@ public:
PRSVideoFrame();
~PRSVideoFrame();
void Overlay(PRSVideoFrame *dst,int x,int y,unsigned char alpha=255);
void Overlay(PRSVideoFrame *dst,int x,int y,unsigned char alpha=255,unsigned char blend=0);
};