Added class TargaImage
~G2k
This commit is contained in:
69
src/tga.cpp
69
src/tga.cpp
@@ -1,13 +1,72 @@
|
||||
|
||||
#include "tga.h"
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
namespace OpenArena{
|
||||
|
||||
uint8 * TargaImage::GetImageData() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
uint32 TargaImage::GetBitsPerPixel() const
|
||||
{
|
||||
return _bpp;
|
||||
}
|
||||
|
||||
uint32 TargaImage::GetBytesPerPixel() const
|
||||
{
|
||||
return _bpp >> 8;
|
||||
}
|
||||
|
||||
uint32 TargaImage::GetWidth() const
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
|
||||
uint32 TargaImage::GetHeight() const
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
|
||||
Image::Type TargaImage::GetType() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
TargaImage::~TargaImage(void)
|
||||
{
|
||||
delete [] _data;
|
||||
}
|
||||
|
||||
TargaImage* TargaImage::CreateFromFile(const char* filename)
|
||||
{
|
||||
TextureImage* texImage = LoadTGA(filename);
|
||||
TargaImage* image = new TargaImage(texImage->sizeX, texImage->sizeY, texImage->bpp);
|
||||
image->_data = texImage->data;
|
||||
image->_type = (Image::Type)texImage->type;
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
TargaImage::TargaImage(uint32 width, uint32 height, uint32 bpp, Image::Type type)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_bpp = bpp;
|
||||
_type = type;
|
||||
_data = new uint8[_width*_height* (_bpp >> 8)];
|
||||
}
|
||||
|
||||
TargaImage::TargaImage()
|
||||
{
|
||||
TargaImage(1,1);
|
||||
}
|
||||
|
||||
TextureImage* LoadTGA(const char * filename)
|
||||
{
|
||||
TGAHeader tgaheader;
|
||||
TargaImage::TGAHeader tgaheader;
|
||||
TextureImage* image;
|
||||
std::string errmsg;
|
||||
FILE* file = fopen(filename, "rb");
|
||||
@@ -23,7 +82,7 @@ TextureImage* LoadTGA(const char * filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(fread(&tgaheader, sizeof(TGAHeader), 1, file) == 0)
|
||||
if(fread(&tgaheader, sizeof(TargaImage::TGAHeader), 1, file) == 0)
|
||||
{
|
||||
//This needs to be abstracted somehow
|
||||
#ifdef WIN32
|
||||
@@ -52,7 +111,7 @@ TextureImage* LoadTGA(const char * filename)
|
||||
|
||||
TextureImage* LoadUncompressedTGA(FILE * fTGA)
|
||||
{
|
||||
TGA tga;
|
||||
TargaImage::TGA tga;
|
||||
TextureImage* image = new TextureImage;
|
||||
|
||||
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
|
||||
@@ -139,7 +198,7 @@ TextureImage* LoadUncompressedTGA(FILE * fTGA)
|
||||
TextureImage* LoadCompressedTGA(FILE * fTGA)
|
||||
{
|
||||
TextureImage* image = new TextureImage;
|
||||
TGA tga;
|
||||
TargaImage::TGA tga;
|
||||
|
||||
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
|
||||
{
|
||||
|
||||
21
src/tga.h
21
src/tga.h
@@ -15,8 +15,19 @@
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include "texture.h"
|
||||
#include "Image.h"
|
||||
|
||||
namespace OpenArena{
|
||||
class TargaImage: public Image{
|
||||
private:
|
||||
TargaImage();
|
||||
TargaImage(uint32 width, uint32 height, uint32 bpp = 24, Image::Type type = Image::Type_RGB);
|
||||
uint32 _width;
|
||||
uint32 _height;
|
||||
uint32 _bpp;
|
||||
Image::Type _type;
|
||||
uint8 * _data;
|
||||
public:
|
||||
struct TGAHeader
|
||||
{
|
||||
GLubyte Header[12]; // File Header To Determine File Type
|
||||
@@ -33,6 +44,16 @@ namespace OpenArena{
|
||||
GLuint Bpp; // Number Of BITS Per Pixel (24 Or 32)
|
||||
};
|
||||
|
||||
virtual uint8 * GetImageData() const;
|
||||
virtual uint32 GetBitsPerPixel() const;
|
||||
virtual uint32 GetBytesPerPixel() const;
|
||||
virtual uint32 GetWidth() const;
|
||||
virtual uint32 GetHeight() const;
|
||||
virtual Image::Type GetType() const;
|
||||
virtual ~TargaImage(void);
|
||||
static TargaImage* CreateFromFile(const char* filename);
|
||||
};
|
||||
|
||||
TextureImage* LoadTGA(const char *filename);
|
||||
|
||||
const GLubyte uTGAcompare[12] = {0,0,2, 0,0,0,0,0,0,0,0,0}; // Uncompressed TGA Header
|
||||
|
||||
Reference in New Issue
Block a user