This commit is contained in:
2024-08-07 09:16:27 -04:00
parent fdfadd5c7e
commit 5f971cf684
5200 changed files with 731717 additions and 0 deletions

151
gif/GIF.CPP Normal file
View File

@@ -0,0 +1,151 @@
#include <gif/gif.hpp>
GIFDecoder::GIFDecoder(void)
: mhGlobalPalette(0), mlpPaletteData(0), mColors(0), mIsInterlaced(0), mBufferCount(0)
{
}
GIFDecoder::~GIFDecoder()
{
if(mhGlobalPalette)
{
::GlobalUnlock(mhGlobalPalette);
::GlobalFree(mhGlobalPalette);
}
}
WORD GIFDecoder::unpackImage(const char *pathFileName)
{
int i;
int hasProcessed;
hasProcessed=FALSE;
open(pathFileName);
if(!isOpen())return FALSE;
if(!getChar())return FALSE;
if('G'!=currentChar())return FALSE;
for(i=0;i<5;i++)if(!getChar())return FALSE;
if(!getWord())return FALSE;
mScreenWidth=currentWord();
if(!getWord())return FALSE;
mScreenHeight=currentWord();
if(!getChar())return FALSE;
mGlobalFlagByte=currentChar();
mColors=1<<((mGlobalFlagByte&0x07)+1);
if(!getChar())return FALSE;
mBackgroundColor=currentChar();
if(!getChar())return FALSE;
// if(currentChar())return FALSE;
if(mGlobalFlagByte&0x80)
{
if(!readPaletteData())return FALSE;
paletteHandler(mlpPaletteData,mColors);
}
while(TRUE)
{
if(!getChar())break;
switch(currentChar())
{
case '!' : // extension folows
while(getChar() && currentChar()!=',');
if(currentChar()!=',')break;
case ',' : // image follows
if(hasProcessed)break;
hasProcessed=TRUE;
if(!processImage())return FALSE;
break;
case ';' : // file is completely processed
continue;
default :
return FALSE;
}
}
closeFile();
return TRUE;
}
WORD GIFDecoder::processImage(void)
{
UCHAR localFlagByte;
if(!getWord())return FALSE;
mImageStartLeft=currentWord();
if(!getWord())return FALSE;
mImageStartTop=currentWord();
if(!getWord())return FALSE;
mImageWide=currentWord();
if(!getWord())return FALSE;
mImageDeep=currentWord();
if(!getChar())return FALSE;
localFlagByte=currentChar();
mIsInterlaced=localFlagByte&0x40;
mPixelSize=(mGlobalFlagByte&0x07)+1;
if(localFlagByte&0x80)
{
mPixelSize=(localFlagByte&0x07)+1;
mColors=1<<((localFlagByte&0x07)+1);
if(!readPaletteData())return FALSE;
paletteHandler(mlpPaletteData,mColors);
}
attributeHandler(mImageWide,mImageDeep,mPixelSize);
backgroundHandler(mBackgroundColor);
mBufferCount=0;
if(!getChar())return FALSE;
unpackData(mImageWide,mImageDeep,mIsInterlaced,mPixelSize);
imageHandler();
return TRUE;
}
WORD GIFDecoder::readPaletteData(void)
{
if(mhGlobalPalette)
{
::GlobalUnlock(mhGlobalPalette);
::GlobalFree(mhGlobalPalette);
}
mhGlobalPalette=::GlobalAlloc(GMEM_FIXED,mColors*3);
if(!mhGlobalPalette)return FALSE;
mlpPaletteData=(UCHAR FAR *)::GlobalLock(mhGlobalPalette);
for(int i=0;i<mColors*3;i+=3)
{
if(!getChar())return FALSE;
*(mlpPaletteData+i)=currentChar();
if(!getChar())return FALSE;
*(mlpPaletteData+i+1)=currentChar();
if(!getChar())return FALSE;
*(mlpPaletteData+i+2)=currentChar();
}
return TRUE;
}
void GIFDecoder::showHandler(UCHAR FAR *lpOutRow,USHORT yLocation)
{
showHandler(mImageWide,mImageDeep,lpOutRow,yLocation);
}
// virtuals
void GIFDecoder::paletteHandler(const UCHAR FAR *lpPaletteData,USHORT numColors)
{
}
void GIFDecoder::attributeHandler(USHORT imageWide,USHORT imageDeep,USHORT pixelSize)
{
}
void GIFDecoder::backgroundHandler(USHORT backgroundColor)
{
}
void GIFDecoder::imageHandler(void)
{
}
void GIFDecoder::showHandler(USHORT imageWide,USHORT imageDeep,const UCHAR FAR *lpRowData,USHORT yLocation)
{
}
void GIFDecoder::errorHandler(const char FAR *message)
{
}

