Small colorspace related code

Originally committed to SVN as r305.
This commit is contained in:
Rodrigo Braz Monteiro 2006-04-04 20:58:20 +00:00
parent 5e9c0aad16
commit c57d6fe5e1
3 changed files with 32 additions and 8 deletions

View File

@ -85,10 +85,16 @@ PVideoFrame __stdcall DrawPRS::GetFrame(int n, IScriptEnvironment* env) {
frame.w = avsFrame->GetRowSize()/4; frame.w = avsFrame->GetRowSize()/4;
frame.h = avsFrame->GetHeight(); frame.h = avsFrame->GetHeight();
frame.pitch = avsFrame->GetPitch(); frame.pitch = avsFrame->GetPitch();
frame.colorSpace = ColorSpace_RGB32;
frame.flipColors = true; frame.flipColors = true;
frame.flipVertical = true; frame.flipVertical = true;
// Set colorspace
VideoInfo vi = child->GetVideoInfo();
if (vi.IsYV12()) frame.colorSpace = ColorSpace_YV12;
else if (vi.IsYUY2()) frame.colorSpace = ColorSpace_YUY2;
else if (vi.IsRGB32()) frame.colorSpace = ColorSpace_RGB32;
else if (vi.IsRGB24()) frame.colorSpace = ColorSpace_RGB24;
// Draw into the frame // Draw into the frame
file.DrawFrame(n,&frame); file.DrawFrame(n,&frame);
} }

View File

@ -119,16 +119,16 @@ Start and end frame numbers are both inclusive.
0x1B blend mode (8 bit unsigned) 0x1B blend mode (8 bit unsigned)
Alpha multiplier: Alpha multiplier:
0x00 is "invisible",0xFF is "fully visible". This value is multiplied onto 0x00 is "invisible", 0xFF is "fully visible". This value is multiplied onto
the alpha value of each pixel in the image to get the actual alpha value for the alpha value of each pixel in the image to get the actual alpha value for
that pixel. that pixel, that is: finalAlpha = pixelAlpha * globalAlpha / 255;
Blend modes: Blend modes:
0 none (dest*(1-alpha) + src*alpha) 0 none (src*alpha + dest*(1-alpha))
1 add (dest*(1-alpha) + (src+dest)*alpha) 1 add (src*alpha + dest)
2 subtract (dest*(1-alpha) + (src-dest)*alpha) 2 subtract (dest - src*alpha);
3 inverse subtract (dest*(1-alpha) + (dest-src)*alpha) 3 inverse subtract (src*alpha - dest) (is this it?)
4 multiply (dest*(1-alpha) + src*dest*alpha) 4 multiply (src*alpha * dst / 255)
Values are clipped before they are multiplied with alpha. Values are clipped before they are multiplied with alpha.
Layers: Layers:

View File

@ -77,6 +77,8 @@ PRSVideoFrame::~PRSVideoFrame () {
/////////////////////////////////// ///////////////////////////////////
// Overlay frame on top of another // Overlay frame on top of another
// This function could get some optimization/assembly love
// Also, perhaps using "(x+1) >> 8" instead of "x / 255" should be considered.
void PRSVideoFrame::Overlay(PRSVideoFrame *dstFrame,int x,int y,unsigned char alpha,unsigned char blend) { 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! // TODO: Colorspace conversion, for now, the function assumes RGB32 on RGB32!
@ -155,6 +157,22 @@ void PRSVideoFrame::Overlay(PRSVideoFrame *dstFrame,int x,int y,unsigned char al
*dst++ = MAX(0,(int(dc3) - sc3*a)/255); *dst++ = MAX(0,(int(dc3) - sc3*a)/255);
*dst++ = 255-(ia*(255-da)/255); // Is this correct? *dst++ = 255-(ia*(255-da)/255); // Is this correct?
} }
// Inverse subtract blend
else if (blend == 3) {
*dst++ = MAX(0,(sc1*a - int(dc1))/255);
*dst++ = MAX(0,(sc2*a - int(dc2))/255);
*dst++ = MAX(0,(sc3*a - int(dc3))/255);
*dst++ = 255-(ia*(255-da)/255); // Is this correct?
}
// Multiply blend
else if (blend == 4) {
*dst++ = MIN(255,(int(sc1)*a * int(dc1) / 255)/255);
*dst++ = MIN(255,(int(sc2)*a * int(dc2) / 255)/255);
*dst++ = MIN(255,(int(sc3)*a * int(dc3) / 255)/255);
*dst++ = 255-(ia*(255-da)/255); // Is this correct?
}
} }
} }
} }