Remove TGA support

This commit is contained in:
Vincent Lejeune 2015-01-16 01:02:48 +01:00
parent 084350ce40
commit 222f335300
7 changed files with 0 additions and 525 deletions

View File

@ -62,7 +62,6 @@ source/Irrlicht/CGUISpriteBank.cpp
source/Irrlicht/CParticleFadeOutAffector.cpp
source/Irrlicht/CGUIMenu.cpp
source/Irrlicht/CSphereSceneNode.cpp
source/Irrlicht/CImageWriterTGA.cpp
source/Irrlicht/CImageWriterPNG.cpp
source/Irrlicht/CSceneNodeAnimatorFollowSpline.cpp
source/Irrlicht/CGUIMessageBox.cpp
@ -136,7 +135,6 @@ source/Irrlicht/CGUIColorSelectDialog.cpp
source/Irrlicht/CSceneManager.cpp
source/Irrlicht/Irrlicht.cpp
source/Irrlicht/COpenGLShaderMaterialRenderer.cpp
source/Irrlicht/CImageLoaderTGA.cpp
source/Irrlicht/COpenGLDriver.cpp
source/Irrlicht/CSceneNodeAnimatorFlyStraight.cpp
source/Irrlicht/irrXML.cpp
@ -180,7 +178,6 @@ source/Irrlicht/CSkinnedMesh.h
source/Irrlicht/COpenGLParallaxMapRenderer.h
source/Irrlicht/CParticleRingEmitter.h
source/Irrlicht/COpenGLShaderMaterialRenderer.h
source/Irrlicht/CImageWriterTGA.h
source/Irrlicht/CImageLoaderPNG.h
source/Irrlicht/COctreeTriangleSelector.h
source/Irrlicht/COpenGLTexture.h
@ -263,7 +260,6 @@ source/Irrlicht/CXMLReaderImpl.h
source/Irrlicht/COpenGLMaterialRenderer.h
source/Irrlicht/CVideoModeList.h
source/Irrlicht/CParticleAnimatedMeshSceneNodeEmitter.h
source/Irrlicht/CImageLoaderTGA.h
source/Irrlicht/CColorConverter.h
source/Irrlicht/CWaterSurfaceSceneNode.h
source/Irrlicht/SoftwareDriver2_compile_config.h

View File

@ -294,11 +294,6 @@ B3D, MS3D or X meshes */
#ifdef NO_IRR_COMPILE_WITH_DDS_LOADER_
#undef _IRR_COMPILE_WITH_DDS_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_TGA_LOADER_ if you want to load .tga files
#define _IRR_COMPILE_WITH_TGA_LOADER_
#ifdef NO_IRR_COMPILE_WITH_TGA_LOADER_
#undef _IRR_COMPILE_WITH_TGA_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_WAL_LOADER_ if you want to load .wal files
#define _IRR_COMPILE_WITH_WAL_LOADER_
#ifdef NO_IRR_COMPILE_WITH_WAL_LOADER_
@ -330,11 +325,6 @@ B3D, MS3D or X meshes */
#ifdef NO_IRR_COMPILE_WITH_PNG_WRITER_
#undef _IRR_COMPILE_WITH_PNG_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_TGA_WRITER_ if you want to write .tga files
//#define _IRR_COMPILE_WITH_TGA_WRITER_
#ifdef NO_IRR_COMPILE_WITH_TGA_WRITER_
#undef _IRR_COMPILE_WITH_TGA_WRITER_
#endif
//! Define __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ if you want to open ZIP and GZIP archives
/** ZIP reading has several more options below to configure. */

View File

