这是啥意思?Pixels = [[0,0,0,0] for n in range(16)]#[ColorIndex][R=0,G=1,B=2,A=3]

foxfire882 2013-06-04 09:07:07
大家好,我这里有个图形编码算法(CMP,S3TC纹理压缩算法)是用Python写的,但是实在没看懂,主要是红色的两句话实在不知道是啥意思,哪位大侠能帮忙翻译成高级语言?C、VB、C++、Java都行,您熟悉啥就用啥。

红色两句实在没看懂。。。帮忙翻译下吧,40分给您了。


Pixels = [[0,0,0,0] for n in range(16)]#[ColorIndex][R=0,G=1,B=2,A=3]
Output = ["" for n in range((AddPadding(Pic.Width,8)*AddPadding(Pic.Height,8))/16)]
ww = AddPadding(Pic.Width,8)


for y in range(0,AddPadding(Pic.Height,8),4):
for x in range(0,AddPadding(Pic.Width,8),4):
MaxColor = [ 0, 0, 0,255]
MinColor = [255,255,255,255]
for y1 in range(0,4):
for x1 in range(0,4):
if y+y1 >= Pic.Height or x+x1 >= Pic.Width:
continue
Pixel = Pic.GetPixel(x+x1,y+y1)
Pixels[x1+y1*4][0] = Pixel>>24
Pixels[x1+y1*4][1] = (Pixel>>16)&0xFF
Pixels[x1+y1*4][2] = (Pixel>>8)&0xFF
Pixels[x1+y1*4][3] = Pixel&0xFF
if (Pixels[x1+y1*4][0]+Pixels[x1+y1*4][1]+Pixels[x1+y1*4][2]) > (MaxColor[0]+MaxColor[1]+MaxColor[2]) and Pixels[x1+y1*4][3] >= 0xDA:
MaxColor = Pixels[x1+y1*4]
MaxColor[3] = 0xFF
elif (Pixels[x1+y1*4][0]+Pixels[x1+y1*4][1]+Pixels[x1+y1*4][2]) < (MinColor[0]+MinColor[1]+MinColor[2]) and Pixels[x1+y1*4][3] >= 0xDA:
MinColor = Pixels[x1+y1*4]
MinColor[3] = 0xFF
if (((MaxColor[0]>>3)<<11)|((MaxColor[1]>> 2)<<5)|(MaxColor[2]>>3)) <= (((MinColor[0]>>3)<<11)|((MinColor[1]>> 2)<<5)|(MinColor[2]>>3)):
Type0 = MinColor
Type1 = MaxColor
else:
Type0 = MaxColor
Type1 = MinColor
Type2 = [(Type0[0]+Type0[0]+Type1[0])/3,(Type0[1]+Type0[1]+Type1[1])/3,(Type0[2]+Type0[2]+Type1[2])/3,0xFF]
Type3 = [(Type0[0]+Type1[0]+Type1[0])/3,(Type0[1]+Type1[1]+Type1[1])/3,(Type0[2]+Type1[2]+Type1[2])/3,0xFF]
Types = 0

Color1 = ((Type0[0]>>3)<<11)|((Type0[1]>> 2)<<5)|(Type0[2]>>3)
Color2 = ((Type1[0]>>3)<<11)|((Type1[1]>> 2)<<5)|(Type1[2]>>3)

for Pixel in Pixels:
I0 = Abs(Pixel[0]-Type0[0]) + Abs(Pixel[1]-Type0[1]) + Abs(Pixel[2]-Type0[2])
I1 = Abs(Pixel[0]-Type1[0]) + Abs(Pixel[1]-Type1[1]) + Abs(Pixel[2]-Type1[2])
I2 = Abs(Pixel[0]-Type2[0]) + Abs(Pixel[1]-Type2[1]) + Abs(Pixel[2]-Type2[2])
I3 = Abs(Pixel[0]-Type3[0]) + Abs(Pixel[1]-Type3[1]) + Abs(Pixel[2]-Type3[2])

Type = 0
if I1 == min((I0,I1,I2,I3)):
Type = 1
elif I2 == min((I0,I1,I2,I3)):
Type = 2
elif I3 == min((I0,I1,I2,I3)) and Color1 > Color2:
Type = 3
Types <<= 2

Types |= Type
Output[((x>>2)&1)+(2*((y>>2)&1))+(4*(x>>3))+((ww/2)*(y>>3))] = DecAsc(Color1,2) + DecAsc(Color2,2) + DecAsc(Types,4)
TextureData[i] += "".join(Output)
...全文
514 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ForestDB 2013-06-04
  • 打赏
  • 举报
回复
Pixels = [[0,0,0,0],[0,0,0,0],[0,0,0,0]...] #一共16组[0,0,0,0]
panghuhu250 2013-06-04
  • 打赏
  • 举报
回复
1. Pixels是一个元素全为0, 大小为16x4的数组, 2。 Output是元素全为""的数组,大小是(AddPadding(Pic.Width,8)*AddPadding(Pic.Height,8))/16。 这两句都用到list comprehension,它是python编程中很常用的结构,建议参看python教程的相关部分,把它弄明白。
foxfire882 2013-06-04
  • 打赏
  • 举报
回复
晕,乱码了,红色两句就是最开始两句:
Pixels = [[0,0,0,0] for n in range(16)]#[ColorIndex][R=0,G=1,B=2,A=3]
			Output = ["" for n in range((AddPadding(Pic.Width,8)*AddPadding(Pic.Height,8))/16)]

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