MBM to PNG file converter - Files
last update: Tuesday, 19 November 2013
=====================================
README-mbm2png - This document
mbm2png        - precompiled for your convenience (Linux 32 bit)
mbm2png64      - precompiled for your convenience (Linux 64 bit)
mbm2png.exe    - precompiled for your convenience (Windows)
gpl-3.0.txt    - General Public License

Sorry, I don't have a MAC, so I wasn't able to provide a precompiled executable
for you Apple users. Maybe someone with a MAC can compile this and upload it?


Quick start
=====================================
This program converts Kerbal Space Program texture files (i.e. "model000.mbm")
into PNG files suitable for editing and use in the KSP game.

To use, simply copy the appropriate executable to your computer, then type

C:\> mbm2png model000.mbm (press enter)
 - or -
C:\> mbm2png (press enter)

If you specify a filename, it will be used. If not, the program will ask you
for it.

The program will run, generate the PNG file, then print a small report:

Converting model000.mbm to model000.png... writing PNG file... Done!
Width: 512, Height: 1024, Bits: 24, MBM size: 1572884, PNG size: 131126


Using PNG textures in the game
=====================================

<<<<<      NOTE: SEE "muedit" included in this package!      >>>>>

In order to make the game utilize textures in the PNG format, you need to edit
the mesh file (typically "model.mu") in the part folder that you want to modify,
and, near the bottom change the file extensions from "mbm" to "png". In a hex
editor, it would look something like this:

Before editing
=====================================
0002B820   00 00 00 00  00 00 06 65  6E 67 69 6E  65 07 00 00  .......engine...
0002B830   00 02 00 00  00 00 00 80  3F 00 00 80  3F 00 00 00  ........?...?...
0002B840   00 00 00 00  00 03 00 00  00 00 00 80  3F 00 00 80  ............?...
0002B850   3F 00 00 00  00 00 00 00  00 C0 AF C6  3D C0 AF C6  ?...........=...
0002B860   3D C0 AF C6  3D 00 00 80  3F BF CC EB  3E 04 00 00  =...=...?...>...
0002B870   00 00 00 80  3F 00 00 80  3F 00 00 00  00 00 00 00  ....?...?.......
0002B880   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 80  ................
0002B890   3F 0C 00 00  00 05 00 00  00 0C 6D 6F  64 65 6C 30  ?.........model0 \
0002B8A0   30 30 2E 6D  62 6D 00 00  00 00 0C 6D  6F 64 65 6C  00.mbm.....model  \
0002B8B0   30 30 31 2E  6D 62 6D 01  00 00 00 0C  6D 6F 64 65  001.mbm.....mode   \ <-- note
0002B8C0   6C 30 30 32  2E 6D 62 6D  00 00 00 00  0C 6D 6F 64  l002.mbm.....mod   /  ".mbm" extension
0002B8D0   65 6C 30 30  33 2E 6D 62  6D 01 00 00  00 0C 6D 6F  el003.mbm.....mo  /
0002B8E0   64 65 6C 30  30 34 2E 6D  62 6D 00 00  00 00        del004.mbm....   /

After editing
=====================================
0002B820   00 00 00 00  00 00 06 65  6E 67 69 6E  65 07 00 00  .......engine...
0002B830   00 02 00 00  00 00 00 80  3F 00 00 80  3F 00 00 00  ........?...?...
0002B840   00 00 00 00  00 03 00 00  00 00 00 80  3F 00 00 80  ............?...
0002B850   3F 00 00 00  00 00 00 00  00 C0 AF C6  3D C0 AF C6  ?...........=...
0002B860   3D C0 AF C6  3D 00 00 80  3F BF CC EB  3E 04 00 00  =...=...?...>...
0002B870   00 00 00 80  3F 00 00 80  3F 00 00 00  00 00 00 00  ....?...?.......
0002B880   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 80  ................
0002B890   3F 0C 00 00  00 05 00 00  00 0C 6D 6F  64 65 6C 30  ?.........model0 \
0002B8A0   30 30 2E 70  6E 67 00 00  00 00 0C 6D  6F 64 65 6C  00.png.....model  \
0002B8B0   30 30 31 2E  70 63 67 01  00 00 00 0C  6D 6F 64 65  001.png.....mode   \ <-- changed
0002B8C0   6C 30 30 32  2E 70 6E 67  00 00 00 00  0C 6D 6F 64  l002.png.....mod   /  to ".png" extension
0002B8D0   65 6C 30 30  33 2E 70 6E  67 01 00 00  00 0C 6D 6F  el003.png.....mo  /
0002B8E0   64 65 6C 30  30 34 2E 70  6E 67 00 00  00 00        del004.png....   /


What the program does (and does not do)
=====================================
(1) It will NOT modify the original MBM file.
(2) It will check for a valid MBM file by looking for the "3KSP" magic number.
(3) It will create a PNG image file with the same base name as the MBM file.
(4) It will NOT overwrite the PNG image file if run again. Delete the PNG to recreate it.
    This is a safety feature to prevent accidental overwrite of an edited PNG image. If you
    want to convert the MBM file to a PNG file again, you must manually delete (or rename)
    the backup file first.


In any case, always make a backup copy of files before you edit them!


Copyright information - mbm2png
=====================================
mbm2png - Converts Kerbal Space Program texture files to png image files
(c) 2013 Roger A. Krupski <rakrupski@verizon.net>

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 3 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.


Copyright information - lodepng PNG library
===========================================
LodePNG version 20130831
Copyright (c) 2005-2013 Lode Vandevenne
URL for PNG library: http://lodev.org/lodepng/

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.

########################################
# One of these       BANG, ZOOM!       #
#   days Alice...       Straight to    #
#                  ^        the Mun!   #
#                 /_\                  #
#                /___\                 #
#                |   |                 #
#                |___|                 #
#                |   |                 #
#                | K |                 #
#                | S |                 #
#                | P |                 #
#                |___|                 #
#                |   |                 #
#               /--|--\                #
#              /- #|#- \               #
#          ___    ###   ___   Wait     #
#          ||_|   ###  |_||   for      #
#          || |    #   | ||   me!      #
#          ||      #     ||            #
#          ||      #     ||   \O/      #
#          ||            ||    |       #
#          ||            ||   / \      #
#    =============================     #
########################################

Enjoy!! -- Roger

Changes since initial upload:
=============================================================================
23 sep 2013
* initial release
=============================================================================
24 sep 2013
* Removed the code that loops through all the ARGV variables (because stupid
  Microsoft Windows console mode doesn't support wildcard expansion). :(
* Added carriage returns to the README file and the source code so that Windows
  users can view the text in Notepad.
* Compiled for Windows and Linux 32 bit since both will work fine in 64 bit
  systems anyway - no point in having separate 32 and 64 bit versions.
=============================================================================
25 sep 2013
* Cleaned up the code that frees buffers. No changes to the functionality
=============================================================================
26 sep 2013
* Changed the code to allow a filename on the command line or else if not, ask
  for one. This was done so both programs would work "the same way". No changes
  made to functionality otherwise.
=============================================================================
03 oct 2013
* Fixed a small bug.
=============================================================================
19 nov 2013
* Fixed a major bug (Windows version only). Filename buffer was too small and
  overflowed when long path names were used. The Linux version did not have
  this problem.
=============================================================================
