/*=========================================================================== * * File: Dfcif.H * Author: Dave Humphrey (uesp@m0use.net) * Created On: Tuesday, June 26, 2001 * * Description * *=========================================================================*/ #ifndef __DFCIF_H #define __DFCIF_H /*=========================================================================== * * Begin Required Include Files * *=========================================================================*/ #include "uesp/dagger/image/dfimg.h" /*=========================================================================== * End of Required Include Files *=========================================================================*/ /*=========================================================================== * * Begin Defines * *=========================================================================*/ /* CIF image and file flag values */ #define DFCIF_FLAG_HASWEAPONHEADER 0x0100 /* Has a weapon group header */ #define DFCIF_FLAG_ISWEAPON 0x0200 /* Is a weapon CIF file? */ #define DFCIF_FLAG_HASNOFIRSTIMAGE 0x0400 /* Weapon files with no first image */ #define DFCIF_FLAG_ISCOMPRESSED 0x0800 /* For special RLE type compressed images */ #define DFCIF_FLAG_HASOFFSETLIST 0x1000 /* For weapon CIF files */ /* Size of the weapon CIF offset list */ #define DFCIF_OFFSETLIST_SIZE 64 /* Number of images allowed per CIF file */ #define DFCIF_MAX_IMAGES 64 /* Minimum number of bytes left to consider data another image record */ #define DFCIF_MINBYTES_LEFT 12 /* Number of subimage offsets in a weapon CIF */ #define DFCIF_NUM_OFFSETS 32 /*=========================================================================== * End of Defines *=========================================================================*/ /*=========================================================================== * * Class CDFCifImage * * Defines a single image contained within a CIF file. * *=========================================================================*/ class CDFCifImage : public CDFImgFile { /*---------- Begin protected Class Members ----------------------*/ protected: int m_CIFGroup; /* The weapon cif group index number */ /*---------- Begin protected Class Methods ----------------------*/ protected: /* Helper input/output routines */ boolean ReadHeader (void); boolean WriteHeader (void); boolean ReadCompressedData (void); boolean WriteCompressedData (void); /*---------- Begin Public Class Methods -------------------------*/ public: /* Overloaded constructor/destructor */ CDFCifImage(); virtual void Destroy (void); /* Check object flags */ boolean HasWeaponHeader (void) const; boolean IsWeaponCIF (void) const; boolean HasCIFOffsetList (void) const; boolean IsCompressed (void) const; int GetCIFGroup (void) const; /* Read/write in image data from a file stream */ virtual boolean Read (void); virtual boolean Write (void); /* Get object flags */ void SetWeaponHeader (const boolean Value); void SetWeaponCIF (const boolean Value); void SetCIFGroup (const int Group); void SetCompressed (const boolean Value); void SetCIFOffsetList (const boolean Value); }; /*=========================================================================== * End of Class CDFCifImage *=========================================================================*/ /*=========================================================================== * * Class CDFCifFile * * Handles the manipulation of Daggerfall CIF type files. * *=========================================================================*/ class CDFCifFile : public CGenFile { /*---------- Begin Private Class Members -------------------------*/ private: int m_GroupCounter; /* Used when loading CIF weapon files */ /*---------- Begin Protected Class Members -----------------------*/ protected: CDFCifImage* m_pImages[DFCIF_MAX_IMAGES]; /* The CIF image data */ int m_NumImages; int m_Flags; /*---------- Begin Protected Class Methods -----------------------*/ protected: /* Input helper functions */ boolean ReadCIF (void); boolean ReadWeaponCIF (void); boolean ReadFirstWeaponImage (void); boolean ReadWeaponGroup (void); boolean ReadWeaponGroupImage (void); /* Output helper functions */ boolean WriteCIF (void); boolean WriteWeaponCIF (void); boolean WriteWeaponGroup (int& Index); /*---------- Begin Public Class Methods --------------------------*/ public: /* Class Constructor and Destructor */ CDFCifFile(); ~CDFCifFile() { Destroy(); } void Destroy (void); /* Class get members */ int GetNumImages (void) const; CDFCifImage* GetImage (const int Index) const; short GetWidth (const int Index) const; short GetHeight (const int Index) const; byte* GetImageData (const int Index) const; boolean IsWeaponCIF (void) const; boolean HasFirstImage (void) const; /* Check for a weapon filename */ static boolean IsWeaponCIFFilename (const char* pFilename); /* Check the validity of a record index */ boolean IsValidIndex (const int Index) const; /* Read/write a CIF file */ boolean Load (const char* pFilename); boolean Save (const char* pFilename); /* Set class members */ void SetWeaponCIF (const boolean Value); void SetHasFirstImage (const boolean Value); }; /*=========================================================================== * End of Class CDFCifFile *=========================================================================*/ /*=========================================================================== * * Begin CDFCifImage Inline Methods * *=========================================================================*/ /* Overloaded constructor/destructor */ inline CDFCifImage::CDFCifImage() { m_CIFGroup = 0; } inline void CDFCifImage::Destroy (void) { m_CIFGroup = 0; } /* Is the image data compressed? */ inline boolean CDFCifImage::IsCompressed (void) const { if (GetUnknown() == 0x0002 || CHECK_BITFLAG(m_Flags, DFCIF_FLAG_ISCOMPRESSED)) return (TRUE); return (FALSE); } /* Get the CIF images flags */ inline boolean CDFCifImage::HasWeaponHeader (void) const { return CHECK_BITFLAG(m_Flags, DFCIF_FLAG_HASWEAPONHEADER); } inline boolean CDFCifImage::HasCIFOffsetList (void) const { return CHECK_BITFLAG(m_Flags, DFCIF_FLAG_HASOFFSETLIST); } inline boolean CDFCifImage::IsWeaponCIF (void) const { return CHECK_BITFLAG(m_Flags, DFCIF_FLAG_ISWEAPON); } inline int CDFCifImage::GetCIFGroup (void) const { return (m_CIFGroup); } /* Set the CIF image flags */ inline void CDFCifImage::SetCIFOffsetList (const boolean Value) { SET_BITFLAG(m_Flags, DFCIF_FLAG_HASOFFSETLIST, Value); } inline void CDFCifImage::SetCompressed (const boolean Value) { SET_BITFLAG(m_Flags, DFCIF_FLAG_ISCOMPRESSED, Value); } inline void CDFCifImage::SetWeaponHeader (const boolean Value) { SET_BITFLAG(m_Flags, DFCIF_FLAG_HASWEAPONHEADER, Value); } inline void CDFCifImage::SetWeaponCIF (const boolean Value) { SET_BITFLAG(m_Flags, DFCIF_FLAG_ISWEAPON, Value); } inline void CDFCifImage::SetCIFGroup (const int Group) { m_CIFGroup = Group; } /*=========================================================================== * End of CDFCifImage Inline Methods *=========================================================================*/ /*=========================================================================== * * Begin CDFCifFile Inline Methods * *=========================================================================*/ /* Get class members */ inline int CDFCifFile::GetNumImages (void) const { return (m_NumImages); } inline CDFCifImage* CDFCifFile::GetImage (const int Index) const { return (IsValidIndex(Index) ? (CDFCifImage*)m_pImages[Index] : NULL); } inline short CDFCifFile::GetWidth (const int Index) const { return (IsValidIndex(Index) ? m_pImages[Index]->GetWidth() : 0); } inline short CDFCifFile::GetHeight (const int Index) const { return (IsValidIndex(Index) ? m_pImages[Index]->GetHeight() : 0); } inline byte* CDFCifFile::GetImageData (const int Index) const { return (IsValidIndex(Index) ? (byte*)m_pImages[Index]->GetImageData() : NULL); } inline boolean CDFCifFile::IsWeaponCIF (void) const { return CHECK_BITFLAG(m_Flags, DFCIF_FLAG_ISWEAPON); } inline boolean CDFCifFile::HasFirstImage (void) const { return !CHECK_BITFLAG(m_Flags, DFCIF_FLAG_HASNOFIRSTIMAGE); } /* Check the validity of a record index */ inline boolean CDFCifFile::IsValidIndex (const int Index) const { return ((Index >= 0 && Index < m_NumImages) ? TRUE : FALSE); } /* Set class members */ inline void CDFCifFile::SetWeaponCIF (const boolean Value) { SET_BITFLAG(m_Flags, DFCIF_FLAG_ISWEAPON, Value); } inline void CDFCifFile::SetHasFirstImage (const boolean Value) { SET_BITFLAG(m_Flags, DFCIF_FLAG_HASNOFIRSTIMAGE, !Value); } /*=========================================================================== * End of CDFCifFile Inline Methods *=========================================================================*/ #endif /*=========================================================================== * End of File DFCif.H *=========================================================================*/