#Include <WinAPI.au3>
Dim $OptionsArray
For $i = 1 To 2
$OptionsArray = AddFile($OptionsArray,@ScriptDir & "\fistcash\fistcash0" & $i & ".gif",10)
Next
MakeGIF("fistcash.gif",$OptionsArray)
Func AddFile($OptionsArray,$sFile,$iDelayTime = 1,$LOOP = True)
if Not IsArray($OptionsArray) Then
Local $XOptionsArray[1][3]
$OptionsArray = $XOptionsArray
Else
ReDim $OptionsArray[UBound($OptionsArray) + 1][3]
EndIf
$OptionsArray[UBound($OptionsArray) - 1][0] = $sFile
$OptionsArray[UBound($OptionsArray) - 1][1] = $iDelayTime
$OptionsArray[UBound($OptionsArray) - 1][2] = $LOOP
Return $OptionsArray
EndFunc
Func MakeGIF($FileOut,$OptionsArray)
Local $iGctSize[8]=[6,12,24,48,96,192,384,768]
Local $LOOP = $OptionsArray[0][2] , $nBytes
$hFileOut =_WinAPI_CreateFile($FileOut,1)
$TegGIF_HEADER = _
"char cSignature[3];" & _
"char cVersion[3]"
$GIF_HEADER = DllStructCreate($TegGIF_HEADER)
DllStructSetData($GIF_HEADER,1,"GIF")
DllStructSetData($GIF_HEADER,2,"89a")
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($GIF_HEADER),DllStructGetSize($GIF_HEADER), $nBytes)
$GIF_LOGICAL_SCREEN_DESCRIPTOR = DllStructCreate("BYTE[7]")
$PGIF_LOGICAL_SCREEN_DESCRIPTOR = DllStructGetPtr($GIF_LOGICAL_SCREEN_DESCRIPTOR)
_WinAPI_WriteFile($hFileOut,$PGIF_LOGICAL_SCREEN_DESCRIPTOR,7, $nBytes)
if ($LOOP) Then
$Struct = DllStructCreate("BYTE[" & StringLen("0x21FF0B4E45545343415045322E300301FFFF00") & "]")
;"\41\377\013NETSCAPE2.0\003\001\377\377\0" ==> 0x21FF0B4E45545343415045322E300301FFFF00
DllStructSetData($Struct,1,"0x21FF0B4E45545343415045322E300301FFFF00")
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($Struct),19, $nBytes)
EndIf
For $i = 0 To UBound($OptionsArray) - 1
$sFile = $OptionsArray[$i][0]
$iDelayTime = $OptionsArray[$i][1]
$hFileIn =_WinAPI_CreateFile($sFile,2,2)
if Not ($hFileIn) Then _
Return MsgBox(0,"MSG","Could not open file. GIF creation aborted.")
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($GIF_HEADER),DllStructGetSize($GIF_HEADER), $nBytes)
$cSignature = DllStructGetData($GIF_HEADER,1)
$cVersion = DllStructGetData($GIF_HEADER,2)
$BOOL = ($cVersion == "89a") Or ($cVersion == "87a")
if Not ($cSignature == "GIF") Or Not ($BOOL) Then
MsgBox(0,"MSG","Not a GIF file, or incorrect version number.")
_WinAPI_CloseHandle($hFileIn)
_WinAPI_CloseHandle($hFileOut)
Return
EndIf
$szColorTable = DllStructCreate("char[768]")
$LGIF_LOGICAL_SCREEN_DESCRIPTOR = DllStructCreate("BYTE[7]")
$PLGIF_LOGICAL_SCREEN_DESCRIPTOR = DllStructGetPtr($LGIF_LOGICAL_SCREEN_DESCRIPTOR)
_WinAPI_ReadFile($hFileIn,$PLGIF_LOGICAL_SCREEN_DESCRIPTOR,7, $nBytes)
$OutPtr = $PLGIF_LOGICAL_SCREEN_DESCRIPTOR + 4
$Structivalue = DllStructCreate("BYTE",$OutPtr)
$value = DllStructGetData($Structivalue,1)
$iGctFlag = int(BitAND(int(0x01) , $value))
$iSizeOfGct = BitAND(int(0xF) , $value)
if ($iGctFlag) Then
_WinAPI_ReadFile($hFileIn, DllStructGetPtr($szColorTable),$iGctSize[$iSizeOfGct], $nBytes)
EndIf
$Structivalue1 = DllStructCreate("USHORT",$PGIF_LOGICAL_SCREEN_DESCRIPTOR)
$OutPtr1 = DllStructGetPtr($Structivalue1)
$AiWidth = DllStructGetData($Structivalue1,1)
$Structivalue2 = DllStructCreate("USHORT",$PLGIF_LOGICAL_SCREEN_DESCRIPTOR)
$OutPtr2 = DllStructGetPtr($Structivalue2)
$BiWidth = DllStructGetData($Structivalue2,1)
$OutPtr3 = $PGIF_LOGICAL_SCREEN_DESCRIPTOR + 2 ; 2 Size Of USHORT
$Structivalue3 = DllStructCreate("USHORT",$OutPtr3)
$AiHeight = DllStructGetData($Structivalue3,1)
$OutPtr4 = $PLGIF_LOGICAL_SCREEN_DESCRIPTOR + 2 ; 2 Size Of USHORT
$Structivalue4 = DllStructCreate("USHORT",$OutPtr4)
$BiHeight = DllStructGetData($Structivalue4,1)
if ($AiWidth < $BiWidth ) Then
RtlMoveMemory($OutPtr1,$OutPtr2,2)
EndIf
if ($AiHeight < $BiHeight) Then
RtlMoveMemory($OutPtr3,$OutPtr4,2)
EndIf
$C = DllStructCreate("BYTE")
While 1
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($C),1,$nBytes,0)
if ($nBytes == 0) Then
MsgBox(0,"MSG","Premature end of file encountered; no GIF image data present.")
_WinAPI_CloseHandle($hFileIn)
_WinAPI_CloseHandle($hFileOut)
return
EndIf
$IC = DllStructGetData($C,1)
if ($IC == 0x2C) Then
$GIF_IMAGE_DESCRIPTOR = DllStructCreate("BYTE[9]")
$PGIF_IMAGE_DESCRIPTOR = DllStructGetPtr($GIF_IMAGE_DESCRIPTOR)
_WinAPI_ReadFile($hFileIn,$PGIF_IMAGE_DESCRIPTOR,9,$nBytes)
$OutPtr5 = $PGIF_IMAGE_DESCRIPTOR + 8 ;Sizeof USHORT * 4
$Structivalue5 = DllStructCreate("BYTE",$OutPtr5)
$value = DllStructGetData($Structivalue5,1)
$iLctFlag = int(BitAND(int(0x01) , $value))
$iSizeOfLct = int(BitAND(int(0xF) , $value))
if ($iLctFlag) Then
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($szColorTable),$iGctSize[$iSizeOfLct],$nBytes)
Else
$Structivalue5 = DllStructCreate("BYTE")
DllStructSetData($Structivalue5,1,0x87)
$outPtr6 = $PGIF_IMAGE_DESCRIPTOR + 8 ;Sizeof USHORT * 4
$OutPtr7 = DllStructGetPtr($Structivalue5)
RtlMoveMemory($OutPtr6,$OutPtr7,1)
$iSizeOfLct = int(BitAND(int(0xF) , 0x87))
EndIf
ExitLoop
ElseIf ($IC == 0x21) Then
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($C),1,$nBytes)
$IC = DllStructGetData($C,1)
if ($IC == 0xF9) Then
$GIF_GRAPHIC_CONTROL_EXTENSION = DllStructCreate("BYTE[6]")
$PGIF_GRAPHIC_CONTROL_EXTENSION = DllStructGetPtr($GIF_GRAPHIC_CONTROL_EXTENSION)
_WinAPI_ReadFile($hFileIn,$PGIF_GRAPHIC_CONTROL_EXTENSION,6,$nBytes)
Else
While 1
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($C),1,$nBytes)
$IC = DllStructGetData($C,1)
if Not ($IC) Then ExitLoop
_WinAPI_SetFilePointer($hFileIn,$IC,1)
WEnd
EndIf
EndIf
WEnd
$Structivalue5 = DllStructCreate("BYTE")
DllStructSetData($Structivalue5,1,4)
$valuePtr1 = DllStructGetPtr($Structivalue5)
RtlMoveMemory($PGIF_GRAPHIC_CONTROL_EXTENSION,$valuePtr1,1)
$Structivalue6 = DllStructCreate("USHORT")
DllStructSetData($Structivalue6,1,$iDelayTime)
$valuePtr2 = DllStructGetPtr($Structivalue6)
$OutPtr8 = $PGIF_GRAPHIC_CONTROL_EXTENSION + 2 ; 2 size Of BYTE * 2
RtlMoveMemory($OutPtr8,$valuePtr2,2)
$Structivalue7 = DllStructCreate("BYTE")
DllStructSetData($Structivalue7,1,9)
$valuePtr3 = DllStructGetPtr($Structivalue7)
$OutPtr9 = $PGIF_GRAPHIC_CONTROL_EXTENSION + 1 ; 1 size Of BYTE
RtlMoveMemory($OutPtr9,$valuePtr3,1)
$C = DllStructCreate("char")
DllStructSetData($C,1,Chr(0x21))
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($C),1, $nBytes)
DllStructSetData($C,1,Chr(0xF9))
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($C),1, $nBytes)
_WinAPI_WriteFile($hFileOut,$PGIF_GRAPHIC_CONTROL_EXTENSION,6, $nBytes)
DllStructSetData($C,1,Chr(0x2C))
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($C),1, $nBytes)
_WinAPI_WriteFile($hFileOut,$PGIF_IMAGE_DESCRIPTOR,9, $nBytes)
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($szColorTable),$iGctSize[$iSizeOfLct], $nBytes)
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($C),1,$nBytes)
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($C),1, $nBytes)
$C = DllStructCreate("BYTE")
While 1
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($C),1,$nBytes)
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($C),1, $nBytes)
$IC = DllStructGetData($C,1)
if Not ($IC) Then ExitLoop
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($szColorTable),$IC,$nBytes)
_WinAPI_WriteFile($hFileOut,DllStructGetPtr($szColorTable),$IC,$nBytes)
WEnd
_WinAPI_CloseHandle($hFileIn)
Next
$C = DllStructCreate("char")
DllStructSetData($C,1,Chr(0x3B))
_WinAPI_WriteFile($hFileOut,DllStructGetPtr($C),1,$nBytes)
_WinAPI_SetFilePointer($hFileOut,6,0)
_WinAPI_WriteFile($hFileOut,$PGIF_LOGICAL_SCREEN_DESCRIPTOR,7, $nBytes)
_WinAPI_CloseHandle($hFileOut)
EndFunc
Func RtlMoveMemory($sourcePtr,$destPtr,$Size)
DllCall("Kernel32.dll","none","RtlMoveMemory","ptr",$sourcePtr,"ptr",$destPtr,"dword",$Size)
EndFunc
|