46
gif/GIF.HPP Normal file
View File

@@ -0,0 +1,46 @@
#ifndef _GIF_GIFDECODER_HPP_
#define _GIF_GIFDECODER_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _LZWDECOMPRESSION_HPP_
#include <gif/lzw.hpp>
#endif
#ifdef _EXPAND_GIFDECODER_TEMPLATES_
#pragma option -Jgd
#endif
class GIFDecoder : public LZWDecompression
{
public:
GIFDecoder(void);
virtual ~GIFDecoder();
WORD unpackImage(const char *pathFileName);
virtual void paletteHandler(const UCHAR FAR *lpPaletteData,USHORT numColors);
virtual void attributeHandler(USHORT imageWide,USHORT imageDeep,USHORT pixelSize);
virtual void backgroundHandler(USHORT backgroundColor);
virtual void imageHandler(void);
virtual void showHandler(USHORT imageWide,USHORT imageDeep,const UCHAR FAR *lpRowData,USHORT yLocation);
virtual void errorHandler(const char FAR *message);
private:
void showHandler(UCHAR FAR *lpOutRow,USHORT yLocation);
WORD processImage(void);
WORD readPaletteData(void);
HGLOBAL mhGlobalPalette;
UCHAR FAR *mlpPaletteData;
USHORT mScreenWidth;
USHORT mScreenHeight;
UCHAR mGlobalFlagByte;
USHORT mColors;
USHORT mBackgroundColor;
USHORT mImageStartLeft;
USHORT mImageStartTop;
USHORT mImageWide;
USHORT mImageDeep;
USHORT mIsInterlaced;
USHORT mBufferCount;
USHORT mPixelSize;
};
#endif

274
gif/GIF.MAK Normal file
View File

