performance texture painting

what i have done is this:
Its painting on a texture with PNMPainter

from pandac.PandaModules import *
from direct.directbase.DirectStart import *
from direct.task import Task
import ctypes

tex = loader.loadTexture("hex.jpg")

i=0
d=0
val=3
myEmptyImage = PNMImage(1024,1024)
painter=PNMPainter(myEmptyImage) 
painter.setPen(PNMBrush.makePixel((1,0,0,0.1)))
tex.load(myEmptyImage)

##add a rotating box
dummy = render.attachNewNode('dummy') 
dummy.setPos(0, 0, 0) 
box=loader.loadModel("models/box")
box.setPos(-1.5,-1.5,-1.5)
box.setScale(3,3,3)
box.reparentTo(dummy)
dummy.hprInterval(9.2,Point3(-360,360,0), startHpr=Point3(0,0,0)).loop()

def SpinCameraTask(task):
	global i,d,val

	if i>355:
		i=0
		d=d+1
		
	if d>0:
		d=0
		if val==1:
			painter.setPen(PNMBrush.makePixel((1,0,0,0.3)))
			val=2
		elif val==2:
			painter.setPen(PNMBrush.makePixel((0,0,1,0.3)))
			val=3
		else:
			val=1
			painter.setPen(PNMBrush.makePixel((0,1,0,0.3)))

	painter.drawLine(0,i>>2,1024,i+i)
	painter.drawLine(0,i>>2,1024,i+i*2)
	painter.drawLine(0,i>>2,1024,i+i*4)

	painter.drawLine(0,i+i,1024,i>>2)
	painter.drawLine(0,i+i*2,1024,i>>2)
	painter.drawLine(0,i+i*4,1024,i>>2)


	tex.load(myEmptyImage)
	i=i+2
	return Task.cont

taskMgr.add(SpinCameraTask, "SpinCameraTask")

base.camera.setPos(10,10,10)
base.camera.lookAt(0,0,0)
base.disableMouse()
box.setTexture(tex,1)

run()

it seems to get quite slow if the texture gets very large.
especially the loading:

tex.load(myEmptyImage)

takes a bit time.
is it possible to do this faster?

The faster solution is to paint directly onto the texture image itself, avoiding the use of PNMImage and PNMPainter. Currently, there are no features in Panda to make this easy for you (though there is some work in progress to integrate a new library for a future release).

David