Class ImageReader
Static helper to read most Daggerfall image files in a simple, consistent manner. Useful for direct-to-texture features like UI elements. Highly simplified compared to TextureReader and MaterialReader. Not intended for generating scene materials.
Namespace: DaggerfallWorkshop.Utility
Assembly: Assembly-CSharp.dll
Syntax
public static class ImageReader
Methods
| Improve this Doc View SourceConvertToRelativeSubRect(Rect, Int32, Int32)
Converts a sub-rect to UV-styled relative coordinates. Intended to get relative coordinates from classic image rects that can be used for replacement textures at higher resolutions. The replacement texture must store sub-elements in proportionally the same place (i.e. be a direct upscale) as classic source.
Declaration
public static Rect ConvertToRelativeSubRect(Rect subRect, int srcWidth, int srcHeight)
Parameters
Type | Name | Description |
---|---|---|
Rect | subRect | Input rect using pixel coordinates into classic texture. |
Int32 | srcWidth | Full width of classic source texture. |
Int32 | srcHeight | Full height of classic source texture. |
Returns
Type | Description |
---|---|
Rect | Converted Rect using relative coordinates. |
GetColors(ImageData)
Gets Color32 array from texture. Generates texture if not present. Origin 0,0 will always be at Unity texture bottom-left.
Declaration
public static Color32[] GetColors(ImageData imageData)
Parameters
Type | Name | Description |
---|---|---|
ImageData | imageData | Source ImageData. |
Returns
Type | Description |
---|---|
Color32[] | Color32 array. |
GetImageData(String, Int32, Int32, Boolean, Boolean, Boolean, Int32)
Reads any Daggerfall image file to ImageData package.
Declaration
public static ImageData GetImageData(string filename, int record = 0, int frame = 0, bool hasAlpha = false, bool createTexture = true, bool createAllFrameTextures = false, int alphaIndex = 0)
Parameters
Type | Name | Description |
---|---|---|
String | filename | Name of standalone file as it appears in arena2 folder. |
Int32 | record | Which image record to read for multi-image files. |
Int32 | frame | Which frame to read for multi-frame images. |
Boolean | hasAlpha | Enable this for image cutouts. |
Boolean | createTexture | Create a Texture2D. |
Boolean | createAllFrameTextures | Creates a Texture2D for every frame in a TEXTURE file (if greater than 1 frames). |
Int32 | alphaIndex | Set palette index for alpha checks (default is 0). |
Returns
Type | Description |
---|---|
ImageData | ImageData. If result.type == ImageTypes.None then read failed. |
GetSubColors(Color32[], Rect, Int32, Int32)
Gets sub-rect of Color32 array.
Declaration
public static Color32[] GetSubColors(Color32[] colors, Rect subRect, int srcWidth, int srcHeight)
Parameters
Type | Name | Description |
---|---|---|
Color32[] | colors | Source Color32 array. |
Rect | subRect | Rectangle of source image to extract. |
Int32 | srcWidth | Source width. |
Int32 | srcHeight | Source height. |
Returns
Type | Description |
---|---|
Color32[] | Color32 array containing sub-rect. |
GetSubTexture(ImageData, Rect)
Cuts out a sub-texture from source ImageData. Texture
Declaration
public static Texture2D GetSubTexture(ImageData imageData, Rect subRect)
Parameters
Type | Name | Description |
---|---|---|
ImageData | imageData | Source ImageData. |
Rect | subRect | Rectangle of source image to extract. Origin 0,0 is top-left. |
Returns
Type | Description |
---|---|
Texture2D | New Texture2D containing sub-texture. |
GetSubTexture(Color32[], Rect, Int32, Int32)
Cuts out a sub-texture from source Color32 array. Useful for slicing up native UI elements into smaller functional units.
Declaration
public static Texture2D GetSubTexture(Color32[] colors, Rect subRect, int srcWidth, int srcHeight)
Parameters
Type | Name | Description |
---|---|---|
Color32[] | colors | Source Color32 array. |
Rect | subRect | Rectangle of source image to extract. Origin 0,0 is top-left. |
Int32 | srcWidth | Source width. |
Int32 | srcHeight | Source height. |
Returns
Type | Description |
---|---|
Texture2D | New Texture2D containing sub-texture. |
GetSubTexture(Texture2D, Rect, DFSize)
Cuts out a sub-texture from source texture using a virtual rect in a resolution-independent manner.
Declaration
public static Texture2D GetSubTexture(Texture2D texture, Rect subRect, DFSize srcSize)
Parameters
Type | Name | Description |
---|---|---|
Texture2D | texture | Source texture. Must be readable. |
Rect | subRect | Input rect using pixel coordinates into classic texture. |
DFSize | srcSize | Full size of classic source texture. |
Returns
Type | Description |
---|---|
Texture2D | New Texture2D containing sub-texture. |
GetSubTexture(Texture2D, Rect, Boolean)
Cuts out a sub-texture from source texture. Useful for slicing up native UI elements into smaller functional units.
Declaration
public static Texture2D GetSubTexture(Texture2D texture, Rect subRect, bool useRelativeCoords = false)
Parameters
Type | Name | Description |
---|---|---|
Texture2D | texture | Source texture. Must be readable. |
Rect | subRect | Rectangle of source image to extract. Origin 0,0 is top-left. |
Boolean | useRelativeCoords | Rect is UV-styled relative coordinates into source texture. |
Returns
Type | Description |
---|---|
Texture2D | New Texture2D containing sub-texture. |
GetTexture(String, Int32, Int32, Boolean, Int32)
Reads any Daggerfall image to Texture2D.
Declaration
public static Texture2D GetTexture(string filename, int record = 0, int frame = 0, bool hasAlpha = false, int alphaIndex = 0)
Parameters
Type | Name | Description |
---|---|---|
String | filename | Name of standalone file as it appears in arena2 folder. |
Int32 | record | Which image record to read for multi-image files. |
Int32 | frame | Which frame to read for multi-frame images. |
Boolean | hasAlpha | Enable this for image cutouts. |
Int32 | alphaIndex | Set the palette index for alpha check (default is 0). |
Returns
Type | Description |
---|---|
Texture2D | Texture2D. |
GetTexture(Color32[], Int32, Int32)
Gets texture from source Color32 array.
Declaration
public static Texture2D GetTexture(Color32[] colors, int srcWidth, int srcHeight)
Parameters
Type | Name | Description |
---|---|---|
Color32[] | colors | Source Color32 array. |
Int32 | srcWidth | Source width. |
Int32 | srcHeight | Source height. |
Returns
Type | Description |
---|---|
Texture2D | Texture2D. |
UpdateMaskTexture(ref ImageData)
Updates mask texture. The assigned Texture2D will have alpha 0 for unmasked areas and alpha 1 for masked areas. If source DFBitmap has no mask indices then mask texture will simply be all clear.
Declaration
public static void UpdateMaskTexture(ref ImageData imageData)
Parameters
Type | Name | Description |
---|---|---|
ImageData | imageData | Source ImageData. |
UpdateTexture(ref ImageData)
Updates Texture2D from DFBitmap data.
Declaration
public static void UpdateTexture(ref ImageData imageData)
Parameters
Type | Name | Description |
---|---|---|
ImageData | imageData | Source ImageData. |
UpdateTexture(ref ImageData, Color)
Updates Texture2D from DFBitmap data.
Declaration
public static void UpdateTexture(ref ImageData imageData, Color maskColor)
Parameters
Type | Name | Description |
---|---|---|
ImageData | imageData | Source ImageData. |
Color | maskColor | Set mask pixels to this colour. |