﻿Engie File Converter
-------------- Created by by Nyerguds (04/04/2017)

This tool was originally created to allow viewing and converting image formats found in the
Nintendo 64 ROM of the Command & Conquer game. Since then, it has evolved into a more general
modding suite supporting a large range of file formats from classic 90's era games.


Special thanks to:
-Kamuix and Chad1233 for their help in testing this
-Moon Flower for the help in designing the palette manager
-MrFlibble for restoring the beta C&C95 Engineer icon.


If you like what I'm doing, and you have too much money, feel free to donate:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=nyerguds@gmail.com&currency_code=EUR


Features:
--------
-Supports opening and saving all classic image types (png/gif/bmp/jpg), and a load of game formats.
-Gives a visual representation of the loaded file, with zoom and adjustable background color.
-Can display and edit the file's color palette, if it has one.
-Can save opened files as any supported format, though some conversions are obviously impossible;
 high-color images can't be saved as palette, and only maps can be saved as maps.
-Preserves the color palette when saving 4-bit and 8-bit paletted images.
-Supports drag & drop for opening files.
-Has utilities to help generate height maps for missions.
-Offers save options for the types that need them.


Acknowledgements:
----------------
Any icons used in the program (except for the Engineer icon) are based on the
Fugue Icons 16x16 pack by Yusuke Kamiyamane (Copyright (C) 2010)
http://p.yusukekamiyamane.com/

The study of the C&C64 files was made possible by the Universal Game Decompressor
(GEDecompressor), made by SubDrag.
http://www.goldeneyevault.com/viewfile.php?id=213

The PC C&C formats were deciphered using documentation written by Vladan Bato.

The compression code used for handling the CPS and LCW formats was gracefully provided by the
people of the Chronosphere (formerly RA++) project. OmniBlade has been particularly helpful.
https://redalertpp.org/

The Dynamix LZW decompression code was converted from the C++ code of VOGONS.org user tikalat's
Midi Tools. It contains no license but I assume the fact he included the code implies that he
doesn't mind it being useful to more people.
https://www.vogons.org/viewtopic.php?p=273448#p273448

The Dynamix LZSHuff decompression was identified thanks to NewRisingSun in that same thread:
https://www.vogons.org/viewtopic.php?p=306003#p306003

The K.O.R.T. image format was decoded thanks to documentation included in the K.O.R.T. savegame
editor written by David Eriksson, aka Edison of 2GooD:
http://www.2good.nu/projekt/korted

The K.O.R.T. BMP format was mapped by TheRuler on the OldGamesItalia forum:
http://www.oldgamesitalia.net/forum/index.php?s=&showtopic=16027&view=findpost&p=360174

The code of ScummVM helped a lot to figure out the compression on the Elvira VGA format.
https://www.scummvm.org/

The Mythos Visage format's RLE compression formats were figured out by user Ceiwad of the
shikadi.net modding wiki, who posted his findings here:
http://www.shikadi.net/moddingwiki/Visage_Format
(though the topic has been thoroughly clarified by me since then :p)

The Dune II SHP format was implemented based on a document written by Ultraq, with further
assistance from OmniBlade.

The DaisyField format's decryption was vastly simplified thanks to some hints from CTPAX-X Team.

The Interactive Girls Club bit mask compression was figured out thanks to CTPAX-X Team.


Version history:
---------------
This tool started as the CnC64ImageViewer, but later got expanded to a full conversion suite.
At that point, it became the CnC64FileConverter v1.0. As of v1.3, it has been renamed to
Engie File Converter.


Engie File Converter versions:

v1.5.1: (28/02/2020 12:11)
-Fixed an error in the save logic for Mythos VDA that made it add an extra frame at the start.

v1.5.0: (26/02/2020 14:19)
-Cleaned up loads of obsolete internals related to color palette handling.
-Six-bit colors now correctly scale up to 0-255, rather than the simple *4 that gave 0-252.
-Added "Save raw" option, for saving the raw bytes of the loaded image.
-Added support for the raw 4-bit "cinema" images accompanying the Nova images in
 Cover Girl Strip Poker. They will be added as frames when found alongside the .PPP file.
