Class MAP
A representation of a DIV Games Studio MAP file.
Implements
Namespace: DIV2.Format.Exporter
Assembly: DIV2.Format.Exporter.dll
Syntax
public sealed class MAP : object, IAssetFile, IFormatValidable, ISerializableAsset, IEnumerable<byte>
Remarks
Implements functions to import and export graphic maps.
Constructors
MAP(PAL, Int16, Int16, Int32, String)
Creates a new MAP instance.
Declaration
public MAP(PAL palette, short width, short height, int graphId = null, string description = "")
Parameters
Type | Name | Description |
---|---|---|
PAL | palette | |
Int16 | width | Bitmap width. |
Int16 | height | Bitmap height. |
Int32 | graphId | MAP graphic identifiers. By default is 1. |
String | description | Optional MAP description. |
Remarks
The description
field in the file only allows a 32 length ASCII null terminated string.
If the input string is shorter than 32 characters, the string is filled with null chars.
If the input string is longer than 32 characters, getting a 32 characters length substring.
MAP(Byte[])
Loads a MAP file from memory.
Declaration
public MAP(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | buffer |
MAP(String)
Loads a MAP file.
Declaration
public MAP(string filename)
Parameters
Type | Name | Description |
---|---|---|
String | filename | Filename to load. |
Fields
DESCRIPTION_LENGTH
Declaration
public const int DESCRIPTION_LENGTH = null
Field Value
Type | Description |
---|---|
Int32 | Max description character length. |
MAX_CONTROL_POINTS
Declaration
public const int MAX_CONTROL_POINTS = null
Field Value
Type | Description |
---|---|
Int32 | Max supported ControlPoints. |
MAX_GRAPH_ID
Declaration
public const int MAX_GRAPH_ID = null
Field Value
Type | Description |
---|---|
Int32 | Max allowed graph id value. |
MIN_GRAPH_ID
Declaration
public const int MIN_GRAPH_ID = null
Field Value
Type | Description |
---|---|
Int32 | Min allowed graph id value. |
MIN_PIXEL_SIZE
Declaration
public const int MIN_PIXEL_SIZE = null
Field Value
Type | Description |
---|---|
Int32 | Min supported size value for width or height properties. |
Properties
ControlPoints
Optional control point list.
Declaration
public List<ControlPoint> ControlPoints { get; }
Property Value
Type | Description |
---|---|
List<ControlPoint> | Returns the ControlPoint list for this MAP object. |
Count
Number of pixels in the bitmap.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 | Returns the number of pixels for this MAP object. |
Description
Optional graphic description.
Declaration
public string Description { get; set; }
Property Value
Type | Description |
---|---|
String | Gets or sets the description for this MAP object. |
Remarks
The description field in the file only allows a 32 length ASCII null terminated string. If the input string is shorter than 32 characters, the string is filled with null chars. If the input string is longer than 32 characters, getting a 32 characters length substring.
GraphId
Graphic identifier used in FPG files.
Declaration
public int GraphId { get; set; }
Property Value
Type | Description |
---|---|
Int32 | Gets or sets the graphic indentifier for this MAP object. |
Height
Height of the graphic map.
Declaration
public short Height { get; }
Property Value
Type | Description |
---|---|
Int16 | Returns the Height value in pixels. |
Item[Int32]
Gets or sets the color index in the bitmap.
Declaration
public byte this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | Pixel index in the bitmap array. |
Property Value
Type | Description |
---|---|
Byte | Returns the color index in the PAL instance. |
Item[Int32, Int32]
Gets or sets the color index in the bitmap.
Declaration
public byte this[int x, int y] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | Horizontal coordinate of the pixel in the bitmap. |
Int32 | y | Vertical coordinate of the pixel in the bitmap. |
Property Value
Type | Description |
---|---|
Byte | Returns the color index in the PAL instance. |
Palette
Color palette used by this graphic map.
Declaration
public PAL Palette { get; }
Property Value
Type | Description |
---|---|
PAL |
Width
Width of the graphic map.
Declaration
public short Width { get; }
Property Value
Type | Description |
---|---|
Int16 | Returns the width value in pixels. |
Methods
Clear()
Clear the bitmap.
Declaration
public void Clear()
Remarks
This function sets all pixels to zero palette color (mostly transparent black).
FromImage(Byte[])
Creates a new MAP instance from a supported image format.
Declaration
public static MAP FromImage(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | buffer |
Returns
Type | Description |
---|---|
MAP | Returns a new MAP instance from the loaded image. |
Remarks
Supported image formats are JPEG, PNG, BMP, GIF and TGA. Also supported 256 color PCX images.
FromImage(Byte[], PAL)
Creates a new MAP instance from a supported image format and converts the colors to the selected PAL instance.
Declaration
public static MAP FromImage(byte[] buffer, PAL palette)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | buffer | |
PAL | palette | PAL instance to convert the loaded image. |
Returns
Type | Description |
---|---|
MAP | Returns a new MAP instance from the loaded image. |
Remarks
Supported image formats are JPEG, PNG, BMP, GIF and TGA. Also supported 256 color PCX images and MAP files, that will be converted to the new setup PAL.
FromImage(String)
Creates a new MAP instance from a supported image format.
Declaration
public static MAP FromImage(string filename)
Parameters
Type | Name | Description |
---|---|---|
String | filename | Image file to load. |
Returns
Type | Description |
---|---|
MAP | Returns a new MAP instance from the loaded image. |
Remarks
Supported image formats are JPEG, PNG, BMP, GIF and TGA. Also supported 256 color PCX images.
FromImage(String, PAL)
Creates a new MAP instance from a supported image format and converts the colors to the selected PAL instance.
Declaration
public static MAP FromImage(string filename, PAL palette)
Parameters
Type | Name | Description |
---|---|---|
String | filename | Image file to load. |
PAL | palette | PAL instance to convert the loaded image. |
Returns
Type | Description |
---|---|
MAP | Returns a new MAP instance from the loaded image. |
Remarks
Supported image formats are JPEG, PNG, BMP, GIF and TGA. Also supported 256 color PCX images and MAP files, that will be converted to the new setup PAL.
GetBitmapArray()
Gets the bitmap array data of this instance.
Declaration
public byte[] GetBitmapArray()
Returns
Type | Description |
---|---|
Byte[] | Returns a |
GetHashCode()
Generates a hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | Returns an |
GetRGBTexture()
Declaration
public Color[] GetRGBTexture()
Returns
Type | Description |
---|---|
Color[] | Returns a new Color array with all pixel data from this bitmap. All colors are RGB format [0..255]. |
Remarks
Use this function when need to render this MAP in any modern system that works in 24 or 32 bits color space.
Save(String)
Saves the instance in a MAP file.
Declaration
public void Save(string filename)
Parameters
Type | Name | Description |
---|---|---|
String | filename | Filename to write the data. |
SetBitmapArray(Byte[])
Sets the bitmap array data for this instance.
Declaration
public void SetBitmapArray(byte[] pixels)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | pixels |
ToString()
Serializes the relevant data of this instance in a
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | Returns a |
Validate(Byte[])
Validates if the file is a valid MAP file.
Declaration
public bool Validate(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | buffer | Memory buffer that contain a MAP file data. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the file is a valid MAP. |
Validate(String)
Validates if the file is a valid MAP file.
Declaration
public bool Validate(string filename)
Parameters
Type | Name | Description |
---|---|---|
String | filename | File to validate. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the file is a valid MAP. |
ValidateFormat(Byte[])
Validates if the file is a valid MAP file.
Declaration
public static bool ValidateFormat(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | buffer | Memory buffer that contain a MAP file data. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the file is a valid MAP. |
ValidateFormat(String)
Validates if the file is a valid MAP file.
Declaration
public static bool ValidateFormat(string filename)
Parameters
Type | Name | Description |
---|---|---|
String | filename | File to validate. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the file is a valid MAP. |
Operators
Equality(MAP, MAP)
Equality operator.
Declaration
public static bool operator ==(MAP a, MAP b)
Parameters
Type | Name | Description |
---|---|---|
MAP | a | Left MAP value to compare. |
MAP | b | Right MAP value to compare. |
Returns
Type | Description |
---|---|
Boolean | Returns true if both values are equal. |
Inequality(MAP, MAP)
Inequality operator.
Declaration
public static bool operator !=(MAP a, MAP b)
Parameters
Type | Name | Description |
---|---|---|
MAP | a | Left MAP value to compare. |
MAP | b | Right MAP value to compare. |
Returns
Type | Description |
---|---|
Boolean | Returns true if both values are not equal. |