@@ -0,0 +1,274 @@
# Microsoft Developer Studio Generated NMAKE File, Format Version 4.20
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
!IF "$(CFG)" == ""
CFG=gif - Win32 Debug
!MESSAGE No configuration specified. Defaulting to gif - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "gif - Win32 Release" && "$(CFG)" != "gif - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE on this makefile
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "gif.mak" CFG="gif - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "gif - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "gif - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
################################################################################
# Begin Project
# PROP Target_Last_Scanned "gif - Win32 Debug"
CPP=cl.exe
!IF "$(CFG)" == "gif - 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 ""
OUTDIR=.\Release
INTDIR=.\Release
ALL : "$(OUTDIR)\gif.lib"
CLEAN :
-@erase "$(INTDIR)\Gif.obj"
-@erase "$(INTDIR)\Gifbmp.obj"
-@erase "$(INTDIR)\Istream.obj"
-@erase "$(INTDIR)\Lzw.obj"
-@erase "$(OUTDIR)\gif.lib"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS"\
/Fp"$(INTDIR)/gif.pch" /YX /Fo"$(INTDIR)/" /c
CPP_OBJS=.\Release/
CPP_SBRS=.\.
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
BSC32_FLAGS=/nologo /o"$(OUTDIR)/gif.bsc"
BSC32_SBRS= \
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
LIB32_FLAGS=/nologo /out:"$(OUTDIR)/gif.lib"
LIB32_OBJS= \
"$(INTDIR)\Gif.obj" \
"$(INTDIR)\Gifbmp.obj" \
"$(INTDIR)\Istream.obj" \
"$(INTDIR)\Lzw.obj"
"$(OUTDIR)\gif.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
$(LIB32) @<<
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
<<
!ELSEIF "$(CFG)" == "gif - 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 "msvcobj"
# PROP Intermediate_Dir "msvcobj"
# PROP Target_Dir ""
OUTDIR=.\msvcobj
INTDIR=.\msvcobj
ALL : "..\exe\msgif.lib"
CLEAN :
-@erase "$(INTDIR)\Gif.obj"
-@erase "$(INTDIR)\Gifbmp.obj"
-@erase "$(INTDIR)\Istream.obj"
-@erase "$(INTDIR)\Lzw.obj"
-@erase "..\exe\msgif.lib"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /Zp1 /MTd /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "STRICT" /D "__FLAT__" /YX /c
CPP_PROJ=/nologo /Zp1 /MTd /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D\
"STRICT" /D "__FLAT__" /Fp"$(INTDIR)/gif.pch" /YX /Fo"$(INTDIR)/" /c
CPP_OBJS=.\msvcobj/
CPP_SBRS=.\.
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
BSC32_FLAGS=/nologo /o"$(OUTDIR)/gif.bsc"
BSC32_SBRS= \
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\exe\msgif.lib"
LIB32_FLAGS=/nologo /out:"..\exe\msgif.lib"
LIB32_OBJS= \
"$(INTDIR)\Gif.obj" \
"$(INTDIR)\Gifbmp.obj" \
"$(INTDIR)\Istream.obj" \
"$(INTDIR)\Lzw.obj"
"..\exe\msgif.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
$(LIB32) @<<
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
<<
!ENDIF
.c{$(CPP_OBJS)}.obj:
$(CPP) $(CPP_PROJ) $<
.cpp{$(CPP_OBJS)}.obj:
$(CPP) $(CPP_PROJ) $<
.cxx{$(CPP_OBJS)}.obj:
$(CPP) $(CPP_PROJ) $<
.c{$(CPP_SBRS)}.sbr:
$(CPP) $(CPP_PROJ) $<
.cpp{$(CPP_SBRS)}.sbr:
$(CPP) $(CPP_PROJ) $<
.cxx{$(CPP_SBRS)}.sbr:
$(CPP) $(CPP_PROJ) $<
################################################################################
# Begin Target
# Name "gif - Win32 Release"
# Name "gif - Win32 Debug"
!IF "$(CFG)" == "gif - Win32 Release"
!ELSEIF "$(CFG)" == "gif - Win32 Debug"
!ENDIF
################################################################################
# Begin Source File
SOURCE=.\Lzw.cpp
DEP_CPP_LZW_C=\
{$(INCLUDE)}"\.\istream.hpp"\
{$(INCLUDE)}"\.\lzw.hpp"\
{$(INCLUDE)}"\common\stdlib.hpp"\
{$(INCLUDE)}"\common\string.hpp"\
{$(INCLUDE)}"\common\windows.hpp"\
{$(INCLUDE)}"\sys\stat.h"\
{$(INCLUDE)}"\sys\types.h"\
"$(INTDIR)\Lzw.obj" : $(SOURCE) $(DEP_CPP_LZW_C) "$(INTDIR)"
# End Source File
################################################################################
# Begin Source File
SOURCE=.\Gifbmp.cpp
DEP_CPP_GIFBM=\
{$(INCLUDE)}"\.\gif.hpp"\
{$(INCLUDE)}"\.\gifbmp.hpp"\
{$(INCLUDE)}"\.\istream.hpp"\
{$(INCLUDE)}"\.\lzw.hpp"\
{$(INCLUDE)}"\common\array.hpp"\
{$(INCLUDE)}"\common\assert.hpp"\
{$(INCLUDE)}"\common\bitmap.hpp"\
{$(INCLUDE)}"\common\bmdata.hpp"\
{$(INCLUDE)}"\common\bminfo.hpp"\
{$(INCLUDE)}"\common\boverlay.hpp"\
{$(INCLUDE)}"\common\except.hpp"\
{$(INCLUDE)}"\common\fixup.hpp"\
{$(INCLUDE)}"\common\gdata.hpp"\
{$(INCLUDE)}"\common\gdata.tpp"\
{$(INCLUDE)}"\common\gdiobj.hpp"\
{$(INCLUDE)}"\common\gdipoint.hpp"\
{$(INCLUDE)}"\common\palentry.hpp"\
{$(INCLUDE)}"\common\pen.hpp"\
{$(INCLUDE)}"\common\point.hpp"\
{$(INCLUDE)}"\common\purebmp.hpp"\
{$(INCLUDE)}"\common\purehdc.hpp"\
{$(INCLUDE)}"\common\purepal.hpp"\
{$(INCLUDE)}"\common\pvector.hpp"\
{$(INCLUDE)}"\common\pvector.tpp"\
{$(INCLUDE)}"\common\rect.hpp"\
{$(INCLUDE)}"\common\rgbcolor.hpp"\
{$(INCLUDE)}"\common\rgbquad.hpp"\
{$(INCLUDE)}"\common\stdlib.hpp"\
{$(INCLUDE)}"\common\string.hpp"\
{$(INCLUDE)}"\common\types.hpp"\
{$(INCLUDE)}"\common\windows.hpp"\
{$(INCLUDE)}"\sys\stat.h"\
{$(INCLUDE)}"\sys\types.h"\
"$(INTDIR)\Gifbmp.obj" : $(SOURCE) $(DEP_CPP_GIFBM) "$(INTDIR)"
# End Source File
################################################################################
# Begin Source File
SOURCE=.\Istream.cpp
DEP_CPP_ISTRE=\
{$(INCLUDE)}"\.\istream.hpp"\
{$(INCLUDE)}"\common\windows.hpp"\
{$(INCLUDE)}"\sys\stat.h"\
{$(INCLUDE)}"\sys\types.h"\
"$(INTDIR)\Istream.obj" : $(SOURCE) $(DEP_CPP_ISTRE) "$(INTDIR)"
# End Source File
################################################################################
# Begin Source File
SOURCE=.\Gif.cpp
DEP_CPP_GIF_C=\
{$(INCLUDE)}"\.\gif.hpp"\
{$(INCLUDE)}"\.\istream.hpp"\
{$(INCLUDE)}"\.\lzw.hpp"\
{$(INCLUDE)}"\common\stdlib.hpp"\
{$(INCLUDE)}"\common\string.hpp"\
{$(INCLUDE)}"\common\windows.hpp"\
{$(INCLUDE)}"\sys\stat.h"\
{$(INCLUDE)}"\sys\types.h"\
"$(INTDIR)\Gif.obj" : $(SOURCE) $(DEP_CPP_GIF_C) "$(INTDIR)"
# End Source File
# End Target
# End Project
################################################################################

