/*=========================================================================== * * File: Dftextimg.H * Author: Dave Humphrey (uesp@m0use.net) * Created On: Thursday, June 28, 2001 * * Defines the DFTextureImage class which handles one image from a * Daggerfall texture file. Should be included by DFTEXTURE.H only. * *=========================================================================*/ #ifndef __DFTEXTIMG_H #define __DFTEXTIMG_H /*=========================================================================== * * Begin Required Include Files * *=========================================================================*/ #include "uesp/dagger/common/dfcommon.h" #include "common/file/genfile.h" /*=========================================================================== * End of Required Include Files *=========================================================================*/ /*=========================================================================== * * Begin Defines * *=========================================================================*/ /* Code set limit used when loading/saving files */ #define DFTEXTURE_MAX_SUBIMAGES 128 /* Standard file offsets to data */ #define DFTEXTURE_HEADER_OFFSET 0l #define DFTEXTURE_OFFSETLIST_OFFSET 26l /* Maximum allowed image sizes */ #define DFTEXTURE_MAXIMAGE_WIDTH 400 #define DFTEXTURE_MAXIMAGE_HEIGHT 300 /* Used to decode RLE type images, Width*4 */ #define DFTEXTURE_MAXRLEROW_SIZE 1600 /* Standard texture record sizes */ #define DFTEXTURE_OFFSET_RECORDSIZE 20 #define DFTEXTURE_HEADER_RECORDSIZE 26 #define DFTEXTURE_IMAGEHEADER_SIZE 28 /* Standard size of texture image rows */ #define DFTEXTURE_IMAGEROW_WIDTH 256 /*=========================================================================== * End of Defines *=========================================================================*/ /*=========================================================================== * * Type and Structure Definitions * *=========================================================================*/ #pragma pack(push, 1) /* Texture image header description */ typedef struct { short XOffset; /* Possible image offset? */ short YOffset; short Width; /* Image dimensions in pixels */ short Height; short CompressType; /* Type of compression used? */ long ImageSize; /* Stored image size in bytes */ long DataOffset; /* File offset to image data from header start */ short SubImageType; /* Type of sub-image data */ short NumSubImages; /* Number of sub-images */ long Unknown1; /* Unknown data */ short Unknown2; } dftextimgheader_t; /* Information needed for sub-image data */ typedef struct { short Width; /* Size of sub-image */ short Height; long Offset; /* Used when loading/saving image */ long ImageSize; /* True size of image in bytes */ byte* pData; /* Sub-image data */ } dftextsubimg_t; /* Used for RLE type image data */ typedef struct { short Offset; unsigned short Compressed; } dftextrleinfo_t; #pragma pack(pop) /*=========================================================================== * End of Type and Structure Definitions *=========================================================================*/ /*=========================================================================== * * Class CDFTextureImage Definition * * Manipulates one image from a Daggerfall texture file. * *=========================================================================*/ class CDFTextureImage : public CGenFile { /*---------- Begin Protected Class Members ----------------------*/ protected: dftextimgheader_t m_Header; /* Image header information */ long m_HeaderOffset; /* Location of header in file */ long m_ImageSize; /* Size of image data in bytes */ dftextsubimg_t* m_pSubImages; /* Array of subimage data */ int m_NumSubImages; int m_Tag; /* Used for custom user data */ /*---------- Begin Protected Class Methods ----------------------*/ protected: /* Helper methods to allocate the sub-image array and data */ void AllocateSubImages (void); byte* AllocateSubImageData (const int Index, const size_t Size); /* Input helper methods */ boolean ReadData (void); boolean ReadHeader (void); boolean ReadRLEData (void); boolean ReadRLESubImageData (void); boolean ReadSubImageData (void); boolean ReadSubImageInfo (void); /* Output helper methods */ //boolean WriteData (void); //boolean WriteHeader (void); //boolean WriteRLEData (void); //boolean WriteRLESubImageData (void); //boolean WriteSubImageData (void); //boolean WriteSubImageInfo (void); /* Helper methods to uncompress a RLE encoded row of image data */ boolean UncompressRLERow (const dftextrleinfo_t& RowInfo, byte** ppDataPtr); boolean UncompressSubImageRow (const int SubImageIndex, byte** ppDataPtr); /*---------- Begin Public Class Methods -------------------------*/ public: /* Class Constructor and Destructor */ CDFTextureImage(); virtual ~CDFTextureImage() { Destroy(); } virtual void Destroy (void); /* Class get members */ short GetXOffset (void) const; short GetYOffset (void) const; short GetWidth (void) const; short GetHeight (void) const; short GetSubImageType (void) const; long GetImageSize (void) const; long GetDataOffset (void) const; long GetAbsDataOffset (void) const; short GetNumSubImages (void) const; short GetCompressType (void) const; long GetUnknown1 (void) const; short GetUnknown2 (void) const; long GetHeaderOffset (void) const; long GetTrueImageSize (void) const; int GetTag (void) const; /* Get the given image data */ byte* GetImageData (const int Index = 0) const; short GetWidth (const int Index) const; short GetHeight (const int Index) const; /* Is the image data compressed */ boolean IsCompressed (void) const; /* Checks the validity of a sub-image index */ boolean IsValidImageIndex (const int Index) const; /* Read/write the image data from/to the current file stream */ boolean Read (void); //boolean Write (void); /* Set class members */ void SetTag (const int Value = 1); }; /*=========================================================================== * End of Class CDFTextureImage Definition *=========================================================================*/ /*=========================================================================== * * Begin CDFTextureImage Inline Methods * *=========================================================================*/ /* Class get members */ inline short CDFTextureImage::GetXOffset (void) const { return (m_Header.XOffset); } inline short CDFTextureImage::GetYOffset (void) const { return (m_Header.YOffset); } inline short CDFTextureImage::GetWidth (void) const { return (m_Header.Width); } inline short CDFTextureImage::GetHeight (void) const { return (m_Header.Height); } inline short CDFTextureImage::GetCompressType (void) const { return (m_Header.CompressType); } inline long CDFTextureImage::GetImageSize (void) const { return (m_Header.ImageSize); } inline long CDFTextureImage::GetDataOffset (void) const { return (m_Header.DataOffset); } inline long CDFTextureImage::GetAbsDataOffset (void) const { return (m_HeaderOffset + m_Header.DataOffset); } inline short CDFTextureImage::GetNumSubImages (void) const { return (m_Header.NumSubImages); } inline short CDFTextureImage::GetSubImageType (void) const { return (m_Header.SubImageType); } inline long CDFTextureImage::GetUnknown1 (void) const { return (m_Header.Unknown1); } inline short CDFTextureImage::GetUnknown2 (void) const { return (m_Header.Unknown2); } inline long CDFTextureImage::GetHeaderOffset (void) const { return (m_HeaderOffset); } inline long CDFTextureImage::GetTrueImageSize (void) const { return (m_ImageSize); } inline int CDFTextureImage::GetTag (void) const { return (m_Tag); } /* Get info on a specific image */ inline short CDFTextureImage::GetWidth (const int Index) const { if (GetNumSubImages() <= 1) return (m_Header.Width); if (IsValidImageIndex(Index)) return (m_pSubImages[Index].Width); return (0); } inline short CDFTextureImage::GetHeight (const int Index) const { if (GetNumSubImages() <= 1) return (m_Header.Height); if (IsValidImageIndex(Index)) return (m_pSubImages[Index].Height); return (0); } inline byte* CDFTextureImage::GetImageData (const int Index) const { if (IsValidImageIndex(Index)) return (m_pSubImages[Index].pData); return (NULL); } /* Check the validity of a sub-image index */ inline boolean CDFTextureImage::IsValidImageIndex (const int Index) const { if (Index >= 0 && Index < GetNumSubImages()) { IASSERT(m_pSubImages != NULL); return (TRUE); } return (FALSE); } /* Is the image data RLE compressed */ inline boolean CDFTextureImage::IsCompressed (void) const { return ((GetCompressType() == 0x1108 || GetCompressType() == 0x0108) ? TRUE : FALSE); } /* Class set members */ inline void CDFTextureImage::SetTag (const int Value) { m_Tag = Value; } /*=========================================================================== * End of CDFTextureImage Inline Methods *=========================================================================*/ #endif /*=========================================================================== * End of File DFTextImg.H *=========================================================================*/