aboutsummaryrefslogtreecommitdiff
path: root/advtrains/textures/advtrains_signal_wall_on.png
blob: b628c7ec6d534cc51acebd400eba2da4137db47a (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 04 00 00 00 04 00 08 03 00 00 00 48 c3 db .PNG........IHDR.............H..
0020 b1 00 00 01 b9 50 4c 54 45 00 00 00 01 01 01 02 02 02 03 03 03 04 04 04 05 05 05 06 06 06 07 07 .....PLTE.......................
0040 07 08 08 08 09 09 09 0a 0a 0a 0b 0b 0b 0c 0c 0c 0d 0d 0d 0e 0e 0e 0f 0f 0f 10 10 10 11 11 11 12 ................................
0060 12 12 13 13 13 14 14 14 15 15 15 16 16 16 17 17 17 18 18 18 19 19 19 1a 1a 1a 1b 1b 1b 1c 1c 1c ................................
0080 1d 1d 1d 1e 1e 1e 1f 1f 1f 20 20 20 21 21 21 22 22 22 23 23 23 24 24 24 25 25 25 26 26 26 27 27 ............!!!"""###$$$%%%&&&''
00a0 27 28 28 28 29 29 29 2a 2a 2a 2b 2b 2b 2c 2c 2c 2d 2d 2d 2e 2e 2e 2f 2f 2f 30 30 30 31 31 31 32 '((()))***+++,,,---...///0001112
00c0 32 32 33 33 33 34 34 34 35 35 35 36 36 36 ff 00 00 37 37 37 38 38 38 39 39 39 3a 3a 3a 3b 3b 3b 22333444555666...777888999:::;;;
00e0 3c 3c 3c 3d 3d 3d 3e 3e 3e 3f 3f 3f 40 40 40 41 41 41 42 42 42 43 43 43 44 44 44 45 45 45 46 46 <<<===>>>???@@@AAABBBCCCDDDEEEFF
0100 46 47 47 47 48 48 48 49 49 49 4a 4a 4a 4b 4b 4b 4c 4c 4c 4d 4d 4d 4e 4e 4e 4f 4f 4f 50 50 50 51 FGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQ
0120 51 51 52 52 52 53 53 53 54 54 54 55 55 55 56 56 56 57 57 57 58 58 58 59 59 59 5a 5a 5a 5b 5b 5b QQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[
0140 5c 5c 5c 5d 5d 5d 5e 5e 5e 5f 5f 5f 60 60 60 61 61 61 62 62 62 63 63 63 64 64 64 65 65 65 66 66 \\\]]]^^^___```aaabbbcccdddeeeff
0160 66 67 67 67 68 68 68 69 69 69 6a 6a 6a 6b 6b 6b 6c 6c 6c 6d 6d 6d 6e 6e 6e 6f 6f 6f 70 70 70 71 fggghhhiiijjjkkklllmmmnnnooopppq
0180 71 71 72 72 72 73 73 73 74 74 74 75 75 75 76 76 76 77 77 77 78 78 78 79 79 79 7a 7a 7a 7b 7b 7b qqrrrssstttuuuvvvwwwxxxyyyzzz{{{
01a0 7c 7c 7c 7d 7d 7d 7e 7e 7e 7f 7f 7f 80 80 80 81 81 81 82 82 82 83 83 83 84 84 84 85 85 85 86 86 |||}}}~~~.......................
01c0 86 87 87 87 88 88 88 89 89 89 8a 8a 8a 8b 8b 8b 8c 8c 8c 8d 8d 8d 8e 8e 8e 8f 8f 8f 90 90 90 19 ................................
01e0 ff 19 3b 76 01 c7 00 00 00 01 62 4b 47 44 00 88 05 1d 48 00 00 00 09 70 48 59 73 00 00 0b 13 00 ..;v......bKGD....H....pHYs.....
0200 00 0b 13 01 00 9a 9c 18 00 00 00 07 74 49 4d 45 07 e1 02 03 0a 0f 03 6a bf 56 aa 00 00 09 b0 49 ............tIME.......j.V.....I
0220 44 41 54 78 da ed d4 41 11 00 00 08 c3 30 6c 60 1b c5 d8 e0 58 22 a1 8f 56 03 b1 4a 02 30 00 c0 DATx...A.....0l`....X"..V..J.0..
0240 00 00 03 00 0c 00 30 00 c0 00 00 03 00 0c 00 30 00 c0 00 00 03 00 0c 00 30 00 c0 00 00 03 00 0c ......0........0........0.......
0260 00 30 00 c0 00 00 03 00 0c 00 30 00 c0 00 00 03 00 0c 00 30 00 c0 00 00 03 00 0c 00 30 00 c0 00 .0........0........0........0...
0280 00 03 00 0c 00 30 00 c0 00 00 03 00 0c 00 0c 00 30 00 c0 00 20 d4 1c 60 00 60 00 06 00 06 60 00 .....0..........0......`.`....`.
02a0 60 00 06 00 06 60 00 60 00 06 00 06 60 00 60 00 06 00 06 60 00 60 00 06 00 06 60 00 60 00 06 00 `....`.`....`.`....`.`....`.`...
02c0 06 60 00 60 00 06 00 06 60 00 60 00 06 00 06 60 00 60 00 80 01 80 01 18 00 18 80 01 80 01 18 00 .`.`....`.`....`.`..............
02e0 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 ................................
0300 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 ................................
0320 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 ................................
0340 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 ................................
0360 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 ................................
0380 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 ................................
03a0 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 ................................
03c0 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 ................................
03e0 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 ................................
0400 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 ................................
0420 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 18 00 18 80 01 80 01 ................................
0440 18 00 60 00 80 01 00 06 00 06 20 01 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 ..`...........`........`........
0460 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 `........`........`........`....
0480 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 06 00 18 ....`........`........`.........
04a0 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 .`........`........`........`...
04c0 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 .....`........`........`........
04e0 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 `........`..........`........`..
0500 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 ......`........`........`.......
0520 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 .`........`........`........`...
0540 00 06 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 .......`........`........`......
0560 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 ..`........`........`........`..
0580 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 06 00 18 00 60 00 80 01 00 06 ......`........`..........`.....
05a0 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 ...`........`........`........`.
05c0 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 .......`........`........`......
05e0 18 00 60 00 80 01 00 06 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 ..`..........`........`........`
0600 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 ........`........`........`.....
0620 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 06 00 18 00 ...`........`........`..........
0640 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 `........`........`........`....
0660 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 ....`........`........`........`
0680 00 80 01 00 06 00 18 00 60 00 80 01 80 01 48 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 ........`.....H.....`........`..
06a0 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 ......`........`........`.......
06c0 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 .`........`........`........`...
06e0 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 .......`........`........`......
0700 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 ..`........`........`........`..
0720 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 80 01 00 06 00 18 00 60 00 80 01 00 06 ......`........`..........`.....
0740 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 ...`........`........`........`.
0760 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 .......`........`........`......
0780 18 00 60 00 80 01 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 ..`..........`........`........`
07a0 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 ........`........`........`.....
07c0 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 80 01 00 06 00 18 00 ...`........`........`..........
07e0 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 `........`........`........`....
0800 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 ....`........`........`........`
0820 00 80 01 00 06 00 18 00 60 00 80 01 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 ........`..........`........`...
0840 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 .....`........`........`........
0860 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 80 `........`........`........`....
0880 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 ......`........`........`.......
08a0 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 .`........`........`........`...
08c0 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 60 00 12 80 01 00 06 00 18 00 60 00 80 01 00 06 .....`........`.`.........`.....
08e0 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 ...`........`........`........`.
0900 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 .......`........`........`......
0920 18 00 60 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 ..`.`........`........`........`
0940 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 ........`........`........`.....
0960 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 60 00 80 01 00 06 00 18 00 ...`........`........`.`........
0980 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 `........`........`........`....
09a0 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 ....`........`........`........`
09c0 00 80 01 00 06 00 18 00 60 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 ........`.`........`........`...
09e0 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 .....`........`........`........
0a00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 60 00 80 `........`........`........`.`..
0a20 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 ......`........`........`.......
0a40 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 .`........`........`........`...
0a60 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 .....`........`.`........`......
0a80 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 ..`........`........`........`..
0aa0 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 ......`........`........`.......
0ac0 00 60 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 .`.`........`........`........`.
0ae0 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 .......`........`........`......
0b00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 18 80 04 60 00 80 01 00 06 00 18 00 ..`........`...........`........
0b20 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 `........`........`........`....
0b40 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 ....`........`........`........`
0b60 00 80 01 00 06 00 18 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 ..........`........`........`...
0b80 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 .....`........`........`........
0ba0 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 60 00 80 01 00 06 00 18 00 18 00 60 00 80 `........`........`..........`..
0bc0 01 00 06 00 18 00 60 00 80 01 00 06 00 3c b1 7e 6b 51 a3 12 bc 98 69 00 00 00 00 49 45 4e 44 ae ......`......<.~kQ....i....IEND.
0be0 42 60 82 B`.
#n637'>637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# COPYING for more details.

# Made by Jogge, modified by celeron55
# 2011-05-29: j0gge: initial release
# 2011-05-30: celeron55: simultaneous support for sectors/sectors2, removed
# 2011-06-02: j0gge: command line parameters, coordinates, players, ...
# 2011-06-04: celeron55: added #!/usr/bin/python2 and converted \r\n to \n
#                        to make it easily executable on Linux
# 2011-07-30: WF: Support for content types extension, refactoring
# 2011-07-30: erlehmann: PEP 8 compliance.

# Requires Python Imaging Library: http://www.pythonware.com/products/pil/

# Some speed-up: ...lol, actually it slows it down.
#import psyco ; psyco.full()
#from psyco.classes import *

import zlib
import os
import string
import time
import getopt
import sys
import array
import cStringIO
import traceback
from PIL import Image, ImageDraw, ImageFont, ImageColor

TRANSLATION_TABLE = {
    1: 0x800,  # CONTENT_GRASS
    4: 0x801,  # CONTENT_TREE
    5: 0x802,  # CONTENT_LEAVES
    6: 0x803,  # CONTENT_GRASS_FOOTSTEPS
    7: 0x804,  # CONTENT_MESE
    8: 0x805,  # CONTENT_MUD
    10: 0x806,  # CONTENT_CLOUD
    11: 0x807,  # CONTENT_COALSTONE
    12: 0x808,  # CONTENT_WOOD
    13: 0x809,  # CONTENT_SAND
    18: 0x80a,  # CONTENT_COBBLE
    19: 0x80b,  # CONTENT_STEEL
    20: 0x80c,  # CONTENT_GLASS
    22: 0x80d,  # CONTENT_MOSSYCOBBLE
    23: 0x80e,  # CONTENT_GRAVEL
    24: 0x80f,  # CONTENT_SANDSTONE
    25: 0x810,  # CONTENT_CACTUS
    26: 0x811,  # CONTENT_BRICK
    27: 0x812,  # CONTENT_CLAY
    28: 0x813,  # CONTENT_PAPYRUS
    29: 0x814}  # CONTENT_BOOKSHELF


def hex_to_int(h):
    i = int(h, 16)
    if(i > 2047):
        i -= 4096
    return i


def hex4_to_int(h):
    i = int(h, 16)
    if(i > 32767):
        i -= 65536
    return i


def int_to_hex3(i):
    if(i < 0):
        return "%03X" % (i + 4096)
    else:
        return "%03X" % i


def int_to_hex4(i):
    if(i < 0):
        return "%04X" % (i + 65536)
    else:
        return "%04X" % i


def getBlockAsInteger(p):
    return p[2]*16777216 + p[1]*4096 + p[0]

def unsignedToSigned(i, max_positive):
    if i < max_positive:
        return i
    else:
        return i - 2*max_positive

def getIntegerAsBlock(i):
    x = unsignedToSigned(i % 4096, 2048)
    i = int((i - x) / 4096)
    y = unsignedToSigned(i % 4096, 2048)
    i = int((i - y) / 4096)
    z = unsignedToSigned(i % 4096, 2048)
    return x,y,z

def limit(i, l, h):
    if(i > h):
        i = h
    if(i < l):
        i = l
    return i

def readU8(f):
    return ord(f.read(1))

def readU16(f):
    return ord(f.read(1))*256 + ord(f.read(1))

def readU32(f):
    return ord(f.read(1))*256*256*256 + ord(f.read(1))*256*256 + ord(f.read(1))*256 + ord(f.read(1))

def readS32(f):
    return unsignedToSigned(ord(f.read(1))*256*256*256 + ord(f.read(1))*256*256 + ord(f.read(1))*256 + ord(f.read(1)), 2**31)

usagetext = """minetestmapper.py [options]
  -i/--input <world_path>
  -o/--output <output_image.png>
  --bgcolor <color>
  --scalecolor <color>
  --playercolor <color>
  --origincolor <color>
  --drawscale
  --drawplayers
  --draworigin
  --drawunderground
Color format: '#000000'"""

def usage():
    print(usagetext)

try:
    opts, args = getopt.getopt(sys.argv[1:], "hi:o:", ["help", "input=",
        "output=", "bgcolor=", "scalecolor=", "origincolor=",
        "playercolor=", "draworigin", "drawplayers", "drawscale",
        "drawunderground"])
except getopt.GetoptError as err:
    # print help information and exit:
    print(str(err))  # will print something like "option -a not recognized"
    usage()
    sys.exit(2)

path = None
output = "map.png"
border = 0
scalecolor = "black"
bgcolor = "white"
origincolor = "red"
playercolor = "red"
drawscale = False
drawplayers = False
draworigin = False
drawunderground = False

sector_xmin = -1500 / 16
sector_xmax = 1500 / 16
sector_zmin = -1500 / 16
sector_zmax = 1500 / 16

for o, a in opts:
    if o in ("-h", "--help"):
        usage()
        sys.exit()
    elif o in ("-i", "--input"):
        path = a
    elif o in ("-o", "--output"):
        output = a
    elif o == "--bgcolor":
        bgcolor = ImageColor.getrgb(a)
    elif o == "--scalecolor":
        scalecolor = ImageColor.getrgb(a)
    elif o == "--playercolor":
        playercolor = ImageColor.getrgb(a)
    elif o == "--origincolor":
        origincolor = ImageColor.getrgb(a)
    elif o == "--drawscale":
        drawscale = True
        border = 40
    elif o == "--drawplayers":
        drawplayers = True
    elif o == "--draworigin":
        draworigin = True
    elif o == "--drawunderground":
        drawunderground = True
    else:
        assert False, "unhandled option"

if path is None:
    print("Please select world path (eg. -i ../worlds/yourworld) (or use --help)")
    sys.exit(1)

if path[-1:] != "/" and path[-1:] != "\\":
    path = path + "/"

# Load color information for the blocks.
colors = {}
try:
    f = file("colors.txt")
except IOError:
    f = file(os.path.join(os.path.dirname(__file__), "colors.txt"))
for line in f:
    values = string.split(line)
    if len(values) < 4:
        continue
    identifier = values[0]
    is_hex = True
    for c in identifier:
        if c not in "0123456789abcdefABCDEF":
            is_hex = False
            break
    if is_hex:
        colors[int(values[0], 16)] = (
            int(values[1]),
            int(values[2]),
            int(values[3]))
    else:
        colors[values[0]] = (
            int(values[1]),
            int(values[2]),
            int(values[3]))
f.close()

#print("colors: "+repr(colors))
#sys.exit(1)

xlist = []
zlist = []

# List all sectors to memory and calculate the width and heigth of the
# resulting picture.

conn = None
cur = None
if os.path.exists(path + "map.sqlite"):
    import sqlite3
    conn = sqlite3.connect(path + "map.sqlite")
    cur = conn.cursor()
    
    cur.execute("SELECT `pos` FROM `blocks`")
    while True:
        r = cur.fetchone()
        if not r:
            break
        
        x, y, z = getIntegerAsBlock(r[0])
        
        if x < sector_xmin or x > sector_xmax:
            continue
        if z < sector_zmin or z > sector_zmax:
            continue
        
        xlist.append(x)
        zlist.append(z)

if os.path.exists(path + "sectors2"):
    for filename in os.listdir(path + "sectors2"):
        for filename2 in os.listdir(path + "sectors2/" + filename):
            x = hex_to_int(filename)
            z = hex_to_int(filename2)
            if x < sector_xmin or x > sector_xmax:
                continue
            if z < sector_zmin or z > sector_zmax:
                continue
            xlist.append(x)
            zlist.append(z)

if os.path.exists(path + "sectors"):
    for filename in os.listdir(path + "sectors"):
        x = hex4_to_int(filename[:4])
        z = hex4_to_int(filename[-4:])
        if x < sector_xmin or x > sector_xmax:
            continue
        if z < sector_zmin or z > sector_zmax:
            continue
        xlist.append(x)
        zlist.append(z)

if len(xlist) == 0 or len(zlist) == 0:
    print("World does not exist.")
    sys.exit(1)

# Get rid of doubles
xlist, zlist = zip(*sorted(set(zip(xlist, zlist))))

minx = min(xlist)
minz = min(zlist)
maxx = max(xlist)
maxz = max(zlist)

w = (maxx - minx) * 16 + 16
h = (maxz - minz) * 16 + 16

print("Result image (w=" + str(w) + " h=" + str(h) + ") will be written to "
        + output)

im = Image.new("RGB", (w + border, h + border), bgcolor)
draw = ImageDraw.Draw(im)
impix = im.load()

stuff = {}

unknown_node_names = []
unknown_node_ids = []

starttime = time.time()

CONTENT_WATER = 2

def content_is_ignore(d):
    return d in [0, "ignore"]

def content_is_water(d):
    return d in [2, 9]

def content_is_air(d):
    return d in [126, 127, 254, "air"]

def read_content(mapdata, version, datapos):
    if version >= 24:
        return (mapdata[datapos*2] << 8) | (mapdata[datapos*2 + 1])
    elif version >= 20:
        if mapdata[datapos] < 0x80:
            return mapdata[datapos]
        else:
            return (mapdata[datapos] << 4) | (mapdata[datapos + 0x2000] >> 4)
    elif 16 <= version < 20:
        return TRANSLATION_TABLE.get(mapdata[datapos], mapdata[datapos])
    else:
        raise Exception("Unsupported map format: " + str(version))


def read_mapdata(mapdata, version, pixellist, water, day_night_differs, id_to_name):
    global stuff  # oh my :-)
    global unknown_node_names
    global unknown_node_ids

    if(len(mapdata) < 4096):
        print("bad: " + xhex + "/" + zhex + "/" + yhex + " " + \
            str(len(mapdata)))
    else:
        chunkxpos = xpos * 16
        chunkypos = ypos * 16
        chunkzpos = zpos * 16
        content = 0
        datapos = 0
        for (x, z) in reversed(pixellist):
            for y in reversed(range(16)):
                datapos = x + y * 16 + z * 256
                content = read_content(mapdata, version, datapos)
                # Try to convert id to name
                try:
                    content = id_to_name[content]
                except KeyError:
                    pass

                if content_is_ignore(content):
                    pass
                elif content_is_air(content):
                    pass
                elif content_is_water(content):
                    water[(x, z)] += 1
                    # Add dummy stuff for drawing sea without seabed
                    stuff[(chunkxpos + x, chunkzpos + z)] = (
                        chunkypos + y, content, water[(x, z)], day_night_differs)
                elif content in colors:
                    # Memorize information on the type and height of
                    # the block and for drawing the picture.
                    stuff[(chunkxpos + x, chunkzpos + z)] = (
                        chunkypos + y, content, water[(x, z)], day_night_differs)
                    pixellist.remove((x, z))
                    break
                else:
                    if type(content) == str:
                        if content not in unknown_node_names:
                            unknown_node_names.append(content)
                        #print("unknown node: %s/%s/%s x: %d y: %d z: %d block name: %s"
                        #        % (xhex, zhex, yhex, x, y, z, content))
                    else:
                        if content not in unknown_node_ids:
                            unknown_node_ids.append(content)
                        #print("unknown node: %s/%s/%s x: %d y: %d z: %d block id: %x"
                        #        % (xhex, zhex, yhex, x, y, z, content))


# Go through all sectors.
for n in range(len(xlist)):
    #if n > 500:
    #   break
    if n % 200 == 0:
        nowtime = time.time()
        dtime = nowtime - starttime
        try:
            n_per_second = 1.0 * n / dtime
        except ZeroDivisionError:
            n_per_second = 0
        if n_per_second != 0:
            seconds_per_n = 1.0 / n_per_second
            time_guess = seconds_per_n * len(xlist)
            remaining_s = time_guess - dtime
            remaining_minutes = int(remaining_s / 60)
            remaining_s -= remaining_minutes * 60
            print("Processing sector " + str(n) + " of " + str(len(xlist))
                    + " (" + str(round(100.0 * n / len(xlist), 1)) + "%)"
                    + " (ETA: " + str(remaining_minutes) + "m "
                    + str(int(remaining_s)) + "s)")

    xpos = xlist[n]
    zpos = zlist[n]

    xhex = int_to_hex3(xpos)
    zhex = int_to_hex3(zpos)
    xhex4 = int_to_hex4(xpos)
    zhex4 = int_to_hex4(zpos)

    sector1 = xhex4.lower() + zhex4.lower()
    sector2 = xhex.lower() + "/" + zhex.lower()

    ylist = []

    sectortype = ""

    if cur:
        psmin = getBlockAsInteger((xpos, -2048, zpos))
        psmax = getBlockAsInteger((xpos, 2047, zpos))
        cur.execute("SELECT `pos` FROM `blocks` WHERE `pos`>=? AND `pos`<=? AND (`pos` - ?) % 4096 = 0", (psmin, psmax, psmin))
        while True:
            r = cur.fetchone()
            if not r:
                break