本文整理汇总了Python中pandac.PandaModules.PNMImage.hasAlpha方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.hasAlpha方法的具体用法?Python PNMImage.hasAlpha怎么用?Python PNMImage.hasAlpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandac.PandaModules.PNMImage
的用法示例。
在下文中一共展示了PNMImage.hasAlpha方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import hasAlpha [as 别名]
def __init__(self, image_path, rowPerFace, name=None,\
rows=1, cols=1, scale=1.0,\
twoSided=False, alpha=TRANS_ALPHA,\
repeatX=1, repeatY=1,\
anchorX=ALIGN_CENTER, anchorY=ALIGN_BOTTOM):
"""
Create a card textured with an image. The card is sized so that the ratio between the
card and image is the same.
"""
global SpriteId
self.spriteNum = str(SpriteId)
SpriteId += 1
scale *= self.PIXEL_SCALE
self.animations = {}
self.scale = scale
self.repeatX = repeatX
self.repeatY = repeatY
self.flip = {'x':False,'y':False}
self.rows = rows
self.cols = cols
self.currentFrame = 0
self.currentAnim = None
self.loopAnim = False
self.frameInterrupt = True
# Create the NodePath
if name:
self.node = NodePath("Sprite2d:%s" % name)
else:
self.node = NodePath("Sprite2d:%s" % image_path)
# Set the attribute for transparency/twosided
self.node.node().setAttrib(TransparencyAttrib.make(alpha))
if twoSided:
self.node.setTwoSided(True)
# Make a filepath
self.imgFile = Filename(image_path)
if self.imgFile.empty():
raise IOError, "File not found"
# Instead of loading it outright, check with the PNMImageHeader if we can open
# the file.
imgHead = PNMImageHeader()
if not imgHead.readHeader(self.imgFile):
raise IOError, "PNMImageHeader could not read file. Try using absolute filepaths"
# Load the image with a PNMImage
image = PNMImage()
image.read(self.imgFile)
self.sizeX = image.getXSize()
self.sizeY = image.getYSize()
# We need to find the power of two size for the another PNMImage
# so that the texture thats loaded on the geometry won't have artifacts
textureSizeX = self.nextsize(self.sizeX)
textureSizeY = self.nextsize(self.sizeY)
# The actual size of the texture in memory
self.realSizeX = textureSizeX
self.realSizeY = textureSizeY
self.paddedImg = PNMImage(textureSizeX, textureSizeY)
if image.hasAlpha():
self.paddedImg.alphaFill(0)
# Copy the source image to the image we're actually using
self.paddedImg.blendSubImage(image, 0, 0)
# We're done with source image, clear it
image.clear()
# The pixel sizes for each cell
self.colSize = self.sizeX/self.cols
self.rowSize = self.sizeY/self.rows
# How much padding the texture has
self.paddingX = textureSizeX - self.sizeX
self.paddingY = textureSizeY - self.sizeY
# Set UV padding
self.uPad = float(self.paddingX)/textureSizeX
self.vPad = float(self.paddingY)/textureSizeY
# The UV dimensions for each cell
self.uSize = (1.0 - self.uPad) / self.cols
self.vSize = (1.0 - self.vPad) / self.rows
self.cards = []
self.rowPerFace = rowPerFace
for i in range(len(rowPerFace)):
card = CardMaker("Sprite2d-Geom")
# The positions to create the card at
if anchorX == self.ALIGN_LEFT:
posLeft = 0
#.........这里部分代码省略.........
示例2: TexturePainter
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import hasAlpha [as 别名]
#.........这里部分代码省略.........
for px in xrange(-smoothRadius,smoothRadius+1):
for py in xrange(-smoothRadius,smoothRadius+1):
if inImage(x+dx+px,y+dy+py):
average += self.editImage.getXelA(x+dx+px,y+dy+py)
dividor += 1
average /= float(dividor)
data[(x+dx,y+dy)] = average
# save to image
for (px,py), newValue in data.items():
currentValue = self.editImage.getXelA(px,py)
diffValue = currentValue - newValue
dx = px - x
dy = py - y
multiplier = getBrushColor(dx, dy)
print dx, dy, multiplier
'''if self.paintSmooth:
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy))) / (radius*radius)
else:
# not sure if this is correct
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy)))'''
'''r = currentValue.getX() * (1-multiplier*self.paintColor.getX()) + diffValue.getX() * multiplier*self.paintColor.getX()
g = currentValue.getY() * (1-multiplier*self.paintColor.getY()) + diffValue.getY() * multiplier*self.paintColor.getY()
b = currentValue.getZ() * (1-multiplier*self.paintColor.getZ()) + diffValue.getZ() * multiplier*self.paintColor.getZ()
a = currentValue.getW() * (1-multiplier*self.paintColor.getW()) + diffValue.getW() * multiplier*self.paintColor.getW()'''
r = currentValue.getX() - multiplier * diffValue.getX()
g = currentValue.getY() - multiplier * diffValue.getY()
b = currentValue.getZ() - multiplier * diffValue.getZ()
a = currentValue.getW() - multiplier * diffValue.getW()
if self.editImage.hasAlpha():
self.editImage.setXelA(px,py,VBase4D(r,g,b,a))
else:
self.editImage.setXel(px,py,VBase3D(r,g,b))
#self.editImage.setXelA(x,y,value)
if self.paintEffect == TEXTUREPAINTER_BRUSH_FLATTEN:
dividor = 0
average = VBase4D(0)
for dx in xrange(-radius, radius+1):
for dy in xrange(-radius, radius+1):
if inImage(x+dx,y+dy):
multiplier = getBrushColor(dx, dy)
'''if self.paintSmooth:
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy))) / (radius*radius)
else:
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy)))'''
dividor += multiplier
average += self.editImage.getXelA(x+dx,y+dy) * multiplier
average /= dividor
for dx in xrange(-radius, radius+1):
for dy in xrange(-radius, radius+1):
if inImage(x+dx,y+dy):
multiplier = getBrushColor(dx, dy)
'''if self.paintSmooth:
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy))) / (radius*radius)
else:
# not sure if this is correct
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy)))'''
currentValue = self.editImage.getXelA(x+dx,y+dy)
r = currentValue.getX() * (1-multiplier*self.paintColor.getX()) + average.getX() * multiplier*self.paintColor.getX()
g = currentValue.getY() * (1-multiplier*self.paintColor.getY()) + average.getY() * multiplier*self.paintColor.getY()