OMC::Cel Class Reference

Detailed Description

An object that contains a reference to a rendered cel (image) in the application.

This is generally provided from the Render Handler (OMH::HarmonyRenderHandler) when a slot or callback function is provided for the on_frame_ready event. The cel represents a rendered image in memory, and provides tools to export it to a file format as needed.

A Render Handler with a Frame-Ready Callback

from PySide6.QtGui import QPixmap, QScreen
from PySide6.QtWidgets import QApplication, QWidget, QLabel, QSizePolicy, QVBoxLayout
import tempfile
import math
import os
from ToonBoom import harmony #Import the Harmony Module
#Helper Class to Render the Results into -- this is pure PySide Qt
class ImageShow(QWidget):
def __init__(self):
super().__init__()
self.init()
def init(self):
self.setWindowTitle( "Render-Tester" )
self.label = QLabel(self)
self.pixmap = QPixmap()
def setImage(self, path, title, frame, count):
self.setWindowTitle( title )
frmn = frame-1 #0-indexed frame
squared = int(math.sqrt(count)+0.5)
offsetx = frmn%squared
offsety = int(frmn/squared)
screenSize = QScreen.availableGeometry( QApplication.primaryScreen() )
width_target = screenSize.width()/squared
height_target = screenSize.height()/squared
self.resize( width_target, height_target )
self.pixmap.load( path )
self.label.setPixmap( self.pixmap.scaled( self.width(), self.height() ) );
frmX = ( screenSize.width () - self.width () ) / 2.0
frmY = ( screenSize.height() - self.height() ) / 2.0
self.move( offsetx*width_target, offsety*height_target )
self.show()
def resizeEvent( self, event ):
self.label.setPixmap( self.pixmap.scaled( self.width(), self.height() ) )
self.label.resize( self.width(), self.height() )
sess = harmony.session() #Get access to the Harmony session, this class.
proj = sess.project #Get the active session's currently loaded project.
scene = proj.scene #Get the top scene in the project.
nodes = scene.nodes
readnode = False
#This will keep the displayers alive -- otherwise they'll open and close as it leaves the method.
displayers = []
#Find the first avbailable read node.
for node in nodes:
if node.type.upper() == "READ":
readnode = node
break
if readnode:
print( "Rendering %s"%(readnode.path) )
renderhandler = proj.create_render_handler() #Create a new render handler.
frame_count = 25
def renderhandler_ready_frame( node, frame, cel ): #This will be the callback function
displayer = ImageShow() #A helper utility for showing the rendered images.
displayers.append( displayer ) #Keep it alive.
print( "Frame Ready : %s at %s"%(node.path, frame) )
#The callback provides a frame.
frame_output = os.path.join( tempfile.gettempdir(), "%s.%05d.png"%(node.name, frame) )
print( "Saving to: %s"%(frame_output) )
cel.write( frame_output ) #Write the cel to a temp directory.
#Show it!
displayer.setImage( frame_output, "%s at %s"%(node.path, frame), frame, frame_count )
renderhandler.frame_ready_callback = renderhandler_ready_frame #Add the callback function to the handler.
renderhandler.node_add( readnode ) #Add the readnode to the list of nodes to render.
renderhandler.render( 1, frame_count ) #Render the frames 1-10
else:
print( "Unable to find a Read Node to render." )

Files

OMC::Rect2Dallocated_rect
 Retrieve allocated area of sparse image. Is equal to full area for non-sparse images. Allocated rect. 4-tuple (x1, y1, width, height).
 
OMC::Rect2Drect
 Retrieve full area of image. Full rect. 4-tuple (x1, y1, width, height).
 
bool cel3D
 True if the cel a 3D cel.
 
QString write () const
 
void write (const QString &path) const
 Get a permanent copy of cel image file of specific format. More...
 
void write (const QString &path, const QString &formatstring, const QString &optionstring) const
 Get a permanent copy of cel image file of specific format. More...
 

Member Function Documentation

◆ write() [1/3]

QString OMC::Cel::write ( ) const

Get a permanent copy of cel image file. This function without parameters is valid only for ports that point to a physically valid file on disk.

◆ write() [2/3]

void OMC::Cel::write ( const QString &  path) const

Get a permanent copy of cel image file of specific format.

Parameters
pathFile path to the file to create

◆ write() [3/3]

void OMC::Cel::write ( const QString &  path,
const QString &  formatstring,
const QString &  optionstring 
) const

Get a permanent copy of cel image file of specific format.

Parameters
pathFile path to the file to create
formatstringFormat to convert image into
optionstringImage extension specific option (ie. TGA, TGA3, TGA4, SGIDP)
Inheritance diagram for OMC::Cel:
Collaboration diagram for OMC::Cel: