/*=========================================================================== * * File: Dfimg.H * Author: Dave Humphrey (uesp@m0use.net) * Created On: Monday, June 25, 2001 * * Implements the CDFImgFile class for handling Daggerfall's IMG type files. * *=========================================================================*/ #ifndef __DFIMG_H #define __DFIMG_H /*=========================================================================== * * Begin Required Include Files * *=========================================================================*/ #include "common/file/genfile.h" #include "common/images/rgbpal.h" #include "uesp/dagger/common/dfcommon.h" /*=========================================================================== * End of Required Include Files *=========================================================================*/ /*=========================================================================== * * Begin Defines * *=========================================================================*/ /* Size of the optional IMG palette data in entries */ #define DFIMG_PALETTE_SIZE 256 /* IMG flag values */ #define DFIMG_FLAG_HASNOHEADER 1 /* For special image files without headers */ #define DFIMG_FLAG_HASPALETTE 2 /* For IMG files with palette data after image */ /*=========================================================================== * End of Defines *=========================================================================*/ /*=========================================================================== * * Begin Type Definitions * * Reset the structure alignment value to 1 byte to define the required * types that need to be exactly sized. * *=========================================================================*/ #pragma pack(push, 1) /* IMG header structure */ typedef struct { short XOffset; /* Image position offset in pixels? */ short YOffset; short Width; /* Image size in pixels */ short Height; short Unknown; /* Unknown value */ ushort ImageSize; /* Size of the image data */ } dfimgheader_t; #pragma pack(pop) /* Structure used to describe for special IMG formats */ typedef struct { long FileSize; /* Filesize for the IMG file */ short Width; /* Resulting image dimensions */ short Height; int Flags; /* Special flags */ } dfimginfo_t; /*=========================================================================== * End of Type Definitions *=========================================================================*/ /*=========================================================================== * * Class CDFImgFile Definition * * Handles manipulation of a Daggerfall IMG type file as well as the base * class for single CIF image records. * *=========================================================================*/ class CDFImgFile : public CGenFile { /*---------- Begin Protected Class Members -----------------------*/ protected: dfimgheader_t m_Header; /* Image header information */ byte* m_pData; /* The raw image data */ rgbpalraw_t* m_pPalette; /* The optional image palette data */ long m_ImageSize; /* The true image size */ int m_Flags; /* Image flags */ /*---------- Begin Protected Class Methods ----------------------*/ protected: /* Check an IMG file for special types */ boolean CheckSpecialIMG (dfimginfo_t& IMGInfo, const long FileSize); /* Helper input routines */ virtual boolean ReadHeader (void); boolean ReadData (void); boolean ReadPalette (void); /* Helper output routines */ virtual boolean WriteHeader (void); boolean WriteData (void); boolean WritePalette (void); /*---------- Begin Public Class Members --------------------------*/ public: /* Class Constructor/Destructor */ CDFImgFile(); virtual ~CDFImgFile() { 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 GetUnknown (void) const; long GetImageSize (void) const; byte* GetImageData (void) const; rgbpalraw_t* GetPalette (void) const; /* Check the object state/flags */ boolean HasHeader (void) const; boolean HasPalette (void) const; /* Read/Write an image file */ boolean Load (const char* pFilename); boolean Save (const char* pFilename); /* Read/write in image data from a file stream */ virtual boolean Read (void); virtual boolean Write (void); /* Class set members */ void SetHasHeader (const boolean Value); void SetHasPalette (const boolean Value); void SetXOffset (const short Value); void SetYOffset (const short Value); void SetHeight (const short Value); void SetWidth (const short Value); void SetImageSize (const long Value); }; /*=========================================================================== * End of Class CDFImgFile Definition *=========================================================================*/ /*=========================================================================== * * Begin CDFImgFile Inline Methods * *=========================================================================*/ /* Class get members */ inline short CDFImgFile::GetXOffset (void) const { return (m_Header.XOffset); } inline short CDFImgFile::GetYOffset (void) const { return (m_Header.YOffset); } inline short CDFImgFile::GetWidth (void) const { return (m_Header.Width); } inline short CDFImgFile::GetHeight (void) const { return (m_Header.Height); } inline short CDFImgFile::GetUnknown (void) const { return (m_Header.Unknown); } inline long CDFImgFile::GetImageSize (void) const { return (m_ImageSize); } inline byte* CDFImgFile::GetImageData (void) const { return (m_pData); } inline rgbpalraw_t* CDFImgFile::GetPalette (void) const { return (m_pPalette); } /* Check object flags */ inline boolean CDFImgFile::HasHeader (void) const { return ((m_Flags & DFIMG_FLAG_HASNOHEADER) ? FALSE : TRUE ); } inline boolean CDFImgFile::HasPalette (void) const { return (boolean) CHECK_BITFLAG(m_Flags, DFIMG_FLAG_HASPALETTE); } /* Class set members */ inline void CDFImgFile::SetHasHeader (const boolean Value) { m_Flags = (Value ? m_Flags & (~DFIMG_FLAG_HASNOHEADER) : m_Flags | DFIMG_FLAG_HASNOHEADER); } inline void CDFImgFile::SetHasPalette (const boolean Value) { SET_BITFLAG(m_Flags, DFIMG_FLAG_HASPALETTE, Value); } inline void CDFImgFile::SetXOffset (const short Value) { m_Header.XOffset = Value; } inline void CDFImgFile::SetYOffset (const short Value) { m_Header.YOffset = Value; } inline void CDFImgFile::SetHeight (const short Value) { m_Header.Height = Value; } inline void CDFImgFile::SetWidth (const short Value) { m_Header.Width = Value; } inline void CDFImgFile::SetImageSize (const long Value) { m_Header.ImageSize = (ushort) Value; m_ImageSize = Value; } /*=========================================================================== * End of CDFImgFile Inline Methods *=========================================================================*/ #endif /*=========================================================================== * End of File DFImg.H *=========================================================================*/