Skip to content

OBS.ImageSource

TheAndyRoid edited this page Nov 4, 2014 · 12 revisions

This is the Class that any custom Python source element must be derived from. This base class has several methods that should be overridden.
A blank template for a ImageSource is shown below:

def example(OBS.ImageSource):
    def __init__(self,config):
		pass
    def BeginScene(self):
        pass
    def EndScene():
	    pass
    def Render(self,pos,size):
		pass
    def Destructor(self):
        pass
	def GlobalSourcesLeaveScene(self):
		pass
	def GlobalSourcesEnterScene(self):
		pass
	def Tick(self):
		pass
	def UpdateSettings(self):
		pass
	def ChangeScene(self):
		pass

##User Overrides

__init__

ImageSource.__init__(self,config)

The Python constructor called when Source is first created.
Parameters:

  • config an OBS.XElement object

###EndScene #####ImageSource.EndScene(self)
Called when the source is no longer in the current Scene.
Happens when the source has been removed from the scene, the scene has changed or the source has been disabled. ###BeginScene #####ImageSource.BeginScene(self)
Called when the source first enters the current scene.
Happens after you switch to a new scene, a source is enabled or a new source has been added to the scene. ###Render #####ImageSource.Render(self,pos,size) Called every frame that the source is expected to render.
Parameters:

  • pos Top left position of the source OBS.Vect2
  • size Source width and height OBS.Vect2

###Tick #####ImageSource.Tick(self,seconds) This is called on a regular occurrence, but does not coincide with the rendering of a frame. Useful for updating elements that have an event loop. Parameters:

  • seconds Time between ticks

###Destructor #####ImageSource.Destructor(self)
This is the final call to a source that is about to be destroyed. ###GlobalSourcesLeaveScene #####ImageSource.GlobalSourcesLeaveScene(self)
Called when a global source is no longer in the current Scene
###GlobalSourcesEnterScene #####ImageSource.GlobalSourcesEnterScene(self)
Called when a global source enters the current scene ###UpdateSetting #####ImageSource.UpdateSetting(self) ###ChangeScene #####ImageSource.ChangeScene(self)

##Defined Methods ###SetBuffers
#####ImageSource.SetBuffers(bufA,bufB,bufferformat,width,height)
#####ImageSource.SetBuffers(bufA,bufferformat,width,height) Supported color formats are A,L,RGB,RGBA,BGR,BGRA
This plugin supports double buffering, when both bufA and bufB are supplied. bufA/bufB will be check for the correct size. Throws an exception.
bufA/bufB must be preallocated with their size unchanged for the duration of the sources life. You must set the buffers again if you wish to change their size.
Modifying the size of a buffer without setting the buffers again has undesirable results.

Parameters:

  • bufA Python pre-allocated bytearray
  • bufB Python pre-allocated bytearray
  • bufferformat Color format string
  • width Width of byte array
  • height Height of byte array

###DrawSprite #####ImageSource.DrawSprite(colour,posX,posY)
#####ImageSource.DrawSprite(colour,posX,posY,posX2,posY2)
#####ImageSource.DrawSprite(colour,posX,posY,posX2,posY2,u,w,u2,w2) Draws the data currently in the front buffer.
Parameters:

  • colour Render hex colour 0xffffffff (White) is most common.
  • posX,posY Top Left position to draw the source.
  • posX2,posY2 Bottom Right position to draw the source.
  • u,w,u2,w2 Texture Scaling

###GetCropping #####ImageSource.GetCropping() It is currently not possible to get the cropping of a global source, will throw an exception
Returns:

  • OBS.Vect4 - The cropping of the current source.

###SetCropping #####ImageSource.SetCropping(left,top,right,bottom) Parameters:

  • left Left crop
  • right Right crop
  • top Top crop
  • bottom Bottom crop

###FlipBuffers #####ImageSource.FlipBuffers()
This will flip the internal buffers for front and back buffer when using double buffering.
When using a single buffer this function will have no effect.
###GetBackBuffer #####ImageSource.GetBackBuffer()
Returns:

  • ByteArray This is the current back buffer.

###GetAddrBackBuffer #####ImageSource.GetAddrBackBuffer() This is useful for when you want to pass a Python library allocated memory.
Returns:

  • Integer - Memory address for the start of the back buffer.

###CopyToBackBuffer #####ImageSource.CopyToBackBuffer(addr) Useful for when you want to copy data to the buffer quickly using C. Parameters:

  • addr - Integer start address of the memory to be copied from into the back buffer.

###CreateHotKey #####ImageSource.CreateHotKey(key,function) It's best to use hex for the hot keys

Parameters:

  • key is the windows virtual key plus any modifier.
  • function this is the user defined function to call. prototype is hotkey(key,isdown)

Returns:

  • Integer - Id this is the hotkey id used for deletion.

###DeleteHotKey #####ImageSource.DeleteHotKey(id) Parameters:

  • id is the value returned when you created the hotkey
Clone this wiki locally