Class PAL
A representation of a DIV Games Studio PAL file.
Implements
Namespace: DIV2.Format.Exporter
Assembly: DIV2.Format.Exporter.dll
Syntax
public sealed class PAL : object, IAssetFile, IFormatValidable, ISerializableAsset, IEnumerable<Color>
Remarks
Implements functions to import and export color palettes.
Constructors
PAL()
Creates a new PAL instance.
Declaration
public PAL()
PAL(Color[])
Declaration
public PAL(Color[] colors)
Parameters
| Type | Name | Description |
|---|---|---|
| Color[] | colors | A 256 length Color array. |
PAL(ColorPalette)
Creates a new PAL instance.
Declaration
public PAL(ColorPalette colors)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorPalette | colors | ColorPalette instance. |
PAL(ColorPalette, ColorRangeTable)
Creates a new PAL instance.
Declaration
public PAL(ColorPalette colors, ColorRangeTable ranges)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorPalette | colors | ColorPalette instance. |
| ColorRangeTable | ranges | ColorRangeTable instance. |
PAL(Byte[])
Loads a PAL file.
Declaration
public PAL(byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | buffer | A memory buffer that contains PAL file. |
PAL(String)
Loads a PAL file.
Declaration
public PAL(string filename)
Parameters
| Type | Name | Description |
|---|---|---|
| String | filename | PAL filename to load. |
Fields
LENGTH
Declaration
public const int LENGTH = null
Field Value
| Type | Description |
|---|---|
| Int32 | Number of colors. |
SIZE
Declaration
public const int SIZE = null
Field Value
| Type | Description |
|---|---|
| Int32 | Memory size. |
Properties
Colors
Palette colors, in DAC format.
Declaration
public ColorPalette Colors { get; }
Property Value
| Type | Description |
|---|---|
| ColorPalette | Returns the ColorPalette instance. |
Item[Int32]
Gets or sets a Color value.
Declaration
public Color this[int index] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index | Color index. |
Property Value
| Type | Description |
|---|---|
| Color | Returns the Color value. |
Ranges
Color range table.
Declaration
public ColorRangeTable Ranges { get; }
Property Value
| Type | Description |
|---|---|
| ColorRangeTable | Returns the ColorRangeTable instance. |
Methods
FromImage(Byte[], Boolean)
Creates new PAL instance from a supported image file.
Declaration
public static PAL FromImage(byte[] buffer, bool sortColors = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | buffer | Memory buffer that contains a supported image file. |
| Boolean | sortColors | Indicates if is needed to sort colors of the imported palette. By default is false. |
Returns
| Type | Description |
|---|---|
| PAL | Returns a new PAL instance. |
Remarks
Supported image formats are JPEG, PNG, BMP, GIF and TGA. Also supported 256 color PCX images, MAP and FPG files.
FromImage(String, Boolean)
Creates new PAL instance from a supported image file.
Declaration
public static PAL FromImage(string filename, bool sortColors = false)
Parameters
| Type | Name | Description |
|---|---|---|
| String | filename | Image file to load. |
| Boolean | sortColors | Indicates if is needed to sort colors of the imported palette. By default is false. |
Returns
| Type | Description |
|---|---|
| PAL | Returns a new PAL instance. |
Remarks
Supported image formats are JPEG, PNG, BMP, GIF and TGA. Also supported 256 color PCX images, MAP and FPG files.
GetHashCode()
Generates a hash code for this instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 | Returns an |
Save(String)
Saves the instance in a PAL file.
Declaration
public void Save(string filename)
Parameters
| Type | Name | Description |
|---|---|---|
| String | filename | Filename to write the data. |
Sort()
Sorts the Color values.
Declaration
public void Sort()
Remarks
This method try to sort the colors using the Nearest Neighbour algorithm, trying to ensure that the black color (0, 0, 0), if exists in palette, be the first color.
ToRGB()
Creates a copy of the Color array converted to full RGB format [0..255].
Declaration
public Color[] ToRGB()
Returns
| Type | Description |
|---|---|
| Color[] | Returns a new Color array in full RGB format [0..255]. In most of the cases, these values are an aproximation to the real RGB value. |
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 PAL file.
Declaration
public bool Validate(byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | buffer | Memory buffer that contain a PAL file data. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the file is a valid PAL. |
Validate(String)
Validates if the file is a valid PAL 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 PAL. |
ValidateFormat(Byte[])
Validates if the file is a valid PAL file.
Declaration
public static bool ValidateFormat(byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | buffer | Memory buffer that contain a PAL file data. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the file is a valid PAL. |
ValidateFormat(String)
Validates if the file is a valid PAL 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 PAL. |
Operators
Equality(PAL, PAL)
Equality operator.
Declaration
public static bool operator ==(PAL a, PAL b)
Parameters
| Type | Name | Description |
|---|---|---|
| PAL | a | Left PAL value to compare. |
| PAL | b | Right PAL value to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if both values are equal. |
Inequality(PAL, PAL)
Inequality operator.
Declaration
public static bool operator !=(PAL a, PAL b)
Parameters
| Type | Name | Description |
|---|---|---|
| PAL | a | Left PAL value to compare. |
| PAL | b | Right PAL value to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if both values are not equal. |