我需要用 pyqt 读取 tga,到目前为止,这似乎工作正常,除非 tga 每个像素有 2 个字节,而不是 3 或 4 个。我的代码取自这里http://pastebin.com/b5Vz61dZ。
特别是本节:
def getPixel( file, bytesPerPixel):
'Given the file object f, and number of bytes per pixel, read in the next pixel and return a qRgba uint'
pixel = []
for i in range(bytesPerPixel):
pixel.append(ord(file.read(1)))
if bytesPerPixel==4:
pixel = [pixel[2], pixel[1], pixel[0], pixel[3]]
color = qRgba(*pixel)
elif bytesPerPixel == 3:
pixel = [pixel[2], pixel[1], pixel[0]]
color = qRgb(*pixel)
elif bytesPerPixel == 2:
# if greyscale
color = QColor.fromHsv( 0, pixel[0] , pixel[1])
color = color.value()
return color
这部分:
elif bytesPerPixel == 2:
# if greyscale
color = QColor.fromHsv( 0, pixel[0] , pixel[1])
color = color.value()
我将如何输入像素 [0] 和像素 [1] 值来创建以正确格式和色彩空间获取值?
任何想法,想法或帮助请!!!