BIN
gif/GIF.MDP Normal file

Binary file not shown.

31
gif/GIF.PLG Normal file
View File

@@ -0,0 +1,31 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: gif - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\WINNT\Profiles\sean\LOCALS~1\Temp\RSP7.tmp" with contents
[
/nologo /Gz /MTd /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "STRICT" /D "__FLAT__" /Fp"msvcobj/gif.pch" /YX /Fo"msvcobj/" /Fd"msvcobj/" /FD /c
"D:\work\GIF\gif.cpp"
"D:\work\GIF\gifbmp.cpp"
"D:\work\GIF\Lzw.cpp"
]
Creating command line "cl.exe @C:\WINNT\Profiles\sean\LOCALS~1\Temp\RSP7.tmp"
Creating command line "link.exe -lib /nologo /out:"..\exe\msgif.lib" .\msvcobj\gif.obj .\msvcobj\gifbmp.obj .\msvcobj\Istream.obj .\msvcobj\Lzw.obj "
<h3>Output Window</h3>
Compiling...
gif.cpp
gifbmp.cpp
Lzw.cpp
Creating library...
<h3>Results</h3>
msgif.lib - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

41
gif/GIFBMP.CPP Normal file
View File

@@ -0,0 +1,41 @@
#include <gif/gifbmp.hpp>
#include <common/array.hpp>
void GIFBitmap::paletteHandler(const UCHAR FAR *lpPaletteData,USHORT numColors)
{
if(numColors>PurePalette::MaxColors)return;
Array<RGBColor> paletteData;
paletteData.size(numColors);
for(int palIndex=0;palIndex<numColors;palIndex++)
{
paletteData[palIndex]=RGBColor(*lpPaletteData,*(lpPaletteData+1),*(lpPaletteData+2));
lpPaletteData+=3;
}
mGIFPalette.setPaletteColors(paletteData);
}
void GIFBitmap::attributeHandler(USHORT imageWide,USHORT imageDeep,USHORT pixelSize)
{
String strPathFileName(mPathFileName.betweenString(0,'.')+String(".bmp"));
(Bitmap&)*this=Bitmap(strPathFileName,imageWide,imageDeep);
((Bitmap&)*this).setPalette(mGIFPalette.getPalette(),FALSE);
}
void GIFBitmap::backgroundHandler(USHORT backgroundColor)
{
}
void GIFBitmap::imageHandler(void)
{
}
void GIFBitmap::showHandler(USHORT imageWide,USHORT imageDeep,const UCHAR FAR *lpRowData,USHORT yLocation)
{
((Bitmap&)*this).setRow(yLocation,(char*)lpRowData);
}
void GIFBitmap::errorHandler(const char FAR *message)
{
}

47
gif/GIFBMP.HPP Normal file
View File

@@ -0,0 +1,47 @@
#ifndef _GIF_GIFBITMAP_HPP_
#define _GIF_GIFBITMAP_HPP_
#ifndef _GIF_GIFDECODER_HPP_
#include <gif/gif.hpp>
#endif
#ifndef _COMMON_BITMAP_HPP_
#include <common/bitmap.hpp>
#endif
#ifndef _COMMON_PUREPALETTE_HPP_
#include <common/purepal.hpp>
#endif
class GIFBitmap : public Bitmap, private GIFDecoder
{
public:
GIFBitmap(void);
BOOL open(const String &strPathFileName);
virtual ~GIFBitmap();
private:
virtual void paletteHandler(const UCHAR FAR *lpPaletteData,USHORT numColors);
virtual void attributeHandler(USHORT imageWide,USHORT imageDeep,USHORT pixelSize);
virtual void backgroundHandler(USHORT backgroundColor);
virtual void imageHandler(void);
virtual void showHandler(USHORT imageWide,USHORT imageDeep,const UCHAR FAR *lpRowData,USHORT yLocation);
virtual void errorHandler(const char FAR *message);
PurePalette mGIFPalette;
String mPathFileName;
};
inline
GIFBitmap::GIFBitmap(void)
{
}
inline
BOOL GIFBitmap::open(const String &strPathFileName)
{
mPathFileName=strPathFileName;
return unpackImage((char*)(String&)strPathFileName);
}
inline
GIFBitmap::~GIFBitmap()
{
}
#endif

