texture.h

00001 /*
00002 * "PS2" Application Framework
00003 *
00004 * University of Abertay Dundee
00005 * May be used for educational purposed only
00006 *
00007 * Author - Dr Henry S Fortuna
00008 *
00009 * $Revision: 1.2 $
00010 * $Date: 2007/08/19 12:45:13 $
00011 *
00012 */
00013 
00014 #ifndef _TEXTURE_H_
00015 #define _TEXTURE_H_
00016 
00017 #include <sps2lib.h>
00018 #include <sps2tags.h>
00019 #include "PS2Defines.h"
00020 
00021 // All the following is the layout of a bitmap file header (the bit before
00022 // the actual image data). The __attribute__((packed)) tells the compiler
00023 // not to insert any annoying padding. (If it was padded we wouldn't be
00024 // able to read it in in one go easily)
00025 #define BITMAP_ID      0x4D42
00026 
00027 struct BitmapFileHeader
00028 {
00029         uint16  bfType;
00030     uint32  bfSize;
00031     uint16  bfReserved1;
00032     uint16  bfReserved2;
00033     uint32  bfOffBits;
00034 } __attribute__((packed));
00035 
00036 /*
00037 The BITMAPFILEHEADER structure contains information about the type, size, and
00038 layout of a device-independent bitmap (DIB) file.
00039 
00040 Member          Description
00041 
00042 bfType          Specifies the type of file. This member must be BM. (0x4D42)
00043 bfSize          Specifies the size of the file, in bytes. 
00044 bfReserved1     Reserved; must be set to zero. 
00045 bfReserved2     Reserved; must be set to zero.
00046 bfOffBits       Specifies the byte offset from the BITMAPFILEHEADER structure
00047                                 to the actual bitmap data in the file.
00048 */
00049 
00050 
00051 struct BitmapInfoHeader
00052 {
00053         uint32  biSize;
00054         int32   biWidth;
00055         int32   biHeight;
00056         uint16  biPlanes;
00057         uint16  biBitCount;
00058         uint32  biCompression;
00059         uint32  biSizeImage;
00060         int32   biXPelsPerMeter;
00061         int32   biYPelsPerMeter;
00062         uint32  biClrUsed;
00063         uint32  biClrImportant;
00064 } __attribute__((packed));
00065 
00066 /*
00067 The BITMAPINFOHEADER structure contains information about the dimensions and
00068 color format of a Windows 3.0 or later device-independent bitmap (DIB).
00069 
00070 Member          Description
00071 
00072 biSize          number of bytes required by the BITMAPINFOHEADER structure.
00073 
00074 biWidth         Specifies the width of the bitmap, in pixels. 
00075 biHeight                Specifies the height of the bitmap, in pixels. 
00076 
00077 biPlanes                Specifies the number of planes for the target device. This
00078                                 member must be set to 1.
00079 
00080 biBitCount      Specifies the number of bits per pixel. This value must be 1,
00081                                 4, 8, or 24.
00082 
00083 biCompression   Specifies the type of compression for a compressed bitmap. It
00084                                 can be one of the following values:
00085 
00086 Value           Meaning
00087 
00088 BI_RGB          Specifies that the bitmap is not compressed. 
00089 
00090 BI_RLE8         Specifies a run-length encoded format for bitmaps with 8 bits
00091                                 per pixel. The compression format is a 2-byte format consisting of a count
00092                                 byte followed by a byte containing a color index.  For more information,
00093                                 see the following Comments section.
00094 
00095 BI_RLE4         Specifies a run-length encoded format for bitmaps with 4 bits
00096                                 per pixel. The compression format is a 2-byte format consisting of a count
00097                                 byte followed by two word-length color indexes.  For more information, see
00098                                 the following Comments section.
00099 
00100 biSizeImage     Specifies the size, in bytes, of the image. It is valid to
00101                                 set this member to zero if the bitmap is in the BI_RGB format.
00102 
00103 biXPelsPerMeter Specifies the horizontal resolution, in pixels per meter, of
00104                                 the target device for the bitmap. An application can use this 
00105                                 value to select a bitmap from a resource group that best matches 
00106                                 the characteristics of the current device.
00107 
00108 biYPelsPerMeter Specifies the vertical resolution, in pixels per meter, of
00109                                 the target device for the bitmap.
00110 
00111 biClrUsed       Specifies the number of color indexes in the color table
00112                                 actually used by the bitmap. If this value is zero, the bitmap uses the
00113                                 maximum number of colors corresponding to the value of the biBitCount
00114                                 member. For more information on the maximum sizes of the color table, 
00115                                 see the description of the BITMAPINFO structure earlier in this topic.
00116 
00117                                 If the biClrUsed member is nonzero, it specifies the actual number of 
00118                                 colors that the graphics engine or device driver will access if the
00119                                 biBitCountmember is less than 24. If biBitCount is set to 24, 
00120                                 biClrUsed specifies the size of the reference color table used
00121                                 to optimize performance of Windows color palettes.  
00122                                 If the bitmap is a packed bitmap (that is, a bitmap in which
00123                                 the bitmap array immediately follows the BITMAPINFO header and which is
00124                                 referenced by a single pointer), the biClrUsed member must be set to zero or
00125                                 to the actual size of the color table.
00126 
00127 biClrImportant  Specifies the number of color indexes that are considered
00128                                 important for displaying the bitmap. If this value is zero, all colors are
00129                                 important.
00130 */
00131 
00132 struct BitmapFile
00133 {
00134         BitmapFileHeader  bitmapfileheader;
00135         BitmapInfoHeader  bitmapinfoheader;
00136 } __attribute__((packed));
00137 
00138 class CTexture
00139 {
00140 public:
00141         CTexture();
00142         ~CTexture();
00143 
00144         bool LoadBitmap(const char * strFilename, bool bBlackTransparent = false, bool bRedAsAlpha = false);
00145         uint64 Upload(uint32 uGSPage);  // This function returns tex0, incase you want to modify it.
00146         void Select(uint64 Tex0 = 0);   // If you modified tex0, you can pass it back here. Otherwise the
00147                                                                         // function will use its own values for tex0.
00148 
00149 private:
00150         int m_iTexAddr;
00151         int m_iClutAddr;
00152 
00153         uint64 m_iTex0;
00154 
00155         int m_iDataSize;
00156 
00157         unsigned char m_pOriginalPalette[256*4];
00158         unsigned int m_pPalette32[256];
00159 
00160         int m_iImageDepth;
00161         int m_iPalBytesPerPixel;
00162 
00163         int m_iWidth, m_iHeight;
00164         int m_l2Width, m_l2Height;
00165 
00166         bool m_bValid;
00167 };
00168 
00169 #endif

Generated on Sun May 18 21:45:09 2008 for PS2X by  doxygen 1.5.4