[Bf-python] Copying transparent images.

Gert De Roost gertderoost at telenet.be
Sat Dec 12 10:31:58 CET 2009


I am busy writing a image manipulation script and for this I need to be
able to copy Images.
This way I can work non-destructively on images.
Also I need to make multiple copies of a fully transparent Image for
doing overlays onscreen.
Blender does not provide functionality for this.  Also the
copy.copy(image) and copy.deepcopy(image) fail with the following error
message:  TypeError: object.__new__(Blender Image) is not safe, use
Blender Image.__new__().

As a workaround I was thinking about saving the images and then loading
them again every time I need an Image copy.  Problem is I make a new
Image containing alpha information and Blender saves without alpha
information.  So this workaround also does not work.

Last trick I was trying was by using OpenGL textures and assigning
buffers to them containing transparent data.
I must be doing something wrong though.  As example this code:

pixels = width * height
whitelist = []
for p in range(pixels/2):
  whitelist.append([1.0, 0.0, 0.0, 0.5])
for p in range(pixels/2):
  whitelist.append([0.0, 0.0, 1.0, 0.5])

namebuffer = Buffer(GL_INT, 1)
glGenTextures(1, namebuffer)
buffer = Buffer(GL_FLOAT, [pixels, 4], whitelist)
#  I checked the buffer, it contains the right values.

glColor4f(1.0, 1.0, 1.0, 1.0)
glEnable(GL_TEXTURE_2D)
glEnable(GL_BLEND)
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glBindTexture(GL_TEXTURE_2D, namebuffer[0])
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_FLOAT, buffer)
glBegin(GL_QUADS)
glTexCoord2f(0.0,0.0)
glVertex2f(0.0,height)
glTexCoord2f(1.0,0.0)
glVertex2f(width/2.0,height)
glTexCoord2f(1.0,1.0)
glVertex2f(width/2.0,0.0)
glTexCoord2f(0.0,1.0)
glVertex2f(0.0,0.0)
glEnd()
glDisable(GL_BLEND)
glDisable(GL_TEXTURE_2D)


This should give me a light red and light blue band, but it just
displays the standart colour white.
Don't know what I am doing wrong...


So what I am asking, if noone knows how to correct the above code, is if
it would be possible to add copying support for Image objects, either by
enabling copy.copy() or by adding support to the API.  Also image.save()
should support alpha.







More information about the Bf-python mailing list