29
gif/Gif.dsw Normal file
View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "gif"=.\gif.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

71
gif/ISTREAM.CPP Normal file
View File

@@ -0,0 +1,71 @@
#include <gif/istream.hpp>
IStream::IStream(void)
: mFileDescriptor(-1), mCurrentWord(0), mCurrentChar(0), mhGlobalBuffer(0),
mlpBuffer(0), mBufferIndex(0), mlpBufferPointer(0)
{
}
IStream::IStream(const char *pathFileName)
: mFileDescriptor(-1), mCurrentWord(0), mCurrentChar(0), mhGlobalBuffer(0),
mlpBuffer(0), mBufferIndex(0), mlpBufferPointer(0)
{
open(pathFileName);
}
IStream::~IStream()
{
close();
}
BOOL IStream::open(const char *pathFileName)
{
close();
if(-1==(mFileDescriptor=::open(pathFileName,O_RDONLY|O_BINARY,0,SH_DENYWR)))return FALSE;
mhGlobalBuffer=::GlobalAlloc(GMEM_FIXED,MaxInputBuffer);
if(!mhGlobalBuffer){close();return FALSE;}
mlpBuffer=(UCHAR FAR *)::GlobalLock(mhGlobalBuffer);
mlpBufferPointer=0;
mBufferIndex=0;
mCurrentChar=0;
mCurrentWord=0;
return TRUE;
}
void IStream::close(void)
{
if(-1!=mFileDescriptor)::close(mFileDescriptor);
mFileDescriptor=-1;
if(mhGlobalBuffer)
{
::GlobalUnlock(mhGlobalBuffer);
::GlobalFree(mhGlobalBuffer);
mhGlobalBuffer=0;
}
}
WORD IStream::getChar(void)
{
if(-1==mFileDescriptor)return FALSE;
if(!mBufferIndex)
{
mBufferIndex=::read(mFileDescriptor,(VPTR)mlpBuffer,MaxInputBuffer);
if(!mBufferIndex)return FALSE;
mlpBufferPointer=mlpBuffer;
}
mCurrentChar=*(mlpBufferPointer);
mlpBufferPointer++;
mBufferIndex--;
return TRUE;
}
WORD IStream::getWord(void)
{
if(-1==mFileDescriptor)return FALSE;
mCurrentWord=0;
if(!getChar())return FALSE;
mCurrentWord=mCurrentChar;
if(!getChar())return FALSE;
mCurrentWord|=((short)mCurrentChar)<<8;
return TRUE;
}

68
gif/ISTREAM.HPP Normal file
View File

@@ -0,0 +1,68 @@
#ifndef _GIF_ISTREAM_HPP_
#define _GIF_ISTREAM_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#include <io.h>
#include <fcntl.h>
#include <share.h>
#include <sys/stat.h>
class IStream
{
public:
#if defined(__FLAT__)
typedef void * VPTR;
#else
typedef void far * VPTR;
#endif
IStream(void);
IStream(const char *pathFileName);
virtual ~IStream();
BOOL open(const char *pathFileName);
void close(void);
WORD isOpen(void)const;
WORD getChar(void);
WORD getWord(void);
UCHAR currentChar(void)const;
USHORT currentWord(void)const;
void closeFile(void);
private:
enum{MaxInputBuffer=6400};
HGLOBAL mhGlobalBuffer;
UCHAR FAR *mlpBuffer;
UCHAR FAR *mlpBufferPointer;
USHORT mBufferIndex;
short mFileDescriptor;
USHORT mCurrentWord;
UCHAR mCurrentChar;
};
inline
UCHAR IStream::currentChar(void)const
{
return mCurrentChar;
}
inline
USHORT IStream::currentWord(void)const
{
return mCurrentWord;
}
inline
void IStream::closeFile(void)
{
if(-1!=mFileDescriptor)::close(mFileDescriptor);
mFileDescriptor=-1;
}
inline
WORD IStream::isOpen(void)const
{
if(-1==mFileDescriptor)return FALSE;
return TRUE;
}
#endif


338
gif/LZW.CPP Normal file
View File