-Fixed transparency issues in the Windows Icon format on 32-bit DIB images.
-Kings of the Beach PAK format no longer needs an external palette; it's standard EGA.
-An image split into frames retains the source file's "needs external palette" status.
-Editing a color on the palette now preserves its alpha value.
-Added automatic palette loading to PC CPS format.
-VGS format no longer thinks its input frames need to be 320x200.
-AdventureSoft VGA format no longer shown the always-empty first frame.
-AdventureSoft icon format no longer shows an image on frame -1.
-AdventureSoft icon format can no longer be converted from one large image, since there
 are tools for splitting frames now.
-When saving an image as icon, the user is give choices of what sizes to include.
-Added support for the Blade Runner 16-bit SHP format.
-Fixed an error that corrupted duplicate characters in the Westwood Font File format.
-Fixed duplicates check in Dynamix BMP Matrix type.
-Removed transparency mask on index 0 from Dynamix BMP Matrix type.
-Removed useless 4-bit view from Dynamix SCR format.

v1.4.9: (29/10/2019 11:05)
-Added palette visualiser to the "Match to palette" function.

v1.4.8: (29/10/2019 10:00)
-Fixed broken detection of Nintendo 64 C&C maps.

v1.4.7: (28/10/2019 19:01)
-"Paste on frames" now also works for a single image.
-Fixed flickering on zoom.
-Added "Match to palette" function under Edit -> Colors.
-The "Palette to image" and "4-bit palette from 8-bit palette" functions now work whenever
 a palette is shown on the UI, including for the '-1' frame on frames with a common palette.
-"Palette to image" will now use the name of the palette if it was selected from the dropdown.

v1.4.6: (14/07/2019 12:00)
-Fixed more bugs in palette management tool
-Added palette manager in menu, independent from palette saving.
-Added an "Image to palette" tool to convert the pixels from an image to palette colors.
-Added a "palette to image" tool to convert the palette of the current image to an image.
-Added own loading logic for BMP format, to correctly identify 16-bit BMP files.

v1.4.5: (18/06/2019 13:56)
-Added support for the Interactive Girls GX2 format.
-Added read-only support for the GX2 images in Interactive Girls .m3 / .slb archives.
-Fixed a crash when converting an indexed image to a smaller palette in the frames splitter.

v1.4.4: (05/06/2019 19:00)
-Single-image Visage files no longer show their dimensions as 0×0.
-Optimised the drawing of the palette control.
-Fixed bug where WSA files continuing from a previous file added messy pixels on the first frame.
-Fixed bug where zooming out from level 2 using mouse scroll or arrows went to -2 instead of 1.
-Added support for the Interactive Girls DMP image format.
-Added support for the DaisyField PIC images format.
-Added support for the Cover Girl Strip Poker NOVA image format.
-Added support for the 15 Move Hole BIF image format.
-Added reading support for the SexTris image format.

v1.4.3: (22/01/2019 18:47)
-Simplified internal workings of the palette panel
-Added support for Playstation and Amiga palettes.
-Added a "paste from clipboard" button on the Paste on Frames dialog.

v1.4.2: (28/11/2018 12:25)
-Fixed several issues with CPS and WSA loading.
-Added support for ToonStruck 640x480 CPS format.

v1.4.1: (16/10/2018 14:42)
-Compacted the UI to allow showing more additional info.
-Fixed the position of Lands of Lore SHP in the save types list.
-Optimised Dune II and Lands of Lore SHP; they no longer store duplicate frames.
-Fixed image to frames splitting for indexed images of types lower than 256 color.
-Splitting an indexed image into frames now also sets the palette on empty frames.
-Added option to save Tiberian Sun SHP as uncompressed; required for the mouse cursor.

v1.4.0: (07/09/2018 13:00)
-Added multithreading to all operations, to prevent UI freezes.
-Pasting on a range of frames no longer makes it lose its "has common palette" status.
-Improved error handling on Mythos VGS/VDA saving.
-Added full support for the Lands of Lore SHP format (Dune II SHP embedded in a CPS file).
-Enhanced WSA chaining logic to allow chaining from CPS files, and from larger dimensions.
-Fixed bugs in WSA detection logic.

v1.3.6: (04/09/2018 16:27)
-Fixed the frame range interpreter used in "Paste image on frames" and in Dune II saving.
-Sped up conversion from high color to palette by caching color values in a lookup table.

v1.3.5: (24/08/2018 07:40)
-Fixed a bug in the splitting logic for non-32bpp high color images.

