Don't expect much. You may want to ignore first two steps.
1)Removed the "x"variable because it appears useless.
2)Removed p: PBGRAPixel; variable because it's used only once and replaced
"p := FVideoBufferBitmap.Scanline[y];
Move(buffer, p, FWidth*4);"
with
"Move(buffer, FVideoBufferBitmap.Scanline[y], FWidth*4);"
3) Replace "frame := Rect(0, 0, Self.Width, Self.Height - Self.StBr_Name.Height);" with
frame.Left:=0;frame.Top:=0;frame.Right:=Self.Width;frame.Bottom:=Self.Height - Self.StBr_Name.Height;
4) Add variable "FWidthx4:integer;",
add line "FWidthx4:=FWidth*4;" before "bufferAllign := FStride - FWidth*4;" and replace all following "FWidth*4" with FWidthx4(including the loop);
procedure TFrm_Preview.FormPaint(Sender: TObject);
var
y: integer;
FWidthx4:integer;
buffer: PChar;
bufferAllign: Integer;
frame: TRect;
formSizeBitmap: TBGRABitmap;
begin
if not (csDestroying in ComponentState) then
if (Self.Visible) and (not Img_Overlay.Visible) and (FWidth > 0) and (FHeight > 0) then
begin
EnterCriticalSection(FCritSection); //ACQUIRE
if (FVideoBufferBitmap = nil) then
FVideoBufferBitmap := TBGRABitmap.Create(FWidth, FHeight)
else if (FVideoBufferBitmap.Width <> FWidth) or (FVideoBufferBitmap.Height <> FHeight) then
begin
FVideoBufferBitmap.Free;
FVideoBufferBitmap := TBGRABitmap.Create(FWidth, FHeight)
end;
buffer := FVideoBuffer;
FWidthx4:=FWidth*4;
bufferAllign := FStride - FWidthx4;
//frame := Rect(0, 0, Self.Width, Self.Height - Self.StBr_Name.Height);
frame.Left:=0;frame.Top:=0;frame.Right:=Self.Width;frame.Bottom:=Self.Height - Self.StBr_Name.Height;
if (bufferAllign = 0) then
begin
if (FVideoBufferPtrBitmap = nil) then
FVideoBufferPtrBitmap := TBGRAPtrBitmap.Create(FWidth, FHeight, buffer)
else if (FVideoBufferPtrBitmap.Width <> FWidth) or (FVideoBufferPtrBitmap.Height <> FHeight) then
begin
FVideoBufferPtrBitmap.Free;
FVideoBufferPtrBitmap := TBGRAPtrBitmap.Create(FWidth, FHeight, buffer)
end
else
FVideoBufferPtrBitmap.SetDataPtr(buffer);
FVideoBufferBitmap.PutImage(0, 0, FVideoBufferPtrBitmap, dmSet, 255);
end
else
begin
for y := 0 to FVideoBufferBitmap.Height-1 do
begin
//p := FVideoBufferBitmap.Scanline[y];
//Move(buffer, p, FWidth*4);
Move(buffer, FVideoBufferBitmap.Scanline[y], FWidthx4);
buffer += FWidthx4 + bufferAllign;
end;
FVideoBufferBitmap.InvalidateBitmap; // changed by direct access
end;
LeaveCriticalSection(FCritSection); //RELEASE
if (Self.Tag = TAG_PREVIEW_FRM) then
FVideoBufferBitmap.HorizontalFlip;
FVideoBufferBitmap.Draw(Canvas, frame, True);
end;
end;