3 # ##### BEGIN GPL LICENSE BLOCK #####
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # ##### END GPL LICENSE BLOCK #####
21 # This script is just to view the icons
24 def write_png(buf, width, height):
27 # reverse the vertical line order and add null bytes at the start
28 width_byte_4 = width * 4
29 raw_data = b"".join(b'\x00' + buf[span:span + width_byte_4] for span in range((height - 1) * width * 4, -1, - width_byte_4))
31 def png_pack(png_tag, data):
32 chunk_head = png_tag + data
33 return struct.pack("!I", len(data)) + chunk_head + struct.pack("!I", 0xFFFFFFFF & zlib.crc32(chunk_head))
37 png_pack(b'IHDR', struct.pack("!2I5B", width, height, 8, 6, 0, 0, 0)),
38 png_pack(b'IDAT', zlib.compress(raw_data, 9)),
39 png_pack(b'IEND', b'')])
42 def icondata_to_png(file_src, file_dst):
45 with open(file_src, 'rb') as f_src:
47 temp_data = f_src.read(4 * 2)
48 w, h = struct.unpack('<2I', temp_data)
49 temp_data = f_src.read(4 * 2) # (x, y) - ignored
50 temp_data = f_src.read(4 * 2) # (xfrom, yfrom) - ignored
52 temp_data = f_src.read(w * h * 4)
54 buf = write_png(temp_data, w, h)
56 with open(file_dst, 'wb') as f_dst:
64 for arg in sys.argv[1:]:
66 file_dst = os.path.splitext(arg)[0] + ".png"
68 icondata_to_png(file_src, file_dst)
71 if __name__ == "__main__":