@ -1,239 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageLoaderTGA.h"
#ifdef _IRR_COMPILE_WITH_TGA_LOADER_
#include "IReadFile.h"
#include "os.h"
#include "CColorConverter.h"
#include "CImage.h"
#include "irrString.h"
namespace irr
{
namespace video
{
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
bool CImageLoaderTGA::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "tga" );
}
//! loads a compressed tga.
u8 *CImageLoaderTGA::loadCompressedImage(io::IReadFile *file, const STGAHeader& header) const
{
// This was written and sent in by Jon Pry, thank you very much!
// I only changed the formatting a little bit.
s32 bytesPerPixel = header.PixelDepth/8;
s32 imageSize = header.ImageHeight * header.ImageWidth * bytesPerPixel;
u8* data = new u8[imageSize];
s32 currentByte = 0;
while(currentByte < imageSize)
{
u8 chunkheader = 0;
file->read(&chunkheader, sizeof(u8)); // Read The Chunk's Header
if(chunkheader < 128) // If The Chunk Is A 'RAW' Chunk
{
chunkheader++; // Add 1 To The Value To Get Total Number Of Raw Pixels
file->read(&data[currentByte], bytesPerPixel * chunkheader);
currentByte += bytesPerPixel * chunkheader;
}
else
{
// thnx to neojzs for some fixes with this code
// If It's An RLE Header
chunkheader -= 127; // Subtract 127 To Get Rid Of The ID Bit
s32 dataOffset = currentByte;
file->read(&data[dataOffset], bytesPerPixel);
currentByte += bytesPerPixel;
for(s32 counter = 1; counter < chunkheader; counter++)
{
for(s32 elementCounter=0; elementCounter < bytesPerPixel; elementCounter++)
data[currentByte + elementCounter] = data[dataOffset + elementCounter];
currentByte += bytesPerPixel;
}
}
}
return data;
}
//! returns true if the file maybe is able to be loaded by this class
bool CImageLoaderTGA::isALoadableFileFormat(io::IReadFile* file) const
{
if (!file)
return false;
STGAFooter footer;
memset(&footer, 0, sizeof(STGAFooter));
file->seek(file->getSize()-sizeof(STGAFooter));
file->read(&footer, sizeof(STGAFooter));
return (!strcmp(footer.Signature,"TRUEVISION-XFILE.")); // very old tgas are refused.
}
//! creates a surface from the file
IImage* CImageLoaderTGA::loadImage(io::IReadFile* file) const
{
STGAHeader header;
u32 *palette = 0;
file->read(&header, sizeof(STGAHeader));
#ifdef __BIG_ENDIAN__
header.ColorMapLength = os::Byteswap::byteswap(header.ColorMapLength);
header.ImageWidth = os::Byteswap::byteswap(header.ImageWidth);
header.ImageHeight = os::Byteswap::byteswap(header.ImageHeight);
#endif
// skip image identification field
if (header.IdLength)
file->seek(header.IdLength, true);
if (header.ColorMapType)
{
// create 32 bit palette
palette = new u32[ header.ColorMapLength];
// read color map
u8 * colorMap = new u8[header.ColorMapEntrySize/8 * header.ColorMapLength];
file->read(colorMap,header.ColorMapEntrySize/8 * header.ColorMapLength);
// convert to 32-bit palette
switch ( header.ColorMapEntrySize )
{
case 16:
CColorConverter::convert_A1R5G5B5toA8R8G8B8(colorMap, header.ColorMapLength, palette);
break;
case 24:
CColorConverter::convert_B8G8R8toA8R8G8B8(colorMap, header.ColorMapLength, palette);
break;
case 32:
CColorConverter::convert_B8G8R8A8toA8R8G8B8(colorMap, header.ColorMapLength, palette);
break;
}
delete [] colorMap;
}
// read image
u8* data = 0;
if ( header.ImageType == 1 || // Uncompressed, color-mapped images.
header.ImageType == 2 || // Uncompressed, RGB images
header.ImageType == 3 // Uncompressed, black and white images
)
{
const s32 imageSize = header.ImageHeight * header.ImageWidth * header.PixelDepth/8;
data = new u8[imageSize];
file->read(data, imageSize);
}
else
if(header.ImageType == 10)
{
// Runlength encoded RGB images
data = loadCompressedImage(file, header);
}
else
{
os::Printer::log("Unsupported TGA file type", file->getFileName(), ELL_ERROR);
delete [] palette;
return 0;
}
IImage* image = 0;
switch(header.PixelDepth)
{
case 8:
{
if (header.ImageType==3) // grey image
{
image = new CImage(ECF_R8G8B8,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert8BitTo24Bit((u8*)data,
(u8*)image->lock(),
header.ImageWidth,header.ImageHeight,
0, 0, (header.ImageDescriptor&0x20)==0);
}
else
{
image = new CImage(ECF_A1R5G5B5,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert8BitTo16Bit((u8*)data,
(s16*)image->lock(),
header.ImageWidth,header.ImageHeight,
(s32*) palette, 0,
(header.ImageDescriptor&0x20)==0);
}
}
break;
case 16:
image = new CImage(ECF_A1R5G5B5,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert16BitTo16Bit((s16*)data,
(s16*)image->lock(), header.ImageWidth, header.ImageHeight, 0, (header.ImageDescriptor&0x20)==0);
break;
case 24:
image = new CImage(ECF_R8G8B8,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert24BitTo24Bit(
(u8*)data, (u8*)image->lock(), header.ImageWidth, header.ImageHeight, 0, (header.ImageDescriptor&0x20)==0, true);
break;
case 32:
image = new CImage(ECF_A8R8G8B8,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert32BitTo32Bit((s32*)data,
(s32*)image->lock(), header.ImageWidth, header.ImageHeight, 0, (header.ImageDescriptor&0x20)==0);
break;
default:
os::Printer::log("Unsupported TGA format", file->getFileName(), ELL_ERROR);
break;
}
if (image)
image->unlock();
delete [] data;
delete [] palette;
return image;
}
//! creates a loader which is able to load tgas
IImageLoader* createImageLoaderTGA()
{
return new CImageLoaderTGA();
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -1,82 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_IMAGE_LOADER_TGA_H_INCLUDED__
#define __C_IMAGE_LOADER_TGA_H_INCLUDED__
#include "IrrCompileConfig.h"
#include "IImageLoader.h"
namespace irr
{
namespace video
{
#if defined(_IRR_COMPILE_WITH_TGA_LOADER_) || defined(_IRR_COMPILE_WITH_TGA_WRITER_)
// byte-align structures
#include "irrpack.h"
// these structs are also used in the TGA writer
struct STGAHeader{
u8 IdLength;
u8 ColorMapType;
u8 ImageType;
u8 FirstEntryIndex[2];
u16 ColorMapLength;
u8 ColorMapEntrySize;
u8 XOrigin[2];
u8 YOrigin[2];
u16 ImageWidth;
u16 ImageHeight;
u8 PixelDepth;
u8 ImageDescriptor;
} PACK_STRUCT;
struct STGAFooter
{
u32 ExtensionOffset;
u32 DeveloperOffset;
c8 Signature[18];
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
#endif // compiled with loader or reader
#ifdef _IRR_COMPILE_WITH_TGA_LOADER_
/*!
Surface Loader for targa images
*/
class CImageLoaderTGA : public IImageLoader
{
public:
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
virtual bool isALoadableFileExtension(const io::path& filename) const;
//! returns true if the file maybe is able to be loaded by this class
virtual bool isALoadableFileFormat(io::IReadFile* file) const;
//! creates a surface from the file
virtual IImage* loadImage(io::IReadFile* file) const;
private:
//! loads a compressed tga. Was written and sent in by Jon Pry, thank you very much!
u8* loadCompressedImage(io::IReadFile *file, const STGAHeader& header) const;
};
#endif // compiled with loader
} // end namespace video
} // end namespace irr
#endif

View File

@ -1,147 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageWriterTGA.h"
#ifdef _IRR_COMPILE_WITH_TGA_WRITER_
#include "CImageLoaderTGA.h"
#include "IWriteFile.h"
#include "CColorConverter.h"
#include "irrString.h"
namespace irr
{
namespace video
{
IImageWriter* createImageWriterTGA()
{
return new CImageWriterTGA;
}
CImageWriterTGA::CImageWriterTGA()
{
#ifdef _DEBUG
setDebugName("CImageWriterTGA");
#endif
}
bool CImageWriterTGA::isAWriteableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "tga" );
}
bool CImageWriterTGA::writeImage(io::IWriteFile *file, IImage *image,u32 param) const
{
STGAHeader imageHeader;
imageHeader.IdLength = 0;
imageHeader.ColorMapType = 0;
imageHeader.ImageType = 2;
imageHeader.FirstEntryIndex[0] = 0;
imageHeader.FirstEntryIndex[1] = 0;
imageHeader.ColorMapLength = 0;
imageHeader.ColorMapEntrySize = 0;
imageHeader.XOrigin[0] = 0;
imageHeader.XOrigin[1] = 0;
imageHeader.YOrigin[0] = 0;
imageHeader.YOrigin[1] = 0;
imageHeader.ImageWidth = image->getDimension().Width;
imageHeader.ImageHeight = image->getDimension().Height;
// top left of image is the top. the image loader needs to
// be fixed to only swap/flip
imageHeader.ImageDescriptor = (1 << 5);
// chances are good we'll need to swizzle data, so i'm going
// to convert and write one scan line at a time. it's also
// a bit cleaner this way
void (*CColorConverter_convertFORMATtoFORMAT)(const void*, s32, void*) = 0;
switch(image->getColorFormat())
{
case ECF_A8R8G8B8:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_A8R8G8B8toA8R8G8B8;
imageHeader.PixelDepth = 32;
imageHeader.ImageDescriptor |= 8;
break;
case ECF_A1R5G5B5:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_A1R5G5B5toA1R5G5B5;
imageHeader.PixelDepth = 16;
imageHeader.ImageDescriptor |= 1;
break;
case ECF_R5G6B5:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_R5G6B5toA1R5G5B5;
imageHeader.PixelDepth = 16;
imageHeader.ImageDescriptor |= 1;
break;
case ECF_R8G8B8:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_R8G8B8toR8G8B8;
imageHeader.PixelDepth = 24;
imageHeader.ImageDescriptor |= 0;
break;
#ifndef _DEBUG
default:
break;
#endif
}
// couldn't find a color converter
if (!CColorConverter_convertFORMATtoFORMAT)
return false;
if (file->write(&imageHeader, sizeof(imageHeader)) != sizeof(imageHeader))
return false;
u8* scan_lines = (u8*)image->lock();
if (!scan_lines)
return false;
// size of one pixel in bytes
u32 pixel_size = image->getBytesPerPixel();
// length of one row of the source image in bytes
u32 row_stride = (pixel_size * imageHeader.ImageWidth);
// length of one output row in bytes
s32 row_size = ((imageHeader.PixelDepth / 8) * imageHeader.ImageWidth);
// allocate a row do translate data into
u8* row_pointer = new u8[row_size];
u32 y;
for (y = 0; y < imageHeader.ImageHeight; ++y)
{
// source, length [pixels], destination
if (image->getColorFormat()==ECF_R8G8B8)
CColorConverter::convert24BitTo24Bit(&scan_lines[y * row_stride], row_pointer, imageHeader.ImageWidth, 1, 0, 0, true);
else
CColorConverter_convertFORMATtoFORMAT(&scan_lines[y * row_stride], imageHeader.ImageWidth, row_pointer);
if (file->write(row_pointer, row_size) != row_size)
break;
}
delete [] row_pointer;
image->unlock();
STGAFooter imageFooter;
imageFooter.ExtensionOffset = 0;
imageFooter.DeveloperOffset = 0;
strncpy(imageFooter.Signature, "TRUEVISION-XFILE.", 18);
if (file->write(&imageFooter, sizeof(imageFooter)) < (s32)sizeof(imageFooter))
return false;
return imageHeader.ImageHeight <= y;
}
} // namespace video
} // namespace irr
#endif

View File

@ -1,37 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_IMAGE_WRITER_TGA_H_INCLUDED__
#define _C_IMAGE_WRITER_TGA_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_TGA_WRITER_
#include "IImageWriter.h"
namespace irr
{
namespace video
{
class CImageWriterTGA : public IImageWriter
{
public:
//! constructor
CImageWriterTGA();
//! return true if this writer can write a file with the given extension
virtual bool isAWriteableFileExtension(const io::path& filename) const;
//! write image to file
virtual bool writeImage(io::IWriteFile *file, IImage *image,u32 param) const;
};
} // namespace video
} // namespace irr
#endif // _C_IMAGE_WRITER_TGA_H_INCLUDED__
#endif

View File

@ -136,9 +136,6 @@ CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& scre
#ifdef _IRR_COMPILE_WITH_DDS_LOADER_
SurfaceLoader.push_back(video::createImageLoaderDDS());
#endif
#ifdef _IRR_COMPILE_WITH_TGA_LOADER_
SurfaceLoader.push_back(video::createImageLoaderTGA());
#endif
#ifdef _IRR_COMPILE_WITH_PNG_LOADER_
SurfaceLoader.push_back(video::createImageLoaderPNG());
#endif
@ -148,9 +145,6 @@ CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& scre
#ifdef _IRR_COMPILE_WITH_BMP_LOADER_
SurfaceLoader.push_back(video::createImageLoaderBMP());
#endif
#ifdef _IRR_COMPILE_WITH_TGA_WRITER_
SurfaceWriter.push_back(video::createImageWriterTGA());
#endif
#ifdef _IRR_COMPILE_WITH_JPG_WRITER_
SurfaceWriter.push_back(video::createImageWriterJPG());
#endif