This commit is contained in:
Daveo 2001-01-19 22:53:27 +00:00
parent b34c800fe4
commit b8a82dd6fe
2 changed files with 233 additions and 0 deletions

137
Utils/Tga2Gfx/Tga2Gfx.cpp Normal file
View File

@ -0,0 +1,137 @@
/***************************/
/*** TGA 2 Gfx Convertor ***/
/***************************/
//#include <windows.h>
#include <stdlib.h>
#include <stdarg.h>
//#include <string.h>
#include <stdio.h>
//#include <time.h>
//#include <math.h>
#include <io.h>
#include <fstream.h>
#include <conio.h>
//***************************************************************************
struct sTgaHdr
{
char id; // 0
char colmaptype; // 1
char imagetype; // 2
char fei[2]; // 3
char cml[2]; // 5
char cmes; // 7
short xorig; // 8
short yorig; // 10
short width; // 12
short height; // 14
char depth; // 15
char imagedesc; // 16
};
//***************************************************************************
sTgaHdr *TGA;
short *Buffer;
char *InFile;
char *OutFile;
//***************************************************************************
void Load()
{
FILE *File;
int Size;
File=fopen(InFile,"rb");
fseek(File,0,SEEK_END);
Size=ftell(File);
fseek(File,0,SEEK_SET);
if( (TGA=(sTgaHdr*)malloc(Size))==NULL ) {printf("Out of memory.\n");exit(123);}
fread(TGA, 1,Size,File);
fclose(File);
if( (Buffer=(short*)malloc(TGA->width*TGA->height*sizeof(short)))==NULL ) {printf("Out of memory.\n");exit(123);}
}
//***************************************************************************
void Process()
{
unsigned char *InSrc=(unsigned char*)TGA+sizeof(sTgaHdr);
short *Dst=Buffer;
/*
printf("width %i\n",TGA->width);
printf("height %i\n",TGA->height);
printf("depth %i\n",TGA->depth);
printf("imagedesc %i\n",TGA->imagedesc);
*/
for (int Y=0; Y<TGA->height; Y++)
{
unsigned char *Src=&InSrc[(TGA->height-Y)*(TGA->width*3)]; // Flip Image
for (int X=0; X<TGA->width; X++)
{
int B=*Src++;
int G=*Src++;
int R=*Src++;
if (TGA->depth==24)
{
R>>=(8-5);
G>>=(8-5);
B>>=(8-5);
}
*Dst=0;
*Dst|=R<<0;
*Dst|=G<<5;
*Dst|=B<<10;
Dst++;
}
}
}
//***************************************************************************
void Write()
{
FILE *File;
File=fopen(OutFile,"wb");
fwrite(Buffer,TGA->width*TGA->height*sizeof(short),1,File);
fclose(File);
free(TGA);
free(Buffer);
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
void Usage(char *ErrStr)
{
printf("\nTga2Gfx: by Dave\n");
printf("Usage: Tga2Gfx <file> [ <file>.. ] [ switches.. ]\n");
printf("Switches:\n");
printf(" -o:[FILE] Set output File\n");
printf("\nERROR: %s\n",ErrStr);
exit(-1);
}
//***************************************************************************
int main(int argc, char *argv[])
{
if (argc!=3) Usage("Incorrect Params");
InFile=argv[1];
OutFile=argv[2];
Load();
Process();
Write();
return(0);
}

96
Utils/Tga2Gfx/Tga2Gfx.dsp Normal file
View File

@ -0,0 +1,96 @@
# Microsoft Developer Studio Project File - Name="Tga2Gfx" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=Tga2Gfx - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Tga2Gfx.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Tga2Gfx.mak" CFG="Tga2Gfx - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Tga2Gfx - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "Tga2Gfx - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "Tga2Gfx - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "Tga2Gfx - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "Tga2Gfx - Win32 Release"
# Name "Tga2Gfx - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project