本文整理汇总了Python中Graphics.decodeImageData方法的典型用法代码示例。如果您正苦于以下问题:Python Graphics.decodeImageData方法的具体用法?Python Graphics.decodeImageData怎么用?Python Graphics.decodeImageData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graphics
的用法示例。
在下文中一共展示了Graphics.decodeImageData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _processRenderSurface
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import decodeImageData [as 别名]
def _processRenderSurface(logDir, attributes):
def attr(name):
return attributes[name]
w, h = attr("render_surface_width"), attr("render_surface_height")
redMask = attr("red_mask")
greenMask = attr("green_mask")
blueMask = attr("blue_mask")
alphaMask = attr("alpha_mask")
depthMask = attr("depth_mask")
stencilMask = attr("stencil_mask")
isLinear = attr("is_linear")
isPremultiplied = attr("is_premultiplied")
# Convert the color buffer
if "color_buffer" in attributes:
fileName = attr("color_buffer")
if not os.path.exists(fileName):
fileName = os.path.join(logDir, fileName)
fileNameOut = fileName.rsplit(".", 1)[0] + ".png"
# Only do the conversion if the image doesn't already exist
# or if the source file is newer.
if fileName.endswith(".dat") and \
(not os.path.exists(fileNameOut) or \
(os.path.exists(fileName) and os.path.getmtime(fileName) > os.path.getmtime(fileNameOut))
):
stride = attr("color_stride")
f = open(fileName, "rb")
data = f.read(stride * h)
f.close()
if len(data) != h * stride or not data:
Log.error("Invalid color buffer data size: %d" % len(data))
return
colorBuffer = Graphics.decodeImageData(data, (w, h), stride, redMask, greenMask, blueMask, alphaMask, isLinear, isPremultiplied)
colorBuffer = colorBuffer.convert("RGBA")
colorBuffer.save(fileNameOut)
# We can remove the original file now
os.unlink(fileName)
# Replace the original file name with the decoded file
attributes["color_buffer"] = fileNameOut
# Eat the render surface attributes since they are of little use further down the road
#for attrName in ["red_mask", "green_mask", "blue_mask", "alpha_mask",
# "depth_mask", "stencil_mask", "color_stride",
# "is_linear", "is_premultiplied", "color_data_type",
# "depth_data_type", "stencil_data_type"]:
# if attrName in attributes:
# del attributes[attrName]
for bufferName in ["depth_buffer", "stencil_buffer"]:
if bufferName in attributes and not os.path.exists(attributes[bufferName]):
# Fill in the full buffer file name
attributes[bufferName] = os.path.join(logDir, attr(bufferName))
示例2: getImageLoaders
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import decodeImageData [as 别名]
def getImageLoaders(project, trace):
"""
Return a list of (event, func) pairs, where event is a image upload event and
func is a function that returns an Image containing the image data when called.
"""
library = project.targets["code"].library
constants = Collections.DictProxy(library.constants)
loaders = []
formats = {
constants.VG_sRGBX_8888: ("b", 4, False, False, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000),
constants.VG_sRGBA_8888: ("b", 4, False, False, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000),
constants.VG_sRGBA_8888_PRE: ("b", 4, False, True, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000),
constants.VG_sRGB_565: ("h", 3, False, False, 0x001f, 0x07e0, 0xf800, 0x0),
constants.VG_sRGBA_5551: ("h", 4, False, False, 0x001f, 0x03e0, 0x7c00, 0x8000),
constants.VG_sRGBA_4444: ("h", 4, False, False, 0x000f, 0x00f0, 0x0f00, 0xf000),
constants.VG_sL_8: ("b", 1, False, False, 0xff, 0x0, 0x0, 0x0),
constants.VG_lRGBX_8888: ("b", 4, True, False, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000),
constants.VG_lRGBA_8888: ("b", 4, True, False, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000),
constants.VG_lRGBA_8888_PRE: ("b", 4, True, True, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000),
constants.VG_lL_8: ("b", 1, True, False, 0xff, 0x0, 0x0, 0x0),
constants.VG_A_8: ("b", 1, True, False, 0xff, 0x0, 0x0, 0x0),
constants.VG_BW_1: ("b", 1, True, False, 0x1, 0x0, 0x0, 0x0),
}
task = Task.startTask("prepare-images", "Looking for images", len(trace.events))
for event in trace.events:
task.step()
if event.name == "vgImageSubData" and event.values.get("data"):
width = event.values["width"]
height = event.values["height"]
stride = event.values["dataStride"]
format = event.values["dataFormat"]
if format in formats:
unit, components, isLinear, isPremultiplied, redMask, greenMask, blueMask, alphaMask = formats[format]
else:
continue
data = event.values["data"]
data = struct.pack("<%d%s" % (len(data), unit), *data)
size = (width, height)
# Construct copies of the passed variables to make sure the proper data goes into the lambda when called
func = lambda d=data, s=size, st=stride, rb=redMask, gb=greenMask, bb=blueMask, ab=alphaMask, il=isLinear, ip=isPremultiplied: \
Graphics.decodeImageData(d, s, st, rb, gb, bb, ab, isLinear = il, isPremultiplied = ip)
loaders.append((event, func))
return loaders
示例3: len
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import decodeImageData [as 别名]
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from AnalyzerEnvironment import *
import struct
import Graphics
for traceName, trace in traces.items():
analyzer.reportInfo("Processing %s" % traceName)
for event in trace.events:
if event.name != "vgReadPixels": continue
if len(event.values) != 7: continue
fn = "frame%05d-%dx%d.png" % (event.seq, event.values["width"], event.values["height"])
d = event.values["data"]
d = struct.pack("%dB" % len(d), *d)
d = Graphics.decodeImageData(d, (event.values["width"], event.values["height"]), event.values["dataStride"], 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000)
#open(fn, "wb").write(d)
d.save(fn)
print event.seq
示例4: getTextureLoaders
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import decodeImageData [as 别名]
def getTextureLoaders(project, trace):
"""
Return a list of (event, func) pairs, where event is a texture upload event and
func is a function that returns an Image containing the texture data when called.
"""
library = project.targets["code"].library
constants = Collections.DictProxy(library.constants)
loaders = []
componentCount = {
constants.GL_ALPHA: 1,
constants.GL_RGB: 3,
constants.GL_RGBA: 4,
constants.GL_LUMINANCE: 1,
constants.GL_LUMINANCE_ALPHA: 2,
}
task = Task.startTask("prepare-textures", "Looking for textures", len(trace.events))
for event in trace.events:
task.step()
# We don't handle compressed texture formats
if event.name in ["glTexImage2D", "glTexSubImage2D"] and event.values.get("pixels"):
width = event.values["width"]
height = event.values["height"]
format = event.values["format"]
type = event.values["type"]
if format in componentCount:
components = componentCount[format]
else:
continue
if type == constants.GL_UNSIGNED_BYTE:
bytesPerPixel = components
format = "b"
redMask = 0x00ff0000
greenMask = 0x0000ff00
blueMask = 0x000000ff
alphaMask = 0xff000000
elif type == constants.GL_UNSIGNED_SHORT_5_6_5:
bytesPerPixel = 2
format = "h"
redMask = 0x001f
greenMask = 0x07e0
blueMask = 0xf800
alphaMask = 0x0000
elif type == constants.GL_UNSIGNED_SHORT_5_5_5_1:
bytesPerPixel = 2
format = "h"
redMask = 0x001f
greenMask = 0x03e0
blueMask = 0x7c00
alphaMask = 0x8000
elif type == constants.GL_UNSIGNED_SHORT_4_4_4_4:
bytesPerPixel = 2
format = "h"
redMask = 0x000f
greenMask = 0x00f0
blueMask = 0x0f00
alphaMask = 0xf000
else:
continue
pixels = event.values["pixels"]
data = struct.pack("<%d%s" % (len(pixels), format), *pixels)
if components < 4:
alphaMask = 0
if components < 3:
blueMask = 0
if components < 2:
greenMask = 0
size = (width, height)
stride = width * bytesPerPixel
# Construct copies of the passed variables to make sure the proper data goes into the lambda when called
func = lambda d=data, s=size, st=stride, rb=redMask, gb=greenMask, bb=blueMask, ab=alphaMask: \
Graphics.decodeImageData(d, s, st, rb, gb, bb, ab)
loaders.append((event, func))
return loaders