/programs/games/fara/trunk/bmp2src/bmp2src.dsp |
---|
0,0 → 1,103 |
# Microsoft Developer Studio Project File - Name="bmp2src" - Package Owner=<4> |
# Microsoft Developer Studio Generated Build File, Format Version 6.00 |
# ** DO NOT EDIT ** |
# TARGTYPE "Win32 (x86) Console Application" 0x0103 |
CFG=bmp2src - 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 "bmp2src.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 "bmp2src.mak" CFG="bmp2src - Win32 Debug" |
!MESSAGE |
!MESSAGE Possible choices for configuration are: |
!MESSAGE |
!MESSAGE "bmp2src - Win32 Release" (based on "Win32 (x86) Console Application") |
!MESSAGE "bmp2src - 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)" == "bmp2src - 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 Ignore_Export_Lib 0 |
# 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 0x419 /d "NDEBUG" |
# ADD RSC /l 0x419 /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 lzmapack.lib /nologo /subsystem:console /machine:I386 /opt:nowin98 |
# SUBTRACT LINK32 /pdb:none |
!ELSEIF "$(CFG)" == "bmp2src - 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 Ignore_Export_Lib 0 |
# 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 0x419 /d "_DEBUG" |
# ADD RSC /l 0x419 /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 lzmapack.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept |
!ENDIF |
# Begin Target |
# Name "bmp2src - Win32 Release" |
# Name "bmp2src - Win32 Debug" |
# Begin Group "Source Files" |
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" |
# Begin Source File |
SOURCE=.\main.cpp |
# End Source File |
# 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 |
/programs/games/fara/trunk/bmp2src/bmp2src.dsw |
---|
0,0 → 1,29 |
Microsoft Developer Studio Workspace File, Format Version 6.00 |
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! |
############################################################################### |
Project: "bmp2src"=.\bmp2src.dsp - Package Owner=<4> |
Package=<5> |
{{{ |
}}} |
Package=<4> |
{{{ |
}}} |
############################################################################### |
Global: |
Package=<5> |
{{{ |
}}} |
Package=<3> |
{{{ |
}}} |
############################################################################### |
/programs/games/fara/trunk/bmp2src/lzmapack.lib |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/programs/games/fara/trunk/bmp2src/main.cpp |
---|
0,0 → 1,166 |
#include <stdio.h> |
#include <stdlib.h> |
extern "C" __stdcall lzma_set_dict_size(unsigned logdictsize); |
extern "C" __stdcall lzma_compress( |
const void* source, |
void* destination, |
unsigned length, |
void* workmem); |
typedef struct |
{ |
short int sizeX; |
short int sizeY; |
int compressedSize; |
int physicalOffset; |
int uncompressedSize; |
} SCompBmpHeader; |
int main(int argc, char* argv[]) |
{ |
if (argc < 3) |
{ |
printf("Usage: bmp2src <destination> <src1> <src2> ...\n"); |
return 1; |
} |
FILE* fo = fopen(argv[1], "wb"); |
if (!fo) |
{ |
printf("Cannot create destination file\n"); |
return 2; |
} |
int n=0; |
SCompBmpHeader* hea = (SCompBmpHeader*)malloc((argc-2)*sizeof(SCompBmpHeader)); |
void** ptrs = (void**)malloc((argc-2)*4); |
lzma_set_dict_size(20); |
void* workmem = (void*)malloc(0x509000 + (1<<20)*19/2); |
for (int i=2;i<argc;i++) |
{ |
FILE* fi = fopen(argv[i], "rb"); |
if (!fi) |
{ |
printf("Cannot open input file %s\n",argv[i]); |
continue; |
} |
unsigned char buf[0x36]; |
fread(buf,1,0x36,fi); |
if (buf[0] != 'B' || buf[1] != 'M') |
{ |
if (buf[0] != 0xFF || buf[1] != 0xD8) |
{ |
printf("%s: unrecognized type\n",argv[i]); |
fclose(fi); |
continue; |
} |
// JPEG |
printf("Processing %s ...",argv[i]); |
fseek(fi,0,SEEK_END); |
unsigned insize = ftell(fi); |
void* output = malloc(insize); |
unsigned char* ptr = (unsigned char*)output; |
*ptr++ = 0xFF; |
*ptr++ = 0xD8; |
// Now load JPEG file, skipping all APPx markers |
fseek(fi,2,SEEK_SET); |
bool bOk = false; |
for (;;) |
{ |
if (fread(buf,1,4,fi) != 4 || buf[0] != 0xFF) |
{ |
printf("%s: invalid JPEG file\n",argv[i]); |
bOk = false; |
break; |
} |
// ignore APPx markers |
if (buf[1] >= 0xE0 && buf[1] <= 0xEF) |
{ |
fseek(fi,buf[2]*256 + buf[3] - 2,SEEK_CUR); |
continue; |
} |
unsigned len = buf[2]*256 + buf[3] + 2; |
fseek(fi,-4,SEEK_CUR); |
fread(ptr,1,len,fi); |
if (buf[1]>=0xC0 && buf[1]<=0xCF && buf[1]!=0xC4 && buf[1]!=0xC8 && buf[1]!=0xCC) |
{ |
// found SOFn marker |
hea[i-2].sizeX = (unsigned char)ptr[4+3]*256 + (unsigned char)ptr[4+4]; |
hea[i-2].sizeY = (unsigned char)ptr[4+1]*256 + (unsigned char)ptr[4+2]; |
bOk = true; |
} |
ptr += len; |
if (buf[1] == 0xDA) |
{ |
// SOS marker |
len = insize - ftell(fi); |
fread(ptr,1,len,fi); |
ptr += len; |
break; |
} |
} |
if (!bOk) {printf(" invalid\n");free(ptr);continue;} |
hea[i-2].compressedSize = ptr - (unsigned char*)output; |
hea[i-2].uncompressedSize = hea[i-2].compressedSize - 1; |
hea[i-2].physicalOffset = (i==2) ? 0 : |
hea[i-3].physicalOffset+hea[i-3].compressedSize; |
ptrs[i-2] = output; |
++n; |
printf(" OK\n"); |
continue; |
} |
if (buf[0x1C] != 24) |
{ |
printf("Input file %s is not 24-bit BMP\n",argv[i]); |
fclose(fi); |
continue; |
} |
int width = *(int*)(buf+0x12); |
int linesize = (width*3+3)&~3; |
int height = *(int*)(buf+0x16); |
void* input = malloc(width*height*3); |
void* packed = malloc(9*width*height*3/8 + 0x80); |
for (int p=0;p<height;p++) |
{ |
fseek(fi,(height-p-1)*linesize+0x36,SEEK_SET); |
fread((char*)input+p*width*3, 1, width*3, fi); |
} |
fclose(fi); |
hea[i-2].sizeX = (short)width; |
hea[i-2].sizeY = (short)height; |
unsigned uncompressedSize = width*height*3; |
hea[i-2].uncompressedSize = uncompressedSize; |
hea[i-2].physicalOffset = (i==2) ? 0 : |
hea[i-3].physicalOffset+hea[i-3].compressedSize; |
printf("Compressing %s ...",argv[i]); |
unsigned compressedSize = lzma_compress(input,packed, |
uncompressedSize,workmem); |
if (compressedSize >= uncompressedSize) |
{ |
compressedSize = uncompressedSize; |
free(packed); |
ptrs[i-2] = input; |
} |
else |
{ |
ptrs[i-2] = packed; |
free(input); |
} |
printf(" %d -> %d\n",uncompressedSize, compressedSize); |
hea[i-2].compressedSize = compressedSize; |
++n; |
} |
for (i=0;i<n;i++) |
hea[i].physicalOffset += 4+n*sizeof(SCompBmpHeader); |
fwrite(&n,4,1,fo); |
fwrite(hea,sizeof(SCompBmpHeader),n,fo); |
for (i=0;i<n;i++) |
{ |
fwrite(ptrs[i],1,hea[i].compressedSize,fo); |
free(ptrs[i]); |
} |
fclose(fo); |
free(hea); |
free(workmem); |
free(ptrs); |
return 0; |
} |
/programs/games/fara/trunk/bmp2src/. |
---|
Property changes: |
Added: tsvn:logminsize |
+5 |
\ No newline at end of property |