Move data between two drawingbuffers

Just starting out? Need help? Post your questions and find answers here.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Move data between two drawingbuffers

Post by wilbert »

Is there any way to work directly with two drawingbuffers ?
Read from one, write to the other (source and target image).
As far as I know you can only access one at a time. :?
Windows (x64)
Raspberry Pi OS (Arm64)
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Move data between two drawingbuffers

Post by Fred »

No, it's not possible, you will have to have a third buffer in between.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Move data between two drawingbuffers

Post by netmaestro »

I must say it does get frustrating when beginners try to answer questions that are above their skill level... :lol: :lol: :lol:

Code: Select all

CompilerIf #PB_Compiler_Thread = 0
  MessageRequester( "OOPS!", "Please compile threadsafe And try again :)" )
CompilerEndIf

Structure ImageData
  *address
  size.i
EndStructure

Declare WorkerBee(*void)

CreateImage( 0, 256, 256, 24, RGB( 255, 0, 0 ) ) ; Image 0 is red
CreateImage( 1, 256, 256, 24, RGB( 0, 0, 255 ) ) ; Image 1 starts out blue

StartDrawing( ImageOutput(0) )
  *imagedata.ImageData = AllocateMemory( SizeOf( ImageData ) )
  With *imagedata
    \address = DrawingBuffer()
    \size    = DrawingBufferPitch() * ImageHeight( 0 )
  EndWith
  tid = CreateThread( @WorkerBee(), *imagedata )
  WaitThread( tid )
StopDrawing()

OpenWindow(0,0,0,256,256,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0, 0, 0, 256, 256, ImageID(1) ) ; Image 1 should show red now
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow

Procedure WorkerBee(*this.ImageData)
  StartDrawing( ImageOutput(1) )
    *that = DrawingBuffer()
    CopyMemory( *this\address, *that, *this\size )
  StopDrawing()
EndProcedure
I couldn't resist it, Fred, don't doofus me ok? :mrgreen:
BERESHEIT
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Move data between two drawingbuffers

Post by wilbert »

Wow, that's a clever solution netmaestro :shock: :D
I never thought of the idea to use a second thread.
Great idea and it seems to be working cross platform as well.
Windows (x64)
Raspberry Pi OS (Arm64)
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Move data between two drawingbuffers

Post by Fred »

:oops:

You're indeed right, each thread has its own context, so it's perfectly legit code !
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Move data between two drawingbuffers

Post by srod »

hehe. Bloody amateurs! :lol:
I may look like a mule, but I'm not a complete ass.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Move data between two drawingbuffers

Post by Fred »

stop laughing damit !! :lol:
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Move data between two drawingbuffers

Post by DontTalkToMe »

It's even hinted in the docs :lol:
help wrote: If "Create thread-safe executable" is enabled in the compiler options then every thread has its own current drawing output, which means two threads can do drawing on separate outputs at the same time.
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Move data between two drawingbuffers

Post by Joris »

What are the benefits of being able to do this ?
(I don't understand netmaestro's sample quit well...)

Thanks.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Move data between two drawingbuffers

Post by wilbert »

Joris wrote:What are the benefits of being able to do this ?
(I don't understand netmaestro's sample quit well...)
Speed and memory usage.
If you can copy something directly Src -> Dst, it's faster compared to Src -> Tmp -> Dst and you don't need the memory Tmp would occupy.
Windows (x64)
Raspberry Pi OS (Arm64)
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Move data between two drawingbuffers

Post by Joris »

Ha okay. Thanks Wilbert.

I began thinking about access for two users at the same time to a drawings surface...
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply