34 #include "loaders/SILLYTGAImageLoader.h"
36 #ifndef SILLY_OPT_INLINE
38 #include "loaders/SILLYTGAImageLoader.icpp"
41 #include "SILLYDataSource.h"
42 #include "loaders/SILLYTGAImageContext.h"
51 TGAImageLoader::TGAImageLoader()
52 : ImageLoader(
"TGA Image loader (builtin)")
56 TGAImageLoader::~TGAImageLoader()
61 #define READ_WORD(res, start) \
63 (res) = data->getDataPtr()[(start) + 1]; \
65 (res) |= data->getDataPtr()[(start)];
67 #define READ_WORD(res, start) \
69 (res) = data->getDataPtr()[(start)]; \
71 (res) |= data->getDataPtr()[(start) + 1];
83 if ((imageType != 2 && imageType != 10) || colorMapType)
102 height = height << 8;
109 formatSource = PF_A1B5G5R5;
112 formatSource = PF_RGB;
115 formatSource = PF_RGBA;
120 description = (*data)[17];
126 context->d_idLength = idLength;
127 context->d_imageType = imageType;
128 context->d_depth = depth;
129 context->d_description = description;
137 size_t bpp = tga->d_depth;
138 size_t w = tga->getWidth();
139 size_t h = tga->getHeight();
140 size_t imgSize = w * h * bpp;
141 size_t offset = 18 + tga->d_idLength;
142 size_t numPixels = w * h;
143 const byte* input = data->
getDataPtr() + offset;
150 if (tga->d_imageType == 2)
156 for(
size_t i = 0 ; i < numPixels ; ++i)
158 unsigned short pixel;
163 alpha = pixel & 0xf000 ? 0xff : 0x00;
164 blue =
static_cast<byte>((pixel & 0x1f) << 3);
165 green =
static_cast<byte>(((pixel >> 5) & 0x1f) << 3);
166 red =
static_cast<byte>(((pixel >> 10) & 0x1f) << 3);
173 for(
size_t i = 0 ; i < numPixels ; ++i)
184 for(
size_t i = 0 ; i < numPixels ; ++i)
197 size_t pixelsRead = 0;
204 while(pixelsRead < numPixels)
207 num = 1 + (header & 0x7f);
210 unsigned short pixel;
215 alpha = pixel & 0xf000 ? 0xff : 0x00;
216 blue =
static_cast<byte>((pixel & 0x1f) << 3);
217 green =
static_cast<byte>(((pixel >> 5) & 0x1f) << 3);
218 red =
static_cast<byte>(((pixel >> 10) & 0x1f) << 3);
219 for(i = 0 ; i < num ; ++i)
226 for (i = 0 ; i < num ; ++i)
228 unsigned short pixel;
232 alpha = pixel & 0xf000 ? 0xff : 0x00;
233 blue =
static_cast<byte>((pixel & 0x1f) << 3);
234 green =
static_cast<byte>(((pixel >> 5) & 0x1f) << 3);
235 red =
static_cast<byte>(((pixel >> 10) & 0x1f) << 3);
245 while(pixelsRead < numPixels)
248 num = 1 + (header & 0x7f);
254 for(i = 0 ; i < num ; ++i)
261 for (i = 0 ; i < num ; ++i)
274 while(pixelsRead < numPixels)
277 num = 1 + (header & 0x7f);
284 for(i = 0 ; i < num ; ++i)
291 for (i = 0 ; i < num ; ++i)
306 if ((tga->d_description & 0x10) == 0x10)
308 if (origin == PO_BOTTOM_LEFT)
313 if (origin == PO_TOP_LEFT)