Add support for Targa type 3 and 11 images (greyscale)

This commit is contained in:
AnyOldName3 2019-05-13 21:56:07 +01:00
parent 7b6135f0f7
commit 8491fd780d

View File

@ -157,6 +157,8 @@ static void
convert_data(const unsigned char * const src, unsigned char * const dest,
const int x, const int srcformat,
const int destformat)
{
if (destformat > 2) /* color */
{
if (srcformat == 2)
{
@ -190,6 +192,21 @@ const int destformat)
}
}
}
else
{
if (destformat == 1)
{
assert(srcformat == 1 || srcformat == 2);
(dest + x * destformat)[0] = (src + x * srcformat)[0];
}
else
{
assert(srcformat == 2 && destformat == 2);
(dest + x * destformat)[0] = (src + x * srcformat)[0];
(dest + x * destformat)[1] = (src + x * srcformat)[1];
}
}
}
/* Intel byte order workaround */
@ -411,7 +428,7 @@ int *numComponents_ret)
fin.seekg(18);
/* check for reasonable values in case this is not a tga file */
if ((type != 1 && type != 2 && type != 9 && type != 10) ||
if ((type != 1 && type != 2 && type != 3 && type != 9 && type != 10 && type != 11) ||
(width < 0 || width > 4096) ||
(height < 0 || height > 4096) ||
(depth < 1 || depth > 4))
@ -460,7 +477,7 @@ int *numComponents_ret)
format = 3;
}
}
else
else if ((type & ~8) != 3) /* color image */
{
if (depth == 2) /* 16 bits */
{
@ -480,6 +497,19 @@ int *numComponents_ret)
format = 3;
}
}
else /* greyscale image */
{
if (depth == 1)
format = 1;
else
{
assert(depth == 2);
if (attributeType == ALPHA_PRESENT || attributeType == ALPHA_PREMULTIPLIED || attributeType == ATTRIBUTE_TYPE_UNSET)
format = 2;
else
format = 1;
}
}
/* SoDebugError::postInfo("simage_tga_load", "TARGA file: %d %d %d %d %d\n", */
/* type, width, height, depth, format); */
@ -566,6 +596,7 @@ int *numComponents_ret)
}
break;
case 2: /* RGB, uncompressed */
case 3: /* greyscale, uncompressed */
{
int x, y;
for (y = 0; y < height; y++)
@ -667,6 +698,7 @@ int *numComponents_ret)
}
break;
case 10: /* RGB, compressed */
case 11: /* greyscale, compressed */
{
int size, x, y;
std::streampos pos = fin.tellg();