Gconvert: Difference between revisions

From Uzebox Wiki
Jump to navigation Jump to search
No edit summary
 
(25 intermediate revisions by 6 users not shown)
Line 1: Line 1:
Gconvert is a command line tool that converts an image into a tileset and one or more maps. It is C/C++ port from an earlier Java tool that was made to more easy to use in the make process. Check the [http://code.google.com/p/uzebox/source/browse/#svn/trunk/demos/Megatris Megatris demo project] for an example of use.
Gconvert is a command line tool that converts an image into a tileset and one or more maps. It's a C/C++ port from an earlier Java tool and was made to integrate more nicely with the makefiles. Check the [https://github.com/Uzebox/uzebox/blob/master/demos/LodeRunner/default/Makefile Lode Runner makefile] for an example of use.


Features (v1.0):
* Accepts raw (8bpp, no headers) and PNG-8 images
* Uses an XML definition file to describe the input/output files and maps to be generated
* Removes duplicate tiles
* Tileset and maps are generated in a single C include file
* Distinct variable names can be specified for the tileset and maps


===Usage===
<source lang="dos">
C:\>gconvert mydef.xml
</source>
===Definition file example===
<source lang="xml">
<source lang="xml">
<?xml version="1.0" ?>
<?xml version="1.0" ?>
<gfx-xform version="1">
<gfx-xform version="1">
    <input file="..\data\graphics.png" type="png" tile-width="6" tile-height="8" />
    <output file="..\data\graphics.inc">
        <tiles var-name="tetrisTiles"/>
        <maps pointers-size="16">
            <map var-name="map_main" left="0" top="9" width="40" height="28"/>
            <map var-name="map_title" left="0" top="37" width="33" height="9"/>
            <mega-map var-name="map_mega_tiles" mega-tile-width="5" mega-tile-height="5">
                <map var-name="map_level" left="0" top="46" width="255" height="25"/>
            </mega-map>
        </maps>
        <defines>
            <define def-name="SKY_TILE" left="0" top="1"/>
            <define def-name="GROUND_TILE" left="10" top="1"/>
            <define def-name="WATER_TILE" left="1" top="2"/>
        </defines>
    </output>
</gfx-xform>
</source>
===Useful information about the definition file===
* If your input file is a raw image file (8bpp, no header), you have to define its width and height in pixels. Example:
<source lang="xml">
<input file="example.raw" type="raw" tile-width="8" tile-height="8" width="96" height="80" />
</source>
* If your input file is a PNG image file, you don't have to define its width and height in pixels. Only 256 colors, palette-based PNG files are supported (PNG-8).  Example:
<source lang="xml">
<input file="example.png" type="png" tile-width="8" tile-height="8" />
</source>
* The ''pointer-size'' attribute in the <maps> element depends on the video mode you will be using. For mode 1, it should be 16. For all other tile-based modes, use 8. Check [[Video Modes]] for video modes information.
* Use the '''type="code"''' attribute of the output element to define the code tiles output type as required by video mode 9. This will generate a valid C include file. Currently, only 6x8 tile sizes are supported. Defaults to "8bpp".
<source lang="xml">
<output file="..\data\graphics.inc" type="code"> ... </output>
</source>
* Often you will want to have some defines that points to specific tiles in your source image. When duplicate tiles are removed during processing this can be tricky.  You can use the <defines> tags for this and it will give you the right tile from the reduced tileset.
===Output Example===
<source lang="c">
/*
* Transformation file: ../data/gconvert.xml
* Source image: ..\data\graphics.png
* Tile width: 6px
* Tile height: 8px
*/
#define SKY_TILE 0
#define GROUND_TILE 10
#define WATER_TILE 22
#define MAP_ANIM_SPARK4_WIDTH 7
#define MAP_ANIM_SPARK4_HEIGHT 4
const int map_anim_spark4[] PROGMEM ={
7,4
,0x15,0x25,0x26,0x27,0x28,0x29,0x15,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x51,0x52,0x53,0x54,0x55,0x56
,0x57,0x15,0x63,0x64,0x65,0x66,0x67,0x15};
#define MAP_ANIM_SPARK3_WIDTH 7
#define MAP_ANIM_SPARK3_HEIGHT 4
const int map_anim_spark3[] PROGMEM ={
7,4
,0x15,0x15,0x15,0x2a,0x15,0x15,0x15,0x15,0x3c,0x3d,0x3e,0x3f,0x40,0x15,0x15,0x58,0x59,0x5a,0x5b,0x5c
,0x15,0x15,0x68,0x69,0x6a,0x6b,0x6c,0x15};
...


<!--<input file="c:/uze/tetris-tiles.raw" type="raw" width="240" height="368" tile-width="6" tile-height="8" />-->
#define MAP_LEVEL_WIDTH 51
#define MAP_LEVEL_HEIGHT 5
const char map_level[] PROGMEM ={
51,5
,0x0,0x1,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x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ILE_WIDTH 5
#define MAP_MEGA_TILES_MEGA_TILE_HEIGHT 5
#define MAP_MEGA_TILES_MEGA_TILE_COUNT 35
const char map_mega_tiles[] PROGMEM ={
0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60, // de-duplicated 5x5 mega tile
0x60,0x60,0x60,0x60,0x60,0x61,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60, // de-duplicated 5x5 mega tile


<output file="..\data\graphics.inc">
...


<tiles var-name="tetrisTiles"/>
};


<maps pointers-size="16">
#define TETRISTILES_SIZE 450
<map var-name="map_main" left="0" top="9" width="40" height="28"/>
const char tetrisTiles[] PROGMEM={
<map var-name="map_title" left="0" top="37" width="33" height="9"/>
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 //tile:0


<map var-name="map_anim_spark4" left="0" top="1" width="7" height="4"/>
...
<map var-name="map_anim_spark3" left="7" top="1" width="7" height="4"/>
<map var-name="map_anim_spark2" left="14" top="1" width="7" height="4"/>
<map var-name="map_anim_spark1" left="21" top="1" width="7" height="4"/>
<map var-name="map_anim_tetris1" left="20" top="5" width="5" height="2"/>
<map var-name="map_anim_tetris2" left="25" top="5" width="5" height="2"/>
<map var-name="map_anim_tetris3" left="30" top="5" width="5" height="2"/>
<map var-name="map_anim_tspin" left="28" top="1" width="5" height="1"/>
<map var-name="map_anim_single" left="33" top="1" width="5" height="1"/>
<map var-name="map_anim_double" left="28" top="2" width="5" height="1"/>
<map var-name="map_anim_triple" left="33" top="2" width="5" height="1"/>
<map var-name="map_anim_backtoback3" left="0" top="5" width="5" height="3"/>
<map var-name="map_anim_backtoback2" left="10" top="5" width="5" height="3"/>
<map var-name="map_anim_backtoback1" left="15" top="5" width="5" height="3"/>
</maps>


</output>
};


</gfx-xform>
</source>
</source>
===Tutorial===
[[Generating Tiles and Maps with gconvert]]
===Downloads===
Definition file XML Schema: [https://github.com/Uzebox/uzebox/blob/master/tools/gconvert/schemas/gconvert_1_0.xsd]
Sources are available here: [https://github.com/Uzebox/uzebox/tree/master/tools/gconvert]
===Features Log===
====V1.7====
* Added support for 'mega-map' tag to allow for mega tile (meta tile) map compression
====V1.6====
* Can specify #define NAME VALUE to point to static tile locations
====V1.1====
* Accepts raw (8bpp, no headers) and PNG-8 images
* Uses an XML definition file to describe the input/output files and maps to be generated
* Removes duplicate tiles
* Tileset and maps are generated in a single C include file
* Distinct variable names can be specified for the tileset and maps
* Two output types: 8bpp (8 bits per pixel) or "code tiles" for use with the high resolution video mode 9

Latest revision as of 12:17, 13 September 2017

Gconvert is a command line tool that converts an image into a tileset and one or more maps. It's a C/C++ port from an earlier Java tool and was made to integrate more nicely with the makefiles. Check the Lode Runner makefile for an example of use.


Usage

C:\>gconvert mydef.xml

Definition file example

<?xml version="1.0" ?>
<gfx-xform version="1">
    <input file="..\data\graphics.png" type="png" tile-width="6" tile-height="8" />
    <output file="..\data\graphics.inc">
        <tiles var-name="tetrisTiles"/>
        <maps pointers-size="16">
            <map var-name="map_main" left="0" top="9" width="40" height="28"/>
            <map var-name="map_title" left="0" top="37" width="33" height="9"/>
            <mega-map var-name="map_mega_tiles" mega-tile-width="5" mega-tile-height="5">
                <map var-name="map_level" left="0" top="46" width="255" height="25"/>
            </mega-map>	
        </maps>	
        <defines>
            <define def-name="SKY_TILE" left="0" top="1"/>
            <define def-name="GROUND_TILE" left="10" top="1"/>
            <define def-name="WATER_TILE" left="1" top="2"/>
        </defines>
    </output>
</gfx-xform>

Useful information about the definition file

  • If your input file is a raw image file (8bpp, no header), you have to define its width and height in pixels. Example:
<input file="example.raw" type="raw" tile-width="8" tile-height="8" width="96" height="80" />
  • If your input file is a PNG image file, you don't have to define its width and height in pixels. Only 256 colors, palette-based PNG files are supported (PNG-8). Example:
<input file="example.png" type="png" tile-width="8" tile-height="8" />
  • The pointer-size attribute in the <maps> element depends on the video mode you will be using. For mode 1, it should be 16. For all other tile-based modes, use 8. Check Video Modes for video modes information.
  • Use the type="code" attribute of the output element to define the code tiles output type as required by video mode 9. This will generate a valid C include file. Currently, only 6x8 tile sizes are supported. Defaults to "8bpp".
 <output file="..\data\graphics.inc" type="code"> ... </output>
  • Often you will want to have some defines that points to specific tiles in your source image. When duplicate tiles are removed during processing this can be tricky. You can use the <defines> tags for this and it will give you the right tile from the reduced tileset.

Output Example

/*
 * Transformation file: ../data/gconvert.xml
 * Source image: ..\data\graphics.png
 * Tile width: 6px
 * Tile height: 8px
 */
#define SKY_TILE 0
#define GROUND_TILE 10
#define WATER_TILE 22

#define MAP_ANIM_SPARK4_WIDTH 7
#define MAP_ANIM_SPARK4_HEIGHT 4
const int map_anim_spark4[] PROGMEM ={
7,4
,0x15,0x25,0x26,0x27,0x28,0x29,0x15,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x51,0x52,0x53,0x54,0x55,0x56
,0x57,0x15,0x63,0x64,0x65,0x66,0x67,0x15};

#define MAP_ANIM_SPARK3_WIDTH 7
#define MAP_ANIM_SPARK3_HEIGHT 4
const int map_anim_spark3[] PROGMEM ={
7,4
,0x15,0x15,0x15,0x2a,0x15,0x15,0x15,0x15,0x3c,0x3d,0x3e,0x3f,0x40,0x15,0x15,0x58,0x59,0x5a,0x5b,0x5c
,0x15,0x15,0x68,0x69,0x6a,0x6b,0x6c,0x15};

...

#define MAP_LEVEL_WIDTH 51
#define MAP_LEVEL_HEIGHT 5
const char map_level[] PROGMEM ={
51,5
,0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,0x15,0x15,0x15,0x15};

#define MAP_MEGA_TILES_MEGA_TILE_WIDTH 5
#define MAP_MEGA_TILES_MEGA_TILE_HEIGHT 5
#define MAP_MEGA_TILES_MEGA_TILE_COUNT 35
const char map_mega_tiles[] PROGMEM ={
0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60, // de-duplicated 5x5 mega tile
0x60,0x60,0x60,0x60,0x60,0x61,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60, // de-duplicated 5x5 mega tile

...

};

#define TETRISTILES_SIZE 450
const char tetrisTiles[] PROGMEM={
 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0		 //tile:0

...

};

Tutorial

Generating Tiles and Maps with gconvert

Downloads

Definition file XML Schema: [1]

Sources are available here: [2]

Features Log

V1.7

  • Added support for 'mega-map' tag to allow for mega tile (meta tile) map compression

V1.6

  • Can specify #define NAME VALUE to point to static tile locations

V1.1

  • Accepts raw (8bpp, no headers) and PNG-8 images
  • Uses an XML definition file to describe the input/output files and maps to be generated
  • Removes duplicate tiles
  • Tileset and maps are generated in a single C include file
  • Distinct variable names can be specified for the tileset and maps
  • Two output types: 8bpp (8 bits per pixel) or "code tiles" for use with the high resolution video mode 9