mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-04 17:20:25 +02:00
Compare commits
7 Commits
1.9.0mt3
...
bitmapfont
Author | SHA1 | Date | |
---|---|---|---|
853939405b | |||
9b0bc2aaed | |||
81bae5b717 | |||
dbd39120e7 | |||
594de99153 | |||
713471e9a2 | |||
ac57007c55 |
@ -6,8 +6,8 @@
|
|||||||
#define __IRR_COMPILE_CONFIG_H_INCLUDED__
|
#define __IRR_COMPILE_CONFIG_H_INCLUDED__
|
||||||
|
|
||||||
//! Identifies the IrrlichtMt fork customized for the Minetest engine
|
//! Identifies the IrrlichtMt fork customized for the Minetest engine
|
||||||
#define IRRLICHT_VERSION_MT_REVISION 3
|
#define IRRLICHT_VERSION_MT_REVISION 4
|
||||||
#define IRRLICHT_VERSION_MT "mt3"
|
#define IRRLICHT_VERSION_MT "mt4"
|
||||||
|
|
||||||
//! Irrlicht SDK Version
|
//! Irrlicht SDK Version
|
||||||
#define IRRLICHT_VERSION_MAJOR 1
|
#define IRRLICHT_VERSION_MAJOR 1
|
||||||
@ -400,6 +400,11 @@ B3D, MS3D or X meshes */
|
|||||||
#ifdef NO_IRR_COMPILE_WITH_PNG_LOADER_
|
#ifdef NO_IRR_COMPILE_WITH_PNG_LOADER_
|
||||||
#undef _IRR_COMPILE_WITH_PNG_LOADER_
|
#undef _IRR_COMPILE_WITH_PNG_LOADER_
|
||||||
#endif
|
#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_JPG_WRITER_ if you want to write .jpg files
|
//! Define _IRR_COMPILE_WITH_JPG_WRITER_ if you want to write .jpg files
|
||||||
#define _IRR_COMPILE_WITH_JPG_WRITER_
|
#define _IRR_COMPILE_WITH_JPG_WRITER_
|
||||||
|
@ -320,19 +320,17 @@ namespace core
|
|||||||
|
|
||||||
inline s32 s32_min(s32 a, s32 b)
|
inline s32 s32_min(s32 a, s32 b)
|
||||||
{
|
{
|
||||||
const s32 mask = (a - b) >> 31;
|
return min_(a, b);
|
||||||
return (a & mask) | (b & ~mask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline s32 s32_max(s32 a, s32 b)
|
inline s32 s32_max(s32 a, s32 b)
|
||||||
{
|
{
|
||||||
const s32 mask = (a - b) >> 31;
|
return max_(a, b);
|
||||||
return (b & mask) | (a & ~mask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline s32 s32_clamp (s32 value, s32 low, s32 high)
|
inline s32 s32_clamp (s32 value, s32 low, s32 high)
|
||||||
{
|
{
|
||||||
return s32_min(s32_max(value,low), high);
|
return clamp(value, low, high);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -381,33 +379,6 @@ namespace core
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//! conditional set based on mask and arithmetic shift
|
|
||||||
REALINLINE u32 if_c_a_else_b ( const s32 condition, const u32 a, const u32 b )
|
|
||||||
{
|
|
||||||
return ( ( -condition >> 31 ) & ( a ^ b ) ) ^ b;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! conditional set based on mask and arithmetic shift
|
|
||||||
REALINLINE u16 if_c_a_else_b ( const s16 condition, const u16 a, const u16 b )
|
|
||||||
{
|
|
||||||
return ( ( -condition >> 15 ) & ( a ^ b ) ) ^ b;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! conditional set based on mask and arithmetic shift
|
|
||||||
REALINLINE u32 if_c_a_else_0 ( const s32 condition, const u32 a )
|
|
||||||
{
|
|
||||||
return ( -condition >> 31 ) & a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (condition) state |= m; else state &= ~m;
|
|
||||||
*/
|
|
||||||
REALINLINE void setbit_cond ( u32 &state, s32 condition, u32 mask )
|
|
||||||
{
|
|
||||||
// 0, or any positive to mask
|
|
||||||
//s32 conmask = -condition >> 31;
|
|
||||||
state ^= ( ( -condition >> 31 ) ^ state ) & mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: This is not as exact as the c99/c++11 round function, especially at high numbers starting with 8388609
|
// NOTE: This is not as exact as the c99/c++11 round function, especially at high numbers starting with 8388609
|
||||||
// (only low number which seems to go wrong is 0.49999997 which is rounded to 1)
|
// (only low number which seems to go wrong is 0.49999997 which is rounded to 1)
|
||||||
|
@ -1278,7 +1278,8 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
IGUIFont* ifont=0;
|
IGUIFont* ifont=0;
|
||||||
#if 0
|
io::IReadFile *file = FileSystem->createAndOpenFile(filename);
|
||||||
|
if (file)
|
||||||
{
|
{
|
||||||
CGUIFont* font = new CGUIFont(this, filename);
|
CGUIFont* font = new CGUIFont(this, filename);
|
||||||
ifont = (IGUIFont*)font;
|
ifont = (IGUIFont*)font;
|
||||||
@ -1286,15 +1287,14 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename)
|
|||||||
// load the font
|
// load the font
|
||||||
io::path directory;
|
io::path directory;
|
||||||
core::splitFilename(filename, &directory);
|
core::splitFilename(filename, &directory);
|
||||||
if (!font->load(xml, directory))
|
if (!font->load(file, directory))
|
||||||
{
|
{
|
||||||
font->drop();
|
font->drop();
|
||||||
font = 0;
|
font = 0;
|
||||||
ifont = 0;
|
ifont = 0;
|
||||||
}
|
}
|
||||||
|
file->drop();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
if (!ifont)
|
if (!ifont)
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#ifdef _IRR_COMPILE_WITH_GUI_
|
#ifdef _IRR_COMPILE_WITH_GUI_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "fast_atof.h"
|
||||||
#include "coreutil.h"
|
#include "coreutil.h"
|
||||||
#include "IGUIEnvironment.h"
|
#include "IGUIEnvironment.h"
|
||||||
#include "IReadFile.h"
|
#include "IReadFile.h"
|
||||||
@ -62,122 +63,106 @@ CGUIFont::~CGUIFont()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
//! loads a font file from tsv
|
||||||
//! loads a font file from xml
|
bool CGUIFont::load(io::IReadFile* file, const io::path& directory)
|
||||||
bool CGUIFont::load(io::IXMLReader* xml, const io::path& directory)
|
|
||||||
{
|
{
|
||||||
if (!SpriteBank)
|
if (!SpriteBank)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SpriteBank->clear();
|
SpriteBank->clear();
|
||||||
|
|
||||||
while (xml->read())
|
const long size = file->getSize();
|
||||||
|
core::stringc Buffer;
|
||||||
|
Buffer.reserve(size + 1);
|
||||||
|
if (file->read(&Buffer[0], size) != static_cast<size_t>(size))
|
||||||
{
|
{
|
||||||
if (io::EXN_ELEMENT == xml->getNodeType())
|
os::Printer::log("Could not read from file", ELL_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Buffer[size] = 0;
|
||||||
|
const c8 *P = &Buffer[0], *End = P + size;
|
||||||
|
|
||||||
|
#define SkipSpace() \
|
||||||
|
while (P < End && (*P == ' ' || *P == '\t' || *P == '\v')) { P++; }
|
||||||
|
#define SkipLine(rest) \
|
||||||
|
while (rest && P < End && *P != '\r' && *P != '\n') P++; \
|
||||||
|
while (P < End && (*P == '\r' || *P == '\n')) { P++; }
|
||||||
|
|
||||||
|
while (P < End)
|
||||||
{
|
{
|
||||||
if (core::stringw(L"Texture") == xml->getNodeName())
|
if (!strncmp(P, "Texture:", 8))
|
||||||
{
|
{
|
||||||
// add a texture
|
// add a texture
|
||||||
core::stringc fn = xml->getAttributeValue(L"filename");
|
P += 8;
|
||||||
u32 i = (u32)xml->getAttributeValueAsInt(L"index");
|
SkipSpace()
|
||||||
core::stringw alpha = xml->getAttributeValue(L"hasAlpha");
|
core::stringc fn;
|
||||||
|
for (; P < End && *P != '\r' && *P != '\n'; P++)
|
||||||
while (i+1 > SpriteBank->getTextureCount())
|
fn.append(*P);
|
||||||
SpriteBank->addTexture(0);
|
SkipLine(0)
|
||||||
|
|
||||||
bool flags[3];
|
bool flags[3];
|
||||||
pushTextureCreationFlags(flags);
|
pushTextureCreationFlags(flags);
|
||||||
|
|
||||||
// load texture
|
// load texture
|
||||||
io::path textureFullName = core::mergeFilename(directory, fn);
|
io::path textureFullName = core::mergeFilename(directory, fn);
|
||||||
SpriteBank->setTexture(i, Driver->getTexture(textureFullName));
|
SpriteBank->setTexture(0, Driver->getTexture(textureFullName));
|
||||||
|
|
||||||
popTextureCreationFlags(flags);
|
popTextureCreationFlags(flags);
|
||||||
|
|
||||||
// couldn't load texture, abort.
|
if (!SpriteBank->getTexture(0))
|
||||||
if (!SpriteBank->getTexture(i))
|
|
||||||
{
|
{
|
||||||
os::Printer::log("Unable to load all textures in the font, aborting", ELL_ERROR);
|
os::Printer::log("Unable to load texture in the font, aborting", ELL_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
// colorkey texture rather than alpha channel?
|
|
||||||
if (alpha == core::stringw("false"))
|
|
||||||
Driver->makeColorKeyTexture(SpriteBank->getTexture(i), core::position2di(0,0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (core::stringw(L"c") == xml->getNodeName())
|
|
||||||
{
|
{
|
||||||
// adding a character to this font
|
// adding a character to this font
|
||||||
SFontArea a;
|
SFontArea a;
|
||||||
SGUISpriteFrame f;
|
SGUISpriteFrame f;
|
||||||
SGUISprite s;
|
SGUISprite s;
|
||||||
core::rect<s32> rectangle;
|
core::rect<s32> rect;
|
||||||
|
wchar_t ch;
|
||||||
|
|
||||||
a.underhang = xml->getAttributeValueAsInt(L"u");
|
// Format of a line:
|
||||||
a.overhang = xml->getAttributeValueAsInt(L"o");
|
// <char (hex)> <X1> <Y1> <X2> <Y2> [u] [o]
|
||||||
a.spriteno = SpriteBank->getSprites().size();
|
|
||||||
s32 texno = xml->getAttributeValueAsInt(L"i");
|
|
||||||
|
|
||||||
// parse rectangle
|
ch = static_cast<wchar_t>(core::strtoul16(P, &P));
|
||||||
core::stringc rectstr = xml->getAttributeValue(L"r");
|
SkipSpace()
|
||||||
wchar_t ch = xml->getAttributeValue(L"c")[0];
|
|
||||||
|
|
||||||
const c8 *c = rectstr.c_str();
|
rect.UpperLeftCorner.X = core::strtol10(P, &P);
|
||||||
s32 val;
|
SkipSpace()
|
||||||
val = 0;
|
rect.UpperLeftCorner.Y = core::strtol10(P, &P);
|
||||||
while (*c >= '0' && *c <= '9')
|
SkipSpace()
|
||||||
|
rect.LowerRightCorner.X = core::strtol10(P, &P);
|
||||||
|
SkipSpace()
|
||||||
|
rect.LowerRightCorner.Y = core::strtol10(P, &P);
|
||||||
|
SkipSpace()
|
||||||
|
|
||||||
|
if (core::isdigit(*P))
|
||||||
{
|
{
|
||||||
val *= 10;
|
a.underhang = core::strtol10(P, &P);
|
||||||
val += *c - '0';
|
SkipSpace()
|
||||||
c++;
|
if (core::isdigit(*P))
|
||||||
|
a.overhang = core::strtol10(P, &P);
|
||||||
}
|
}
|
||||||
rectangle.UpperLeftCorner.X = val;
|
|
||||||
while (*c == L' ' || *c == L',') c++;
|
|
||||||
|
|
||||||
val = 0;
|
SkipLine(1)
|
||||||
while (*c >= '0' && *c <= '9')
|
|
||||||
{
|
|
||||||
val *= 10;
|
|
||||||
val += *c - '0';
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
rectangle.UpperLeftCorner.Y = val;
|
|
||||||
while (*c == L' ' || *c == L',') c++;
|
|
||||||
|
|
||||||
val = 0;
|
|
||||||
while (*c >= '0' && *c <= '9')
|
|
||||||
{
|
|
||||||
val *= 10;
|
|
||||||
val += *c - '0';
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
rectangle.LowerRightCorner.X = val;
|
|
||||||
while (*c == L' ' || *c == L',') c++;
|
|
||||||
|
|
||||||
val = 0;
|
|
||||||
while (*c >= '0' && *c <= '9')
|
|
||||||
{
|
|
||||||
val *= 10;
|
|
||||||
val += *c - '0';
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
rectangle.LowerRightCorner.Y = val;
|
|
||||||
|
|
||||||
CharacterMap.insert(ch, Areas.size());
|
CharacterMap.insert(ch, Areas.size());
|
||||||
|
|
||||||
// make frame
|
// make frame
|
||||||
f.rectNumber = SpriteBank->getPositions().size();
|
f.rectNumber = SpriteBank->getPositions().size();
|
||||||
f.textureNumber = texno;
|
f.textureNumber = 0;
|
||||||
|
|
||||||
// add frame to sprite
|
// add frame to sprite
|
||||||
s.Frames.push_back(f);
|
s.Frames.push_back(f);
|
||||||
s.frameTime = 0;
|
s.frameTime = 0;
|
||||||
|
|
||||||
// add rectangle to sprite bank
|
// add rectangle to sprite bank
|
||||||
SpriteBank->getPositions().push_back(rectangle);
|
SpriteBank->getPositions().push_back(rect);
|
||||||
a.width = rectangle.getWidth();
|
a.width = rect.getWidth();
|
||||||
|
a.spriteno = SpriteBank->getSprites().size();
|
||||||
|
|
||||||
// add sprite to sprite bank
|
// add sprite to sprite bank
|
||||||
SpriteBank->getSprites().push_back(s);
|
SpriteBank->getSprites().push_back(s);
|
||||||
@ -186,7 +171,9 @@ bool CGUIFont::load(io::IXMLReader* xml, const io::path& directory)
|
|||||||
Areas.push_back(a);
|
Areas.push_back(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
#undef SkipSpace
|
||||||
|
#undef SkipLine
|
||||||
|
|
||||||
// set bad character
|
// set bad character
|
||||||
WrongCharacter = getAreaFromCharacter(L' ');
|
WrongCharacter = getAreaFromCharacter(L' ');
|
||||||
@ -195,7 +182,6 @@ bool CGUIFont::load(io::IXMLReader* xml, const io::path& directory)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void CGUIFont::setMaxHeight()
|
void CGUIFont::setMaxHeight()
|
||||||
|
@ -44,6 +44,10 @@ public:
|
|||||||
//! loads a font from a texture file
|
//! loads a font from a texture file
|
||||||
bool load(io::IReadFile* file);
|
bool load(io::IReadFile* file);
|
||||||
|
|
||||||
|
//! loads a font from a TSV file
|
||||||
|
// \param directory Directory in which the bitmaps can be found
|
||||||
|
bool load(io::IReadFile* file, const io::path& directory);
|
||||||
|
|
||||||
//! draws an text and clips it to the specified rectangle if wanted
|
//! draws an text and clips it to the specified rectangle if wanted
|
||||||
virtual void draw(const core::stringw& text, const core::rect<s32>& position,
|
virtual void draw(const core::stringw& text, const core::rect<s32>& position,
|
||||||
video::SColor color, bool hcenter=false,
|
video::SColor color, bool hcenter=false,
|
||||||
|
@ -13,6 +13,13 @@ namespace irr
|
|||||||
namespace video
|
namespace video
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//! check sanity of image dimensions to prevent issues later, for use by CImageLoaders
|
||||||
|
inline bool checkImageDimensions(u32 width, u32 height)
|
||||||
|
{
|
||||||
|
// 4 * 23000 * 23000 is just under S32_MAX
|
||||||
|
return width <= 23000 && height <= 23000;
|
||||||
|
}
|
||||||
|
|
||||||
//! IImage implementation with a lot of special image operations for
|
//! IImage implementation with a lot of special image operations for
|
||||||
//! 16 bit A1R5G5B5/32 Bit A8R8G8B8 images, which are used by the SoftwareDevice.
|
//! 16 bit A1R5G5B5/32 Bit A8R8G8B8 images, which are used by the SoftwareDevice.
|
||||||
class CImage : public IImage
|
class CImage : public IImage
|
||||||
|
@ -252,6 +252,12 @@ IImage* CImageLoaderBMP::loadImage(io::IReadFile* file) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (header.BPP > 32 || !checkImageDimensions(header.Width, header.Height))
|
||||||
|
{
|
||||||
|
os::Printer::log("Rejecting BMP with unreasonable size or BPP.", ELL_ERROR);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// adjust bitmap data size to dword boundary
|
// adjust bitmap data size to dword boundary
|
||||||
header.BitmapDataSize += (4-(header.BitmapDataSize%4))%4;
|
header.BitmapDataSize += (4-(header.BitmapDataSize%4))%4;
|
||||||
|
|
||||||
|
@ -221,11 +221,15 @@ IImage* CImageLoaderJPG::loadImage(io::IReadFile* file) const
|
|||||||
cinfo.output_gamma=2.2;
|
cinfo.output_gamma=2.2;
|
||||||
cinfo.do_fancy_upsampling=FALSE;
|
cinfo.do_fancy_upsampling=FALSE;
|
||||||
|
|
||||||
|
// reject unreasonable sizes
|
||||||
|
if (!checkImageDimensions(cinfo.image_width, cinfo.image_height))
|
||||||
|
longjmp(jerr.setjmp_buffer, 1);
|
||||||
|
|
||||||
// Start decompressor
|
// Start decompressor
|
||||||
jpeg_start_decompress(&cinfo);
|
jpeg_start_decompress(&cinfo);
|
||||||
|
|
||||||
// Get image data
|
// Get image data
|
||||||
u16 rowspan = cinfo.image_width * cinfo.out_color_components;
|
u32 rowspan = cinfo.image_width * cinfo.out_color_components;
|
||||||
u32 width = cinfo.image_width;
|
u32 width = cinfo.image_width;
|
||||||
u32 height = cinfo.image_height;
|
u32 height = cinfo.image_height;
|
||||||
|
|
||||||
|
@ -154,6 +154,9 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const
|
|||||||
Height=h;
|
Height=h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!checkImageDimensions(Width, Height))
|
||||||
|
png_cpexcept_error(png_ptr, "Unreasonable size");
|
||||||
|
|
||||||
// Convert palette color to true color
|
// Convert palette color to true color
|
||||||
if (ColorType==PNG_COLOR_TYPE_PALETTE)
|
if (ColorType==PNG_COLOR_TYPE_PALETTE)
|
||||||
png_set_palette_to_rgb(png_ptr);
|
png_set_palette_to_rgb(png_ptr);
|
||||||
|
243
source/Irrlicht/CImageLoaderTGA.cpp
Normal file
243
source/Irrlicht/CImageLoaderTGA.cpp
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
|
if (!checkImageDimensions(header.ImageWidth, header.ImageHeight))
|
||||||
|
{
|
||||||
|
os::Printer::log("Rejecting TGA with unreasonable size.", ELL_ERROR);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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->getData(),
|
||||||
|
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->getData(),
|
||||||
|
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->getData(), 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->getData(), 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->getData(), header.ImageWidth, header.ImageHeight, 0, (header.ImageDescriptor&0x20)==0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
os::Printer::log("Unsupported TGA format", file->getFileName(), ELL_ERROR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
82
source/Irrlicht/CImageLoaderTGA.h
Normal file
82
source/Irrlicht/CImageLoaderTGA.h
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
// 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 _IRR_OVERRIDE_;
|
||||||
|
|
||||||
|
//! returns true if the file maybe is able to be loaded by this class
|
||||||
|
virtual bool isALoadableFileFormat(io::IReadFile* file) const _IRR_OVERRIDE_;
|
||||||
|
|
||||||
|
//! creates a surface from the file
|
||||||
|
virtual IImage* loadImage(io::IReadFile* file) const _IRR_OVERRIDE_;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -171,6 +171,7 @@ set(IRRIMAGEOBJ
|
|||||||
CImageLoaderBMP.cpp
|
CImageLoaderBMP.cpp
|
||||||
CImageLoaderJPG.cpp
|
CImageLoaderJPG.cpp
|
||||||
CImageLoaderPNG.cpp
|
CImageLoaderPNG.cpp
|
||||||
|
CImageLoaderTGA.cpp
|
||||||
CImageWriterJPG.cpp
|
CImageWriterJPG.cpp
|
||||||
CImageWriterPNG.cpp
|
CImageWriterPNG.cpp
|
||||||
)
|
)
|
||||||
|
97
tools/XMLFontConverter.cpp
Normal file
97
tools/XMLFontConverter.cpp
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <irrlicht.h>
|
||||||
|
|
||||||
|
using namespace irr;
|
||||||
|
|
||||||
|
// Builds with an Irrlicht version that still has XML (e.g. 1.9.0mt2)
|
||||||
|
// g++ -Wall -O2 XMLFontConverter.cpp -o XMLFontConverter -I/tmp/irrlicht/include -L/tmp/irrlicht/lib/Linux -lIrrlichtMt
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
if (argc < 3)
|
||||||
|
{
|
||||||
|
printf("Usage: XMLFontConverter <source.xml> <destination.tsv>\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
IrrlichtDevice *device = createDevice(video::EDT_NULL,
|
||||||
|
core::dimension2d<u32>(800, 600), 32, false, false, false, 0);
|
||||||
|
|
||||||
|
io::IXMLReader *xml = device->getFileSystem()->createXMLReader(argv[1]);
|
||||||
|
io::IWriteFile *wf = device->getFileSystem()->createAndWriteFile(argv[2]);
|
||||||
|
u32 nchars = 0;
|
||||||
|
|
||||||
|
while (xml->read())
|
||||||
|
{
|
||||||
|
if (io::EXN_ELEMENT != xml->getNodeType())
|
||||||
|
continue;
|
||||||
|
if (core::stringw(L"Texture") == xml->getNodeName())
|
||||||
|
{
|
||||||
|
core::stringc fn = xml->getAttributeValue(L"filename");
|
||||||
|
|
||||||
|
core::stringc line("Texture: ");
|
||||||
|
line.append(fn);
|
||||||
|
line.append('\n');
|
||||||
|
wf->write(line.c_str(), line.size());
|
||||||
|
}
|
||||||
|
else if (core::stringw(L"c") == xml->getNodeName())
|
||||||
|
{
|
||||||
|
core::rect<s32> rect;
|
||||||
|
s32 underhang = xml->getAttributeValueAsInt(L"u");
|
||||||
|
s32 overhang = xml->getAttributeValueAsInt(L"o");
|
||||||
|
core::stringc rectstr = xml->getAttributeValue(L"r");
|
||||||
|
wchar_t ch = xml->getAttributeValue(L"c")[0];
|
||||||
|
|
||||||
|
nchars++;
|
||||||
|
|
||||||
|
const c8 *c = rectstr.c_str();
|
||||||
|
s32 val = core::strtol10(c, &c);
|
||||||
|
rect.UpperLeftCorner.X = val;
|
||||||
|
while (*c == L' ' || *c == L',') c++;
|
||||||
|
val = core::strtol10(c, &c);
|
||||||
|
rect.UpperLeftCorner.Y = val;
|
||||||
|
while (*c == L' ' || *c == L',') c++;
|
||||||
|
val = core::strtol10(c, &c);
|
||||||
|
rect.LowerRightCorner.X = val;
|
||||||
|
while (*c == L' ' || *c == L',') c++;
|
||||||
|
val = core::strtol10(c, &c);
|
||||||
|
rect.LowerRightCorner.Y = val;
|
||||||
|
|
||||||
|
core::stringc line;
|
||||||
|
char tmp[6];
|
||||||
|
|
||||||
|
snprintf(tmp, 6, "%04X", static_cast<u32>(ch));
|
||||||
|
line.append(tmp);
|
||||||
|
line.append('\t');
|
||||||
|
|
||||||
|
line.append(core::stringc(rect.UpperLeftCorner.X));
|
||||||
|
line.append('\t');
|
||||||
|
line.append(core::stringc(rect.UpperLeftCorner.Y));
|
||||||
|
line.append('\t');
|
||||||
|
line.append(core::stringc(rect.LowerRightCorner.X));
|
||||||
|
line.append('\t');
|
||||||
|
line.append(core::stringc(rect.LowerRightCorner.Y));
|
||||||
|
|
||||||
|
if (underhang != 0 || overhang != 0)
|
||||||
|
{
|
||||||
|
line.append('\t');
|
||||||
|
line.append(core::stringc(underhang));
|
||||||
|
if (overhang != 0)
|
||||||
|
{
|
||||||
|
line.append('\t');
|
||||||
|
line.append(core::stringc(overhang));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line.append('\n');
|
||||||
|
wf->write(line.c_str(), line.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Success: %d chars\n", nchars);
|
||||||
|
xml->drop();
|
||||||
|
wf->drop();
|
||||||
|
device->drop();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user