mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-10 09:41:09 +00:00
Accept type 1 tgas (paletted)
This commit is contained in:
parent
85821b6fab
commit
9058a4fadb
1 changed files with 42 additions and 5 deletions
|
@ -285,11 +285,19 @@ byte *Image_LoadTGA (FILE *fin, int *width, int *height)
|
||||||
targa_header.pixel_size = fgetc(fin);
|
targa_header.pixel_size = fgetc(fin);
|
||||||
targa_header.attributes = fgetc(fin);
|
targa_header.attributes = fgetc(fin);
|
||||||
|
|
||||||
if (targa_header.image_type!=2 && targa_header.image_type!=10)
|
if (targa_header.image_type==1)
|
||||||
Sys_Error ("Image_LoadTGA: %s is not a type 2 or type 10 targa\n", loadfilename);
|
{
|
||||||
|
if (targa_header.pixel_size != 8 || targa_header.colormap_size != 24 || targa_header.colormap_length > 256)
|
||||||
|
Sys_Error ("Image_LoadTGA: %s has an %ibit palette\n", loadfilename, targa_header.colormap_type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (targa_header.image_type!=2 && targa_header.image_type!=10)
|
||||||
|
Sys_Error ("Image_LoadTGA: %s is not a type 2 or type 10 targa (%i)\n", loadfilename, targa_header.image_type);
|
||||||
|
|
||||||
if (targa_header.colormap_type !=0 || (targa_header.pixel_size!=32 && targa_header.pixel_size!=24))
|
if (targa_header.colormap_type !=0 || (targa_header.pixel_size!=32 && targa_header.pixel_size!=24))
|
||||||
Sys_Error ("Image_LoadTGA: %s is not a 24bit or 32bit targa\n", loadfilename);
|
Sys_Error ("Image_LoadTGA: %s is not a 24bit or 32bit targa\n", loadfilename);
|
||||||
|
}
|
||||||
|
|
||||||
columns = targa_header.width;
|
columns = targa_header.width;
|
||||||
rows = targa_header.height;
|
rows = targa_header.height;
|
||||||
|
@ -303,7 +311,36 @@ byte *Image_LoadTGA (FILE *fin, int *width, int *height)
|
||||||
|
|
||||||
buf = Buf_Alloc(fin);
|
buf = Buf_Alloc(fin);
|
||||||
|
|
||||||
if (targa_header.image_type==2) // Uncompressed, RGB images
|
if (targa_header.image_type==1) // Uncompressed, paletted images
|
||||||
|
{
|
||||||
|
byte palette[256*4];
|
||||||
|
int i;
|
||||||
|
//palette data comes first
|
||||||
|
for (i = 0; i < targa_header.colormap_length; i++)
|
||||||
|
{ //this palette data is bgr.
|
||||||
|
palette[i*3+2] = Buf_GetC(buf);
|
||||||
|
palette[i*3+1] = Buf_GetC(buf);
|
||||||
|
palette[i*3+0] = Buf_GetC(buf);
|
||||||
|
palette[i*3+3] = 255;
|
||||||
|
}
|
||||||
|
for (i = targa_header.colormap_length*4; i < sizeof(palette); i++)
|
||||||
|
palette[i] = 0;
|
||||||
|
for(row=rows-1; row>=0; row--)
|
||||||
|
{
|
||||||
|
realrow = upside_down ? row : rows - 1 - row;
|
||||||
|
pixbuf = targa_rgba + realrow*columns*4;
|
||||||
|
|
||||||
|
for(column=0; column<columns; column++)
|
||||||
|
{
|
||||||
|
i = Buf_GetC(buf);
|
||||||
|
*pixbuf++= palette[i*3+0];
|
||||||
|
*pixbuf++= palette[i*3+1];
|
||||||
|
*pixbuf++= palette[i*3+2];
|
||||||
|
*pixbuf++= palette[i*3+3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (targa_header.image_type==2) // Uncompressed, RGB images
|
||||||
{
|
{
|
||||||
for(row=rows-1; row>=0; row--)
|
for(row=rows-1; row>=0; row--)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue