wolf9228 Posted January 4, 2010 Share Posted January 4, 2010 expandcollapse popup#Include <WinAPI.au3> Dim $OptionsArray For $i = 1 To 11 $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 unfreez http://www.whitsoftdev.com/unfreez/ expandcollapse popupunfreez http://www.whitsoftdev.com/unfreez/ typedef struct { char cSignature[3]; // Must be 'GIF' char cVersion[3]; // Must be '89a' } GIF_HEADER; typedef struct { // 7 bytes unsigned short iWidth; unsigned short iHeight; unsigned char iSizeOfGct : 3; unsigned char iSortFlag : 1; unsigned char iColorResolution : 3; unsigned char iGctFlag : 1; unsigned char iBackgroundColorIndex; unsigned char iPixelAspectRatio; } GIF_LOGICAL_SCREEN_DESCRIPTOR; typedef struct { // 6 bytes unsigned char iBlockSize; // Must be 4 unsigned char iTransparentColorFlag : 1; unsigned char iUserInputFlag : 1; unsigned char iDisposalMethod : 3; unsigned char iReserved : 3; unsigned short iDelayTime; unsigned char iTransparentColorIndex; unsigned char iBlockTerminator; // Must be 0 } GIF_GRAPHIC_CONTROL_EXTENSION; typedef struct { // 9 bytes unsigned short iLeft; unsigned short iTop; unsigned short iWidth; unsigned short iHeight; unsigned char iSizeOfLct : 3; unsigned char iReserved : 2; unsigned char iSortFlag : 1; unsigned char iInterlaceFlag : 1; unsigned char iLctFlag : 1; } GIF_IMAGE_DESCRIPTOR; #pragma pack(pop,gifpacking) unsigned short iGctSize[]={6,12,24,48,96,192,384,768}; void MakeGIF() { OPENFILENAME ofn; char szFileName[MAX_PATH]; DWORD dwIndex, dw; char szColorTable[768]; unsigned char c; HANDLE hFileOut, hFileIn; GIF_HEADER gh; GIF_LOGICAL_SCREEN_DESCRIPTOR glsd1, glsd; GIF_GRAPHIC_CONTROL_EXTENSION ggce; GIF_IMAGE_DESCRIPTOR gid; ZeroMemory(&glsd1,sizeof(GIF_LOGICAL_SCREEN_DESCRIPTOR)); szFileName[0]=0; ofn.lStructSize=sizeof(ofn); ofn.hwndOwner=hMainDlg; ofn.hInstance=hInst; ofn.lpstrFilter="GIF Files (*.gif)\0*.gif\0"; ofn.lpstrCustomFilter=NULL; ofn.nMaxCustFilter=0; ofn.nFilterIndex=1; ofn.lpstrFile=szFileName; ofn.nMaxFile=MAX_PATH; ofn.lpstrFileTitle=NULL; ofn.nMaxFileTitle=0; ofn.lpstrInitialDir=NULL; ofn.lpstrTitle="Make Animated GIF"; ofn.Flags=OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST; ofn.nFileOffset=NULL; ofn.nFileExtension=NULL; ofn.lpstrDefExt="gif"; ofn.lCustData=NULL; ofn.lpfnHook=NULL; ofn.lpTemplateName=NULL; if (GetSaveFileName(&ofn)) { hFileOut=CreateFile(szFileName,GENERIC_WRITE,FILE_SHARE_READ,0,CREATE_ALWAYS,0,0); strncpy((char *)&gh,"GIF89a",6); WriteFile(hFileOut,&gh,sizeof(GIF_HEADER),&dw,0); WriteFile(hFileOut,&glsd1,sizeof(GIF_LOGICAL_SCREEN_DESCRIPTOR),&dw,0); if (IsDlgButtonChecked(hMainDlg,IDC_CHECK_MAIN_LOOP)) { WriteFile(hFileOut,"\41\377\013NETSCAPE2.0\003\001\377\377\0",19,&dw,0); } for (dwIndex=0;dwIndex<(unsigned)SendDlgItemMessage(hMainDlg,IDC_LIST_MAIN_FRAMES,LB_GETCOUNT,0,0);dwIndex++) { ZeroMemory(&glsd,sizeof(GIF_LOGICAL_SCREEN_DESCRIPTOR)); ZeroMemory(&ggce,sizeof(GIF_GRAPHIC_CONTROL_EXTENSION)); ZeroMemory(&gid,sizeof(GIF_IMAGE_DESCRIPTOR)); hFileIn=CreateFile((char *)SendDlgItemMessage(hMainDlg,IDC_LIST_MAIN_FRAMES,LB_GETITEMDATA,dwIndex,0),GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0); if (hFileIn==INVALID_HANDLE_VALUE) { MessageBox(hMainDlg,"Could not open file. GIF creation aborted.",0,0); CloseHandle(hFileOut); return; } ReadFile(hFileIn,&gh,sizeof(GIF_HEADER),&dw,0); if (strncmp(gh.cSignature,"GIF",3) || (strncmp(gh.cVersion,"89a",3) && strncmp(gh.cVersion,"87a",3))) { MessageBox(hMainDlg,"Not a GIF file, or incorrect version number.",0,MB_ICONEXCLAMATION); CloseHandle(hFileIn); CloseHandle(hFileOut); return; } ReadFile(hFileIn,&glsd,sizeof(GIF_LOGICAL_SCREEN_DESCRIPTOR),&dw,0); if (glsd.iGctFlag) ReadFile(hFileIn,szColorTable,iGctSize[glsd.iSizeOfGct],&dw,0); if (glsd1.iWidth<glsd.iWidth) glsd1.iWidth=glsd.iWidth; if (glsd1.iHeight<glsd.iHeight) glsd1.iHeight=glsd.iHeight; for (;;) { ReadFile(hFileIn,&c,1,&dw,0); if (dw==0) { MessageBox(hMainDlg,"Premature end of file encountered; no GIF image data present.",0,MB_ICONEXCLAMATION); CloseHandle(hFileIn); CloseHandle(hFileOut); return; } if (c==0x2C) { ReadFile(hFileIn,&gid,sizeof(GIF_IMAGE_DESCRIPTOR),&dw,0); if (gid.iLctFlag) { ReadFile(hFileIn,szColorTable,iGctSize[gid.iSizeOfLct],&dw,0); } else { gid.iLctFlag=1; gid.iSizeOfLct=glsd.iSizeOfGct; } break; } else if (c==0x21) { ReadFile(hFileIn,&c,1,&dw,0); if (c==0xF9) { ReadFile(hFileIn,&ggce,sizeof(GIF_GRAPHIC_CONTROL_EXTENSION),&dw,0); } else { for (;;) { ReadFile(hFileIn,&c,1,&dw,0); if (!c) break; SetFilePointer(hFileIn,c,0,FILE_CURRENT); } } } } ggce.iBlockSize=4; ggce.iDelayTime=(unsigned short)GetDlgItemInt(hMainDlg,IDC_EDIT_MAIN_DELAY,0,0); ggce.iDisposalMethod=2; c=(char)0x21; WriteFile(hFileOut,&c,1,&dw,0); c=(char)0xF9; WriteFile(hFileOut,&c,1,&dw,0); WriteFile(hFileOut,&ggce,sizeof(GIF_GRAPHIC_CONTROL_EXTENSION),&dw,0); c=(char)0x2C; WriteFile(hFileOut,&c,1,&dw,0); WriteFile(hFileOut,&gid,sizeof(GIF_IMAGE_DESCRIPTOR),&dw,0); WriteFile(hFileOut,szColorTable,iGctSize[gid.iSizeOfLct],&dw,0); ReadFile(hFileIn,&c,1,&dw,0); WriteFile(hFileOut,&c,1,&dw,0); for (;;) { ReadFile(hFileIn,&c,1,&dw,0); WriteFile(hFileOut,&c,1,&dw,0); if (!c) break; ReadFile(hFileIn,szColorTable,c,&dw,0); WriteFile(hFileOut,szColorTable,c,&dw,0); } CloseHandle(hFileIn); } c=(char)0x3B; WriteFile(hFileOut,&c,1,&dw,0); SetFilePointer(hFileOut,6,0,FILE_BEGIN); WriteFile(hFileOut,&glsd1,sizeof(GIF_LOGICAL_SCREEN_DESCRIPTOR),&dw,0); CloseHandle(hFileOut); } } صرح السماء كان هنا Link to comment Share on other sites More sharing options...
UEZ Posted January 5, 2010 Share Posted January 5, 2010 Good example. Thanks for sharing! Regards, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
wolf9228 Posted January 5, 2010 Author Share Posted January 5, 2010 (edited) Good example. Thanks for sharing!Regards,UEZThank you Edited January 5, 2010 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now