@@ -0,0 +1,338 @@
#include <gif/lzw.hpp>
USHORT LZWDecompression::mStartTable[LZWDecompression::STARTTABLESIZE]=
{0x00,0x04,0x02,0x01,0x00};
USHORT LZWDecompression::mIncTable[LZWDecompression::INCTABLESIZE]=
{0x08,0x08,0x04,0x02,0x00};
USHORT LZWDecompression::mcMask[LZWDecompression::CMASKSIZE]=
{0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF};
CHAR LZWDecompression::errorMessage[]="Error reading data.";
LZWDecompression::LZWDecompression(void)
: mhGlobalctFirst(0), mhGlobalctLast(0), mhGlobalctLink(0),
mhGlobalOutRow(0), mhGlobalStack(0), mlpctFirst(0), mlpctLast(0),
mlpctLink(0), mlpOutRow(0), mlpStack(0), mNextCode(0), mNextLimit(0),
mBufferCount(0), mRemct(0), mRem(0), mPass(0), mxLocation(0),
myLocation(0), mRowCount(0), mIsConstructed(FALSE), mReqct(0), mCode(0)
{
initialize();
}
LZWDecompression::~LZWDecompression()
{
if(!mIsConstructed)return;
cleanup();
}
BOOL LZWDecompression::initialize(void)
{
cleanup();
mhGlobalctFirst=::GlobalAlloc(GMEM_FIXED,CTSIZE);
mhGlobalctLast=::GlobalAlloc(GMEM_FIXED,CTSIZE);
mhGlobalctLink=::GlobalAlloc(GMEM_FIXED,CTSIZE*sizeof(USHORT));
mhGlobalOutRow=::GlobalAlloc(GMEM_FIXED,OUTROWSIZE);
mhGlobalStack=::GlobalAlloc(GMEM_FIXED,STACKSIZE);
if(!mhGlobalctFirst||!mhGlobalctLast||!mhGlobalctLink||!mhGlobalOutRow||!mhGlobalStack)return FALSE;
mlpctFirst=(CHAR FAR *)::GlobalLock(mhGlobalctFirst);
mlpctLast=(CHAR FAR *)::GlobalLock(mhGlobalctLast);
mlpctLink=(SHORT FAR *)::GlobalLock(mhGlobalctLink);
mlpOutRow=(UCHAR FAR *)::GlobalLock(mhGlobalOutRow);
mlpStack=(UCHAR FAR *)::GlobalLock(mhGlobalStack);
::memset(mlpctFirst,0,CTSIZE);
::memset(mlpctLast,0,CTSIZE);
::memset(mlpctLink,0,CTSIZE*sizeof(USHORT));
::memset(mlpOutRow,0,OUTROWSIZE);
::memset(mlpStack,0,STACKSIZE);
mIsConstructed=TRUE;
return TRUE;
}
BOOL LZWDecompression::unpackData(USHORT imageWide,USHORT imageDeep,USHORT isInterlaced,USHORT bitsPerPixel)
{
USHORT clearCode;
USHORT pixelSize;
USHORT endOfInput;
CHAR firstCode;
initialize();
firstCode=currentChar();
mImageWide=imageWide;
mImageDeep=imageDeep;
mIsInterlaced=isInterlaced;
pixelSize=bitsPerPixel;
clearCode=(1<<currentChar());
endOfInput=(1<<currentChar())+1;
mReqct=currentChar()+1;
initializeTable(clearCode);
mOldCode=0xFFFF;
mPass=0x0000;
mRowCount=mImageWide;
mxLocation=0x0000;
myLocation=0x0000;
while(TRUE)
{
mCode=getCode(mReqct);
if(mCode==clearCode)
{
initializeTable(clearCode);
mReqct=firstCode+1;
mOldCode=0xFFFF;
}
else
{
if(mCode==endOfInput)
{
flush();
break;
}
else
{
if(0xFFFE!=(USHORT)*(mlpctLink+mCode))
{
if(0xFFFF!=mOldCode)if(!insertCode(mCode))break;
}
else if(!insertCode(mOldCode))break;
}
putx(mCode,pixelSize);
mOldCode=mCode;
}
}
return TRUE;
}
void LZWDecompression::putx(SHORT code,SHORT pixelSize)
{
SHORT tempCode;
UCHAR FAR *lpStack=mlpStack;
int i=0;
while(TRUE)
{
*lpStack=*(mlpctLast+code);
lpStack++;
i++;
code=*(mlpctLink+code);
if(-1>=code)break;
}
if(1==pixelSize)
{
while(i>0)
{
lpStack--;
tempCode=(*lpStack)&0x0001;
doPixel(tempCode);
tempCode=(*lpStack)&0x00FF;
tempCode>>=1;
doPixel(tempCode);
i--;
}
}
else
{
while(i>0)
{
lpStack--;
tempCode=(*lpStack)&0x00FF;
doPixel(tempCode);
i--;
}
}
}
void LZWDecompression::doPixel(CHAR tempCode)
{
*(mlpOutRow+mxLocation)=tempCode;
mxLocation++;
mRowCount--;
if(0!=mRowCount)return;
showHandler(mlpOutRow,myLocation);
mxLocation=0;
mRowCount=mImageWide;
if(!mIsInterlaced)
{
myLocation++;
if(myLocation>=mImageDeep)myLocation=0;
}
else
{
myLocation+=mIncTable[mPass];
if(myLocation<mImageDeep)return;
myLocation=mStartTable[++mPass];
}
return;
}
void LZWDecompression::initializeTable(SHORT clearCode)
{
mNextCode=clearCode+2;
mNextLimit=(clearCode<<1);
for(int i=0;i<CTSIZE;i++)
{
if(i<clearCode)
{
*(mlpctFirst+i)=i;
*(mlpctLast+i)=i;
*(mlpctLink+i)=-1;
}
else *(mlpctLink+i)=-2;
}
}
UCHAR LZWDecompression::getGB(void)
{
if(0!=mBufferCount)
{
if(!getChar())
{
errorHandler(errorMessage);
return currentChar();
}
mBufferCount--;
return currentChar();
}
if(!getChar())
{
errorHandler(errorMessage);
return currentChar();
}
mBufferCount=currentChar();
if(!mBufferCount)errorHandler(errorMessage);
if(!getChar())return currentChar();
mBufferCount--;
return currentChar();
}
USHORT LZWDecompression::getBCode(USHORT code)
{
USHORT tempCode;
USHORT temp;
if(0==mRemct)
{
mRem=getGB();
mRemct=8;
}
if(mRemct<code)
{
tempCode=getGB();
tempCode<<=mRemct;
mRem|=tempCode;
mRemct+=8;
}
temp=mcMask[code];
temp&=0x00FF;
tempCode=mRem;
tempCode&=temp;
mRemct-=code;
mRem>>=(code&0x00FF);
return tempCode;
}
USHORT LZWDecompression::getCode(USHORT reqct)
{
USHORT tempCode1;
USHORT tempCode2;
if(reqct<=8)return getBCode(reqct);
tempCode1=getBCode(8);
tempCode2=getBCode(reqct-8);
tempCode2<<=8;
tempCode2|=tempCode1;
return tempCode2;
}
WORD LZWDecompression::insertCode(SHORT code)
{
if(mNextCode>=CTSIZE)return FALSE;
*(mlpctLink+mNextCode)=mOldCode;
*(mlpctLast+mNextCode)=*(mlpctFirst+code);
*(mlpctFirst+mNextCode)=*(mlpctFirst+mOldCode);
mNextCode++;
if(mNextCode!=mNextLimit)return TRUE;
if(mReqct>=12)return TRUE;
mReqct++;
mNextLimit<<=1;
return TRUE;
}
void LZWDecompression::flush(void)
{
while(TRUE)
{
if(0==mBufferCount)
{
if(!getChar())return;
mBufferCount=currentChar();
if(0==mBufferCount)return;
}
else
{
if(!getChar())return;
mBufferCount--;
}
}
}
void LZWDecompression::cleanup(void)
{
if(mhGlobalctFirst)
{
::GlobalUnlock(mhGlobalctFirst);
::GlobalFree(mhGlobalctFirst);
mhGlobalctFirst=0;
}
if(mhGlobalctLast)
{
::GlobalUnlock(mhGlobalctLast);
::GlobalFree(mhGlobalctLast);
mhGlobalctLast=0;
}
if(mhGlobalctLink)
{
::GlobalUnlock(mhGlobalctLink);
::GlobalFree(mhGlobalctLink);
mhGlobalctLink=0;
}
if(mhGlobalOutRow)
{
::GlobalUnlock(mhGlobalOutRow);
::GlobalFree(mhGlobalOutRow);
mhGlobalOutRow=0;
}
if(mhGlobalStack)
{
::GlobalUnlock(mhGlobalStack);
::GlobalFree(mhGlobalStack);
mhGlobalStack=0;
}
mIsConstructed=FALSE;
mlpctFirst=0;
mlpctLast=0;
mlpctLink=0;
mlpOutRow=0;
mlpStack=0;
mNextCode=0;
mNextLimit=0;
mBufferCount=0;
mRemct=0;
mRem=0;
mPass=0;
mxLocation=0;
myLocation=0;
mRowCount=0;
mReqct=0;
mCode=0;
}
// VIRTUALS
void LZWDecompression::showHandler(UCHAR FAR * /*lpOutRow*/,USHORT /*yLocation*/)
{
}
void LZWDecompression::errorHandler(CHAR * /*errorMessage*/)
{
}

