diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-01-13 16:47:33 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-01-13 17:14:03 +0400 |
commit | 4c9a3a53bd3154954bc2bcf73684b87a79332a71 (patch) | |
tree | ca297c79f831f46117e1638640a187e98ddbd01c /source/blender/datatoc/datatoc_icon_split_to_png.py | |
parent | 08981f3a91a687efa8d28d308d6033e5a9e68b1f (diff) |
UI Icons: store icons in git as uncompressed pixmaps (D196)
this allows for updating icons without committing a new PNG each time
(which is inefficient with git). The data files are converted into a
PNG at builds time and used just as they were before.
Diffstat (limited to 'source/blender/datatoc/datatoc_icon_split_to_png.py')
-rwxr-xr-x | source/blender/datatoc/datatoc_icon_split_to_png.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/source/blender/datatoc/datatoc_icon_split_to_png.py b/source/blender/datatoc/datatoc_icon_split_to_png.py new file mode 100755 index 00000000000..39bbf1110fb --- /dev/null +++ b/source/blender/datatoc/datatoc_icon_split_to_png.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# This script is just to view the icons + + +def write_png(buf, width, height): + import zlib + import struct + # reverse the vertical line order and add null bytes at the start + width_byte_4 = width * 4 + raw_data = b"".join(b'\x00' + buf[span:span + width_byte_4] for span in range((height - 1) * width * 4, -1, - width_byte_4)) + + def png_pack(png_tag, data): + chunk_head = png_tag + data + return struct.pack("!I", len(data)) + chunk_head + struct.pack("!I", 0xFFFFFFFF & zlib.crc32(chunk_head)) + + return b"".join([ + b'\x89PNG\r\n\x1a\n', + png_pack(b'IHDR', struct.pack("!2I5B", width, height, 8, 6, 0, 0, 0)), + png_pack(b'IDAT', zlib.compress(raw_data, 9)), + png_pack(b'IEND', b'')]) + + +def icondata_to_png(file_src, file_dst): + import struct + + with open(file_src, 'rb') as f_src: + # 2 ints + temp_data = f_src.read(4 * 2) + w, h = struct.unpack('<2I', temp_data) + temp_data = f_src.read(4 * 2) # (x, y) - ignored + temp_data = f_src.read(4 * 2) # (xfrom, yfrom) - ignored + # pixels + temp_data = f_src.read(w * h * 4) + + buf = write_png(temp_data, w, h) + + with open(file_dst, 'wb') as f_dst: + f_dst.write(buf) + + +def main(): + import sys + import os + + for arg in sys.argv[1:]: + file_src = arg + file_dst = os.path.splitext(arg)[0] + ".png" + + icondata_to_png(file_src, file_dst) + +if __name__ == "__main__": + main() |