Small class to load a TGA-file into a memory buffer.
| 15 | |
| 16 | //! Small class to load a TGA-file into a memory buffer. |
| 17 | class IMAGE |
| 18 | { |
| 19 | public: |
| 20 | IMAGE (); |
| 21 | |
| 22 | //! Loads a TGA. Can be 8, 24 or 32 Bits per pixel, uncompressed or (RLE) compressed. Returns false, if the TGA could not be loaded. |
| 23 | bool LoadTGA (const char* szFile); |
| 24 | |
| 25 | //! Returns the width of the image in pixels |
| 26 | int getWidth (void) const {return (m_iImageWidth);} |
| 27 | //! Returns the height of the image in pixels |
| 28 | int getHeight (void) const {return (m_iImageHeight);} |
| 29 | |
| 30 | //! Returns the pixel at location (x,y). |
| 31 | /*! ATTENTION: |
| 32 | "getPixel (x,y)[0]" is BLUE |
| 33 | "getPixel (x,y)[1]" is GREEN |
| 34 | "getPixel (x,y)[2]" is RED |
| 35 | "getPixel (x,y)[3]" is ALPHA |
| 36 | This allows faster load-times (TGAs are stored this way natively) and faster upload-times to OpenGL. |
| 37 | Use GL_BGRA as "format", when uploading the data to OpenGL. |
| 38 | */ |
| 39 | const unsigned char* getPixel (int x, int y) const {return (&m_Pixels[(y * m_iImageWidth + x) *4]);} |
| 40 | |
| 41 | //! Returns the raw array, as needed when uploading the image to OpenGL. |
| 42 | /*! Upload the image to OpenGL like this: |
| 43 | IMAGE Image; |
| 44 | gluBuild2DMipmaps (GL_TEXTURE_2D, 4, Image.getWidth (), Image.getHeight (), GL_BGRA, GL_UNSIGNED_BYTE, Image.getDataForOpenGL ()); |
| 45 | */ |
| 46 | const unsigned char* getDataForOpenGL (void) const {return (&m_Pixels[0]);} |
| 47 | |
| 48 | private: |
| 49 | void LoadCompressedTGA (FILE* pFile); |
| 50 | void LoadUncompressedTGA (FILE* pFile); |
| 51 | |
| 52 | vector<unsigned char> m_Pixels; |
| 53 | |
| 54 | int m_iImageWidth; |
| 55 | int m_iImageHeight; |
| 56 | int m_iBytesPerPixel; |
| 57 | }; |
| 58 | |
| 59 | |
| 60 |
nothing calls this directly
no outgoing calls
no test coverage detected