70
gif/LZW.HPP Normal file
View File

@@ -0,0 +1,70 @@
#ifndef _LZWDECOMPRESSION_HPP_
#define _LZWDECOMPRESSION_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _GIF_ISTREAM_HPP_
#include <gif/istream.hpp>
#endif
class LZWDecompression : public IStream
{
public:
LZWDecompression(void);
virtual ~LZWDecompression();
BOOL unpackData(USHORT imageWide,USHORT imageDeep,USHORT isInterlaced,USHORT pixelSize);
protected:
virtual void errorHandler(CHAR *errorMessage);
virtual void showHandler(UCHAR FAR *lpOutRow,USHORT yLocation);
private:
enum{CMASKSIZE=9,STARTTABLESIZE=5,INCTABLESIZE=5};
enum{OUTROWSIZE=2048,CTSIZE=4096,STACKSIZE=4096};
BOOL initialize(void);
void cleanup(void);
void flush(void);
void initializeTable(SHORT clearCode);
WORD insertCode(SHORT code);
void putx(SHORT code,SHORT pixelSize);
void doPixel(CHAR tempCode);
USHORT getCode(USHORT reqct);
USHORT getBCode(USHORT code);
UCHAR getGB(void);
static USHORT mcMask[];
static USHORT mStartTable[];
static USHORT mIncTable[];
static CHAR errorMessage[];
USHORT mImageWide;
USHORT mImageDeep;
USHORT mIsInterlaced;
USHORT mOldCode;
USHORT mNextCode;
USHORT mCode;
USHORT mPixelSize;
USHORT mNextLimit;
USHORT mBufferCount;
USHORT mRemct;
USHORT mReqct;
USHORT mRem;
USHORT mPass;
USHORT mxLocation;
USHORT myLocation;
USHORT mRowCount;
CHAR FAR *mlpctFirst;
CHAR FAR *mlpctLast;
SHORT FAR *mlpctLink;
UCHAR FAR *mlpOutRow;
UCHAR FAR *mlpStack;
HGLOBAL mhGlobalctFirst;
HGLOBAL mhGlobalctLast;
HGLOBAL mhGlobalctLink;
HGLOBAL mhGlobalOutRow;
HGLOBAL mhGlobalStack;
WORD mIsConstructed;
};
#endif


