MCPcopy Create free account
hub / github.com/IENT/YUView / readRunLengthColor

Function readRunLengthColor

YUViewLib/src/decoder/decoderTarga.cpp:308–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308color_t readRunLengthColor(std::ifstream &file, const Header &header)
309{
310 color_t color{};
311 if (header.imageType == ImageType::RleIndexed)
312 {
313 auto colormapIndex = read8(file);
314 color = header.colormap[colormapIndex];
315 }
316 else if (header.imageType == ImageType::RleGray)
317 {
318 auto greyValue = read8(file);
319 color = rgba(greyValue, greyValue, greyValue);
320 }
321 else if (header.imageType == ImageType::RleRgb)
322 {
323 switch (header.bitsPerPixel)
324 {
325 case 15:
326 case 16:
327 color = read16AsRgb(file, header.hasAlpha);
328 break;
329 case 24:
330 color = read24AsRgb(file);
331 break;
332 case 32:
333 color = read32AsRgb(file, header.hasAlpha);
334 break;
335 default:
336 assert(false);
337 break;
338 }
339 }
340 else
341 assert(false);
342 return color;
343}
344
345// In the best case (TGA 2.0 spec) this should read just one
346// scanline, but in old TGA versions (1.0) it was possible to save

Callers 1

Calls 5

read8Function · 0.85
rgbaFunction · 0.85
read16AsRgbFunction · 0.85
read24AsRgbFunction · 0.85
read32AsRgbFunction · 0.85

Tested by

no test coverage detected