37,720
社区成员
发帖
与我相关
我的任务
分享
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)
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)]