#!BPY
"""
Name: 'bleed'
Blender: 249
Group: 'Image'
Tooltip: 'extend pixels at uv-borders'
"""
import Blender
from Blender import Image
background = [1.0,1.0,1.0,1.0] # white
#--------------------------------------------------------------------------------
def clamp(x, a, b):
if x < a: return a
if x > b: return b
return x
#--------------------------------------------------------------------------------
def bleed(image, passes):
print "extending pixels..."
width, height = image.getMaxXY()
def processpixel(x, y, ox, oy, image, original):
ox = clamp(x + ox, 0, width - 1)
oy = clamp(y + oy, 0, height - 1)
c = image.getPixelF(ox, oy)
if original[oy*width+ox] and c != background:
image.setPixelF(x, y, c)
return True
return False
for p in range(passes):
print " pass", p
original = []
for y in range(height):
for x in range(width):
if image.getPixelF(x, y) == background:
original.append(False)
else:
original.append(True)
for y in range(height):
for x in range(width):
if image.getPixelF(x, y) == background:
if processpixel(x, y, 1, 0, image, original): continue
if processpixel(x, y, 0, -1, image, original): continue
if processpixel(x, y, -1, 0, image, original): continue
if processpixel(x, y, 0, 1, image, original): continue
bleed(Image.GetCurrent(), 8)
Blender.Redraw()