v1.3.4: (23/08/2018 18:40)
-Improved the radar color options for Tiberian Sun SHP files.
-Added support for Amiga CPS files. The multi-palette types are handled as frames.

v1.3.3: (21/08/2018 12:20)
-Fixed scaling issue on images with custom DPI setting.
-Added automatic maximum zoom boundary to avoid memory corruption in PictureBox.
-Added zoom levels below "1". Negative values are seen as fractions, so it skips 0 and -1.

v1.3.2: (20/08/2018 14:15)
-Added a palette selector for the fill color in the frames-to-image options list.
-Fixed a crash when matching an indexed image to a palette in the image-to-frames window.

v1.3.1: (18/08/2018 20:15)
-The background color selector on the UI is now a control selectable with [Tab].
-Added support for C&C SHP files with a loop frame.
-Added support for the Monopoly type to the WSA format.
-Fixed palette handling so type-based transparency is only applied once, on file load.
-Enhanced frames-to-image with a background color fill option.
-Enhanced image-to-frames with a background color trim option.
-Enhanced image-to-frames with a palette matching option.

v1.3.0: (10/08/2018 23:05)
-Renamed the project. Original projected name was "Nyerguds's Game File Converter", or "NGFC",
 which then mutated into "Engie FC", or "Engie File Converter".
-Visage Animation load chaining now also works with a png file as base for a chain.
-Fixed a problem with 16bpp formats in the "Paste on frames" function.
-Disabled command line conversion; it was unfinished and unmaintained. Might fix it up later.
-Added function to convert a single image to frames, by specifying the frame size.
-Added function to convert frames to a single image, with the option to expand the frame sizes.


CnC64FileConverter versions:

v1.2.20: (03/08/2018 12:40)
-Added better memory management in the "paste image on frames" feature.
-Optimised the paste logic for frame ranges containing palette differences.
-Files that were pasted on will no longer identify as having a common palette if they don't.
-Visage Animation continued from a previous file will now use its own palette everywhere.

v1.2.19: (03/08/2018 21:20)
-Loading a Visage Animation's initial state from PNG no longer messed up the save logic.
-Added feature to paste an image on a range of frames.

v1.2.18: (27/07/2018 20:30)
-Implemented Westwood Dune II Shape (SHP) support.
-Save options can now get disabled based on a parent option's value.
-Save options with text input can now filter out illegal characters.

v1.2.17: (19/07/2018 19:21)
-Implemented Westwood Tiberian Sun Shape (SHP) support.

v1.2.16: (16/07/2018 08:50)
-Implemented Westwood C&C1/RA1 Shape (SHP) support.
-Fixed slow loading on VDA files due to bug in color palette handling.

v1.2.15: (10/07/2018 18:35)
-Saving Mythos VDA no longer allows frames after 0 to have pixels of color 255 on new locations.
-Disallowed saving frame types as palettes since some types don't have a global palette.
-Fixed "File not found" error when trying to load a Mythos VDA file without VDX.
-Added the ability to change the alpha value on palette indices. PNG supports such palette-alpha.
-Mythos animations now show the total chunk count in the file on the index frame.
-Added more detailed save options for the Mythos animations compression algorithm.

