Page 1 of 1

How to avoid copying frame bitmap and use pointer to data instead

Posted: Thu Aug 20, 2020 11:53 am
by ya_vanka
Got one more question.

At some moment this update was done: https://www.trichview.com/forums/viewto ... 950#p36950

This should have made possible not to copy frame bitmap.


I have a working code:

Code: Select all

FLastFrame: TRVMBitmap;

procedure TVideoDlgForm2.RVCamera1GetImage(Sender: TObject; img: TRVMBitmap);
begin
  LastGotVideoData := MyNowEx;

  FVideoWidth := img.Width;
  FVideoHeight := img.Height;

  FLastFrame.AssignRVMBitmap(img);
end;

function TVideoDlgForm2.VideoData : PByte;
begin
  Result := Pointer(FLastFrame.Data);
end;



procedure TGLVideoToolWin.DoPaint;
if (VideoDlgForm2.VideoData <> nil) then
begin
  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VideoDlgForm2.FVideoWidth, VideoDlgForm2.FVideoHeight, GL_BGRA, GL_UNSIGNED_BYTE, VideoDlgForm2.VideoData);
  DrawTexture2DAtPos(0, 0, FVideoTexPart.TexPart, true);
end;

But want to remove FLastFrame.AssignRVMBitmap(img).
Tried to use pointer variable:

Code: Select all

PImgBuffer : Pointer;

procedure TVideoDlgForm2.RVCamera1GetImage(Sender: TObject; img: TRVMBitmap);
begin
  LastGotVideoData := MyNowEx;

  FVideoWidth := img.Width;
  FVideoHeight := img.Height;

  PImgBuffer := Pointer(img.Data);
end;

function TVideoDlgForm2.VideoData : PByte;
begin
  Result := PImgBuffer;
end;



procedure TGLVideoToolWin.DoPaint;
if (VideoDlgForm2.VideoData <> nil) then
begin
  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VideoDlgForm2.FVideoWidth, VideoDlgForm2.FVideoHeight, GL_BGRA, GL_UNSIGNED_BYTE, VideoDlgForm2.VideoData);
  DrawTexture2DAtPos(0, 0, FVideoTexPart.TexPart, true);
end;
But that didn't work.

Procedure TGLVideoToolWin.DoPaint; is called not from RVCamera1GetImage, but on getting user message signalizing that a window should be repainted.

How can I avoid FLastFrame.AssignRVMBitmap(img) correctly?

And is it worth removing (I mean will it increase performance significantly in case of HD ready or Full HD video)?