4
gif/SCRAPS.TXT Normal file
View File

@@ -0,0 +1,4 @@
// if(-1==(mFileDescriptor=::open(pathFileName,O_RDONLY|O_BINARY,0,SH_DENYWR)))return;
// mhGlobalBuffer=::GlobalAlloc(GMEM_FIXED,MaxInputBuffer);
// if(!mhGlobalBuffer)return;
// mlpBuffer=(UCHAR FAR *)::GlobalLock(mhGlobalBuffer);

94
gif/gif.001 Normal file
View File

@@ -0,0 +1,94 @@
# Microsoft Developer Studio Project File - Name="gif" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 5.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=gif - 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 "gif.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 "gif.mak" CFG="gif - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "gif - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "gif - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
!IF "$(CFG)" == "gif - 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 "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "gif - 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 "msvcobj"
# PROP Intermediate_Dir "msvcobj"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /Zp1 /MTd /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "STRICT" /D "__FLAT__" /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\exe\msgif.lib"
!ENDIF
# Begin Target
# Name "gif - Win32 Release"
# Name "gif - Win32 Debug"
# Begin Source File
SOURCE=.\gif.cpp
# End Source File
# Begin Source File
SOURCE=.\gifbmp.cpp
# End Source File
# Begin Source File
SOURCE=.\Istream.cpp
# End Source File
# Begin Source File
SOURCE=.\Lzw.cpp
# End Source File
# End Target
# End Project

100
gif/gif.dsp Normal file
View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="gif" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=gif - 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 "gif.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 "gif.mak" CFG="gif - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "gif - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "gif - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "gif - 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 "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "gif - 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 "msvcobj"
# PROP Intermediate_Dir "msvcobj"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /Gz /Zp8 /MTd /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "STRICT" /D "__FLAT__" /YX /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\exe\msgif.lib"
!ENDIF
# Begin Target
# Name "gif - Win32 Release"
# Name "gif - Win32 Debug"
# Begin Source File
SOURCE=.\gif.cpp
# End Source File
# Begin Source File
SOURCE=.\gifbmp.cpp
# End Source File
# Begin Source File
SOURCE=.\Istream.cpp
# End Source File
# Begin Source File
SOURCE=.\Lzw.cpp
# End Source File
# End Target
# End Project