v1.2.14: (28/06/2018 13:50)
-A VDA chained from png will now indicate its first frame the same way as a normally loaded png.
-Fixed bug that could let WSA load chaining skip missing files (which wouldn't load correctly).
-Fixed chunk overflow check mechanism in the VDA animations save process.
-Indexed images saved as png get a save option asking to save without transparency.
 This option defaults to true on types with a fixed transparency index determined by the game.
-Fixed bug in Mythos collapsed-transparency compression that made it save a wrong header size.
-Changed Windows icon handling so it no longer shows up as a type that supports frame input.
-Fixed focus issues in the save options window.

v1.2.13: (26/06/2018 13:04)
-Added check on maximum compressed length in Mythos RLE format; it can't exceed 0xFFFF.
-Added check on maximum amount of chunks when saving Mythos VDA format; it can't exceed 0x7FFF.
-Added a leniency (of 8/256) to the palette match check in Mythos VDA chaining logic.
-Added ability to override normal chaining with a single png image of the same name.
-Added proper cleanup of temporary images in memory loaded in the chaining logics.
-Added fixes for some unlikely fringe cases in VDA chaining that could crash the program.

v1.2.12: (24/06/2018 19:25)
-Changed load chaining on the Mythos animation format so the found base frame is added.
 Westwood WSA format reserves an empty frame for this anyway, so it remains unchanged.

v1.2.11: (24/06/2018 17:00)
-Changed chunk merging on Mythos VDA format to a save option.
-Improved multiple-extensions support in saving dialog.
-Optimised Mythos animation VDX writing to avoid using expensive 'new offset' commands.
-Fixed bug that made Mythos animations not save from loaded image file frames.
-Added load chaining for Mythos VDA and Westwood WSA format.
-Improved support for opening Windows icon files.

v1.2.10: (23/06/2018 01:00)
-Fixed transparency support in several supported types.
-Added identical-tile optimising in C&C tileset saving.
-Fixed bug in PixelFormatter that corrupted color writing by mixing up the channels order.
-Fixed bug in the Mythos RLE compression when saving flag bytes near the end of a line.
-Implemented loading and saving of Mythos animation and palette files.

v1.2.9: (06/06/2018 14:40)
-Added Westwood palette stretch tables as new supported type.
-When zooming in, the image panel will stay centered on one point.
-Unloaded images are now properly cleaned up and removed from memory.
-Upgraded the general pixel format converter used for N64 16-bit images.
-Changed name of "Mythos VGS format" to "Mythos Visage format".
-Fixed bug that removed transparency from the last frame in Mythos Visage format.
-Implemented full compression loading and saving support for Mythos Visage format.

v1.2.8: (25/01/2018 18:50)
-Added vertical image scrolling with shift + scrollwheel.
-Image types that can natively be opened by the .Net framework but are not specifically
 supported in the editor (like .tif) will now open as general type "Image".
-The disabled palette dropdown will now correctly display the reason why it is disabled.
-When loading a file, the zoom factor will automatically adjust to the loaded image.

v1.2.7: (15/11/2017 07:36)
-Fixed background handling in MA8 chunk data by switching index 00 and FF on the image.

v1.2.6: (15/11/2017 14:32)
-Added support for MA8 format used in the Macintosh versions of the Dynamix images.

v1.2.5: (09/11/2017 13:47)
-Fixed the X and Y trimming functions to make WSA save work correctly.

v1.2.4: (20/10/2017 13:37)
-Fixed some checks in the file load to make them fail properly instead of giving internal errors.
-Added Westwood WSA format, though the detection might not be 100% correct yet.

v1.2.3: (26/09/2017 19:05)
-Fixed oversight in the KotB format. The written files now work correctly in the game.

v1.2.2: (24/09/2017 16:50)
-Fixed main chunks in Dynamix files not saving as container chunks.

v1.2.1: (23/09/2017 21:23)
-Fixed crash when saving images with uneven width in Dynamix VGA/BIN format.
-Added tighter checks on Dynamix image input; they can only handle widths divisible by 8.
-Exporting to frames now always takes png as default format.

v1.2: (22/09/2017 15:30)
-Added new Save Options dialog for types that need extra options for saving.
-Added very efficient automatic filter system to determine what types a file can be saved as.
-Removed "export" function; it was no longer useful.
-Fixed errors in loading and saving code for Kings of the Beach .PAK format.
-Restricted Kings of the Beach .PAK format to 320x200 for better autodetect accuracy.
-Changed form size to be able to display a 640x480 image without needing a resize.
-Optimised, simplified and unified all the different RLE compression methods.
-Added support for loading and saving Westwood CPS using the standard LZW algorithm.
-Removed automatic grayscale conversion on paletteless C&C64 images.
-Detects most specific type when opening a general format like "Image" through the Open menu.
-Type detection is restricted to the types contained in the chosen type in the Open File menu.

v1.1.4: (13/09/2017 09:27)
-Improved file detection checks and error message handling in several file types.

v1.1.3: (12/09/2017 21:20)
-Optimised RLE compression for Elvira VGA format to compress better than the original.
-Added checks on empty data before saving.
-Changed frames handling so types can have frames without being seen as a frames container.
-Added support for viewing the 4-bit version of Dynamix SCR files using new frames system.
-Disabled support for Dynamix BMP files; the image data can't actually be viewed anyway.
-When opening an empty file, the program will not not attempt type detection.
-Importing a range of frames from numbered files now also works when opening an empty file.
-Saving frames data without a full image filters out non-frames types in the Save dialog.
-Fixed bug where the stride wasn't collapsed to the width on grayscale C&C64 images.
-Added support for King of the Beach .PAK image format.

v1.1.2: (07/09/2017 15:03)
-Added better support for frames; when opening an image with a numeric suffix that is part of
 a range of images, the tool will ask to load it as frames.
-Added Elvira VGA writing support.

v1.1.1: (10/08/2017 15:53)
-Added support for different compression types in CPS files.

v1.1.0: (05/08/2017 19:43)
-Added support for the KORT_DAT.### images of "King Arthur's Knights of the Round Table"
-For formats with optional compression, (like SCR), hold shift while clicking "save"
 to save as uncompressed.

v1.0.9: (31/07/2017 00:24)
-Fixed confusing naming in internal toolsets, and simplified byte reading/writing methods.
-Fixed bug where the height map conversion tools caused files to lose their file name,
 which caused crashes when trying to save the result.
-Fixed errors in CPS reading.
-Added Dynamix SCR reading and writing, though only the VGA/BIN type is supported.

v1.0.8: (05/05/2017 17:53)
-Fixed bugs in opening logic that made the program give errors on opening .IMG files.
-Fixed oversight in .IMG saving logics that didn't pass on the palette length.
-Fixed bug in the N64 8-bit palette data that gave it the .pa4 extension.
-Added support for reading and writing LCW-compressed images.

v1.0.7: (01/05/2017 20:08)
-Added an option to copy the image to the clipboard.
-Added palette support for paletteless file formats.
-Added the ability to open C&C template (tileset) files.

v1.0.6: (07/04/2017 22:34)
-Fixed bug in the file open logic that prevented opening certain types through the menus.

v1.0.5: (07/04/2017 21:21)
-Fixed a bug that prevented full clearing of the left map edge
-Fixed a minor bug in the terrain type definitions.
-When an ini file dropped into the program it will check if a map can be found for it.
-UI options now get disabled when not applicable.

v1.0.4: (07/04/2017 17:32)
-The converted 65x65 height maps will immediately be loaded in the program as paletteless IMG
 format, so they can more easily be saved into that format.

v1.0.3: (07/04/2017 15:30)
-Fixed small palette import bug in tilesets
-Added tools to generate height maps from missions.

v1.0.2: (04/04/2017 23:53)
-Fixed png export of map files.

v1.0.1: (04/04/2017 23:33)
-Fixed behaviour of map import to allow PC maps saved by CCMAP.

v1.0: (04/04/2017 22:33)
-Removed img type debug info (internal data size) from the user interface.
-Can now open normal images (png/gif/bmp/jpg).
-Can now open both PC and N64 format C&C maps, visualizing them as 64x64 image with terrain types,
 and allowing saving as the other type (or as image).
-Added code to correctly open paletted png images that contain transparency.
-Added code to correctly open and save paletted png images with incomplete color palettes.
-Added theater detection for maps. If there's an ini, it'll read it from that.
-Added support for PC and N64 color palettes.
-Added support for saving N64 IMG format, and specifically paletteless greyscale IMG.
-Added read support for terrain tiles; the're triplets of DA4/ND4/PA4 or DA8/ND8/PA8 files.


CnC64ImageViewer versions:

v1.2.2: (03/02/2017 08:00)
-Fixed a crash in the zooming panel arrow keys scrolling.

v1.2.1: (20/11/2016 16:00)
-Added error checking and feedback on failure to load.
-Optimized palette viewer, and added an indicator for transparency.
-Version number is shown on the title bar.
-Fixed a bug in the viewer that made it shift the image slightly up.

v1.2: (19/11/2016 17:21)
-Identified last unknown value in the header as part of the "number of colors" value.
-Added palette viewer.
-Added icon.

v1.1: (19/11/2016 14:35)
-Tool now shows the full header data and other file info.
-Implemented zoom on the viewer.
-Transparency color in the viewer can be customized.
-Added classic Open / Save buttons with dialogs.

v1.0: (19/11/2016 01:04)
-Very rudimentary decoder and viewer.
-Double-clicking an image saves it to disk as png in folder of origin.
