Fix indentation

This commit is contained in:
Florent 2013-10-16 22:31:30 +02:00 committed by Florent Fourcot
commit 64ff95396c
2 changed files with 117 additions and 111 deletions

View file

@ -22,25 +22,28 @@
# [6] http://code.google.com/p/casadebender/source/browse/python/PIL/Win32IconImagePlugin.py # [6] http://code.google.com/p/casadebender/source/browse/python/PIL/Win32IconImagePlugin.py
# [7] http://www.osphp.com.cn/read.php/290.htm # [7] http://www.osphp.com.cn/read.php/290.htm
from PIL import Image from PIL import Image
import sys import sys
import os import os
# data: a size*size of (r,g,b,t) tuples, t for tansparency(if True) # data: a size*size of (r,g,b,t) tuples, t for tansparency(if True)
# (r,g,b,a) if bpp is 32 # (r,g,b,a) if bpp is 32
# size: could be 16 or 32 or 48 or 64, other value NOT supported # size: could be 16 or 32 or 48 or 64, other value NOT supported
# bpp: bits per pixel, could *only* be 24 or 32! # bpp: bits per pixel, could *only* be 24 or 32!
# return: an "array" of BYTES which, if write to file, is a size*size ico file # return: an "array" of BYTES which, if write to file, is a size*size ico file
def genico(data, size=16, bpp=24): def genico(data, size=16, bpp=24):
from array import array from array import array
a = array('B') a = array('B')
#header(ref1&5) #header(ref1&5)
a.extend((0,0, 1,0, 1,0)) #reserved*2, icon,0, 1 image per-file,0 a.extend((0,0, 1,0, 1,0)) #reserved*2, icon,0, 1 image per-file,0
#directory(ref1&5&7) #directory(ref1&5&7)
imglen = 40+size*(size*3 + (size+16)/32*32/8) #image-part length in bytes # image-part length in bytes
# !hack! AND bits align to 32 bits per line # !hack! AND bits align to 32 bits per line
# !shit! MSDN says nothing about this # !shit! MSDN says nothing about this
imglen = 40+size*(size*3 + (size+16)/32*32/8)
if bpp == 32: if bpp == 32:
imglen += size*size #1 more byte for alpha value of each pixel imglen += size*size #1 more byte for alpha value of each pixel
a.extend((size,size, 0,0, 1,0, bpp,0)) #w,h, reserved*2, 1plane*2, bpp*2 a.extend((size,size, 0,0, 1,0, bpp,0)) #w,h, reserved*2, 1plane*2, bpp*2
@ -76,6 +79,8 @@ def genico(data, size=16, bpp=24):
a.extend(AND) a.extend(AND)
return a return a
# x,y indicate the hotspot position # x,y indicate the hotspot position
# simply set the type/hotspot(x&y) after generates the icon # simply set the type/hotspot(x&y) after generates the icon
def gencur(data, size=16, bpp=24, x=0, y=0): def gencur(data, size=16, bpp=24, x=0, y=0):
@ -83,6 +88,8 @@ def gencur(data, size=16, bpp=24, x=0, y=0):
a[3], a[10], a[12] = 2, x, y a[3], a[10], a[12] = 2, x, y
return a return a
#C:\Python27\Lib\site-packages\weboob-0.g-py2.7.egg\share\icons\hicolor\64x64\apps #C:\Python27\Lib\site-packages\weboob-0.g-py2.7.egg\share\icons\hicolor\64x64\apps
if __name__ == "__main__": if __name__ == "__main__":
@ -102,7 +109,6 @@ if __name__ == "__main__":
for j in range(wh): for j in range(wh):
data.append(rgba.getpixel((i,j))) data.append(rgba.getpixel((i,j)))
icoflow = genico(data, wh, 32) icoflow = genico(data, wh, 32)
_file = open(ico_file, "wb") _file = open(ico_file, "wb")
icoflow.tofile(_file) icoflow.tofile(_file)