1 (изменено: Malcev, 2019-10-08 11:24:08)

Тема: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Перенес код отсюда:
https://stackoverflow.com/questions/300 … 4#30138664
Воспользовался библиотеками:
https://www.autohotkey.com/boards/viewt … mp;t=28834
https://github.com/neptercn/Component_A … er/wic.ahk
Тестировал на Win-7, на win8+ рекомендуют сохранять экран через Desktop Duplication API:
https://docs.microsoft.com/en-us/window … op-dup-api
По скорости у меня при статичном экране получается где-то 60 снимков в секунду.
Код выполняет 100 итераций захвата экрана, показывает время выполнения и сохраняет последний снимок на диск.

;
; Script Requirements:
;
;   DirectX - March 2008 or later. (d3dx9_37.dll)
;     DirectX End-User Runtime Web Installer (March 2008):
;     http://www.microsoft.com/downloads/details.aspx?FamilyId=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&displaylang=en
;
file := "test.png"
setbatchlines -1

; init D3D and get screen size
d3d := Direct3DCreate9(D3D_SDK_VERSION := 32) 
if !d3d
{
    MsgBox, 16, Error, Direct3DCreate9 failed.
    ExitApp
}
VarSetCapacity(D3DDISPLAYMODE, 16, 0)
IDirect3D9_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT := 0, &D3DDISPLAYMODE)
Windowed := true
BackBufferCount := 1
BackBufferHeight := NumGet(D3DDISPLAYMODE, 4, "uint")
BackBufferWidth := NumGet(D3DDISPLAYMODE, 0, "uint")
SwapEffect := 1   ; D3DSWAPEFFECT_DISCARD
hDeviceWindow := 0

; create device & capture surface
VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0) 
NumPut(BackBufferWidth, D3DPRESENT_PARAMETERS, 0)
NumPut(BackBufferHeight, D3DPRESENT_PARAMETERS, 4)
NumPut(BackBufferCount, D3DPRESENT_PARAMETERS, 12)
NumPut(SwapEffect, D3DPRESENT_PARAMETERS, 24)
NumPut(hDeviceWindow, D3DPRESENT_PARAMETERS, 24+A_PtrSize)
NumPut(Windowed, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)
IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT := 0, D3DDEVTYPE_HAL := 1, 0, D3DCREATE_SOFTWARE_VERTEXPROCESSING := 0x00000020, &D3DPRESENT_PARAMETERS, device)
IDirect3DDevice9_CreateOffscreenPlainSurface(device, BackBufferWidth, BackBufferHeight, D3DFMT_A8R8G8B8 := 21, D3DPOOL_SYSTEMMEM := 2, surface, 0)

a := a_tickcount
loop 100
{
   ; get the data
   IDirect3DDevice9_GetFrontBufferData(device, 0, surface)

   ; copy it into our buffers
   VarSetCapacity(D3DLOCKED_RECT, A_PtrSize*2, 0)
   IDirect3DSurface9_LockRect(surface, &D3DLOCKED_RECT, 0, 0)
   pitch := NumGet(D3DLOCKED_RECT, 0, "int")
   pBits := NumGet(D3DLOCKED_RECT, A_PtrSize, "ptr")
   IDirect3DSurface9_UnlockRect(surface)
}
msgbox % a_tickcount - a

SavePixelsToFile32bppPBGRA(BackBufferWidth, BackBufferHeight, pitch, pBits, file, "GUID_ContainerFormatPng")

Release(surface)
Release(device)
Release(d3d)
msgbox done
return



Direct3DCreate9(SDKVersion) {
    if !DllCall("GetModuleHandle","str","d3d9")
        DllCall("LoadLibrary","str","d3d9")
    return DllCall("d3d9\Direct3DCreate9", "uint", SDKVersion)
}

IDirect3D9_GetAdapterDisplayMode(this,Adapter,pMode)
{
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize),"ptr",this,"uint",Adapter,"ptr",pMode)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3D9_CreateDevice(this,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ByRef ppReturnedDeviceInterface)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize),"ptr",this,"uint",Adapter,"uint",DeviceType,"ptr",hFocusWindow,"uint",BehaviorFlags,"ptr",pPresentationParameters,"ptr*",ppReturnedDeviceInterface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DDevice9_GetFrontBufferData(this,iSwapChain,pDestSurface)
{
   hr := DllCall(NumGet(NumGet(this+0)+33*A_PtrSize),"ptr",this,"uint",iSwapChain,"ptr",pDestSurface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DDevice9_CreateOffscreenPlainSurface(this,Width,Height,Format,Pool,ByRef ppSurface,pSharedHandle)
{
   hr := DllCall(NumGet(NumGet(this+0)+36*A_PtrSize),"ptr",this,"uint",Width,"uint",Height,"uint",Format,"uint",Pool,"ptr*",ppSurface,"ptr",pSharedHandle)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DSurface9_LockRect(this,pLockedRect,pRect,Flags)
{
   hr := DllCall(NumGet(NumGet(this+0)+13*A_PtrSize),"ptr",this,"ptr",pLockedRect,"ptr",pRect,"uint",Flags)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DSurface9_UnlockRect(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+14*A_PtrSize),"ptr",this)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

Release(this) { ; COM_Release. So far the only required COM_* function...
    return DllCall(NumGet(NumGet(this+0)+2*A_PtrSize), "ptr", this)
}

_Error(val)
{
   msgbox % val
   ExitApp
}

SavePixelsToFile32bppPBGRA(width, height, stride, pixels, filePath, GUID)
{
   wic := IWICCreate()
   IWICImagingFactory_CreateStream(wic, stream)
   IWICStream_InitializeFromFilename(stream, filePath, GENERIC_WRITE := 0x40000000)
   IWICImagingFactory_CreateEncoder(wic, GUID, 0, encoder)
   IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache := 0x2)
   IWICBitmapEncoder_CreateNewFrame(encoder, frame)
   IWICBitmapFrameEncode_Initialize(frame)
   IWICBitmapFrameEncode_SetSize(frame, width, height)
   IWICBitmapFrameEncode_SetPixelFormat(frame, "GUID_WICPixelFormat32bppPBGRA")
   IWICBitmapFrameEncode_WritePixels(frame, height, stride, stride * height, pixels)
   IWICBitmapFrameEncode_Commit(frame)
   IWICBitmapEncoder_Commit(encoder)
   Release(stream)
   Release(frame)
   Release(encoder)
   Release(factory)
   ObjRelease(wic)
   return
}

IWICCreate()
{
   return ComObjCreate("{cacaf262-9370-4615-a13b-9f5539da4c0a}", "{ec5ec8a9-c395-4314-9c77-54d7a935ff70}")
}

IWICImagingFactory_CreateStream(this, ByRef ppIWICStream)
{
   hr := DllCall(NumGet(NumGet(this+0)+14*A_PtrSize), "ptr", this, "ptr*", ppIWICStream)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateEncoder(this, guidContainerFormat, pguidVendor, ByRef ppIEncoder)
{
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize), "ptr", this, "ptr", WIC_GUID(GUID1, guidContainerFormat), "ptr", WIC_GUID(GUID2, pguidVendor), "ptr*", ppIEncoder)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICStream_InitializeFromFilename(this, wzFileName, dwDesiredAccess)
{
   hr := DllCall(NumGet(NumGet(this+0)+15*A_PtrSize), "ptr", this, "str", wzFileName, "uint", dwDesiredAccess)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_Initialize(this, pIStream, cacheOption)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), "ptr", this, "ptr", pIStream, "int", cacheOption)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_CreateNewFrame(this, ByRef ppIFrameEncode, ppIEncoderOptions := 0)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "ptr*", ppIFrameEncode, "ptr*", ppIEncoderOptions)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_Commit(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+11*A_PtrSize), "ptr", this)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_Initialize(this, pIEncoderOptions := 0)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), "ptr", this, "ptr", pIEncoderOptions)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_SetSize(this, uiWidth, uiHeight)
{
   hr := DllCall(NumGet(NumGet(this+0)+4*A_PtrSize), "ptr", this, "uint", uiWidth, "uint", uiHeight)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_SetPixelFormat(this, pPixelFormat)
{
   hr := DllCall(NumGet(NumGet(this+0)+6*A_PtrSize), "ptr", this, "ptr", WIC_GUID(GUID, pPixelFormat))
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_WritePixels(this, lineCount, cbStride, cbBufferSize, pbPixels)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "uint", lineCount, "uint", cbStride, "uint", cbBufferSize, "ptr", pbPixels)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_Commit(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+12*A_PtrSize), "ptr", this)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

WIC_GUID(ByRef GUID,name){
	static init:=1,_:={}
	if init {
	init:=0
	; Decoders
	 _.CLSID_WICBmpDecoder:=[0x6b462062, 0x7cbf, 0x400d, 0x9f, 0xdb, 0x81, 0x3d, 0xd1, 0xf, 0x27, 0x78]
	,_.CLSID_WICPngDecoder:=[0x389ea17b, 0x5078, 0x4cde, 0xb6, 0xef, 0x25, 0xc1, 0x51, 0x75, 0xc7, 0x51]
	,_.CLSID_WICIcoDecoder:=[0xc61bfcdf, 0x2e0f, 0x4aad, 0xa8, 0xd7, 0xe0, 0x6b, 0xaf, 0xeb, 0xcd, 0xfe]
	,_.CLSID_WICJpegDecoder:=[0x9456a480, 0xe88b, 0x43ea, 0x9e, 0x73, 0xb, 0x2d, 0x9b, 0x71, 0xb1, 0xca]
	,_.CLSID_WICGifDecoder:=[0x381dda3c, 0x9ce9, 0x4834, 0xa2, 0x3e, 0x1f, 0x98, 0xf8, 0xfc, 0x52, 0xbe]
	,_.CLSID_WICTiffDecoder:=[0xb54e85d9, 0xfe23, 0x499f, 0x8b, 0x88, 0x6a, 0xce, 0xa7, 0x13, 0x75, 0x2b]
	,_.CLSID_WICWmpDecoder:=[0xa26cec36, 0x234c, 0x4950, 0xae, 0x16, 0xe3, 0x4a, 0xac, 0xe7, 0x1d, 0x0d]
	; Encoders
	 _.CLSID_WICBmpEncoder:=[0x69be8bb4, 0xd66d, 0x47c8, 0x86, 0x5a, 0xed, 0x15, 0x89, 0x43, 0x37, 0x82]
	,_.CLSID_WICPngEncoder:=[0x27949969, 0x876a, 0x41d7, 0x94, 0x47, 0x56, 0x8f, 0x6a, 0x35, 0xa4, 0xdc]
	,_.CLSID_WICJpegEncoder:=[0x1a34f5c1, 0x4a5a, 0x46dc, 0xb6, 0x44, 0x1f, 0x45, 0x67, 0xe7, 0xa6, 0x76]
	,_.CLSID_WICGifEncoder:=[0x114f5598, 0xb22, 0x40a0, 0x86, 0xa1, 0xc8, 0x3e, 0xa4, 0x95, 0xad, 0xbd]
	,_.CLSID_WICTiffEncoder:=[0x0131be10, 0x2001, 0x4c5f, 0xa9, 0xb0, 0xcc, 0x88, 0xfa, 0xb6, 0x4c, 0xe8]
	,_.CLSID_WICWmpEncoder:=[0xac4ce3cb, 0xe1c1, 0x44cd, 0x82, 0x15, 0x5a, 0x16, 0x65, 0x50, 0x9e, 0xc2]
	; Container Formats
	 _.GUID_ContainerFormatBmp:=[0xaf1d87e, 0xfcfe, 0x4188, 0xbd, 0xeb, 0xa7, 0x90, 0x64, 0x71, 0xcb, 0xe3]
	,_.GUID_ContainerFormatPng:=[0x1b7cfaf4, 0x713f, 0x473c, 0xbb, 0xcd, 0x61, 0x37, 0x42, 0x5f, 0xae, 0xaf]
	,_.GUID_ContainerFormatIco:=[0xa3a860c4, 0x338f, 0x4c17, 0x91, 0x9a, 0xfb, 0xa4, 0xb5, 0x62, 0x8f, 0x21]
	,_.GUID_ContainerFormatJpeg:=[0x19e4a5aa, 0x5662, 0x4fc5, 0xa0, 0xc0, 0x17, 0x58, 0x2, 0x8e, 0x10, 0x57]
	,_.GUID_ContainerFormatTiff:=[0x163bcc30, 0xe2e9, 0x4f0b, 0x96, 0x1d, 0xa3, 0xe9, 0xfd, 0xb7, 0x88, 0xa3]
	,_.GUID_ContainerFormatGif:=[0x1f8a5601, 0x7d4d, 0x4cbd, 0x9c, 0x82, 0x1b, 0xc8, 0xd4, 0xee, 0xb9, 0xa5]
	,_.GUID_ContainerFormatWmp:=[0x57a37caa, 0x367a, 0x4540, 0x91, 0x6b, 0xf1, 0x83, 0xc5, 0x09, 0x3a, 0x4b]
	; Component Identifiers
	 _.CLSID_WICImagingCategories:=[0xfae3d380, 0xfea4, 0x4623, 0x8c, 0x75, 0xc6, 0xb6, 0x11, 0x10, 0xb6, 0x81]
	,_.CATID_WICBitmapDecoders:=[0x7ed96837, 0x96f0, 0x4812, 0xb2, 0x11, 0xf1, 0x3c, 0x24, 0x11, 0x7e, 0xd3]
	,_.CATID_WICBitmapEncoders:=[0xac757296, 0x3522, 0x4e11, 0x98, 0x62, 0xc1, 0x7b, 0xe5, 0xa1, 0x76, 0x7e]
	,_.CATID_WICPixelFormats:=[0x2b46e70f, 0xcda7, 0x473e, 0x89, 0xf6, 0xdc, 0x96, 0x30, 0xa2, 0x39, 0x0b]
	,_.CATID_WICFormatConverters:=[0x7835eae8, 0xbf14, 0x49d1, 0x93, 0xce, 0x53, 0x3a, 0x40, 0x7b, 0x22, 0x48]
	,_.CATID_WICMetadataReader:=[0x05af94d8, 0x7174, 0x4cd2, 0xbe, 0x4a, 0x41, 0x24, 0xb8, 0x0e, 0xe4, 0xb8]
	,_.CATID_WICMetadataWriter:=[0xabe3b9a4, 0x257d, 0x4b97, 0xbd, 0x1a, 0x29, 0x4a, 0xf4, 0x96, 0x22, 0x2e]
	; Format Converters
	 _.CLSID_WICDefaultFormatConverter:=[0x1a3f11dc, 0xb514, 0x4b17, 0x8c, 0x5f, 0x21, 0x54, 0x51, 0x38, 0x52, 0xf1]
	,_.CLSID_WICFormatConverterHighColor:=[0xac75d454, 0x9f37, 0x48f8, 0xb9, 0x72, 0x4e, 0x19, 0xbc, 0x85, 0x60, 0x11]
	,_.CLSID_WICFormatConverterNChannel:=[0xc17cabb2, 0xd4a3, 0x47d7, 0xa5, 0x57, 0x33, 0x9b, 0x2e, 0xfb, 0xd4, 0xf1]
	,_.CLSID_WICFormatConverterWMPhoto:=[0x9cb5172b, 0xd600, 0x46ba, 0xab, 0x77, 0x77, 0xbb, 0x7e, 0x3a, 0x00, 0xd9]
	; Metadata Handlers
	 _.GUID_MetadataFormatUnknown:=[0xA45E592F, 0x9078, 0x4A7C, 0xAD, 0xB5, 0x4E, 0xDC, 0x4F, 0xD6, 0x1B, 0x1F]
	,_.GUID_MetadataFormatIfd:=[0x537396C6, 0x2D8A, 0x4BB6, 0x9B, 0xF8, 0x2F, 0x0A, 0x8E, 0x2A, 0x3A, 0xDF]
	,_.GUID_MetadataFormatSubIfd:=[0x58A2E128, 0x2DB9, 0x4E57, 0xBB, 0x14, 0x51, 0x77, 0x89, 0x1E, 0xD3, 0x31]
	,_.GUID_MetadataFormatExif:=[0x1C3C4F9D, 0xB84A, 0x467D, 0x94, 0x93, 0x36, 0xCF, 0xBD, 0x59, 0xEA, 0x57]
	,_.GUID_MetadataFormatGps:=[0x7134AB8A, 0x9351, 0x44AD, 0xAF, 0x62, 0x44, 0x8D, 0xB6, 0xB5, 0x02, 0xEC]
	,_.GUID_MetadataFormatInterop:=[0xED686F8E, 0x681F, 0x4C8B, 0xBD, 0x41, 0xA8, 0xAD, 0xDB, 0xF6, 0xB3, 0xFC]
	,_.GUID_MetadataFormatApp0:=[0x79007028, 0x268D, 0x45d6, 0xA3, 0xC2, 0x35, 0x4E, 0x6A, 0x50, 0x4B, 0xC9]
	,_.GUID_MetadataFormatApp1:=[0x8FD3DFC3, 0xF951, 0x492B, 0x81, 0x7F, 0x69, 0xC2, 0xE6, 0xD9, 0xA5, 0xB0]
	,_.GUID_MetadataFormatApp13:=[0x326556A2, 0xF502, 0x4354, 0x9C, 0xC0, 0x8E, 0x3F, 0x48, 0xEA, 0xF6, 0xB5]
	,_.GUID_MetadataFormatIPTC:=[0x4FAB0914, 0xE129, 0x4087, 0xA1, 0xD1, 0xBC, 0x81, 0x2D, 0x45, 0xA7, 0xB5]
	,_.GUID_MetadataFormatIRB:=[0x16100D66, 0x8570, 0x4BB9, 0xB9, 0x2D, 0xFD, 0xA4, 0xB2, 0x3E, 0xCE, 0x67]
	,_.GUID_MetadataFormat8BIMIPTC:=[0x0010568c, 0x0852, 0x4e6a, 0xb1, 0x91, 0x5c, 0x33, 0xac, 0x5b, 0x04, 0x30]
	,_.GUID_MetadataFormat8BIMResolutionInfo:=[0x739F305D, 0x81DB, 0x43CB, 0xAC, 0x5E, 0x55, 0x01, 0x3E, 0xF9, 0xF0, 0x03]
	 _.GUID_MetadataFormat8BIMIPTCDigest:=[0x1CA32285, 0x9CCD, 0x4786, 0x8B, 0xD8, 0x79, 0x53, 0x9D, 0xB6, 0xA0, 0x06]
	,_.GUID_MetadataFormatXMP:=[0xBB5ACC38, 0xF216, 0x4CEC, 0xA6, 0xC5, 0x5F, 0x6E, 0x73, 0x97, 0x63, 0xA9]
	,_.GUID_MetadataFormatThumbnail:=[0x243dcee9, 0x8703, 0x40ee, 0x8e, 0xf0, 0x22, 0xa6, 0x0, 0xb8, 0x5, 0x8c]
	,_.GUID_MetadataFormatChunktEXt:=[0x568d8936, 0xc0a9, 0x4923, 0x90, 0x5d, 0xdf, 0x2b, 0x38, 0x23, 0x8f, 0xbc]
	,_.GUID_MetadataFormatXMPStruct:=[0x22383CF1, 0xED17, 0x4E2E, 0xAF, 0x17, 0xD8, 0x5B, 0x8F, 0x6B, 0x30, 0xD0]
	,_.GUID_MetadataFormatXMPBag:=[0x833CCA5F, 0xDCB7, 0x4516, 0x80, 0x6F, 0x65, 0x96, 0xAB, 0x26, 0xDC, 0xE4]
	,_.GUID_MetadataFormatXMPSeq:=[0x63E8DF02, 0xEB6C,0x456C, 0xA2, 0x24, 0xB2, 0x5E, 0x79, 0x4F, 0xD6, 0x48]
	,_.GUID_MetadataFormatXMPAlt:=[0x7B08A675, 0x91AA, 0x481B, 0xA7, 0x98, 0x4D, 0xA9, 0x49, 0x08, 0x61, 0x3B]
	,_.GUID_MetadataFormatLSD:=[0xE256031E, 0x6299, 0x4929, 0xB9, 0x8D, 0x5A, 0xC8, 0x84, 0xAF, 0xBA, 0x92]
	,_.GUID_MetadataFormatIMD:=[0xBD2BB086, 0x4D52, 0x48DD, 0x96, 0x77, 0xDB, 0x48, 0x3E, 0x85, 0xAE, 0x8F]
	,_.GUID_MetadataFormatGCE:=[0x2A25CAD8, 0xDEEB, 0x4C69, 0xA7, 0x88, 0xE, 0xC2, 0x26, 0x6D, 0xCA, 0xFD]
	,_.GUID_MetadataFormatAPE:=[0x2E043DC2, 0xC967, 0x4E05, 0x87, 0x5E, 0x61, 0x8B, 0xF6, 0x7E, 0x85, 0xC3]
	 _.GUID_MetadataFormatJpegChrominance:=[0xF73D0DCF, 0xCEC6, 0x4F85, 0x9B, 0x0E, 0x1C, 0x39, 0x56, 0xB1, 0xBE, 0xF7]
	,_.GUID_MetadataFormatJpegLuminance:=[0x86908007, 0xEDFC, 0x4860, 0x8D, 0x4B, 0x4E, 0xE6, 0xE8, 0x3E, 0x60, 0x58]
	,_.GUID_MetadataFormatJpegComment:=[0x220E5F33, 0xAFD3, 0x474E, 0x9D, 0x31, 0x7D, 0x4F, 0xE7, 0x30, 0xF5, 0x57]
	,_.GUID_MetadataFormatGifComment:=[0xC4B6E0E0, 0xCFB4, 0x4AD3, 0xAB, 0x33, 0x9A, 0xAD, 0x23, 0x55, 0xA3, 0x4A]
	,_.GUID_MetadataFormatChunkgAMA:=[0xF00935A5, 0x1D5D, 0x4CD1, 0x81, 0xB2, 0x93, 0x24, 0xD7, 0xEC, 0xA7, 0x81]
	,_.GUID_MetadataFormatChunkbKGD:=[0xE14D3571, 0x6B47, 0x4DEA, 0xB6, 0xA, 0x87, 0xCE, 0xA, 0x78, 0xDF, 0xB7]
	,_.GUID_MetadataFormatChunkiTXt:=[0xC2BEC729, 0xB68, 0x4B77, 0xAA, 0xE, 0x62, 0x95, 0xA6, 0xAC, 0x18, 0x14]
	,_.GUID_MetadataFormatChunkcHRM:=[0x9DB3655B, 0x2842, 0x44B3, 0x80, 0x67, 0x12, 0xE9, 0xB3, 0x75, 0x55, 0x6A]
	,_.GUID_MetadataFormatChunkhIST:=[0xC59A82DA, 0xDB74, 0x48A4, 0xBD, 0x6A, 0xB6, 0x9C, 0x49, 0x31, 0xEF, 0x95]
	,_.GUID_MetadataFormatChunkiCCP:=[0xEB4349AB, 0xB685, 0x450F, 0x91, 0xB5, 0xE8, 0x2, 0xE8, 0x92, 0x53, 0x6C]
	,_.GUID_MetadataFormatChunksRGB:=[0xC115FD36, 0xCC6F, 0x4E3F, 0x83, 0x63, 0x52, 0x4B, 0x87, 0xC6, 0xB0, 0xD9]
	,_.GUID_MetadataFormatChunktIME:=[0x6B00AE2D, 0xE24B, 0x460A, 0x98, 0xB6, 0x87, 0x8B, 0xD0, 0x30, 0x72, 0xFD]
	; Vendor Identification
	 _.GUID_VendorMicrosoft:=[0x69fd0fdc, 0xa866, 0x4108, 0xb3, 0xb2, 0x98, 0x44, 0x7f, 0xa9, 0xed, 0xd4]
	,_.GUID_VendorMicrosoftBuiltIn:=[0x257a30fd, 0x6b6, 0x462b, 0xae, 0xa4, 0x63, 0xf7, 0xb, 0x86, 0xe5, 0x33]
	; WICBitmapPaletteType
	 _.GUID_WICPixelFormatDontCare:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x00]
	,_.GUID_WICPixelFormat1bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x01]
	,_.GUID_WICPixelFormat2bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x02]
	,_.GUID_WICPixelFormat4bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x03]
	,_.GUID_WICPixelFormat8bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x04]
	,_.GUID_WICPixelFormatBlackWhite:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x05]
	,_.GUID_WICPixelFormat2bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x06]
	,_.GUID_WICPixelFormat4bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x07]
	,_.GUID_WICPixelFormat8bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x08]
	,_.GUID_WICPixelFormat8bppAlpha:=[0xe6cd0116, 0xeeba, 0x4161, 0xaa, 0x85, 0x27, 0xdd, 0x9f, 0xb3, 0xa8, 0x95]
	,_.GUID_WICPixelFormat16bppBGR555:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x09]
	,_.GUID_WICPixelFormat16bppBGR565:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0a]
	,_.GUID_WICPixelFormat16bppBGRA5551:=[0x05ec7c2b, 0xf1e6, 0x4961, 0xad, 0x46, 0xe1, 0xcc, 0x81, 0x0a, 0x87, 0xd2]
	 _.GUID_WICPixelFormat16bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0b]
	,_.GUID_WICPixelFormat24bppBGR:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0c]
	,_.GUID_WICPixelFormat24bppRGB:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0d]
	,_.GUID_WICPixelFormat32bppBGR:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0e]
	,_.GUID_WICPixelFormat32bppBGRA:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0f]
	,_.GUID_WICPixelFormat32bppPBGRA:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x10]
	,_.GUID_WICPixelFormat32bppGrayFloat:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x11]
	,_.GUID_WICPixelFormat32bppRGBA:=[0xf5c7ad2d, 0x6a8d, 0x43dd, 0xa7, 0xa8, 0xa2, 0x99, 0x35, 0x26, 0x1a, 0xe9]
	,_.GUID_WICPixelFormat32bppPRGBA:=[0x3cc4a650, 0xa527, 0x4d37, 0xa9, 0x16, 0x31, 0x42, 0xc7, 0xeb, 0xed, 0xba]
	,_.GUID_WICPixelFormat48bppRGB:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x15]
	,_.GUID_WICPixelFormat48bppBGR:=[0xe605a384, 0xb468, 0x46ce, 0xbb, 0x2e, 0x36, 0xf1, 0x80, 0xe6, 0x43, 0x13]
	,_.GUID_WICPixelFormat64bppRGBA:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x16]
	,_.GUID_WICPixelFormat64bppBGRA:=[ 0x1562ff7c, 0xd352, 0x46f9, 0x97, 0x9e, 0x42, 0x97, 0x6b, 0x79, 0x22, 0x46]
	 _.GUID_WICPixelFormat64bppPRGBA:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x17]
	,_.GUID_WICPixelFormat64bppPBGRA:=[0x8c518e8e, 0xa4ec, 0x468b, 0xae, 0x70, 0xc9, 0xa3, 0x5a, 0x9c, 0x55, 0x30]
	,_.GUID_WICPixelFormat16bppGrayFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x13]
	,_.GUID_WICPixelFormat32bppBGR101010:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x14]
	,_.GUID_WICPixelFormat48bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x12]
	,_.GUID_WICPixelFormat48bppBGRFixedPoint:=[0x49ca140e, 0xcab6, 0x493b, 0x9d, 0xdf, 0x60, 0x18, 0x7c, 0x37, 0x53, 0x2a]
	,_.GUID_WICPixelFormat96bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x18]
	,_.GUID_WICPixelFormat128bppRGBAFloat:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x19]
	,_.GUID_WICPixelFormat128bppPRGBAFloat:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1a]
	,_.GUID_WICPixelFormat128bppRGBFloat:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1b]
	,_.GUID_WICPixelFormat32bppCMYK:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1c]
	,_.GUID_WICPixelFormat64bppRGBAFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1d]
	,_.GUID_WICPixelFormat64bppBGRAFixedPoint:=[0x356de33c, 0x54d2, 0x4a23, 0xbb, 0x4, 0x9b, 0x7b, 0xf9, 0xb1, 0xd4, 0x2d]
	 _.GUID_WICPixelFormat64bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x40]
	,_.GUID_WICPixelFormat128bppRGBAFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1e]
	,_.GUID_WICPixelFormat128bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x41]
	,_.GUID_WICPixelFormat64bppRGBAHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3a]
	,_.GUID_WICPixelFormat64bppRGBHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x42]
	,_.GUID_WICPixelFormat48bppRGBHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3b]
	,_.GUID_WICPixelFormat32bppRGBE:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3d]
	,_.GUID_WICPixelFormat16bppGrayHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3e]
	,_.GUID_WICPixelFormat32bppGrayFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3f]
	,_.GUID_WICPixelFormat32bppRGBA1010102:=[0x25238D72, 0xFCF9, 0x4522, 0xb5, 0x14, 0x55, 0x78, 0xe5, 0xad, 0x55, 0xe0]
	,_.GUID_WICPixelFormat32bppRGBA1010102XR:=[0x00DE6B9A, 0xC101, 0x434b, 0xb5, 0x02, 0xd0, 0x16, 0x5e, 0xe1, 0x12, 0x2c]
	,_.GUID_WICPixelFormat64bppCMYK:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1f]
	,_.GUID_WICPixelFormat24bpp3Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x20]
	 _.GUID_WICPixelFormat32bpp4Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x21]
	,_.GUID_WICPixelFormat40bpp5Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x22]
	,_.GUID_WICPixelFormat48bpp6Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x23]
	,_.GUID_WICPixelFormat56bpp7Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x24]
	,_.GUID_WICPixelFormat64bpp8Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x25]
	,_.GUID_WICPixelFormat48bpp3Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x26]
	,_.GUID_WICPixelFormat64bpp4Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x27]
	,_.GUID_WICPixelFormat80bpp5Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x28]
	,_.GUID_WICPixelFormat96bpp6Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x29]
	,_.GUID_WICPixelFormat112bpp7Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2a]
	,_.GUID_WICPixelFormat128bpp8Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2b]
	,_.GUID_WICPixelFormat40bppCMYKAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2c]
	,_.GUID_WICPixelFormat80bppCMYKAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2d]
	,_.GUID_WICPixelFormat32bpp3ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2e]
	 _.GUID_WICPixelFormat40bpp4ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2f]
	,_.GUID_WICPixelFormat48bpp5ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x30]
	,_.GUID_WICPixelFormat56bpp6ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x31]
	,_.GUID_WICPixelFormat64bpp7ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x32]
	,_.GUID_WICPixelFormat72bpp8ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x33]
	,_.GUID_WICPixelFormat64bpp3ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x34]
	,_.GUID_WICPixelFormat80bpp4ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x35]
	,_.GUID_WICPixelFormat96bpp5ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x36]
	,_.GUID_WICPixelFormat112bpp6ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x37]
	,_.GUID_WICPixelFormat128bpp7ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x38]
	,_.GUID_WICPixelFormat144bpp8ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x39]

	}
	if _.haskey(name){
		p:=_[name]
		VarSetCapacity(GUID,16)
		,NumPut(p.1+(p.2<<32)+(p.3<<48),GUID,0,"int64")
		,NumPut(p.4+(p.5<<8)+(p.6<<16)+(p.7<<24)+(p.8<<32)+(p.9<<40)+(p.10<<48)+(p.11<<56),GUID,8,"int64")
		return &GUID
	}else return name
}

Второй вариант с сохранением через D3DXSaveSurfaceToFile:

;
; Script Requirements:
;
;   DirectX - March 2008 or later. (d3dx9_37.dll)
;     DirectX End-User Runtime Web Installer (March 2008):
;     http://www.microsoft.com/downloads/details.aspx?FamilyId=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&displaylang=en
;
file := "test.png"
setbatchlines -1

; init D3D and get screen size
d3d := Direct3DCreate9(D3D_SDK_VERSION := 32) 
if !d3d
{
    MsgBox, 16, Error, Direct3DCreate9 failed.
    ExitApp
}
VarSetCapacity(D3DDISPLAYMODE, 16, 0)
IDirect3D9_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT := 0, &D3DDISPLAYMODE)
Windowed := true
BackBufferCount := 1
BackBufferHeight := NumGet(D3DDISPLAYMODE, 4, "uint")
BackBufferWidth := NumGet(D3DDISPLAYMODE, 0, "uint")
SwapEffect := 1   ; D3DSWAPEFFECT_DISCARD
hDeviceWindow := 0

; create device & capture surface
VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0) 
NumPut(BackBufferWidth, D3DPRESENT_PARAMETERS, 0)
NumPut(BackBufferHeight, D3DPRESENT_PARAMETERS, 4)
NumPut(BackBufferCount, D3DPRESENT_PARAMETERS, 12)
NumPut(SwapEffect, D3DPRESENT_PARAMETERS, 24)
NumPut(hDeviceWindow, D3DPRESENT_PARAMETERS, 24+A_PtrSize)
NumPut(Windowed, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)
IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT := 0, D3DDEVTYPE_HAL := 1, 0, D3DCREATE_SOFTWARE_VERTEXPROCESSING := 0x00000020, &D3DPRESENT_PARAMETERS, device)
IDirect3DDevice9_CreateOffscreenPlainSurface(device, BackBufferWidth, BackBufferHeight, D3DFMT_A8R8G8B8 := 21, D3DPOOL_SYSTEMMEM := 2, surface, 0)

a := a_tickcount
loop 100
{
   ; get the data
   IDirect3DDevice9_GetFrontBufferData(device, 0, surface)
}
msgbox % a_tickcount - a

D3DXSaveSurfaceToFile(file, D3DXIFF_PNG := 3,  surface, 0, 0)

Release(surface)
Release(device)
Release(d3d)
msgbox done
return



Direct3DCreate9(SDKVersion) {
    if !DllCall("GetModuleHandle","str","d3d9")
        DllCall("LoadLibrary","str","d3d9")
    return DllCall("d3d9\Direct3DCreate9", "uint", SDKVersion)
}

IDirect3D9_GetAdapterDisplayMode(this,Adapter,pMode)
{
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize),"ptr",this,"uint",Adapter,"ptr",pMode)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3D9_CreateDevice(this,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ByRef ppReturnedDeviceInterface)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize),"ptr",this,"uint",Adapter,"uint",DeviceType,"ptr",hFocusWindow,"uint",BehaviorFlags,"ptr",pPresentationParameters,"ptr*",ppReturnedDeviceInterface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DDevice9_GetFrontBufferData(this,iSwapChain,pDestSurface)
{
   hr := DllCall(NumGet(NumGet(this+0)+33*A_PtrSize),"ptr",this,"uint",iSwapChain,"ptr",pDestSurface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DDevice9_CreateOffscreenPlainSurface(this,Width,Height,Format,Pool,ByRef ppSurface,pSharedHandle)
{
   hr := DllCall(NumGet(NumGet(this+0)+36*A_PtrSize),"ptr",this,"uint",Width,"uint",Height,"uint",Format,"uint",Pool,"ptr*",ppSurface,"ptr",pSharedHandle)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

D3DXSaveSurfaceToFile(pDestFile, DestFormat, pSrcSurface, pSrcPalette, pSrcRect)
{
   hr := DllCall("d3dx9_37\D3DXSaveSurfaceToFile", "str", pDestFile, "uint", DestFormat , "ptr", pSrcSurface, "ptr", pSrcPalette, "ptr", pSrcRect)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

Release(this) { ; COM_Release. So far the only required COM_* function...
    return DllCall(NumGet(NumGet(this+0)+2*A_PtrSize), "ptr", this)
}

_Error(val)
{
   msgbox % val
   ExitApp
}

2

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

У меня 30 в секунду.
Это можно использовать для захвата с DX9? DX11?

По вопросам возмездной помощи пишите на E-Mail: serzh82saratov@mail.ru
Win10x64, AutoHotkey_L v1.1.30.03 (Unicode 32-bit). AhkSpy, Hotkey, ClockGui

3 (изменено: Malcev, 2019-01-24 14:44:45)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Не знаю, у меня не на чем протестировать.
Самому интересно.
Подправил код в первом посте - убрал clipboard в IDirect3D9_CreateDevice.
Спрошу на оффоруме почему на x64 не запускается.

4

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

serzh82saratov пишет:

Это можно использовать для захвата с DX9? DX11?

Покопался в интернете - и понял, что не всё так просто.
Для Win-7 скорее всего придется хукать процесс, после чего получать доступ к буферу.
http://spazzarama.com/2011/03/14/c-scre … api-hooks/
И видно это не всегда получится:
https://github.com/spazzarama/Direct3DHook/issues/69
Похоже легче всё это провернуть на Win8+ - там ничего хукать не надо.
Даже есть готовые dll и код на автоит:
https://www.autoitscript.com/forum/topi … ll-failed/
Либо можно пойти другим путем и написать враппер для DXGI.
На автоит даже положили начало:
https://www.autoitscript.com/forum/topi … n-capture/

5 (изменено: teadrinker, 2019-01-24 17:23:11)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Malcev пишет:

Спрошу на оффоруме почему на x64 не запускается.

Пару ошибок вижу. У тебя в IDirect3DDevice9_GetFrontBufferData() this имеет тип UInt, нужно Ptr. Кроме того все pDestSurface должны быть пойнтерами, судя по префиксу.

Malcev пишет:
VarSetCapacity(D3DLOCKED_RECT, 4+A_PtrSize, 0)
...
pBits := NumGet(D3DLOCKED_RECT, 4, "ptr")

Здесь наверняка ошибка. Пойнтер не может иметь оффсет 4 в 64-битной структуре.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

6 (изменено: Malcev, 2019-01-24 17:26:51)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

teadrinker пишет:

У тебя в IDirect3DDevice9_GetFrontBufferData() this имеет тип UInt, нужно Ptr

Да, пропустил. Исправил.

teadrinker пишет:

Кроме того все pDestSurface должны быть пойнтерами, судя по префиксу.

А где там остальные, которые используются в коде?

teadrinker пишет:

Здесь наверняка ошибка. Пойнтер не может иметь оффсет 4 в 64-битной структуре.

Почему не может?
https://docs.microsoft.com/en-us/window … ocked-rect
Код выводит ошибку на создании устройства:

d3d := Direct3DCreate9(D3D_SDK_VERSION := 32) 
if !d3d
{
    MsgBox, 16, Error, Direct3DCreate9 failed.
    ExitApp
}

BackBufferWidth := 800
BackBufferHeight := 600
BackBufferCount := 1
SwapEffect := 1   ; D3DSWAPEFFECT_DISCARD
hDeviceWindow := 0
Windowed := true

VarSetCapacity(D3DPRESENT_PARAMETERS, 52+A_PtrSize, 0) 
NumPut(BackBufferWidth, D3DPRESENT_PARAMETERS, 0)
NumPut(BackBufferHeight, D3DPRESENT_PARAMETERS, 4)
NumPut(BackBufferCount, D3DPRESENT_PARAMETERS, 12)
NumPut(SwapEffect, D3DPRESENT_PARAMETERS, 24)
NumPut(hDeviceWindow, D3DPRESENT_PARAMETERS, 28)
NumPut(Windowed, D3DPRESENT_PARAMETERS, 28+A_PtrSize)
IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT := 0, D3DDEVTYPE_HAL := 1, 0, D3DCREATE_SOFTWARE_VERTEXPROCESSING := 0x00000020, &D3DPRESENT_PARAMETERS, device)
msgbox done

Direct3DCreate9(SDKVersion) {
    if !DllCall("GetModuleHandle","str","d3d9")
        DllCall("LoadLibrary","str","d3d9")
    return DllCall("d3d9\Direct3DCreate9", "uint", SDKVersion)
}

IDirect3D9_CreateDevice(this,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ByRef ppReturnedDeviceInterface)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize),"ptr",this,"uint",Adapter,"uint",DeviceType,"ptr",hFocusWindow,"uint",BehaviorFlags,"ptr",pPresentationParameters,"uint*",ppReturnedDeviceInterface)
   if hr
   {
      SetFormat, Integer, H
      hr &= 0xFFFFFFFF
      MsgBox, 16, Error, IDirect3D9_CreateDevice returned error code %hr%.
      ExitApp
   }
}

7

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Malcev пишет:

А где там остальные?

Например здесь:

IDirect3DDevice9_CreateOffscreenPlainSurface(this,Width,Height,Format,Pool,ByRef ppSurface,pSharedHandle)
{
   hr := DllCall(NumGet(NumGet(this+0)+36*A_PtrSize),"ptr",this,"uint",Width,"uint",Height,"uint",Format,"uint",Pool,"uint*",ppSurface,"ptr",pSharedHandle)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}
"uint*",ppSurface

Почему не может?

Если указатель идёт за Integer, это не значит, что оффсет будет 4. Элемент должен находиться на границе своего типа, добавляется паддинг 4 байта. YMP же недавно объяснял.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

8

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Malcev пишет:

Код выводит ошибку на создании устройства:

Здесь тоже ошибку вижу:

"uint*",ppReturnedDeviceInterface

А вообще может неправильно структура составлена, подробно пока не смотрел.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

9

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

teadrinker пишет:

Если указатель идёт за Integer, это не значит, что оффсет будет 4. Элемент должен находиться на границе своего типа, добавляется паддинг 4 байта. YMP же недавно объяснял.

Я думал это надо учитывать только при передачи копии структуры функции.

10

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Нет, при создании и заполнении структуры.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

11 (изменено: Malcev, 2019-01-24 18:31:18)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Получилось.

d3d := Direct3DCreate9(D3D_SDK_VERSION := 32) 
if !d3d
{
    MsgBox, 16, Error, Direct3DCreate9 failed.
    ExitApp
}

BackBufferWidth := 800
BackBufferHeight := 600
BackBufferCount := 1
SwapEffect := 1   ; D3DSWAPEFFECT_DISCARD
hDeviceWindow := 0
Windowed := true

VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0) 
NumPut(BackBufferWidth, D3DPRESENT_PARAMETERS, 0)
NumPut(BackBufferHeight, D3DPRESENT_PARAMETERS, 4)
NumPut(BackBufferCount, D3DPRESENT_PARAMETERS, 12)
NumPut(SwapEffect, D3DPRESENT_PARAMETERS, 24)
NumPut(hDeviceWindow, D3DPRESENT_PARAMETERS, 24+A_PtrSize)
NumPut(Windowed, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)
IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT := 0, D3DDEVTYPE_HAL := 1, 0, D3DCREATE_SOFTWARE_VERTEXPROCESSING := 0x00000020, &D3DPRESENT_PARAMETERS, device)
msgbox done

Direct3DCreate9(SDKVersion) {
    if !DllCall("GetModuleHandle","str","d3d9")
        DllCall("LoadLibrary","str","d3d9")
    return DllCall("d3d9\Direct3DCreate9", "uint", SDKVersion)
}

IDirect3D9_CreateDevice(this,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ByRef ppReturnedDeviceInterface)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize),"ptr",this,"uint",Adapter,"uint",DeviceType,"ptr",hFocusWindow,"uint",BehaviorFlags,"ptr",pPresentationParameters,"uptr*",ppReturnedDeviceInterface)
   if hr
   {
      SetFormat, Integer, H
      hr &= 0xFFFFFFFF
      MsgBox, 16, Error, IDirect3D9_CreateDevice returned error code %hr%.
      ExitApp
   }
}

Спасибо!

12 (изменено: Malcev, 2019-01-24 19:29:15)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

teadrinker пишет:

"uint*",ppReturnedDeviceInterface

А uint* правильно замещать на ptr* или uptr*?
Или это не имеет значения?

13

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Формально UPtrP, фактически без разницы.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

14 (изменено: Malcev, 2019-01-27 17:54:13)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Решил убрать простыню из ненужных функций с 1 поста, добавил второй вариант с сохранением файла через D3DXSaveSurfaceToFile.
Игры на полном экране таким способом не захватываются - нужно хукать endscene и запрашивать getbackbuffer.
http://spazzarama.com/2010/03/29/screen … -api-hooks
И нашел Desktop Duplication for Windows 7:
https://github.com/rgcjonas/dd4seven

15

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Malcev пишет:

Код выполняет 100 итераций захвата экрана, показывает время выполнения и сохраняет последний снимок на диск.

Хотел гифку создать, но на GUID_ContainerFormatGif выдаёт ошибку.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

16

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Для гифа там конвертация нужна.
Я только вечером смогу поправить.
Ну или сам можешь взять функции, например, отсюда.
http://forum.script-coding.com/viewtopi … 39#p136639

   if !wic
      wic := IWICCreate()
   IWICImagingFactory_CreateStream(wic, stream)
   IWICStream_InitializeFromFilename(stream, file, GENERIC_WRITE := 0x40000000)
   IWICImagingFactory_CreateEncoder(wic, ContainerFormat, 0, encoder)
   IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache := 0x2)
   IWICBitmapEncoder_CreateNewFrame(encoder, frame)
   IWICBitmapFrameEncode_Initialize(frame)
   IWICBitmapFrameEncode_SetSize(frame, width, height)
   if IWICBitmapFrameEncode_SetPixelFormat(frame, formatGuid, NewFormat, guid)
   {
      msgbox конвертация не нужна
      IWICBitmapFrameEncode_WritePixels(frame, height, pitch, pitch * height, pBits)
   }
   else
   {
      IWICImagingFactory_CreateFormatConverter(wic, FormatConverter)
      IWICFormatConverter_CanConvert(FormatConverter, formatGuid, &NewFormat)
      IWICImagingFactory_CreateBitmapFromMemory(wic, width, height, formatGuid, pitch, pitch * height, pBits, Bitmap)
      IWICFormatConverter_Initialize(FormatConverter, Bitmap, "GUID_WICPixelFormat24bppBGR", WICBitmapDitherTypeNone := 0, 0, 0, WICBitmapPaletteTypeMedianCut := 0x1)
      IWICBitmapFrameEncode_SetPixelFormat(frame, &NewFormat)
      VarSetCapacity(Rect, 16, 0)
      NumPut(width, Rect, 8, "int")
      NumPut(height, Rect, 12, "int")
      IWICBitmapFrameEncode_WriteSource(frame, FormatConverter, &Rect)
      Release(FormatConverter)
      Release(Bitmap)
      FormatConverter := Bitmap := ""
   }
   IWICBitmapFrameEncode_Commit(frame)
   IWICBitmapEncoder_Commit(encoder)
   Release(stream)
   Release(frame)
   Release(encoder)
   stream := frame := encoder := ""

17

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Да, я уже понял, что нужна конвертация. Но я хочу гиф, как видео создавать, наверно успевать не будет конвертировать.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

18

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Думаю, должен,  Только там алгоритм другой будет для создания animated gif. Создаешь контейнер и заполняешь его кадрами.

19

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Попробую.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

20

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Вышло, но медленно, 10 кадров в секунду примерно.

#NoEnv
SetBatchLines, -1

file := A_Desktop . "\test.gif"
x := 100, y := 300, w := 500, h := 300

IDirect3DDevice9 := CreateDevice(width, height)
IDirect3DSurface9 := CreateOffscreenPlainSurface(IDirect3DDevice9, width, height)
IWICImagingFactory := CreateIWICImagingFactory()
Enc := new Encoder(IWICImagingFactory, file)
IWICBitmapEncoder := Enc.encoder

start := A_TickCount
Loop {
   GetFrontBufferData(IDirect3DDevice9, IDirect3DSurface9)
   LockRect(IDirect3DSurface9, x, y, w, h, pitch, pBits)
   IWICBitmapFrameEncode := CreateNewFrame(IWICBitmapEncoder, w, h)
   ConvertFormat(IWICImagingFactory, IWICBitmapFrameEncode, w, h, pitch, pBits)
   CommitIWICBitmapFrameEncode(IWICBitmapFrameEncode)
} until A_TickCount - start > 5000
CommitIWICBitmapEncoder(IWICBitmapEncoder)

ObjRelease(IWICBitmapFrameEncode)
Enc := ""
ObjRelease(IDirect3DSurface9)
ObjRelease(IDirect3DDevice9)
Return

CreateDevice(ByRef BackBufferWidth, ByRef BackBufferHeight) {
   static D3D_SDK_VERSION := 32, D3DADAPTER_DEFAULT := 0, D3DSWAPEFFECT_DISCARD := 1
        , D3DDEVTYPE_HAL := 1, D3DCREATE_SOFTWARE_VERTEXPROCESSING := 0x00000020
        , Windowed := true, BackBufferCount := 1
   
   IsError := Func("ErrorText").Bind(error := [])
   hLib := DllCall("LoadLibrary", "Str", "d3d9")

   Loop 1 {
      IDirect3D9 := DllCall("d3d9\Direct3DCreate9", "Uint", D3D_SDK_VERSION)
      if ( !IDirect3D9 && error[1] := "Direct3DCreate9 failed" )
         break
         
      VarSetCapacity(D3DDISPLAYMODE, 16, 0)
      hr := VTable(IDirect3D9, GetAdapterDisplayMode := 8).Call("UInt", D3DADAPTER_DEFAULT, "Ptr", &D3DDISPLAYMODE)
      if IsError.Call("IDirect3D9::GetAdapterDisplayMode", hr)
         break
      
      VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0)
      BackBufferWidth  := NumGet(D3DDISPLAYMODE, 0, "UInt")
      BackBufferHeight := NumGet(D3DDISPLAYMODE, 4, "UInt")
      NumPut(BackBufferWidth, D3DPRESENT_PARAMETERS, 0)
      NumPut(BackBufferHeight, D3DPRESENT_PARAMETERS, 4)
      NumPut(BackBufferCount, D3DPRESENT_PARAMETERS, 12)
      NumPut(D3DSWAPEFFECT_DISCARD := 1, D3DPRESENT_PARAMETERS, 24)
      NumPut(Windowed, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)
      
      hr := VTable(IDirect3D9, CreateDevice := 16).Call( "UInt", D3DADAPTER_DEFAULT, "UInt", D3DDEVTYPE_HAL
                                                       , "Ptr", 0, "UInt", D3DCREATE_SOFTWARE_VERTEXPROCESSING
                                                       , "Ptr", &D3DPRESENT_PARAMETERS, "PtrP", IDirect3DDevice9 )
      IsError.Call("IDirect3D9::GetAdapterDisplayMode", hr)
   }
   DllCall("FreeLibrary", "Ptr", hLib)
   ( IDirect3D9 && ObjRelease(IDirect3D9) )
   if error[1]
      throw Exception(error[1])
   Return IDirect3DDevice9
}

CreateOffscreenPlainSurface(IDirect3DDevice9, width, height) {
   static D3DFMT_A8R8G8B8 := 21, D3DPOOL_SYSTEMMEM := 2
   IsError := Func("ErrorText").Bind(error := [])
   hr := VTable(IDirect3DDevice9, CreateOffscreenPlainSurface := 36).Call( "UInt", width, "UInt", height
                                                                         , "UInt", D3DFMT_A8R8G8B8, "UInt", D3DPOOL_SYSTEMMEM
                                                                         , "PtrP", IDirect3DSurface9, "Ptr", 0 )
   IsError.Call("IDirect3DDevice9::CreateOffscreenPlainSurface", hr)
   if error[1]
      throw Exception(error[1])
   Return IDirect3DSurface9
}

CreateIWICImagingFactory() {
   static CLSID_WICImagingFactory := "{CACAF262-9370-4615-A13B-9F5539DA4C0A}"
        , IID_IWICImagingFactory  := "{EC5EC8A9-C395-4314-9C77-54D7A935FF70}"
   Return ComObjCreate(CLSID_WICImagingFactory, IID_IWICImagingFactory)
}

class Encoder {
   __New(IWICImagingFactory, file) {
      static ContainerFormatGif := "{1F8A5601-7D4D-4CBD-9C82-1BC8D4EEB9A5}"
           , GENERIC_WRITE := 0x40000000, WICBitmapEncoderNoCache := 0x2
      IsError := Func("ErrorText").Bind(error := [])
      
      Loop 1 {
         hr := VTable(IWICImagingFactory, CreateStream := 14).Call("PtrP", IWICStream)
         if IsError.Call("IWICImagingFactory::CreateStream", hr)
            break
         this.stream := IWICStream
         
         hr := VTable(IWICStream, InitializeFromFilename := 15).Call("Str", file, "UInt", GENERIC_WRITE)
         if IsError.Call("IWICStream::InitializeFromFilename", hr)
            break
         
         CLSIDFromString(ContainerFormatGif, GUID_ContainerFormatGif)
         hr := VTable(IWICImagingFactory, CreateEncoder := 8).Call("Ptr", &GUID_ContainerFormatGif, "Ptr", 0, "PtrP", IWICBitmapEncoder)
         if IsError.Call("IWICImagingFactory::CreateEncoder", hr)
            break
         this.encoder := IWICBitmapEncoder
         
         hr := VTable(IWICBitmapEncoder, Initialize := 3).Call("Ptr", IWICStream, "Int", WICBitmapEncoderNoCache)
         IsError.Call("IWICImagingFactory::CreateEncoder", hr)
      }
      if error[1]
         throw Exception(error[1])
   }
   
   __Delete() {
      ( this.encoder && ObjRelease(this.encoder) )
      ( this.stream  && ObjRelease(this.stream ) )
   }
}

GetFrontBufferData(IDirect3DDevice9, IDirect3DSurface9) {
   hr := VTable(IDirect3DDevice9, GetFrontBufferData := 33).Call("UInt", 0, "Ptr", IDirect3DSurface9)
   if (hr != 0)
      throw Exception( ErrorText([], "IDirect3DDevice9::GetFrontBufferData", hr) )
}

LockRect(IDirect3DSurface9, x, y, w, h, ByRef pitch, ByRef pBits) {
   IsError := Func("ErrorText").Bind(error := [])
   Loop 1 {
      VarSetCapacity(D3DLOCKED_RECT, A_PtrSize*2, 0)
      VarSetCapacity(RECT, 16, 0)
      NumPut(x, RECT), NumPut(y, RECT, 4), NumPut(x + w, RECT, 8), NumPut(y + h, RECT, 12, "UInt")
      hr := VTable(IDirect3DSurface9, LockRect := 13).Call("Ptr", &D3DLOCKED_RECT, "Ptr", &RECT, "UInt", 0)
      if IsError.Call("IDirect3DSurface9::LockRect", hr)
         break

      pitch := NumGet(D3DLOCKED_RECT, 0, "Int")
      pBits := NumGet(D3DLOCKED_RECT, A_PtrSize, "Ptr")
      hr := VTable(IDirect3DSurface9, UnlockRect := 14).Call()
      IsError.Call("IDirect3DSurface9::UnlockRect", hr)
   }
   if error[1]
      throw Exception(error[1])
}

CreateNewFrame(IWICBitmapEncoder, width, height) {
   IsError := Func("ErrorText").Bind(error := [])
   Loop 1 {
      hr := VTable(IWICBitmapEncoder, CreateNewFrame := 10).Call("PtrP", IWICBitmapFrameEncode, "PtrP", IPropertyBag2 := 0)
      if IsError.Call("IWICBitmapEncoder::CreateNewFrame", hr)
         break
      
      hr := VTable(IWICBitmapFrameEncode, Initialise := 3).Call("Ptr", IPropertyBag2)
      if IsError.Call("IWICBitmapEncoder::CreateNewFrame", hr)
         break
   
      hr := VTable(IWICBitmapFrameEncode, SetSize := 4).Call("UInt", width, "UInt", height)
      IsError.Call("IWICBitmapEncoder::CreateNewFrame", hr)
   }
   ( IPropertyBag2 && ObjRelease(IPropertyBag2) )
   if error[1]
      throw Exception(error[1])
   Return IWICBitmapFrameEncode
}

ConvertFormat(IWICImagingFactory, IWICBitmapFrameEncode, width, height, pitch, pBits) {
   static WICPixelFormat32bppBGRA := "{6FDDC324-4E03-4BFE-B185-3D77768DC90F}"
        , WICPixelFormat24bppBGR  := "{6FDDC324-4E03-4BFE-B185-3D77768DC90C}"
        , WICBitmapDitherTypeNone := 0, WICBitmapPaletteTypeMedianCut := 0x1
   IsError := Func("ErrorText").Bind(error := [])
   Loop 1 {
      hr := VTable(IWICImagingFactory, CreateFormatConverter := 10).Call("PtrP", IWICFormatConverter)
      if IsError.Call("IWICImagingFactory::CreateFormatConverter", hr)
         break
      
      CLSIDFromString(WICPixelFormat32bppBGRA, GUID_WICPixelFormat32bppBGRA)
      CLSIDFromString(WICPixelFormat24bppBGR,  GUID_WICPixelFormat24bppBGR)
      /*
      hr := VTable(IWICFormatConverter, CanConvert := 9).Call( "Ptr", &GUID_WICPixelFormat32bppBGRA
                                                             , "Ptr", &GUID_WICPixelFormat24bppBGR
                                                             , "UIntP", CanConvert )
      if IsError.Call("IWICFormatConverter::CanConvert", hr)
         break
      MsgBox, % CanConvert
      */
      hr := VTable(IWICImagingFactory, CreateBitmapFromMemory := 20).Call( "UInt", width, "UInt", height, "Ptr", &GUID_WICPixelFormat32bppBGRA
                                                                         , "UInt", pitch, "UInt", pitch*height, "Ptr", pBits, "PtrP", IWICBitmap )
      if IsError.Call("IWICImagingFactory::CreateBitmapFromMemory", hr)
         break
      
      hr := VTable(IWICFormatConverter, Initialize := 8).Call( "Ptr", IWICBitmap, "Ptr", &GUID_WICPixelFormat24bppBGR, "UInt", WICBitmapDitherTypeNone
                                                             , "Ptr", 0, "Double", 0, "UInt", WICBitmapPaletteTypeMedianCut )
      if IsError.Call("IWICFormatConverter::Initialize", hr)
         break
      
      hr := VTable(IWICBitmapFrameEncode, SetPixelFormat := 6).Call("Ptr", &GUID_WICPixelFormat24bppBGR)
      if IsError.Call("IWICBitmapFrameEncode::SetPixelFormat", hr)
         break
      
      VarSetCapacity(RECT, 16, 0)
      NumPut(width, RECT, 8), NumPut(height, RECT, 12, "UInt")
      hr := VTable(IWICBitmapFrameEncode, WriteSource := 11).Call("Ptr", IWICBitmap, "Ptr", &RECT)
      IsError.Call("IWICBitmapFrameEncode::SetPixelFormat", hr)
   }
   ( IWICFormatConverter && ObjRelease(IWICFormatConverter) )
   ( IWICBitmap          && ObjRelease(IWICBitmap) )
   if error[1]
      throw Exception(error[1])
}

CommitIWICBitmapFrameEncode(IWICBitmapFrameEncode) {
   hr := VTable(IWICBitmapFrameEncode, Commit := 12).Call()
   if (hr != 0)
      throw Exception( ErrorText([], "IWICBitmapFrameEncode::Commit", hr) )
}

CommitIWICBitmapEncoder(IWICBitmapEncoder) {
   hr := VTable(IWICBitmapEncoder, Commit := 11).Call()
   if (hr != 0)
      throw Exception( ErrorText([], "IWICBitmapEncoder::Commit", hr) )
}

VTable(ppv, idx)  {
   Return Func("DllCall").Bind(NumGet(NumGet(ppv + 0) + A_PtrSize*idx), "Ptr", ppv)
}

ErrorText(error, method, result) {
   Return result = 0 ? 0 : error[1] := method . " failed. Result: " . (result = "" ? "" : Format("{:#x}", result & 0xFFFFFFFF))
}

CLSIDFromString(IID, ByRef CLSID) {
   VarSetCapacity(CLSID, 16, 0)
   if res := DllCall("ole32\CLSIDFromString", "WStr", IID, "Ptr", &CLSID)
      throw Exception("CLSIDFromString failed. Error: " . Format("{:#x}", res))
   Return &CLSID
}

Надо бы ещё IPropertyBag2 заполнить, но примеров не нашёл.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

21 (изменено: Malcev, 2019-12-23 05:40:12)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Ну не знаю.
У меня выходит более чем 25 кадров в секунду.

;
; Script Requirements:
;
;   DirectX - March 2008 or later. (d3dx9_37.dll)
;     DirectX End-User Runtime Web Installer (March 2008):
;     http://www.microsoft.com/downloads/details.aspx?FamilyId=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&displaylang=en
;
file := "test.gif"
width := 500, height := 300

setbatchlines -1
ContainerFormat := "GUID_ContainerFormatGif"
formatGuid := WIC_GUID(GUID, "GUID_WICPixelFormat32bppBGRA")
; init D3D and get screen size
d3d := Direct3DCreate9(D3D_SDK_VERSION := 32) 
if !d3d
{
    MsgBox, 16, Error, Direct3DCreate9 failed.
    ExitApp
}
VarSetCapacity(D3DDISPLAYMODE, 16, 0)
IDirect3D9_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT := 0, &D3DDISPLAYMODE)
Windowed := true
BackBufferCount := 1
BackBufferHeight := NumGet(D3DDISPLAYMODE, 4, "uint")
BackBufferWidth := NumGet(D3DDISPLAYMODE, 0, "uint")
SwapEffect := 1   ; D3DSWAPEFFECT_DISCARD
hDeviceWindow := 0

; create device & capture surface
VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0) 
NumPut(BackBufferWidth, D3DPRESENT_PARAMETERS, 0)
NumPut(BackBufferHeight, D3DPRESENT_PARAMETERS, 4)
NumPut(BackBufferCount, D3DPRESENT_PARAMETERS, 12)
NumPut(SwapEffect, D3DPRESENT_PARAMETERS, 24)
NumPut(hDeviceWindow, D3DPRESENT_PARAMETERS, 24+A_PtrSize)
NumPut(Windowed, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)
IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT := 0, D3DDEVTYPE_HAL := 1, 0, D3DCREATE_SOFTWARE_VERTEXPROCESSING := 0x00000020, &D3DPRESENT_PARAMETERS, device)
IDirect3DDevice9_CreateOffscreenPlainSurface(device, BackBufferWidth, BackBufferHeight, D3DFMT_A8R8G8B8 := 21, D3DPOOL_SYSTEMMEM := 2, surface, 0)

if !wic
   wic := IWICCreate()
IWICImagingFactory_CreateStream(wic, stream)
IWICStream_InitializeFromFilename(stream, file, GENERIC_WRITE := 0x40000000)
IWICImagingFactory_CreateEncoder(wic, ContainerFormat, 0, encoder)
IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache := 0x2)

a := a_tickcount
loop 100
{
   IDirect3DDevice9_GetFrontBufferData(device, 0, surface)
   VarSetCapacity(D3DLOCKED_RECT, A_PtrSize*2, 0)
   VarSetCapacity(RECT, 16, 0)
   NumPut(width, RECT, 8, "uint")
   NumPut(height, RECT, 12, "uint")
   IDirect3DSurface9_LockRect(surface, &D3DLOCKED_RECT, &RECT, 0)
   pitch := NumGet(D3DLOCKED_RECT, 0, "int")
   pBits := NumGet(D3DLOCKED_RECT, A_PtrSize, "ptr")

   IWICBitmapEncoder_CreateNewFrame(encoder, frame)
   IWICBitmapFrameEncode_Initialize(frame)
   IWICBitmapFrameEncode_SetSize(frame, width, height)
   IWICImagingFactory_CreateFormatConverter(wic, FormatConverter)
   IWICImagingFactory_CreateBitmapFromMemory(wic, width, height, formatGuid, pitch, pitch * height, pBits, Bitmap)
   IWICFormatConverter_Initialize(FormatConverter, Bitmap, "GUID_WICPixelFormat24bppBGR", WICBitmapDitherTypeNone := 0, 0, 0, WICBitmapPaletteTypeMedianCut := 0x1)
   VarSetCapacity(Rect, 16, 0)
   NumPut(width, Rect, 8, "int")
   NumPut(height, Rect, 12, "int")
   IWICBitmapFrameEncode_WriteSource(frame, FormatConverter, &Rect)
   Release(FormatConverter)
   Release(Bitmap)
   FormatConverter := Bitmap := ""
   IWICBitmapFrameEncode_Commit(frame)
   Release(frame)
   frame := ""
   IDirect3DSurface9_UnlockRect(surface)
}
IWICBitmapEncoder_Commit(encoder)
Release(encoder)
Release(stream)
stream := encoder := ""
msgbox % a_tickcount - a

Release(surface)
Release(device)
Release(d3d)
msgbox done
return



Direct3DCreate9(SDKVersion) {
    if !DllCall("GetModuleHandle","str","d3d9")
        DllCall("LoadLibrary","str","d3d9")
    return DllCall("d3d9\Direct3DCreate9", "uint", SDKVersion)
}

IDirect3D9_GetAdapterDisplayMode(this,Adapter,pMode)
{
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize),"ptr",this,"uint",Adapter,"ptr",pMode)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3D9_CreateDevice(this,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ByRef ppReturnedDeviceInterface)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize),"ptr",this,"uint",Adapter,"uint",DeviceType,"ptr",hFocusWindow,"uint",BehaviorFlags,"ptr",pPresentationParameters,"ptr*",ppReturnedDeviceInterface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DDevice9_GetFrontBufferData(this,iSwapChain,pDestSurface)
{
   hr := DllCall(NumGet(NumGet(this+0)+33*A_PtrSize),"ptr",this,"uint",iSwapChain,"ptr",pDestSurface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DDevice9_CreateOffscreenPlainSurface(this,Width,Height,Format,Pool,ByRef ppSurface,pSharedHandle)
{
   hr := DllCall(NumGet(NumGet(this+0)+36*A_PtrSize),"ptr",this,"uint",Width,"uint",Height,"uint",Format,"uint",Pool,"ptr*",ppSurface,"ptr",pSharedHandle)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DSurface9_LockRect(this,pLockedRect,pRect,Flags)
{
   hr := DllCall(NumGet(NumGet(this+0)+13*A_PtrSize),"ptr",this,"ptr",pLockedRect,"ptr",pRect,"uint",Flags)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DSurface9_UnlockRect(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+14*A_PtrSize),"ptr",this)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

QueryInterface(ComObject, SID, ByRef InterfacePointer)
{
   InterfacePointer := ComObjQuery(ComObject, SID)
   if !InterfacePointer or ErrorLevel
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

Release(this)
{
   DllCall(NumGet(NumGet(this+0)+2*A_PtrSize), "ptr", this)
   if ErrorLevel
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

GUID(ByRef GUID, sGUID)
{
    VarSetCapacity(GUID, 16, 0)
    return DllCall("ole32\CLSIDFromString", "WStr", sGUID, "Ptr", &GUID) >= 0 ? &GUID : ""
}

_Error(val)
{
   msgbox % val
   ExitApp
}


IWICCreate()
{
   return ComObjCreate("{cacaf262-9370-4615-a13b-9f5539da4c0a}", "{ec5ec8a9-c395-4314-9c77-54d7a935ff70}")
}

IWICImagingFactory_CreateStream(this, ByRef ppIWICStream)
{
   hr := DllCall(NumGet(NumGet(this+0)+14*A_PtrSize), "ptr", this, "ptr*", ppIWICStream)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateFormatConverter(this, ByRef ppIFormatConverter)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "ptr*", ppIFormatConverter)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICStream_InitializeFromFilename(this, wzFileName, dwDesiredAccess)
{
   hr := DllCall(NumGet(NumGet(this+0)+15*A_PtrSize), "ptr", this, "str", wzFileName, "uint", dwDesiredAccess)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateEncoder(this, guidContainerFormat, pguidVendor, ByRef ppIEncoder)
{
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize), "ptr", this, "ptr", WIC_GUID(GUID1, guidContainerFormat), "ptr", WIC_GUID(GUID2, pguidVendor), "ptr*", ppIEncoder)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_Initialize(this, pIStream, cacheOption)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), "ptr", this, "ptr", pIStream, "int", cacheOption)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_CreateNewFrame(this, ByRef ppIFrameEncode, ppIEncoderOptions := 0)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "ptr*", ppIFrameEncode, "ptr*", ppIEncoderOptions)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_Commit(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+11*A_PtrSize), "ptr", this)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_Initialize(this, pIEncoderOptions := 0)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), "ptr", this, "ptr", pIEncoderOptions)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_SetSize(this, uiWidth, uiHeight)
{
   hr := DllCall(NumGet(NumGet(this+0)+4*A_PtrSize), "ptr", this, "uint", uiWidth, "uint", uiHeight)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_WritePixels(this, lineCount, cbStride, cbBufferSize, pbPixels)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "uint", lineCount, "uint", cbStride, "uint", cbBufferSize, "ptr", pbPixels)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_Commit(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+12*A_PtrSize), "ptr", this)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_WriteSource(this, pIBitmapSource, prc)
{
   hr := DllCall(NumGet(NumGet(this+0)+11*A_PtrSize), "ptr", this, "ptr", pIBitmapSource, "ptr", prc)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateBitmapFromMemory(this, uiWidth, uiHeight, pixelFormat, cbStride, cbBufferSize, pbBuffer, ByRef ppIBitmap)
{
   hr := DllCall(NumGet(NumGet(this+0)+20*A_PtrSize), "ptr", this, "uint", uiWidth, "uint", uiHeight, "ptr", pixelFormat, "uint", cbStride, "uint", cbBufferSize, "ptr", pbBuffer, "ptr*", ppIBitmap)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICFormatConverter_Initialize(this, pISource, dstFormat, dither, pIPalette, alphaThresholdPercent, paletteTranslate)
{
   dstFormat := WIC_GUID(GUID, dstFormat)
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize), "ptr", this, "ptr", pISource, "ptr", dstFormat, "uint", dither, "ptr", pIPalette, "double", alphaThresholdPercent, "uint", alphaThresholdPercent)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICFormatConverter_CanConvert(this, srcPixelFormat, dstPixelFormat)
{
   hr := DllCall(NumGet(NumGet(this+0)+9*A_PtrSize), "ptr", this, "ptr", srcPixelFormat, "ptr", dstPixelFormat, "ptr*", pfCanConvert)
   if hr or ErrorLevel or !pfCanConvert
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel "`npfCanConvert=0")
}

IWICBitmapFrameEncode_SetPixelFormat(this, ByRef pPixelFormat)
{
   hr := DllCall(NumGet(NumGet(this+0)+6*A_PtrSize), "ptr", this, "ptr*", pPixelFormat)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}


WIC_GUID(ByRef GUID,name){
	static init:=1,_:={}
	if init {
	init:=0
	; Decoders
	 _.CLSID_WICBmpDecoder:=[0x6b462062, 0x7cbf, 0x400d, 0x9f, 0xdb, 0x81, 0x3d, 0xd1, 0xf, 0x27, 0x78]
	,_.CLSID_WICPngDecoder:=[0x389ea17b, 0x5078, 0x4cde, 0xb6, 0xef, 0x25, 0xc1, 0x51, 0x75, 0xc7, 0x51]
	,_.CLSID_WICIcoDecoder:=[0xc61bfcdf, 0x2e0f, 0x4aad, 0xa8, 0xd7, 0xe0, 0x6b, 0xaf, 0xeb, 0xcd, 0xfe]
	,_.CLSID_WICJpegDecoder:=[0x9456a480, 0xe88b, 0x43ea, 0x9e, 0x73, 0xb, 0x2d, 0x9b, 0x71, 0xb1, 0xca]
	,_.CLSID_WICGifDecoder:=[0x381dda3c, 0x9ce9, 0x4834, 0xa2, 0x3e, 0x1f, 0x98, 0xf8, 0xfc, 0x52, 0xbe]
	,_.CLSID_WICTiffDecoder:=[0xb54e85d9, 0xfe23, 0x499f, 0x8b, 0x88, 0x6a, 0xce, 0xa7, 0x13, 0x75, 0x2b]
	,_.CLSID_WICWmpDecoder:=[0xa26cec36, 0x234c, 0x4950, 0xae, 0x16, 0xe3, 0x4a, 0xac, 0xe7, 0x1d, 0x0d]
	; Encoders
	 _.CLSID_WICBmpEncoder:=[0x69be8bb4, 0xd66d, 0x47c8, 0x86, 0x5a, 0xed, 0x15, 0x89, 0x43, 0x37, 0x82]
	,_.CLSID_WICPngEncoder:=[0x27949969, 0x876a, 0x41d7, 0x94, 0x47, 0x56, 0x8f, 0x6a, 0x35, 0xa4, 0xdc]
	,_.CLSID_WICJpegEncoder:=[0x1a34f5c1, 0x4a5a, 0x46dc, 0xb6, 0x44, 0x1f, 0x45, 0x67, 0xe7, 0xa6, 0x76]
	,_.CLSID_WICGifEncoder:=[0x114f5598, 0xb22, 0x40a0, 0x86, 0xa1, 0xc8, 0x3e, 0xa4, 0x95, 0xad, 0xbd]
	,_.CLSID_WICTiffEncoder:=[0x0131be10, 0x2001, 0x4c5f, 0xa9, 0xb0, 0xcc, 0x88, 0xfa, 0xb6, 0x4c, 0xe8]
	,_.CLSID_WICWmpEncoder:=[0xac4ce3cb, 0xe1c1, 0x44cd, 0x82, 0x15, 0x5a, 0x16, 0x65, 0x50, 0x9e, 0xc2]
	; Container Formats
	 _.GUID_ContainerFormatBmp:=[0xaf1d87e, 0xfcfe, 0x4188, 0xbd, 0xeb, 0xa7, 0x90, 0x64, 0x71, 0xcb, 0xe3]
	,_.GUID_ContainerFormatPng:=[0x1b7cfaf4, 0x713f, 0x473c, 0xbb, 0xcd, 0x61, 0x37, 0x42, 0x5f, 0xae, 0xaf]
	,_.GUID_ContainerFormatIco:=[0xa3a860c4, 0x338f, 0x4c17, 0x91, 0x9a, 0xfb, 0xa4, 0xb5, 0x62, 0x8f, 0x21]
	,_.GUID_ContainerFormatJpeg:=[0x19e4a5aa, 0x5662, 0x4fc5, 0xa0, 0xc0, 0x17, 0x58, 0x2, 0x8e, 0x10, 0x57]
	,_.GUID_ContainerFormatTiff:=[0x163bcc30, 0xe2e9, 0x4f0b, 0x96, 0x1d, 0xa3, 0xe9, 0xfd, 0xb7, 0x88, 0xa3]
	,_.GUID_ContainerFormatGif:=[0x1f8a5601, 0x7d4d, 0x4cbd, 0x9c, 0x82, 0x1b, 0xc8, 0xd4, 0xee, 0xb9, 0xa5]
	,_.GUID_ContainerFormatWmp:=[0x57a37caa, 0x367a, 0x4540, 0x91, 0x6b, 0xf1, 0x83, 0xc5, 0x09, 0x3a, 0x4b]
	; Component Identifiers
	 _.CLSID_WICImagingCategories:=[0xfae3d380, 0xfea4, 0x4623, 0x8c, 0x75, 0xc6, 0xb6, 0x11, 0x10, 0xb6, 0x81]
	,_.CATID_WICBitmapDecoders:=[0x7ed96837, 0x96f0, 0x4812, 0xb2, 0x11, 0xf1, 0x3c, 0x24, 0x11, 0x7e, 0xd3]
	,_.CATID_WICBitmapEncoders:=[0xac757296, 0x3522, 0x4e11, 0x98, 0x62, 0xc1, 0x7b, 0xe5, 0xa1, 0x76, 0x7e]
	,_.CATID_WICPixelFormats:=[0x2b46e70f, 0xcda7, 0x473e, 0x89, 0xf6, 0xdc, 0x96, 0x30, 0xa2, 0x39, 0x0b]
	,_.CATID_WICFormatConverters:=[0x7835eae8, 0xbf14, 0x49d1, 0x93, 0xce, 0x53, 0x3a, 0x40, 0x7b, 0x22, 0x48]
	,_.CATID_WICMetadataReader:=[0x05af94d8, 0x7174, 0x4cd2, 0xbe, 0x4a, 0x41, 0x24, 0xb8, 0x0e, 0xe4, 0xb8]
	,_.CATID_WICMetadataWriter:=[0xabe3b9a4, 0x257d, 0x4b97, 0xbd, 0x1a, 0x29, 0x4a, 0xf4, 0x96, 0x22, 0x2e]
	; Format Converters
	 _.CLSID_WICDefaultFormatConverter:=[0x1a3f11dc, 0xb514, 0x4b17, 0x8c, 0x5f, 0x21, 0x54, 0x51, 0x38, 0x52, 0xf1]
	,_.CLSID_WICFormatConverterHighColor:=[0xac75d454, 0x9f37, 0x48f8, 0xb9, 0x72, 0x4e, 0x19, 0xbc, 0x85, 0x60, 0x11]
	,_.CLSID_WICFormatConverterNChannel:=[0xc17cabb2, 0xd4a3, 0x47d7, 0xa5, 0x57, 0x33, 0x9b, 0x2e, 0xfb, 0xd4, 0xf1]
	,_.CLSID_WICFormatConverterWMPhoto:=[0x9cb5172b, 0xd600, 0x46ba, 0xab, 0x77, 0x77, 0xbb, 0x7e, 0x3a, 0x00, 0xd9]
	; Metadata Handlers
	 _.GUID_MetadataFormatUnknown:=[0xA45E592F, 0x9078, 0x4A7C, 0xAD, 0xB5, 0x4E, 0xDC, 0x4F, 0xD6, 0x1B, 0x1F]
	,_.GUID_MetadataFormatIfd:=[0x537396C6, 0x2D8A, 0x4BB6, 0x9B, 0xF8, 0x2F, 0x0A, 0x8E, 0x2A, 0x3A, 0xDF]
	,_.GUID_MetadataFormatSubIfd:=[0x58A2E128, 0x2DB9, 0x4E57, 0xBB, 0x14, 0x51, 0x77, 0x89, 0x1E, 0xD3, 0x31]
	,_.GUID_MetadataFormatExif:=[0x1C3C4F9D, 0xB84A, 0x467D, 0x94, 0x93, 0x36, 0xCF, 0xBD, 0x59, 0xEA, 0x57]
	,_.GUID_MetadataFormatGps:=[0x7134AB8A, 0x9351, 0x44AD, 0xAF, 0x62, 0x44, 0x8D, 0xB6, 0xB5, 0x02, 0xEC]
	,_.GUID_MetadataFormatInterop:=[0xED686F8E, 0x681F, 0x4C8B, 0xBD, 0x41, 0xA8, 0xAD, 0xDB, 0xF6, 0xB3, 0xFC]
	,_.GUID_MetadataFormatApp0:=[0x79007028, 0x268D, 0x45d6, 0xA3, 0xC2, 0x35, 0x4E, 0x6A, 0x50, 0x4B, 0xC9]
	,_.GUID_MetadataFormatApp1:=[0x8FD3DFC3, 0xF951, 0x492B, 0x81, 0x7F, 0x69, 0xC2, 0xE6, 0xD9, 0xA5, 0xB0]
	,_.GUID_MetadataFormatApp13:=[0x326556A2, 0xF502, 0x4354, 0x9C, 0xC0, 0x8E, 0x3F, 0x48, 0xEA, 0xF6, 0xB5]
	,_.GUID_MetadataFormatIPTC:=[0x4FAB0914, 0xE129, 0x4087, 0xA1, 0xD1, 0xBC, 0x81, 0x2D, 0x45, 0xA7, 0xB5]
	,_.GUID_MetadataFormatIRB:=[0x16100D66, 0x8570, 0x4BB9, 0xB9, 0x2D, 0xFD, 0xA4, 0xB2, 0x3E, 0xCE, 0x67]
	,_.GUID_MetadataFormat8BIMIPTC:=[0x0010568c, 0x0852, 0x4e6a, 0xb1, 0x91, 0x5c, 0x33, 0xac, 0x5b, 0x04, 0x30]
	,_.GUID_MetadataFormat8BIMResolutionInfo:=[0x739F305D, 0x81DB, 0x43CB, 0xAC, 0x5E, 0x55, 0x01, 0x3E, 0xF9, 0xF0, 0x03]
	 _.GUID_MetadataFormat8BIMIPTCDigest:=[0x1CA32285, 0x9CCD, 0x4786, 0x8B, 0xD8, 0x79, 0x53, 0x9D, 0xB6, 0xA0, 0x06]
	,_.GUID_MetadataFormatXMP:=[0xBB5ACC38, 0xF216, 0x4CEC, 0xA6, 0xC5, 0x5F, 0x6E, 0x73, 0x97, 0x63, 0xA9]
	,_.GUID_MetadataFormatThumbnail:=[0x243dcee9, 0x8703, 0x40ee, 0x8e, 0xf0, 0x22, 0xa6, 0x0, 0xb8, 0x5, 0x8c]
	,_.GUID_MetadataFormatChunktEXt:=[0x568d8936, 0xc0a9, 0x4923, 0x90, 0x5d, 0xdf, 0x2b, 0x38, 0x23, 0x8f, 0xbc]
	,_.GUID_MetadataFormatXMPStruct:=[0x22383CF1, 0xED17, 0x4E2E, 0xAF, 0x17, 0xD8, 0x5B, 0x8F, 0x6B, 0x30, 0xD0]
	,_.GUID_MetadataFormatXMPBag:=[0x833CCA5F, 0xDCB7, 0x4516, 0x80, 0x6F, 0x65, 0x96, 0xAB, 0x26, 0xDC, 0xE4]
	,_.GUID_MetadataFormatXMPSeq:=[0x63E8DF02, 0xEB6C,0x456C, 0xA2, 0x24, 0xB2, 0x5E, 0x79, 0x4F, 0xD6, 0x48]
	,_.GUID_MetadataFormatXMPAlt:=[0x7B08A675, 0x91AA, 0x481B, 0xA7, 0x98, 0x4D, 0xA9, 0x49, 0x08, 0x61, 0x3B]
	,_.GUID_MetadataFormatLSD:=[0xE256031E, 0x6299, 0x4929, 0xB9, 0x8D, 0x5A, 0xC8, 0x84, 0xAF, 0xBA, 0x92]
	,_.GUID_MetadataFormatIMD:=[0xBD2BB086, 0x4D52, 0x48DD, 0x96, 0x77, 0xDB, 0x48, 0x3E, 0x85, 0xAE, 0x8F]
	,_.GUID_MetadataFormatGCE:=[0x2A25CAD8, 0xDEEB, 0x4C69, 0xA7, 0x88, 0xE, 0xC2, 0x26, 0x6D, 0xCA, 0xFD]
	,_.GUID_MetadataFormatAPE:=[0x2E043DC2, 0xC967, 0x4E05, 0x87, 0x5E, 0x61, 0x8B, 0xF6, 0x7E, 0x85, 0xC3]
	 _.GUID_MetadataFormatJpegChrominance:=[0xF73D0DCF, 0xCEC6, 0x4F85, 0x9B, 0x0E, 0x1C, 0x39, 0x56, 0xB1, 0xBE, 0xF7]
	,_.GUID_MetadataFormatJpegLuminance:=[0x86908007, 0xEDFC, 0x4860, 0x8D, 0x4B, 0x4E, 0xE6, 0xE8, 0x3E, 0x60, 0x58]
	,_.GUID_MetadataFormatJpegComment:=[0x220E5F33, 0xAFD3, 0x474E, 0x9D, 0x31, 0x7D, 0x4F, 0xE7, 0x30, 0xF5, 0x57]
	,_.GUID_MetadataFormatGifComment:=[0xC4B6E0E0, 0xCFB4, 0x4AD3, 0xAB, 0x33, 0x9A, 0xAD, 0x23, 0x55, 0xA3, 0x4A]
	,_.GUID_MetadataFormatChunkgAMA:=[0xF00935A5, 0x1D5D, 0x4CD1, 0x81, 0xB2, 0x93, 0x24, 0xD7, 0xEC, 0xA7, 0x81]
	,_.GUID_MetadataFormatChunkbKGD:=[0xE14D3571, 0x6B47, 0x4DEA, 0xB6, 0xA, 0x87, 0xCE, 0xA, 0x78, 0xDF, 0xB7]
	,_.GUID_MetadataFormatChunkiTXt:=[0xC2BEC729, 0xB68, 0x4B77, 0xAA, 0xE, 0x62, 0x95, 0xA6, 0xAC, 0x18, 0x14]
	,_.GUID_MetadataFormatChunkcHRM:=[0x9DB3655B, 0x2842, 0x44B3, 0x80, 0x67, 0x12, 0xE9, 0xB3, 0x75, 0x55, 0x6A]
	,_.GUID_MetadataFormatChunkhIST:=[0xC59A82DA, 0xDB74, 0x48A4, 0xBD, 0x6A, 0xB6, 0x9C, 0x49, 0x31, 0xEF, 0x95]
	,_.GUID_MetadataFormatChunkiCCP:=[0xEB4349AB, 0xB685, 0x450F, 0x91, 0xB5, 0xE8, 0x2, 0xE8, 0x92, 0x53, 0x6C]
	,_.GUID_MetadataFormatChunksRGB:=[0xC115FD36, 0xCC6F, 0x4E3F, 0x83, 0x63, 0x52, 0x4B, 0x87, 0xC6, 0xB0, 0xD9]
	,_.GUID_MetadataFormatChunktIME:=[0x6B00AE2D, 0xE24B, 0x460A, 0x98, 0xB6, 0x87, 0x8B, 0xD0, 0x30, 0x72, 0xFD]
	; Vendor Identification
	 _.GUID_VendorMicrosoft:=[0x69fd0fdc, 0xa866, 0x4108, 0xb3, 0xb2, 0x98, 0x44, 0x7f, 0xa9, 0xed, 0xd4]
	,_.GUID_VendorMicrosoftBuiltIn:=[0x257a30fd, 0x6b6, 0x462b, 0xae, 0xa4, 0x63, 0xf7, 0xb, 0x86, 0xe5, 0x33]
	; WICBitmapPaletteType
	 _.GUID_WICPixelFormatDontCare:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x00]
	,_.GUID_WICPixelFormat1bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x01]
	,_.GUID_WICPixelFormat2bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x02]
	,_.GUID_WICPixelFormat4bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x03]
	,_.GUID_WICPixelFormat8bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x04]
	,_.GUID_WICPixelFormatBlackWhite:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x05]
	,_.GUID_WICPixelFormat2bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x06]
	,_.GUID_WICPixelFormat4bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x07]
	,_.GUID_WICPixelFormat8bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x08]
	,_.GUID_WICPixelFormat8bppAlpha:=[0xe6cd0116, 0xeeba, 0x4161, 0xaa, 0x85, 0x27, 0xdd, 0x9f, 0xb3, 0xa8, 0x95]
	,_.GUID_WICPixelFormat16bppBGR555:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x09]
	,_.GUID_WICPixelFormat16bppBGR565:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0a]
	,_.GUID_WICPixelFormat16bppBGRA5551:=[0x05ec7c2b, 0xf1e6, 0x4961, 0xad, 0x46, 0xe1, 0xcc, 0x81, 0x0a, 0x87, 0xd2]
	 _.GUID_WICPixelFormat16bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0b]
	,_.GUID_WICPixelFormat24bppBGR:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0c]
	,_.GUID_WICPixelFormat24bppRGB:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0d]
	,_.GUID_WICPixelFormat32bppBGR:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0e]
	,_.GUID_WICPixelFormat32bppBGRA:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0f]
	,_.GUID_WICPixelFormat32bppPBGRA:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x10]
	,_.GUID_WICPixelFormat32bppGrayFloat:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x11]
	,_.GUID_WICPixelFormat32bppRGBA:=[0xf5c7ad2d, 0x6a8d, 0x43dd, 0xa7, 0xa8, 0xa2, 0x99, 0x35, 0x26, 0x1a, 0xe9]
	,_.GUID_WICPixelFormat32bppPRGBA:=[0x3cc4a650, 0xa527, 0x4d37, 0xa9, 0x16, 0x31, 0x42, 0xc7, 0xeb, 0xed, 0xba]
	,_.GUID_WICPixelFormat48bppRGB:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x15]
	,_.GUID_WICPixelFormat48bppBGR:=[0xe605a384, 0xb468, 0x46ce, 0xbb, 0x2e, 0x36, 0xf1, 0x80, 0xe6, 0x43, 0x13]
	,_.GUID_WICPixelFormat64bppRGBA:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x16]
	,_.GUID_WICPixelFormat64bppBGRA:=[ 0x1562ff7c, 0xd352, 0x46f9, 0x97, 0x9e, 0x42, 0x97, 0x6b, 0x79, 0x22, 0x46]
	 _.GUID_WICPixelFormat64bppPRGBA:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x17]
	,_.GUID_WICPixelFormat64bppPBGRA:=[0x8c518e8e, 0xa4ec, 0x468b, 0xae, 0x70, 0xc9, 0xa3, 0x5a, 0x9c, 0x55, 0x30]
	,_.GUID_WICPixelFormat16bppGrayFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x13]
	,_.GUID_WICPixelFormat32bppBGR101010:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x14]
	,_.GUID_WICPixelFormat48bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x12]
	,_.GUID_WICPixelFormat48bppBGRFixedPoint:=[0x49ca140e, 0xcab6, 0x493b, 0x9d, 0xdf, 0x60, 0x18, 0x7c, 0x37, 0x53, 0x2a]
	,_.GUID_WICPixelFormat96bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x18]
	,_.GUID_WICPixelFormat128bppRGBAFloat:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x19]
	,_.GUID_WICPixelFormat128bppPRGBAFloat:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1a]
	,_.GUID_WICPixelFormat128bppRGBFloat:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1b]
	,_.GUID_WICPixelFormat32bppCMYK:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1c]
	,_.GUID_WICPixelFormat64bppRGBAFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1d]
	,_.GUID_WICPixelFormat64bppBGRAFixedPoint:=[0x356de33c, 0x54d2, 0x4a23, 0xbb, 0x4, 0x9b, 0x7b, 0xf9, 0xb1, 0xd4, 0x2d]
	 _.GUID_WICPixelFormat64bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x40]
	,_.GUID_WICPixelFormat128bppRGBAFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1e]
	,_.GUID_WICPixelFormat128bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x41]
	,_.GUID_WICPixelFormat64bppRGBAHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3a]
	,_.GUID_WICPixelFormat64bppRGBHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x42]
	,_.GUID_WICPixelFormat48bppRGBHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3b]
	,_.GUID_WICPixelFormat32bppRGBE:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3d]
	,_.GUID_WICPixelFormat16bppGrayHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3e]
	,_.GUID_WICPixelFormat32bppGrayFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3f]
	,_.GUID_WICPixelFormat32bppRGBA1010102:=[0x25238D72, 0xFCF9, 0x4522, 0xb5, 0x14, 0x55, 0x78, 0xe5, 0xad, 0x55, 0xe0]
	,_.GUID_WICPixelFormat32bppRGBA1010102XR:=[0x00DE6B9A, 0xC101, 0x434b, 0xb5, 0x02, 0xd0, 0x16, 0x5e, 0xe1, 0x12, 0x2c]
	,_.GUID_WICPixelFormat64bppCMYK:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1f]
	,_.GUID_WICPixelFormat24bpp3Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x20]
	 _.GUID_WICPixelFormat32bpp4Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x21]
	,_.GUID_WICPixelFormat40bpp5Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x22]
	,_.GUID_WICPixelFormat48bpp6Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x23]
	,_.GUID_WICPixelFormat56bpp7Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x24]
	,_.GUID_WICPixelFormat64bpp8Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x25]
	,_.GUID_WICPixelFormat48bpp3Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x26]
	,_.GUID_WICPixelFormat64bpp4Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x27]
	,_.GUID_WICPixelFormat80bpp5Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x28]
	,_.GUID_WICPixelFormat96bpp6Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x29]
	,_.GUID_WICPixelFormat112bpp7Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2a]
	,_.GUID_WICPixelFormat128bpp8Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2b]
	,_.GUID_WICPixelFormat40bppCMYKAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2c]
	,_.GUID_WICPixelFormat80bppCMYKAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2d]
	,_.GUID_WICPixelFormat32bpp3ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2e]
	 _.GUID_WICPixelFormat40bpp4ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2f]
	,_.GUID_WICPixelFormat48bpp5ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x30]
	,_.GUID_WICPixelFormat56bpp6ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x31]
	,_.GUID_WICPixelFormat64bpp7ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x32]
	,_.GUID_WICPixelFormat72bpp8ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x33]
	,_.GUID_WICPixelFormat64bpp3ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x34]
	,_.GUID_WICPixelFormat80bpp4ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x35]
	,_.GUID_WICPixelFormat96bpp5ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x36]
	,_.GUID_WICPixelFormat112bpp6ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x37]
	,_.GUID_WICPixelFormat128bpp7ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x38]
	,_.GUID_WICPixelFormat144bpp8ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x39]

	}
	if _.haskey(name){
		p:=_[name]
		VarSetCapacity(GUID,16)
		,NumPut(p.1+(p.2<<32)+(p.3<<48),GUID,0,"int64")
		,NumPut(p.4+(p.5<<8)+(p.6<<16)+(p.7<<24)+(p.8<<32)+(p.9<<40)+(p.10<<48)+(p.11<<56),GUID,8,"int64")
		return &GUID
	}else return name
}

WIC_hr(a){
	static init:=1,err:={0x8000FFFF:"Catastrophic failure error.",0x80004001:"Not implemented error.",0x8007000E:"Out of memory error.",0x80070057:"One or more arguments are not valid error.",0x80004002:"Interface not supported error.",0x80004003:"Pointer not valid error.",0x80070006:"Handle not valid error.",0x80004004:"Operation aborted error.",0x80004005:"Unspecified error.",0x80070005:"General access denied error.",0x800401E5:"The object identified by this moniker could not be found."}
	if init{
		init:=0
		 err[0x80004005]:="WINCODEC_ERR_GENERIC_ERROR"
		,err[0x80070057]:="WINCODEC_ERR_INVALIDPARAMETER"
		,err[0x8007000E]:="WINCODEC_ERR_OUTOFMEMORY"
		,err[0x80004001]:="WINCODEC_ERR_NOTIMPLEMENTED"
		,err[0x80004004]:="WINCODEC_ERR_ABORTED"
		,err[0x80070005]:="WINCODEC_ERR_ACCESSDENIED"
		,err[0x88982f04]:="WINCODEC_ERR_WRONGSTATE"
		,err[0x88982f05]:="WINCODEC_ERR_VALUEOUTOFRANGE"
		,err[0x88982f07]:="WINCODEC_ERR_UNKNOWNIMAGEFORMAT"
		,err[0x88982f0B]:="WINCODEC_ERR_UNSUPPORTEDVERSION"
		,err[0x88982f0C]:="WINCODEC_ERR_NOTINITIALIZED"
		,err[0x88982f0D]:="WINCODEC_ERR_ALREADYLOCKED"
		,err[0x88982f40]:="WINCODEC_ERR_PROPERTYNOTFOUND"
		,err[0x88982f41]:="WINCODEC_ERR_PROPERTYNOTSUPPORTED"
		,err[0x88982f42]:="WINCODEC_ERR_PROPERTYSIZE"
		,err[0x88982f43]:="WINCODEC_ERR_CODECPRESENT"
		,err[0x88982f44]:="WINCODEC_ERR_CODECNOTHUMBNAIL"
		,err[0x88982f45]:="WINCODEC_ERR_PALETTEUNAVAILABLE"
		,err[0x88982f46]:="WINCODEC_ERR_CODECTOOMANYSCANLINES"
		,err[0x88982f48]:="WINCODEC_ERR_INTERNALERROR"
		,err[0x88982f49]:="WINCODEC_ERR_SOURCERECTDOESNOTMATCHDIMENSIONS"
		,err[0x88982f50]:="WINCODEC_ERR_COMPONENTNOTFOUND"
		 err[0x88982f51]:="WINCODEC_ERR_IMAGESIZEOUTOFRANGE"
		,err[0x88982f52]:="WINCODEC_ERR_TOOMUCHMETADATA"
		,err[0x88982f60]:="WINCODEC_ERR_BADIMAGE"
		,err[0x88982f61]:="WINCODEC_ERR_BADHEADER"
		,err[0x88982f62]:="WINCODEC_ERR_FRAMEMISSING"
		,err[0x88982f63]:="WINCODEC_ERR_BADMETADATAHEADER"
		,err[0x88982f70]:="WINCODEC_ERR_BADSTREAMDATA"
		,err[0x88982f71]:="WINCODEC_ERR_STREAMWRITE"
		,err[0x88982f72]:="WINCODEC_ERR_STREAMREAD"
		,err[0x88982f73]:="WINCODEC_ERR_STREAMNOTAVAILABLE"
		,err[0x88982f80]:="WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT"
		,err[0x88982f81]:="WINCODEC_ERR_UNSUPPORTEDOPERATION"
		,err[0x88982f8A]:="WINCODEC_ERR_INVALIDREGISTRATION"
		,err[0x88982f8B]:="WINCODEC_ERR_COMPONENTINITIALIZEFAILURE"
		,err[0x88982f8C]:="WINCODEC_ERR_INSUFFICIENTBUFFER"
		,err[0x88982f8D]:="WINCODEC_ERR_DUPLICATEMETADATAPRESENT"
		,err[0x88982f8E]:="WINCODEC_ERR_PROPERTYUNEXPECTEDTYPE"
		,err[0x88982f8F]:="WINCODEC_ERR_UNEXPECTEDSIZE"
		,err[0x88982f90]:="WINCODEC_ERR_INVALIDQUERYREQUEST"
		,err[0x88982f91]:="WINCODEC_ERR_UNEXPECTEDMETADATATYPE"
		,err[0x88982f92]:="WINCODEC_ERR_REQUESTONLYVALIDATMETADATAROOT"
		,err[0x88982f93]:="WINCODEC_ERR_INVALIDQUERYCHARACTER"
	}	
	if a && (a&=0xFFFFFFFF)
        { 
	   if err.haskey(a)
              return err[a]
        }
	return a
}

22 (изменено: teadrinker, 2019-12-23 10:54:40)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

В порядке действий разницы не заметил, наверно, это моя конструкция с VTable() даёт такой эффект. У тебя вроде IDirect3DSurface9_UnlockRect(surface) не на месте.
В любом случае в таком виде это не годится, нужно задержку между кадрами устанавливать.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

23

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Почему не на месте?
Задержку установить можно, только зачем?
Ты хочешь не более 15 кадров в секунду?

24

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

По-моему, так должно быть:

   IDirect3DSurface9_LockRect(surface, &D3DLOCKED_RECT, &RECT, 0)
   pitch := NumGet(D3DLOCKED_RECT, 0, "int")
   pBits := NumGet(D3DLOCKED_RECT, A_PtrSize, "ptr")
   IDirect3DSurface9_UnlockRect(surface)

Задержку для воспроизведения, определяется в IPropertyBag2. У меня твой гиф воспроизводится гораздо быстрее, чем нужно.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

25

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

По-моему надо сначала перенаправлять pitch и pbits и только потом делать unlock. Для увеличения fps можно полученные значения копировать в массив например с помощью CopyMemory и после окончания получения всех скриншотов, обрабатывать этот массив через wic.
Вот примеры с ipropertybag.
https://docs.microsoft.com/ru-ru/window … ng-encoderНо тебе по-моему надо копать в сторону метаданных.
https://docs.microsoft.com/ru-ru/window … f-metadata
https://docs.microsoft.com/en-us/window … uerywriter Сам не могу проверить - пишу с телефона.

26

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Кстати, мой код даёт задержку между кадрами, очевидно есть какая-то по умолчанию. А твой почему-то нет.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

27

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Не углублялся почему у тебя идет задержка, но настроить delay на 25 кадров в секунду можно так:


; Script Requirements:
;
;   DirectX - March 2008 or later. (d3dx9_37.dll)
;     DirectX End-User Runtime Web Installer (March 2008):
;     http://www.microsoft.com/downloads/details.aspx?FamilyId=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&displaylang=en
;
file := "test.gif"
width := 500, height := 300
video_fps := 25

setbatchlines -1
ContainerFormat := "GUID_ContainerFormatGif"
formatGuid := WIC_GUID(GUID, "GUID_WICPixelFormat32bppBGRA")
; init D3D and get screen size
d3d := Direct3DCreate9(D3D_SDK_VERSION := 32) 
if !d3d
{
    MsgBox, 16, Error, Direct3DCreate9 failed.
    ExitApp
}
VarSetCapacity(D3DDISPLAYMODE, 16, 0)
IDirect3D9_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT := 0, &D3DDISPLAYMODE)
Windowed := true
BackBufferCount := 1
BackBufferHeight := NumGet(D3DDISPLAYMODE, 4, "uint")
BackBufferWidth := NumGet(D3DDISPLAYMODE, 0, "uint")
SwapEffect := 1   ; D3DSWAPEFFECT_DISCARD
hDeviceWindow := 0

; create device & capture surface
VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0) 
NumPut(BackBufferWidth, D3DPRESENT_PARAMETERS, 0)
NumPut(BackBufferHeight, D3DPRESENT_PARAMETERS, 4)
NumPut(BackBufferCount, D3DPRESENT_PARAMETERS, 12)
NumPut(SwapEffect, D3DPRESENT_PARAMETERS, 24)
NumPut(hDeviceWindow, D3DPRESENT_PARAMETERS, 24+A_PtrSize)
NumPut(Windowed, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)
IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT := 0, D3DDEVTYPE_HAL := 1, 0, D3DCREATE_SOFTWARE_VERTEXPROCESSING := 0x00000020, &D3DPRESENT_PARAMETERS, device)
IDirect3DDevice9_CreateOffscreenPlainSurface(device, BackBufferWidth, BackBufferHeight, D3DFMT_A8R8G8B8 := 21, D3DPOOL_SYSTEMMEM := 2, surface, 0)

if !wic
   wic := IWICCreate()
IWICImagingFactory_CreateStream(wic, stream)
IWICStream_InitializeFromFilename(stream, file, GENERIC_WRITE := 0x40000000)
IWICImagingFactory_CreateEncoder(wic, ContainerFormat, 0, encoder)
IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache := 0x2)
VarSetCapacity(PROPVARIANT, A_PtrSize*2+8, 0)
NumPut(VT_UI2 := 0x12, PROPVARIANT, 0, "ushort")
NumPut(delay := 4, PROPVARIANT, 8, "ushort")

fps := 1000/video_fps
a := A_TickCount
loop 100
{
   DllCall("Winmm\timeBeginPeriod", "UInt", 3)
   if (A_Index = 1)
      timeElapsed := A_TickCount
   else
   {
      loop
      {
         if (A_TickCount - timeElapsed >= fps)
         {
            timeElapsed+=fps
            break
         }
         DllCall("Sleep", "UInt", 1)
      }
   }
   DllCall("Winmm\timeEndPeriod", "UInt", 3)

   IDirect3DDevice9_GetFrontBufferData(device, 0, surface)
   VarSetCapacity(D3DLOCKED_RECT, A_PtrSize*2, 0)
   VarSetCapacity(RECT, 16, 0)
   NumPut(width, RECT, 8, "uint")
   NumPut(height, RECT, 12, "uint")
   IDirect3DSurface9_LockRect(surface, &D3DLOCKED_RECT, &RECT, 0)
   pitch := NumGet(D3DLOCKED_RECT, 0, "int")
   pBits := NumGet(D3DLOCKED_RECT, A_PtrSize, "ptr")

   IWICImagingFactory_CreateBitmapFromMemory(wic, width, height, formatGuid, pitch, pitch * height, pBits, Bitmap)
   IWICImagingFactory_CreateFormatConverter(wic, FormatConverter)
   IWICFormatConverter_Initialize(FormatConverter, Bitmap, "GUID_WICPixelFormat24bppBGR", WICBitmapDitherTypeNone := 0, 0, 0, WICBitmapPaletteTypeMedianCut := 0x1)
   IWICBitmapEncoder_CreateNewFrame(encoder, frame)
   IWICBitmapFrameEncode_Initialize(frame)
   IWICBitmapFrameEncode_WriteSource(frame, FormatConverter, 0)
   if (A_Index = 1)
      IWICBitmapFrameEncode_GetMetadataQueryWriter(frame, ppIMetadataQueryWriter)
   IWICBitmapFrameEncode_Commit(frame)
   if (A_Index = 1)
   {
      IWICMetadataQueryWriter_SetMetadataByName(ppIMetadataQueryWriter, "/grctlext/Delay", &PROPVARIANT)
      Release(ppIMetadataQueryWriter)
      ppIMetadataQueryWriter := ""
   }
   Release(Bitmap)
   Release(FormatConverter)
   Release(frame)
   Bitmap := FormatConverter := frame := ""

   IDirect3DSurface9_UnlockRect(surface)
}
IWICBitmapEncoder_Commit(encoder)
Release(encoder)
Release(stream)
Release(surface)
Release(device)
Release(d3d)
encoder := stream := surface := device := d3d := ""
msgbox % A_TickCount - a
ExitApp




Direct3DCreate9(SDKVersion) {
    if !DllCall("GetModuleHandle","str","d3d9")
        DllCall("LoadLibrary","str","d3d9")
    return DllCall("d3d9\Direct3DCreate9", "uint", SDKVersion)
}

IDirect3D9_GetAdapterDisplayMode(this,Adapter,pMode)
{
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize),"ptr",this,"uint",Adapter,"ptr",pMode)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3D9_CreateDevice(this,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ByRef ppReturnedDeviceInterface)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize),"ptr",this,"uint",Adapter,"uint",DeviceType,"ptr",hFocusWindow,"uint",BehaviorFlags,"ptr",pPresentationParameters,"ptr*",ppReturnedDeviceInterface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DDevice9_GetFrontBufferData(this,iSwapChain,pDestSurface)
{
   hr := DllCall(NumGet(NumGet(this+0)+33*A_PtrSize),"ptr",this,"uint",iSwapChain,"ptr",pDestSurface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DDevice9_CreateOffscreenPlainSurface(this,Width,Height,Format,Pool,ByRef ppSurface,pSharedHandle)
{
   hr := DllCall(NumGet(NumGet(this+0)+36*A_PtrSize),"ptr",this,"uint",Width,"uint",Height,"uint",Format,"uint",Pool,"ptr*",ppSurface,"ptr",pSharedHandle)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DSurface9_LockRect(this,pLockedRect,pRect,Flags)
{
   hr := DllCall(NumGet(NumGet(this+0)+13*A_PtrSize),"ptr",this,"ptr",pLockedRect,"ptr",pRect,"uint",Flags)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DSurface9_UnlockRect(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+14*A_PtrSize),"ptr",this)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

QueryInterface(ComObject, SID, ByRef InterfacePointer)
{
   InterfacePointer := ComObjQuery(ComObject, SID)
   if !InterfacePointer or ErrorLevel
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

Release(this)
{
   DllCall(NumGet(NumGet(this+0)+2*A_PtrSize), "ptr", this)
   if ErrorLevel
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

GUID(ByRef GUID, sGUID)
{
    VarSetCapacity(GUID, 16, 0)
    return DllCall("ole32\CLSIDFromString", "WStr", sGUID, "Ptr", &GUID) >= 0 ? &GUID : ""
}

_Error(val)
{
   msgbox % val
   ExitApp
}


IWICCreate()
{
   return ComObjCreate("{cacaf262-9370-4615-a13b-9f5539da4c0a}", "{ec5ec8a9-c395-4314-9c77-54d7a935ff70}")
}

IWICImagingFactory_CreateStream(this, ByRef ppIWICStream)
{
   hr := DllCall(NumGet(NumGet(this+0)+14*A_PtrSize), "ptr", this, "ptr*", ppIWICStream)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateFormatConverter(this, ByRef ppIFormatConverter)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "ptr*", ppIFormatConverter)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICStream_InitializeFromFilename(this, wzFileName, dwDesiredAccess)
{
   hr := DllCall(NumGet(NumGet(this+0)+15*A_PtrSize), "ptr", this, "str", wzFileName, "uint", dwDesiredAccess)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateEncoder(this, guidContainerFormat, pguidVendor, ByRef ppIEncoder)
{
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize), "ptr", this, "ptr", WIC_GUID(GUID1, guidContainerFormat), "ptr", WIC_GUID(GUID2, pguidVendor), "ptr*", ppIEncoder)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_Initialize(this, pIStream, cacheOption)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), "ptr", this, "ptr", pIStream, "int", cacheOption)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_CreateNewFrame(this, ByRef ppIFrameEncode, ppIEncoderOptions := 0)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "ptr*", ppIFrameEncode, "ptr*", ppIEncoderOptions)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_Commit(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+11*A_PtrSize), "ptr", this)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_Initialize(this, pIEncoderOptions := 0)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), "ptr", this, "ptr", pIEncoderOptions)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_SetSize(this, uiWidth, uiHeight)
{
   hr := DllCall(NumGet(NumGet(this+0)+4*A_PtrSize), "ptr", this, "uint", uiWidth, "uint", uiHeight)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_WritePixels(this, lineCount, cbStride, cbBufferSize, pbPixels)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "uint", lineCount, "uint", cbStride, "uint", cbBufferSize, "ptr", pbPixels)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_Commit(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+12*A_PtrSize), "ptr", this)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_WriteSource(this, pIBitmapSource, prc)
{
   hr := DllCall(NumGet(NumGet(this+0)+11*A_PtrSize), "ptr", this, "ptr", pIBitmapSource, "ptr", prc)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateBitmapFromMemory(this, uiWidth, uiHeight, pixelFormat, cbStride, cbBufferSize, pbBuffer, ByRef ppIBitmap)
{
   hr := DllCall(NumGet(NumGet(this+0)+20*A_PtrSize), "ptr", this, "uint", uiWidth, "uint", uiHeight, "ptr", pixelFormat, "uint", cbStride, "uint", cbBufferSize, "ptr", pbBuffer, "ptr*", ppIBitmap)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICFormatConverter_Initialize(this, pISource, dstFormat, dither, pIPalette, alphaThresholdPercent, paletteTranslate)
{
   dstFormat := WIC_GUID(GUID, dstFormat)
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize), "ptr", this, "ptr", pISource, "ptr", dstFormat, "uint", dither, "ptr", pIPalette, "double", alphaThresholdPercent, "uint", alphaThresholdPercent)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICFormatConverter_CanConvert(this, srcPixelFormat, dstPixelFormat)
{
   hr := DllCall(NumGet(NumGet(this+0)+9*A_PtrSize), "ptr", this, "ptr", srcPixelFormat, "ptr", dstPixelFormat, "ptr*", pfCanConvert)
   if hr or ErrorLevel or !pfCanConvert
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel "`npfCanConvert=0")
}

IWICBitmapFrameEncode_SetPixelFormat(this, ByRef pPixelFormat)
{
   hr := DllCall(NumGet(NumGet(this+0)+6*A_PtrSize), "ptr", this, "ptr*", pPixelFormat)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_GetMetadataQueryWriter(this, ByRef ppIMetadataQueryWriter)
{
   hr := DllCall(NumGet(NumGet(this+0)+13*A_PtrSize), "ptr", this, "ptr*", ppIMetadataQueryWriter)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}


IWICMetadataQueryWriter_SetMetadataByName(this, wzName, pvarValue)
{
   hr := DllCall(NumGet(NumGet(this+0)+7*A_PtrSize), "ptr", this, "str", wzName, "ptr", pvarValue)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}


WIC_GUID(ByRef GUID,name){
	static init:=1,_:={}
	if init {
	init:=0
	; Decoders
	 _.CLSID_WICBmpDecoder:=[0x6b462062, 0x7cbf, 0x400d, 0x9f, 0xdb, 0x81, 0x3d, 0xd1, 0xf, 0x27, 0x78]
	,_.CLSID_WICPngDecoder:=[0x389ea17b, 0x5078, 0x4cde, 0xb6, 0xef, 0x25, 0xc1, 0x51, 0x75, 0xc7, 0x51]
	,_.CLSID_WICIcoDecoder:=[0xc61bfcdf, 0x2e0f, 0x4aad, 0xa8, 0xd7, 0xe0, 0x6b, 0xaf, 0xeb, 0xcd, 0xfe]
	,_.CLSID_WICJpegDecoder:=[0x9456a480, 0xe88b, 0x43ea, 0x9e, 0x73, 0xb, 0x2d, 0x9b, 0x71, 0xb1, 0xca]
	,_.CLSID_WICGifDecoder:=[0x381dda3c, 0x9ce9, 0x4834, 0xa2, 0x3e, 0x1f, 0x98, 0xf8, 0xfc, 0x52, 0xbe]
	,_.CLSID_WICTiffDecoder:=[0xb54e85d9, 0xfe23, 0x499f, 0x8b, 0x88, 0x6a, 0xce, 0xa7, 0x13, 0x75, 0x2b]
	,_.CLSID_WICWmpDecoder:=[0xa26cec36, 0x234c, 0x4950, 0xae, 0x16, 0xe3, 0x4a, 0xac, 0xe7, 0x1d, 0x0d]
	; Encoders
	 _.CLSID_WICBmpEncoder:=[0x69be8bb4, 0xd66d, 0x47c8, 0x86, 0x5a, 0xed, 0x15, 0x89, 0x43, 0x37, 0x82]
	,_.CLSID_WICPngEncoder:=[0x27949969, 0x876a, 0x41d7, 0x94, 0x47, 0x56, 0x8f, 0x6a, 0x35, 0xa4, 0xdc]
	,_.CLSID_WICJpegEncoder:=[0x1a34f5c1, 0x4a5a, 0x46dc, 0xb6, 0x44, 0x1f, 0x45, 0x67, 0xe7, 0xa6, 0x76]
	,_.CLSID_WICGifEncoder:=[0x114f5598, 0xb22, 0x40a0, 0x86, 0xa1, 0xc8, 0x3e, 0xa4, 0x95, 0xad, 0xbd]
	,_.CLSID_WICTiffEncoder:=[0x0131be10, 0x2001, 0x4c5f, 0xa9, 0xb0, 0xcc, 0x88, 0xfa, 0xb6, 0x4c, 0xe8]
	,_.CLSID_WICWmpEncoder:=[0xac4ce3cb, 0xe1c1, 0x44cd, 0x82, 0x15, 0x5a, 0x16, 0x65, 0x50, 0x9e, 0xc2]
	; Container Formats
	 _.GUID_ContainerFormatBmp:=[0xaf1d87e, 0xfcfe, 0x4188, 0xbd, 0xeb, 0xa7, 0x90, 0x64, 0x71, 0xcb, 0xe3]
	,_.GUID_ContainerFormatPng:=[0x1b7cfaf4, 0x713f, 0x473c, 0xbb, 0xcd, 0x61, 0x37, 0x42, 0x5f, 0xae, 0xaf]
	,_.GUID_ContainerFormatIco:=[0xa3a860c4, 0x338f, 0x4c17, 0x91, 0x9a, 0xfb, 0xa4, 0xb5, 0x62, 0x8f, 0x21]
	,_.GUID_ContainerFormatJpeg:=[0x19e4a5aa, 0x5662, 0x4fc5, 0xa0, 0xc0, 0x17, 0x58, 0x2, 0x8e, 0x10, 0x57]
	,_.GUID_ContainerFormatTiff:=[0x163bcc30, 0xe2e9, 0x4f0b, 0x96, 0x1d, 0xa3, 0xe9, 0xfd, 0xb7, 0x88, 0xa3]
	,_.GUID_ContainerFormatGif:=[0x1f8a5601, 0x7d4d, 0x4cbd, 0x9c, 0x82, 0x1b, 0xc8, 0xd4, 0xee, 0xb9, 0xa5]
	,_.GUID_ContainerFormatWmp:=[0x57a37caa, 0x367a, 0x4540, 0x91, 0x6b, 0xf1, 0x83, 0xc5, 0x09, 0x3a, 0x4b]
	; Component Identifiers
	 _.CLSID_WICImagingCategories:=[0xfae3d380, 0xfea4, 0x4623, 0x8c, 0x75, 0xc6, 0xb6, 0x11, 0x10, 0xb6, 0x81]
	,_.CATID_WICBitmapDecoders:=[0x7ed96837, 0x96f0, 0x4812, 0xb2, 0x11, 0xf1, 0x3c, 0x24, 0x11, 0x7e, 0xd3]
	,_.CATID_WICBitmapEncoders:=[0xac757296, 0x3522, 0x4e11, 0x98, 0x62, 0xc1, 0x7b, 0xe5, 0xa1, 0x76, 0x7e]
	,_.CATID_WICPixelFormats:=[0x2b46e70f, 0xcda7, 0x473e, 0x89, 0xf6, 0xdc, 0x96, 0x30, 0xa2, 0x39, 0x0b]
	,_.CATID_WICFormatConverters:=[0x7835eae8, 0xbf14, 0x49d1, 0x93, 0xce, 0x53, 0x3a, 0x40, 0x7b, 0x22, 0x48]
	,_.CATID_WICMetadataReader:=[0x05af94d8, 0x7174, 0x4cd2, 0xbe, 0x4a, 0x41, 0x24, 0xb8, 0x0e, 0xe4, 0xb8]
	,_.CATID_WICMetadataWriter:=[0xabe3b9a4, 0x257d, 0x4b97, 0xbd, 0x1a, 0x29, 0x4a, 0xf4, 0x96, 0x22, 0x2e]
	; Format Converters
	 _.CLSID_WICDefaultFormatConverter:=[0x1a3f11dc, 0xb514, 0x4b17, 0x8c, 0x5f, 0x21, 0x54, 0x51, 0x38, 0x52, 0xf1]
	,_.CLSID_WICFormatConverterHighColor:=[0xac75d454, 0x9f37, 0x48f8, 0xb9, 0x72, 0x4e, 0x19, 0xbc, 0x85, 0x60, 0x11]
	,_.CLSID_WICFormatConverterNChannel:=[0xc17cabb2, 0xd4a3, 0x47d7, 0xa5, 0x57, 0x33, 0x9b, 0x2e, 0xfb, 0xd4, 0xf1]
	,_.CLSID_WICFormatConverterWMPhoto:=[0x9cb5172b, 0xd600, 0x46ba, 0xab, 0x77, 0x77, 0xbb, 0x7e, 0x3a, 0x00, 0xd9]
	; Metadata Handlers
	 _.GUID_MetadataFormatUnknown:=[0xA45E592F, 0x9078, 0x4A7C, 0xAD, 0xB5, 0x4E, 0xDC, 0x4F, 0xD6, 0x1B, 0x1F]
	,_.GUID_MetadataFormatIfd:=[0x537396C6, 0x2D8A, 0x4BB6, 0x9B, 0xF8, 0x2F, 0x0A, 0x8E, 0x2A, 0x3A, 0xDF]
	,_.GUID_MetadataFormatSubIfd:=[0x58A2E128, 0x2DB9, 0x4E57, 0xBB, 0x14, 0x51, 0x77, 0x89, 0x1E, 0xD3, 0x31]
	,_.GUID_MetadataFormatExif:=[0x1C3C4F9D, 0xB84A, 0x467D, 0x94, 0x93, 0x36, 0xCF, 0xBD, 0x59, 0xEA, 0x57]
	,_.GUID_MetadataFormatGps:=[0x7134AB8A, 0x9351, 0x44AD, 0xAF, 0x62, 0x44, 0x8D, 0xB6, 0xB5, 0x02, 0xEC]
	,_.GUID_MetadataFormatInterop:=[0xED686F8E, 0x681F, 0x4C8B, 0xBD, 0x41, 0xA8, 0xAD, 0xDB, 0xF6, 0xB3, 0xFC]
	,_.GUID_MetadataFormatApp0:=[0x79007028, 0x268D, 0x45d6, 0xA3, 0xC2, 0x35, 0x4E, 0x6A, 0x50, 0x4B, 0xC9]
	,_.GUID_MetadataFormatApp1:=[0x8FD3DFC3, 0xF951, 0x492B, 0x81, 0x7F, 0x69, 0xC2, 0xE6, 0xD9, 0xA5, 0xB0]
	,_.GUID_MetadataFormatApp13:=[0x326556A2, 0xF502, 0x4354, 0x9C, 0xC0, 0x8E, 0x3F, 0x48, 0xEA, 0xF6, 0xB5]
	,_.GUID_MetadataFormatIPTC:=[0x4FAB0914, 0xE129, 0x4087, 0xA1, 0xD1, 0xBC, 0x81, 0x2D, 0x45, 0xA7, 0xB5]
	,_.GUID_MetadataFormatIRB:=[0x16100D66, 0x8570, 0x4BB9, 0xB9, 0x2D, 0xFD, 0xA4, 0xB2, 0x3E, 0xCE, 0x67]
	,_.GUID_MetadataFormat8BIMIPTC:=[0x0010568c, 0x0852, 0x4e6a, 0xb1, 0x91, 0x5c, 0x33, 0xac, 0x5b, 0x04, 0x30]
	,_.GUID_MetadataFormat8BIMResolutionInfo:=[0x739F305D, 0x81DB, 0x43CB, 0xAC, 0x5E, 0x55, 0x01, 0x3E, 0xF9, 0xF0, 0x03]
	 _.GUID_MetadataFormat8BIMIPTCDigest:=[0x1CA32285, 0x9CCD, 0x4786, 0x8B, 0xD8, 0x79, 0x53, 0x9D, 0xB6, 0xA0, 0x06]
	,_.GUID_MetadataFormatXMP:=[0xBB5ACC38, 0xF216, 0x4CEC, 0xA6, 0xC5, 0x5F, 0x6E, 0x73, 0x97, 0x63, 0xA9]
	,_.GUID_MetadataFormatThumbnail:=[0x243dcee9, 0x8703, 0x40ee, 0x8e, 0xf0, 0x22, 0xa6, 0x0, 0xb8, 0x5, 0x8c]
	,_.GUID_MetadataFormatChunktEXt:=[0x568d8936, 0xc0a9, 0x4923, 0x90, 0x5d, 0xdf, 0x2b, 0x38, 0x23, 0x8f, 0xbc]
	,_.GUID_MetadataFormatXMPStruct:=[0x22383CF1, 0xED17, 0x4E2E, 0xAF, 0x17, 0xD8, 0x5B, 0x8F, 0x6B, 0x30, 0xD0]
	,_.GUID_MetadataFormatXMPBag:=[0x833CCA5F, 0xDCB7, 0x4516, 0x80, 0x6F, 0x65, 0x96, 0xAB, 0x26, 0xDC, 0xE4]
	,_.GUID_MetadataFormatXMPSeq:=[0x63E8DF02, 0xEB6C,0x456C, 0xA2, 0x24, 0xB2, 0x5E, 0x79, 0x4F, 0xD6, 0x48]
	,_.GUID_MetadataFormatXMPAlt:=[0x7B08A675, 0x91AA, 0x481B, 0xA7, 0x98, 0x4D, 0xA9, 0x49, 0x08, 0x61, 0x3B]
	,_.GUID_MetadataFormatLSD:=[0xE256031E, 0x6299, 0x4929, 0xB9, 0x8D, 0x5A, 0xC8, 0x84, 0xAF, 0xBA, 0x92]
	,_.GUID_MetadataFormatIMD:=[0xBD2BB086, 0x4D52, 0x48DD, 0x96, 0x77, 0xDB, 0x48, 0x3E, 0x85, 0xAE, 0x8F]
	,_.GUID_MetadataFormatGCE:=[0x2A25CAD8, 0xDEEB, 0x4C69, 0xA7, 0x88, 0xE, 0xC2, 0x26, 0x6D, 0xCA, 0xFD]
	,_.GUID_MetadataFormatAPE:=[0x2E043DC2, 0xC967, 0x4E05, 0x87, 0x5E, 0x61, 0x8B, 0xF6, 0x7E, 0x85, 0xC3]
	 _.GUID_MetadataFormatJpegChrominance:=[0xF73D0DCF, 0xCEC6, 0x4F85, 0x9B, 0x0E, 0x1C, 0x39, 0x56, 0xB1, 0xBE, 0xF7]
	,_.GUID_MetadataFormatJpegLuminance:=[0x86908007, 0xEDFC, 0x4860, 0x8D, 0x4B, 0x4E, 0xE6, 0xE8, 0x3E, 0x60, 0x58]
	,_.GUID_MetadataFormatJpegComment:=[0x220E5F33, 0xAFD3, 0x474E, 0x9D, 0x31, 0x7D, 0x4F, 0xE7, 0x30, 0xF5, 0x57]
	,_.GUID_MetadataFormatGifComment:=[0xC4B6E0E0, 0xCFB4, 0x4AD3, 0xAB, 0x33, 0x9A, 0xAD, 0x23, 0x55, 0xA3, 0x4A]
	,_.GUID_MetadataFormatChunkgAMA:=[0xF00935A5, 0x1D5D, 0x4CD1, 0x81, 0xB2, 0x93, 0x24, 0xD7, 0xEC, 0xA7, 0x81]
	,_.GUID_MetadataFormatChunkbKGD:=[0xE14D3571, 0x6B47, 0x4DEA, 0xB6, 0xA, 0x87, 0xCE, 0xA, 0x78, 0xDF, 0xB7]
	,_.GUID_MetadataFormatChunkiTXt:=[0xC2BEC729, 0xB68, 0x4B77, 0xAA, 0xE, 0x62, 0x95, 0xA6, 0xAC, 0x18, 0x14]
	,_.GUID_MetadataFormatChunkcHRM:=[0x9DB3655B, 0x2842, 0x44B3, 0x80, 0x67, 0x12, 0xE9, 0xB3, 0x75, 0x55, 0x6A]
	,_.GUID_MetadataFormatChunkhIST:=[0xC59A82DA, 0xDB74, 0x48A4, 0xBD, 0x6A, 0xB6, 0x9C, 0x49, 0x31, 0xEF, 0x95]
	,_.GUID_MetadataFormatChunkiCCP:=[0xEB4349AB, 0xB685, 0x450F, 0x91, 0xB5, 0xE8, 0x2, 0xE8, 0x92, 0x53, 0x6C]
	,_.GUID_MetadataFormatChunksRGB:=[0xC115FD36, 0xCC6F, 0x4E3F, 0x83, 0x63, 0x52, 0x4B, 0x87, 0xC6, 0xB0, 0xD9]
	,_.GUID_MetadataFormatChunktIME:=[0x6B00AE2D, 0xE24B, 0x460A, 0x98, 0xB6, 0x87, 0x8B, 0xD0, 0x30, 0x72, 0xFD]
	; Vendor Identification
	 _.GUID_VendorMicrosoft:=[0x69fd0fdc, 0xa866, 0x4108, 0xb3, 0xb2, 0x98, 0x44, 0x7f, 0xa9, 0xed, 0xd4]
	,_.GUID_VendorMicrosoftBuiltIn:=[0x257a30fd, 0x6b6, 0x462b, 0xae, 0xa4, 0x63, 0xf7, 0xb, 0x86, 0xe5, 0x33]
	; WICBitmapPaletteType
	 _.GUID_WICPixelFormatDontCare:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x00]
	,_.GUID_WICPixelFormat1bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x01]
	,_.GUID_WICPixelFormat2bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x02]
	,_.GUID_WICPixelFormat4bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x03]
	,_.GUID_WICPixelFormat8bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x04]
	,_.GUID_WICPixelFormatBlackWhite:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x05]
	,_.GUID_WICPixelFormat2bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x06]
	,_.GUID_WICPixelFormat4bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x07]
	,_.GUID_WICPixelFormat8bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x08]
	,_.GUID_WICPixelFormat8bppAlpha:=[0xe6cd0116, 0xeeba, 0x4161, 0xaa, 0x85, 0x27, 0xdd, 0x9f, 0xb3, 0xa8, 0x95]
	,_.GUID_WICPixelFormat16bppBGR555:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x09]
	,_.GUID_WICPixelFormat16bppBGR565:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0a]
	,_.GUID_WICPixelFormat16bppBGRA5551:=[0x05ec7c2b, 0xf1e6, 0x4961, 0xad, 0x46, 0xe1, 0xcc, 0x81, 0x0a, 0x87, 0xd2]
	 _.GUID_WICPixelFormat16bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0b]
	,_.GUID_WICPixelFormat24bppBGR:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0c]
	,_.GUID_WICPixelFormat24bppRGB:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0d]
	,_.GUID_WICPixelFormat32bppBGR:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0e]
	,_.GUID_WICPixelFormat32bppBGRA:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0f]
	,_.GUID_WICPixelFormat32bppPBGRA:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x10]
	,_.GUID_WICPixelFormat32bppGrayFloat:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x11]
	,_.GUID_WICPixelFormat32bppRGBA:=[0xf5c7ad2d, 0x6a8d, 0x43dd, 0xa7, 0xa8, 0xa2, 0x99, 0x35, 0x26, 0x1a, 0xe9]
	,_.GUID_WICPixelFormat32bppPRGBA:=[0x3cc4a650, 0xa527, 0x4d37, 0xa9, 0x16, 0x31, 0x42, 0xc7, 0xeb, 0xed, 0xba]
	,_.GUID_WICPixelFormat48bppRGB:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x15]
	,_.GUID_WICPixelFormat48bppBGR:=[0xe605a384, 0xb468, 0x46ce, 0xbb, 0x2e, 0x36, 0xf1, 0x80, 0xe6, 0x43, 0x13]
	,_.GUID_WICPixelFormat64bppRGBA:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x16]
	,_.GUID_WICPixelFormat64bppBGRA:=[ 0x1562ff7c, 0xd352, 0x46f9, 0x97, 0x9e, 0x42, 0x97, 0x6b, 0x79, 0x22, 0x46]
	 _.GUID_WICPixelFormat64bppPRGBA:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x17]
	,_.GUID_WICPixelFormat64bppPBGRA:=[0x8c518e8e, 0xa4ec, 0x468b, 0xae, 0x70, 0xc9, 0xa3, 0x5a, 0x9c, 0x55, 0x30]
	,_.GUID_WICPixelFormat16bppGrayFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x13]
	,_.GUID_WICPixelFormat32bppBGR101010:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x14]
	,_.GUID_WICPixelFormat48bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x12]
	,_.GUID_WICPixelFormat48bppBGRFixedPoint:=[0x49ca140e, 0xcab6, 0x493b, 0x9d, 0xdf, 0x60, 0x18, 0x7c, 0x37, 0x53, 0x2a]
	,_.GUID_WICPixelFormat96bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x18]
	,_.GUID_WICPixelFormat128bppRGBAFloat:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x19]
	,_.GUID_WICPixelFormat128bppPRGBAFloat:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1a]
	,_.GUID_WICPixelFormat128bppRGBFloat:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1b]
	,_.GUID_WICPixelFormat32bppCMYK:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1c]
	,_.GUID_WICPixelFormat64bppRGBAFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1d]
	,_.GUID_WICPixelFormat64bppBGRAFixedPoint:=[0x356de33c, 0x54d2, 0x4a23, 0xbb, 0x4, 0x9b, 0x7b, 0xf9, 0xb1, 0xd4, 0x2d]
	 _.GUID_WICPixelFormat64bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x40]
	,_.GUID_WICPixelFormat128bppRGBAFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1e]
	,_.GUID_WICPixelFormat128bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x41]
	,_.GUID_WICPixelFormat64bppRGBAHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3a]
	,_.GUID_WICPixelFormat64bppRGBHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x42]
	,_.GUID_WICPixelFormat48bppRGBHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3b]
	,_.GUID_WICPixelFormat32bppRGBE:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3d]
	,_.GUID_WICPixelFormat16bppGrayHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3e]
	,_.GUID_WICPixelFormat32bppGrayFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3f]
	,_.GUID_WICPixelFormat32bppRGBA1010102:=[0x25238D72, 0xFCF9, 0x4522, 0xb5, 0x14, 0x55, 0x78, 0xe5, 0xad, 0x55, 0xe0]
	,_.GUID_WICPixelFormat32bppRGBA1010102XR:=[0x00DE6B9A, 0xC101, 0x434b, 0xb5, 0x02, 0xd0, 0x16, 0x5e, 0xe1, 0x12, 0x2c]
	,_.GUID_WICPixelFormat64bppCMYK:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1f]
	,_.GUID_WICPixelFormat24bpp3Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x20]
	 _.GUID_WICPixelFormat32bpp4Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x21]
	,_.GUID_WICPixelFormat40bpp5Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x22]
	,_.GUID_WICPixelFormat48bpp6Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x23]
	,_.GUID_WICPixelFormat56bpp7Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x24]
	,_.GUID_WICPixelFormat64bpp8Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x25]
	,_.GUID_WICPixelFormat48bpp3Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x26]
	,_.GUID_WICPixelFormat64bpp4Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x27]
	,_.GUID_WICPixelFormat80bpp5Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x28]
	,_.GUID_WICPixelFormat96bpp6Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x29]
	,_.GUID_WICPixelFormat112bpp7Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2a]
	,_.GUID_WICPixelFormat128bpp8Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2b]
	,_.GUID_WICPixelFormat40bppCMYKAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2c]
	,_.GUID_WICPixelFormat80bppCMYKAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2d]
	,_.GUID_WICPixelFormat32bpp3ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2e]
	 _.GUID_WICPixelFormat40bpp4ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2f]
	,_.GUID_WICPixelFormat48bpp5ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x30]
	,_.GUID_WICPixelFormat56bpp6ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x31]
	,_.GUID_WICPixelFormat64bpp7ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x32]
	,_.GUID_WICPixelFormat72bpp8ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x33]
	,_.GUID_WICPixelFormat64bpp3ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x34]
	,_.GUID_WICPixelFormat80bpp4ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x35]
	,_.GUID_WICPixelFormat96bpp5ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x36]
	,_.GUID_WICPixelFormat112bpp6ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x37]
	,_.GUID_WICPixelFormat128bpp7ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x38]
	,_.GUID_WICPixelFormat144bpp8ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x39]

	}
	if _.haskey(name){
		p:=_[name]
		VarSetCapacity(GUID,16)
		,NumPut(p.1+(p.2<<32)+(p.3<<48),GUID,0,"int64")
		,NumPut(p.4+(p.5<<8)+(p.6<<16)+(p.7<<24)+(p.8<<32)+(p.9<<40)+(p.10<<48)+(p.11<<56),GUID,8,"int64")
		return &GUID
	}else return name
}

WIC_hr(a){
	static init:=1,err:={0x8000FFFF:"Catastrophic failure error.",0x80004001:"Not implemented error.",0x8007000E:"Out of memory error.",0x80070057:"One or more arguments are not valid error.",0x80004002:"Interface not supported error.",0x80004003:"Pointer not valid error.",0x80070006:"Handle not valid error.",0x80004004:"Operation aborted error.",0x80004005:"Unspecified error.",0x80070005:"General access denied error.",0x800401E5:"The object identified by this moniker could not be found."}
	if init{
		init:=0
		 err[0x80004005]:="WINCODEC_ERR_GENERIC_ERROR"
		,err[0x80070057]:="WINCODEC_ERR_INVALIDPARAMETER"
		,err[0x8007000E]:="WINCODEC_ERR_OUTOFMEMORY"
		,err[0x80004001]:="WINCODEC_ERR_NOTIMPLEMENTED"
		,err[0x80004004]:="WINCODEC_ERR_ABORTED"
		,err[0x80070005]:="WINCODEC_ERR_ACCESSDENIED"
		,err[0x88982f04]:="WINCODEC_ERR_WRONGSTATE"
		,err[0x88982f05]:="WINCODEC_ERR_VALUEOUTOFRANGE"
		,err[0x88982f07]:="WINCODEC_ERR_UNKNOWNIMAGEFORMAT"
		,err[0x88982f0B]:="WINCODEC_ERR_UNSUPPORTEDVERSION"
		,err[0x88982f0C]:="WINCODEC_ERR_NOTINITIALIZED"
		,err[0x88982f0D]:="WINCODEC_ERR_ALREADYLOCKED"
		,err[0x88982f40]:="WINCODEC_ERR_PROPERTYNOTFOUND"
		,err[0x88982f41]:="WINCODEC_ERR_PROPERTYNOTSUPPORTED"
		,err[0x88982f42]:="WINCODEC_ERR_PROPERTYSIZE"
		,err[0x88982f43]:="WINCODEC_ERR_CODECPRESENT"
		,err[0x88982f44]:="WINCODEC_ERR_CODECNOTHUMBNAIL"
		,err[0x88982f45]:="WINCODEC_ERR_PALETTEUNAVAILABLE"
		,err[0x88982f46]:="WINCODEC_ERR_CODECTOOMANYSCANLINES"
		,err[0x88982f48]:="WINCODEC_ERR_INTERNALERROR"
		,err[0x88982f49]:="WINCODEC_ERR_SOURCERECTDOESNOTMATCHDIMENSIONS"
		,err[0x88982f50]:="WINCODEC_ERR_COMPONENTNOTFOUND"
		 err[0x88982f51]:="WINCODEC_ERR_IMAGESIZEOUTOFRANGE"
		,err[0x88982f52]:="WINCODEC_ERR_TOOMUCHMETADATA"
		,err[0x88982f60]:="WINCODEC_ERR_BADIMAGE"
		,err[0x88982f61]:="WINCODEC_ERR_BADHEADER"
		,err[0x88982f62]:="WINCODEC_ERR_FRAMEMISSING"
		,err[0x88982f63]:="WINCODEC_ERR_BADMETADATAHEADER"
		,err[0x88982f70]:="WINCODEC_ERR_BADSTREAMDATA"
		,err[0x88982f71]:="WINCODEC_ERR_STREAMWRITE"
		,err[0x88982f72]:="WINCODEC_ERR_STREAMREAD"
		,err[0x88982f73]:="WINCODEC_ERR_STREAMNOTAVAILABLE"
		,err[0x88982f80]:="WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT"
		,err[0x88982f81]:="WINCODEC_ERR_UNSUPPORTEDOPERATION"
		,err[0x88982f8A]:="WINCODEC_ERR_INVALIDREGISTRATION"
		,err[0x88982f8B]:="WINCODEC_ERR_COMPONENTINITIALIZEFAILURE"
		,err[0x88982f8C]:="WINCODEC_ERR_INSUFFICIENTBUFFER"
		,err[0x88982f8D]:="WINCODEC_ERR_DUPLICATEMETADATAPRESENT"
		,err[0x88982f8E]:="WINCODEC_ERR_PROPERTYUNEXPECTEDTYPE"
		,err[0x88982f8F]:="WINCODEC_ERR_UNEXPECTEDSIZE"
		,err[0x88982f90]:="WINCODEC_ERR_INVALIDQUERYREQUEST"
		,err[0x88982f91]:="WINCODEC_ERR_UNEXPECTEDMETADATATYPE"
		,err[0x88982f92]:="WINCODEC_ERR_REQUESTONLYVALIDATMETADATAROOT"
		,err[0x88982f93]:="WINCODEC_ERR_INVALIDQUERYCHARACTER"
	}	
	if a && (a&=0xFFFFFFFF)
        { 
	   if err.haskey(a)
              return err[a]
        }
	return a
}

28

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Не работает, пока проверил на Windows 10. Вроде один раз сработало, но не уверен, и перестало.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

29

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

А чем проверяшь?  Quicktime player показывает 25 fps. И ie нормально проигрывает.

30

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

У меня IE тоже не видит задержку.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

31

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Ну не знаю тогда.
У меня на 3 разных компьютерах с разными Win-10 IE видит.
На всех длительность полученного гифа - 4 секунды.

32

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Сейчас на Windows 7 проверил — тоже не сработало.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

33

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Можешь прислать файл, который у тебя получается?

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

34

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

https://ru.files.fm/u/h2fkqwe7

35

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

У меня без задержи проигрывается.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

36

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

То есть не за 4 секунды?

37

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Вот видео снял.

Post's attachments

test.mp4 1.23 mb, 4 downloads since 2019-12-24 

You don't have the permssions to download the attachments of this post.
Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

38 (изменено: Malcev, 2019-12-24 18:08:12)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Странно, гиф у тебя зацикливается, хотя в нем такого флага не стоит.
Надо попробовать еще глобальные метаданные вписать - может тогда распознает.

39

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Вот код на gdiplus, определяющий задержку — определяет:

Gdip := new GDIplus
pBitmap := Gdip.CreateBitmapFromFile("D:\Downloads\test.gif")
arr := Gdip.GetFrameDelay(pBitmap)
Gdip.DisposeImage(pBitmap)
Gdip := ""
for k, v in arr
   MsgBox, % v

class GDIplus  {
   __New() {
      if !DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
         DllCall("LoadLibrary", Str, "gdiplus")
      VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
      DllCall("gdiplus\GdiplusStartup", UPtrP, pToken, Ptr, &si, Ptr, 0)
      this.token := pToken
   }
   
   __Delete()  {
      DllCall("gdiplus\GdiplusShutdown", Ptr, this.token)
      if hModule := DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
         DllCall("FreeLibrary", Ptr, hModule)
   }
   
   CreateBitmapFromFile(sFile)  {
      DllCall("gdiplus\GdipCreateBitmapFromFile", WStr, sFile, PtrP, pBitmap)
      Return pBitmap
   }
   
   DisposeImage(pBitmap)  {
      return DllCall("gdiplus\GdipDisposeImage", Ptr, pBitmap)
   }
   
   GetFrameDelay(pImage) {
      static PropertyTagFrameDelay := 0x5100

      DllCall("Gdiplus\GdipGetPropertyItemSize", "Ptr", pImage, "UInt", PropertyTagFrameDelay, "UInt*", ItemSize)
      VarSetCapacity(Item, ItemSize, 0)
      DllCall("Gdiplus\GdipGetPropertyItem"    , "Ptr", pImage, "UInt", PropertyTagFrameDelay, "UInt", ItemSize, "Ptr", &Item)

      PropLen := NumGet(Item, 4, "UInt")
      PropVal := NumGet(Item, 8 + A_PtrSize, "UPtr")

      outArray := []
      Loop, % PropLen//4 {
         if !n := NumGet(PropVal+0, (A_Index-1)*4, "UInt")
            n := 10
         outArray[A_Index-1] := n * 10
      }
      return outArray
   }
}
Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

40 (изменено: Malcev, 2019-12-25 20:56:51)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Попробуй так (вписал глобальные метаданные + добавил IWICPalette для конвертирования в GUID_WICPixelFormat8bppIndexed).

; Script Requirements:
;
;   DirectX - March 2008 or later. (d3dx9_37.dll)
;     DirectX End-User Runtime Web Installer (March 2008):
;     http://www.microsoft.com/downloads/details.aspx?FamilyId=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&displaylang=en
;
file := "test.gif"
width := 500, height := 300
video_fps := 25


setbatchlines -1

; init D3D and get screen size
d3d := Direct3DCreate9(D3D_SDK_VERSION := 32) 
if !d3d
{
    MsgBox, 16, Error, Direct3DCreate9 failed.
    ExitApp
}
VarSetCapacity(D3DDISPLAYMODE, 16, 0)
IDirect3D9_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT := 0, &D3DDISPLAYMODE)
Windowed := true
BackBufferCount := 1
BackBufferHeight := NumGet(D3DDISPLAYMODE, 4, "uint")
BackBufferWidth := NumGet(D3DDISPLAYMODE, 0, "uint")
SwapEffect := 1   ; D3DSWAPEFFECT_DISCARD
hDeviceWindow := 0

; create device & capture surface
VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0) 
NumPut(BackBufferWidth, D3DPRESENT_PARAMETERS, 0)
NumPut(BackBufferHeight, D3DPRESENT_PARAMETERS, 4)
NumPut(BackBufferCount, D3DPRESENT_PARAMETERS, 12)
NumPut(SwapEffect, D3DPRESENT_PARAMETERS, 24)
NumPut(hDeviceWindow, D3DPRESENT_PARAMETERS, 24+A_PtrSize)
NumPut(Windowed, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)
IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT := 0, D3DDEVTYPE_HAL := 1, 0, D3DCREATE_SOFTWARE_VERTEXPROCESSING := 0x00000020, &D3DPRESENT_PARAMETERS, device)
IDirect3DDevice9_CreateOffscreenPlainSurface(device, BackBufferWidth, BackBufferHeight, D3DFMT_A8R8G8B8 := 21, D3DPOOL_SYSTEMMEM := 2, surface, 0)

if !wic
   wic := IWICCreate()
IWICImagingFactory_CreateStream(wic, stream)
IWICStream_InitializeFromFilename(stream, file, GENERIC_WRITE := 0x40000000)
IWICImagingFactory_CreateEncoder(wic, WIC_GUID(GUID, "GUID_ContainerFormatGif"), 0, encoder)
IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache := 0x2)
IWICBitmapEncoder_GetMetadataQueryWriter(encoder, pEncoderMetadataQueryWriter)

VarSetCapacity(pElems, 11, 0)
NumPut(asc("N"), pElems, 0, "uchar")
NumPut(asc("E"), pElems, 1, "uchar")
NumPut(asc("T"), pElems, 2, "uchar")
NumPut(asc("S"), pElems, 3, "uchar")
NumPut(asc("C"), pElems, 4, "uchar")
NumPut(asc("A"), pElems, 5, "uchar")
NumPut(asc("P"), pElems, 6, "uchar")
NumPut(asc("E"), pElems, 7, "uchar")
NumPut(asc("2"), pElems, 8, "uchar")
NumPut(asc("."), pElems, 9, "uchar")
NumPut(asc("0"), pElems, 10, "uchar")
VarSetCapacity(PROPVARIANT, A_PtrSize*2+8, 0)
NumPut(VT_UI1 := 0x11|VT_VECTOR := 0x1000, PROPVARIANT, 0, "ushort")
NumPut(11, PROPVARIANT, 8, "uint")
NumPut(&pElems, PROPVARIANT, 8+A_PtrSize, "ptr")
IWICMetadataQueryWriter_SetMetadataByName(pEncoderMetadataQueryWriter, "/appext/Application", &PROPVARIANT)

VarSetCapacity(pElems, 0)
VarSetCapacity(pElems, 5, 0)
NumPut(3, pElems, 0, "uchar")
NumPut(1, pElems, 1, "uchar")
NumPut(0, pElems, 2, "uchar")
NumPut(0, pElems, 3, "uchar")
NumPut(0, pElems, 4, "uchar")
NumPut(5, PROPVARIANT, 8, "uint")
NumPut(&pElems, PROPVARIANT, 8+A_PtrSize, "ptr")
IWICMetadataQueryWriter_SetMetadataByName(pEncoderMetadataQueryWriter, "/appext/Data", &PROPVARIANT)
Release(pEncoderMetadataQueryWriter)
pEncoderMetadataQueryWriter := ""
VarSetCapacity(PROPVARIANT, A_PtrSize*2+8, 0)
NumPut(VT_UI2 := 0x12, PROPVARIANT, 0, "ushort")
NumPut(delay := 4, PROPVARIANT, 8, "ushort")

fps := 1000/video_fps
a := A_TickCount
loop 100
{
   DllCall("Winmm\timeBeginPeriod", "UInt", 3)
   if (A_Index = 1)
      timeElapsed := A_TickCount
   else
   {
      loop
      {
         if (A_TickCount - timeElapsed >= fps)
         {
            timeElapsed+=fps
            break
         }
         DllCall("Sleep", "UInt", 1)
      }
   }
   DllCall("Winmm\timeEndPeriod", "UInt", 3)

   IDirect3DDevice9_GetFrontBufferData(device, 0, surface)
   VarSetCapacity(D3DLOCKED_RECT, A_PtrSize*2, 0)
   VarSetCapacity(RECT, 16, 0)
   NumPut(width, RECT, 8, "uint")
   NumPut(height, RECT, 12, "uint")
   IDirect3DSurface9_LockRect(surface, &D3DLOCKED_RECT, &RECT, 0)
   pitch := NumGet(D3DLOCKED_RECT, 0, "int")
   pBits := NumGet(D3DLOCKED_RECT, A_PtrSize, "ptr")

   IWICImagingFactory_CreateBitmapFromMemory(wic, width, height, WIC_GUID(GUID, "GUID_WICPixelFormat32bppBGRA"), pitch, pitch * height, pBits, Bitmap)
   IWICImagingFactory_CreatePalette(wic, pPalette)
   IWICPalette_InitializeFromBitmap(pPalette, Bitmap, 256, 1)
   IWICImagingFactory_CreateFormatConverter(wic, FormatConverter)
   IWICFormatConverter_Initialize(FormatConverter, bitmap, WIC_GUID(GUID, "GUID_WICPixelFormat8bppIndexed"), WICBitmapDitherTypeErrorDiffusion := 0x00000008, pPalette, 0, WICBitmapPaletteTypeMedianCut := 1)
   IWICBitmapEncoder_CreateNewFrame(encoder, frame)
   IWICBitmapFrameEncode_Initialize(frame)
   IWICBitmapFrameEncode_WriteSource(frame, FormatConverter, 0)
   IWICBitmapFrameEncode_GetMetadataQueryWriter(frame, ppIMetadataQueryWriter)
   IWICBitmapFrameEncode_Commit(frame)
   IWICMetadataQueryWriter_SetMetadataByName(ppIMetadataQueryWriter, "/grctlext/Delay", &PROPVARIANT)
   Release(ppIMetadataQueryWriter)
   Release(pPalette)
   Release(Bitmap)
   Release(FormatConverter)
   Release(frame)
   ppIMetadataQueryWriter := pPalette := Bitmap := FormatConverter := frame := ""

   IDirect3DSurface9_UnlockRect(surface)
}
IWICBitmapEncoder_Commit(encoder)
Release(encoder)
Release(stream)
Release(surface)
Release(device)
Release(d3d)
encoder := stream := surface := device := d3d := ""
msgbox % A_TickCount - a
ExitApp




Direct3DCreate9(SDKVersion) {
 	DllCall("LoadLibrary","str","Windowscodecs.dll")
    if !DllCall("GetModuleHandle","str","d3d9")
        DllCall("LoadLibrary","str","d3d9")
    return DllCall("d3d9\Direct3DCreate9", "uint", SDKVersion)
}

IDirect3D9_GetAdapterDisplayMode(this,Adapter,pMode)
{
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize),"ptr",this,"uint",Adapter,"ptr",pMode)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3D9_CreateDevice(this,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ByRef ppReturnedDeviceInterface)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize),"ptr",this,"uint",Adapter,"uint",DeviceType,"ptr",hFocusWindow,"uint",BehaviorFlags,"ptr",pPresentationParameters,"ptr*",ppReturnedDeviceInterface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DDevice9_GetFrontBufferData(this,iSwapChain,pDestSurface)
{
   hr := DllCall(NumGet(NumGet(this+0)+33*A_PtrSize),"ptr",this,"uint",iSwapChain,"ptr",pDestSurface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DDevice9_CreateOffscreenPlainSurface(this,Width,Height,Format,Pool,ByRef ppSurface,pSharedHandle)
{
   hr := DllCall(NumGet(NumGet(this+0)+36*A_PtrSize),"ptr",this,"uint",Width,"uint",Height,"uint",Format,"uint",Pool,"ptr*",ppSurface,"ptr",pSharedHandle)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DSurface9_LockRect(this,pLockedRect,pRect,Flags)
{
   hr := DllCall(NumGet(NumGet(this+0)+13*A_PtrSize),"ptr",this,"ptr",pLockedRect,"ptr",pRect,"uint",Flags)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IDirect3DSurface9_UnlockRect(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+14*A_PtrSize),"ptr",this)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

QueryInterface(ComObject, SID, ByRef InterfacePointer)
{
   InterfacePointer := ComObjQuery(ComObject, SID)
   if !InterfacePointer or ErrorLevel
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

Release(this)
{
   DllCall(NumGet(NumGet(this+0)+2*A_PtrSize), "ptr", this)
   if ErrorLevel
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

GUID(ByRef GUID, sGUID)
{
    VarSetCapacity(GUID, 16, 0)
    return DllCall("ole32\CLSIDFromString", "WStr", sGUID, "Ptr", &GUID) >= 0 ? &GUID : ""
}

_Error(val)
{
   msgbox % val
   ExitApp
}


IWICCreate()
{
   return ComObjCreate("{cacaf262-9370-4615-a13b-9f5539da4c0a}", "{ec5ec8a9-c395-4314-9c77-54d7a935ff70}")
}

IWICImagingFactory_CreateStream(this, ByRef ppIWICStream)
{
   hr := DllCall(NumGet(NumGet(this+0)+14*A_PtrSize), "ptr", this, "ptr*", ppIWICStream)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateFormatConverter(this, ByRef ppIFormatConverter)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "ptr*", ppIFormatConverter)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateBitmapScaler(this, ByRef ppIBitmapScaler)
{
   hr := DllCall(NumGet(NumGet(this+0)+11*A_PtrSize), "ptr", this, "ptr*", ppIBitmapScaler)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICStream_InitializeFromFilename(this, wzFileName, dwDesiredAccess)
{
   hr := DllCall(NumGet(NumGet(this+0)+15*A_PtrSize), "ptr", this, "str", wzFileName, "uint", dwDesiredAccess)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateEncoder(this, guidContainerFormat, pguidVendor, ByRef ppIEncoder)
{
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize), "ptr", this, "ptr", guidContainerFormat, "ptr", pguidVendor, "ptr*", ppIEncoder)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_Initialize(this, pIStream, cacheOption)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), "ptr", this, "ptr", pIStream, "int", cacheOption)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_CreateNewFrame(this, ByRef ppIFrameEncode, ppIEncoderOptions := 0)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "ptr*", ppIFrameEncode, "ptr*", ppIEncoderOptions)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_Commit(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+11*A_PtrSize), "ptr", this)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_Initialize(this, pIEncoderOptions := 0)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), "ptr", this, "ptr", pIEncoderOptions)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_SetSize(this, uiWidth, uiHeight)
{
   hr := DllCall(NumGet(NumGet(this+0)+4*A_PtrSize), "ptr", this, "uint", uiWidth, "uint", uiHeight)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_WritePixels(this, lineCount, cbStride, cbBufferSize, pbPixels)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), "ptr", this, "uint", lineCount, "uint", cbStride, "uint", cbBufferSize, "ptr", pbPixels)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_Commit(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+12*A_PtrSize), "ptr", this)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_WriteSource(this, pIBitmapSource, prc)
{
   hr := DllCall(NumGet(NumGet(this+0)+11*A_PtrSize), "ptr", this, "ptr", pIBitmapSource, "ptr", prc)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreateBitmapFromMemory(this, uiWidth, uiHeight, pixelFormat, cbStride, cbBufferSize, pbBuffer, ByRef ppIBitmap)
{
   hr := DllCall(NumGet(NumGet(this+0)+20*A_PtrSize), "ptr", this, "uint", uiWidth, "uint", uiHeight, "ptr", pixelFormat, "uint", cbStride, "uint", cbBufferSize, "ptr", pbBuffer, "ptr*", ppIBitmap)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICFormatConverter_Initialize(this, pISource, dstFormat, dither, pIPalette, alphaThresholdPercent, paletteTranslate)
{
   dstFormat := WIC_GUID(GUID, dstFormat)
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize), "ptr", this, "ptr", pISource, "ptr", dstFormat, "uint", dither, "ptr", pIPalette, "double", alphaThresholdPercent, "uint", alphaThresholdPercent)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICFormatConverter_CanConvert(this, srcPixelFormat, dstPixelFormat)
{
   hr := DllCall(NumGet(NumGet(this+0)+9*A_PtrSize), "ptr", this, "ptr", srcPixelFormat, "ptr", dstPixelFormat, "ptr*", pfCanConvert)
   if hr or ErrorLevel or !pfCanConvert
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel "`npfCanConvert=0")
}

IWICBitmapFrameEncode_SetPixelFormat(this, ByRef pPixelFormat)
{
   hr := DllCall(NumGet(NumGet(this+0)+6*A_PtrSize), "ptr", this, "ptr*", pPixelFormat)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IWICBitmapEncoder_GetMetadataQueryWriter(this, ByRef ppIMetadataQueryWriter)
{
   hr := DllCall(NumGet(NumGet(this+0)+12*A_PtrSize), "ptr", this, "ptr*", ppIMetadataQueryWriter)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICBitmapFrameEncode_GetMetadataQueryWriter(this, ByRef ppIMetadataQueryWriter)
{
   hr := DllCall(NumGet(NumGet(this+0)+13*A_PtrSize), "ptr", this, "ptr*", ppIMetadataQueryWriter)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICMetadataQueryWriter_SetMetadataByName(this, wzName, pvarValue)
{
   hr := DllCall(NumGet(NumGet(this+0)+7*A_PtrSize), "ptr", this, "wstr", wzName, "ptr", pvarValue)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICPalette_InitializeFromBitmap(this, pISurface, cCount, fAddTransparentColor)
{
   hr := DllCall(NumGet(NumGet(this+0)+5*A_PtrSize), "ptr", this, "ptr", pISurface, "uint", cCount, "int", fAddTransparentColor)
   if hr or ErrorLevel
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}

IWICImagingFactory_CreatePalette(this, ByRef ppIPalette)	
{
   hr := DllCall(NumGet(NumGet(this+0)+9*A_PtrSize), "ptr", this, "ptr*", ppIPalette)
   if hr
      _Error(A_ThisFunc " error: " WIC_hr(hr) "`nErrorLevel: " ErrorLevel)
}



WIC_GUID(ByRef GUID,name){
	static init:=1,_:={}
	if init {
	init:=0
	; Decoders
	 _.CLSID_WICBmpDecoder:=[0x6b462062, 0x7cbf, 0x400d, 0x9f, 0xdb, 0x81, 0x3d, 0xd1, 0xf, 0x27, 0x78]
	,_.CLSID_WICPngDecoder:=[0x389ea17b, 0x5078, 0x4cde, 0xb6, 0xef, 0x25, 0xc1, 0x51, 0x75, 0xc7, 0x51]
	,_.CLSID_WICIcoDecoder:=[0xc61bfcdf, 0x2e0f, 0x4aad, 0xa8, 0xd7, 0xe0, 0x6b, 0xaf, 0xeb, 0xcd, 0xfe]
	,_.CLSID_WICJpegDecoder:=[0x9456a480, 0xe88b, 0x43ea, 0x9e, 0x73, 0xb, 0x2d, 0x9b, 0x71, 0xb1, 0xca]
	,_.CLSID_WICGifDecoder:=[0x381dda3c, 0x9ce9, 0x4834, 0xa2, 0x3e, 0x1f, 0x98, 0xf8, 0xfc, 0x52, 0xbe]
	,_.CLSID_WICTiffDecoder:=[0xb54e85d9, 0xfe23, 0x499f, 0x8b, 0x88, 0x6a, 0xce, 0xa7, 0x13, 0x75, 0x2b]
	,_.CLSID_WICWmpDecoder:=[0xa26cec36, 0x234c, 0x4950, 0xae, 0x16, 0xe3, 0x4a, 0xac, 0xe7, 0x1d, 0x0d]
	; Encoders
	 _.CLSID_WICBmpEncoder:=[0x69be8bb4, 0xd66d, 0x47c8, 0x86, 0x5a, 0xed, 0x15, 0x89, 0x43, 0x37, 0x82]
	,_.CLSID_WICPngEncoder:=[0x27949969, 0x876a, 0x41d7, 0x94, 0x47, 0x56, 0x8f, 0x6a, 0x35, 0xa4, 0xdc]
	,_.CLSID_WICJpegEncoder:=[0x1a34f5c1, 0x4a5a, 0x46dc, 0xb6, 0x44, 0x1f, 0x45, 0x67, 0xe7, 0xa6, 0x76]
	,_.CLSID_WICGifEncoder:=[0x114f5598, 0xb22, 0x40a0, 0x86, 0xa1, 0xc8, 0x3e, 0xa4, 0x95, 0xad, 0xbd]
	,_.CLSID_WICTiffEncoder:=[0x0131be10, 0x2001, 0x4c5f, 0xa9, 0xb0, 0xcc, 0x88, 0xfa, 0xb6, 0x4c, 0xe8]
	,_.CLSID_WICWmpEncoder:=[0xac4ce3cb, 0xe1c1, 0x44cd, 0x82, 0x15, 0x5a, 0x16, 0x65, 0x50, 0x9e, 0xc2]
	; Container Formats
	 _.GUID_ContainerFormatBmp:=[0xaf1d87e, 0xfcfe, 0x4188, 0xbd, 0xeb, 0xa7, 0x90, 0x64, 0x71, 0xcb, 0xe3]
	,_.GUID_ContainerFormatPng:=[0x1b7cfaf4, 0x713f, 0x473c, 0xbb, 0xcd, 0x61, 0x37, 0x42, 0x5f, 0xae, 0xaf]
	,_.GUID_ContainerFormatIco:=[0xa3a860c4, 0x338f, 0x4c17, 0x91, 0x9a, 0xfb, 0xa4, 0xb5, 0x62, 0x8f, 0x21]
	,_.GUID_ContainerFormatJpeg:=[0x19e4a5aa, 0x5662, 0x4fc5, 0xa0, 0xc0, 0x17, 0x58, 0x2, 0x8e, 0x10, 0x57]
	,_.GUID_ContainerFormatTiff:=[0x163bcc30, 0xe2e9, 0x4f0b, 0x96, 0x1d, 0xa3, 0xe9, 0xfd, 0xb7, 0x88, 0xa3]
	,_.GUID_ContainerFormatGif:=[0x1f8a5601, 0x7d4d, 0x4cbd, 0x9c, 0x82, 0x1b, 0xc8, 0xd4, 0xee, 0xb9, 0xa5]
	,_.GUID_ContainerFormatWmp:=[0x57a37caa, 0x367a, 0x4540, 0x91, 0x6b, 0xf1, 0x83, 0xc5, 0x09, 0x3a, 0x4b]
	; Component Identifiers
	 _.CLSID_WICImagingCategories:=[0xfae3d380, 0xfea4, 0x4623, 0x8c, 0x75, 0xc6, 0xb6, 0x11, 0x10, 0xb6, 0x81]
	,_.CATID_WICBitmapDecoders:=[0x7ed96837, 0x96f0, 0x4812, 0xb2, 0x11, 0xf1, 0x3c, 0x24, 0x11, 0x7e, 0xd3]
	,_.CATID_WICBitmapEncoders:=[0xac757296, 0x3522, 0x4e11, 0x98, 0x62, 0xc1, 0x7b, 0xe5, 0xa1, 0x76, 0x7e]
	,_.CATID_WICPixelFormats:=[0x2b46e70f, 0xcda7, 0x473e, 0x89, 0xf6, 0xdc, 0x96, 0x30, 0xa2, 0x39, 0x0b]
	,_.CATID_WICFormatConverters:=[0x7835eae8, 0xbf14, 0x49d1, 0x93, 0xce, 0x53, 0x3a, 0x40, 0x7b, 0x22, 0x48]
	,_.CATID_WICMetadataReader:=[0x05af94d8, 0x7174, 0x4cd2, 0xbe, 0x4a, 0x41, 0x24, 0xb8, 0x0e, 0xe4, 0xb8]
	,_.CATID_WICMetadataWriter:=[0xabe3b9a4, 0x257d, 0x4b97, 0xbd, 0x1a, 0x29, 0x4a, 0xf4, 0x96, 0x22, 0x2e]
	; Format Converters
	 _.CLSID_WICDefaultFormatConverter:=[0x1a3f11dc, 0xb514, 0x4b17, 0x8c, 0x5f, 0x21, 0x54, 0x51, 0x38, 0x52, 0xf1]
	,_.CLSID_WICFormatConverterHighColor:=[0xac75d454, 0x9f37, 0x48f8, 0xb9, 0x72, 0x4e, 0x19, 0xbc, 0x85, 0x60, 0x11]
	,_.CLSID_WICFormatConverterNChannel:=[0xc17cabb2, 0xd4a3, 0x47d7, 0xa5, 0x57, 0x33, 0x9b, 0x2e, 0xfb, 0xd4, 0xf1]
	,_.CLSID_WICFormatConverterWMPhoto:=[0x9cb5172b, 0xd600, 0x46ba, 0xab, 0x77, 0x77, 0xbb, 0x7e, 0x3a, 0x00, 0xd9]
	; Metadata Handlers
	 _.GUID_MetadataFormatUnknown:=[0xA45E592F, 0x9078, 0x4A7C, 0xAD, 0xB5, 0x4E, 0xDC, 0x4F, 0xD6, 0x1B, 0x1F]
	,_.GUID_MetadataFormatIfd:=[0x537396C6, 0x2D8A, 0x4BB6, 0x9B, 0xF8, 0x2F, 0x0A, 0x8E, 0x2A, 0x3A, 0xDF]
	,_.GUID_MetadataFormatSubIfd:=[0x58A2E128, 0x2DB9, 0x4E57, 0xBB, 0x14, 0x51, 0x77, 0x89, 0x1E, 0xD3, 0x31]
	,_.GUID_MetadataFormatExif:=[0x1C3C4F9D, 0xB84A, 0x467D, 0x94, 0x93, 0x36, 0xCF, 0xBD, 0x59, 0xEA, 0x57]
	,_.GUID_MetadataFormatGps:=[0x7134AB8A, 0x9351, 0x44AD, 0xAF, 0x62, 0x44, 0x8D, 0xB6, 0xB5, 0x02, 0xEC]
	,_.GUID_MetadataFormatInterop:=[0xED686F8E, 0x681F, 0x4C8B, 0xBD, 0x41, 0xA8, 0xAD, 0xDB, 0xF6, 0xB3, 0xFC]
	,_.GUID_MetadataFormatApp0:=[0x79007028, 0x268D, 0x45d6, 0xA3, 0xC2, 0x35, 0x4E, 0x6A, 0x50, 0x4B, 0xC9]
	,_.GUID_MetadataFormatApp1:=[0x8FD3DFC3, 0xF951, 0x492B, 0x81, 0x7F, 0x69, 0xC2, 0xE6, 0xD9, 0xA5, 0xB0]
	,_.GUID_MetadataFormatApp13:=[0x326556A2, 0xF502, 0x4354, 0x9C, 0xC0, 0x8E, 0x3F, 0x48, 0xEA, 0xF6, 0xB5]
	,_.GUID_MetadataFormatIPTC:=[0x4FAB0914, 0xE129, 0x4087, 0xA1, 0xD1, 0xBC, 0x81, 0x2D, 0x45, 0xA7, 0xB5]
	,_.GUID_MetadataFormatIRB:=[0x16100D66, 0x8570, 0x4BB9, 0xB9, 0x2D, 0xFD, 0xA4, 0xB2, 0x3E, 0xCE, 0x67]
	,_.GUID_MetadataFormat8BIMIPTC:=[0x0010568c, 0x0852, 0x4e6a, 0xb1, 0x91, 0x5c, 0x33, 0xac, 0x5b, 0x04, 0x30]
	,_.GUID_MetadataFormat8BIMResolutionInfo:=[0x739F305D, 0x81DB, 0x43CB, 0xAC, 0x5E, 0x55, 0x01, 0x3E, 0xF9, 0xF0, 0x03]
	 _.GUID_MetadataFormat8BIMIPTCDigest:=[0x1CA32285, 0x9CCD, 0x4786, 0x8B, 0xD8, 0x79, 0x53, 0x9D, 0xB6, 0xA0, 0x06]
	,_.GUID_MetadataFormatXMP:=[0xBB5ACC38, 0xF216, 0x4CEC, 0xA6, 0xC5, 0x5F, 0x6E, 0x73, 0x97, 0x63, 0xA9]
	,_.GUID_MetadataFormatThumbnail:=[0x243dcee9, 0x8703, 0x40ee, 0x8e, 0xf0, 0x22, 0xa6, 0x0, 0xb8, 0x5, 0x8c]
	,_.GUID_MetadataFormatChunktEXt:=[0x568d8936, 0xc0a9, 0x4923, 0x90, 0x5d, 0xdf, 0x2b, 0x38, 0x23, 0x8f, 0xbc]
	,_.GUID_MetadataFormatXMPStruct:=[0x22383CF1, 0xED17, 0x4E2E, 0xAF, 0x17, 0xD8, 0x5B, 0x8F, 0x6B, 0x30, 0xD0]
	,_.GUID_MetadataFormatXMPBag:=[0x833CCA5F, 0xDCB7, 0x4516, 0x80, 0x6F, 0x65, 0x96, 0xAB, 0x26, 0xDC, 0xE4]
	,_.GUID_MetadataFormatXMPSeq:=[0x63E8DF02, 0xEB6C,0x456C, 0xA2, 0x24, 0xB2, 0x5E, 0x79, 0x4F, 0xD6, 0x48]
	,_.GUID_MetadataFormatXMPAlt:=[0x7B08A675, 0x91AA, 0x481B, 0xA7, 0x98, 0x4D, 0xA9, 0x49, 0x08, 0x61, 0x3B]
	,_.GUID_MetadataFormatLSD:=[0xE256031E, 0x6299, 0x4929, 0xB9, 0x8D, 0x5A, 0xC8, 0x84, 0xAF, 0xBA, 0x92]
	,_.GUID_MetadataFormatIMD:=[0xBD2BB086, 0x4D52, 0x48DD, 0x96, 0x77, 0xDB, 0x48, 0x3E, 0x85, 0xAE, 0x8F]
	,_.GUID_MetadataFormatGCE:=[0x2A25CAD8, 0xDEEB, 0x4C69, 0xA7, 0x88, 0xE, 0xC2, 0x26, 0x6D, 0xCA, 0xFD]
	,_.GUID_MetadataFormatAPE:=[0x2E043DC2, 0xC967, 0x4E05, 0x87, 0x5E, 0x61, 0x8B, 0xF6, 0x7E, 0x85, 0xC3]
	 _.GUID_MetadataFormatJpegChrominance:=[0xF73D0DCF, 0xCEC6, 0x4F85, 0x9B, 0x0E, 0x1C, 0x39, 0x56, 0xB1, 0xBE, 0xF7]
	,_.GUID_MetadataFormatJpegLuminance:=[0x86908007, 0xEDFC, 0x4860, 0x8D, 0x4B, 0x4E, 0xE6, 0xE8, 0x3E, 0x60, 0x58]
	,_.GUID_MetadataFormatJpegComment:=[0x220E5F33, 0xAFD3, 0x474E, 0x9D, 0x31, 0x7D, 0x4F, 0xE7, 0x30, 0xF5, 0x57]
	,_.GUID_MetadataFormatGifComment:=[0xC4B6E0E0, 0xCFB4, 0x4AD3, 0xAB, 0x33, 0x9A, 0xAD, 0x23, 0x55, 0xA3, 0x4A]
	,_.GUID_MetadataFormatChunkgAMA:=[0xF00935A5, 0x1D5D, 0x4CD1, 0x81, 0xB2, 0x93, 0x24, 0xD7, 0xEC, 0xA7, 0x81]
	,_.GUID_MetadataFormatChunkbKGD:=[0xE14D3571, 0x6B47, 0x4DEA, 0xB6, 0xA, 0x87, 0xCE, 0xA, 0x78, 0xDF, 0xB7]
	,_.GUID_MetadataFormatChunkiTXt:=[0xC2BEC729, 0xB68, 0x4B77, 0xAA, 0xE, 0x62, 0x95, 0xA6, 0xAC, 0x18, 0x14]
	,_.GUID_MetadataFormatChunkcHRM:=[0x9DB3655B, 0x2842, 0x44B3, 0x80, 0x67, 0x12, 0xE9, 0xB3, 0x75, 0x55, 0x6A]
	,_.GUID_MetadataFormatChunkhIST:=[0xC59A82DA, 0xDB74, 0x48A4, 0xBD, 0x6A, 0xB6, 0x9C, 0x49, 0x31, 0xEF, 0x95]
	,_.GUID_MetadataFormatChunkiCCP:=[0xEB4349AB, 0xB685, 0x450F, 0x91, 0xB5, 0xE8, 0x2, 0xE8, 0x92, 0x53, 0x6C]
	,_.GUID_MetadataFormatChunksRGB:=[0xC115FD36, 0xCC6F, 0x4E3F, 0x83, 0x63, 0x52, 0x4B, 0x87, 0xC6, 0xB0, 0xD9]
	,_.GUID_MetadataFormatChunktIME:=[0x6B00AE2D, 0xE24B, 0x460A, 0x98, 0xB6, 0x87, 0x8B, 0xD0, 0x30, 0x72, 0xFD]
	; Vendor Identification
	 _.GUID_VendorMicrosoft:=[0x69fd0fdc, 0xa866, 0x4108, 0xb3, 0xb2, 0x98, 0x44, 0x7f, 0xa9, 0xed, 0xd4]
	,_.GUID_VendorMicrosoftBuiltIn:=[0x257a30fd, 0x6b6, 0x462b, 0xae, 0xa4, 0x63, 0xf7, 0xb, 0x86, 0xe5, 0x33]
	; WICBitmapPaletteType
	 _.GUID_WICPixelFormatDontCare:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x00]
	,_.GUID_WICPixelFormat1bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x01]
	,_.GUID_WICPixelFormat2bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x02]
	,_.GUID_WICPixelFormat4bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x03]
	,_.GUID_WICPixelFormat8bppIndexed:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x04]
	,_.GUID_WICPixelFormatBlackWhite:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x05]
	,_.GUID_WICPixelFormat2bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x06]
	,_.GUID_WICPixelFormat4bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x07]
	,_.GUID_WICPixelFormat8bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x08]
	,_.GUID_WICPixelFormat8bppAlpha:=[0xe6cd0116, 0xeeba, 0x4161, 0xaa, 0x85, 0x27, 0xdd, 0x9f, 0xb3, 0xa8, 0x95]
	,_.GUID_WICPixelFormat16bppBGR555:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x09]
	,_.GUID_WICPixelFormat16bppBGR565:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0a]
	,_.GUID_WICPixelFormat16bppBGRA5551:=[0x05ec7c2b, 0xf1e6, 0x4961, 0xad, 0x46, 0xe1, 0xcc, 0x81, 0x0a, 0x87, 0xd2]
	 _.GUID_WICPixelFormat16bppGray:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0b]
	,_.GUID_WICPixelFormat24bppBGR:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0c]
	,_.GUID_WICPixelFormat24bppRGB:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0d]
	,_.GUID_WICPixelFormat32bppBGR:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0e]
	,_.GUID_WICPixelFormat32bppBGRA:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0f]
	,_.GUID_WICPixelFormat32bppPBGRA:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x10]
	,_.GUID_WICPixelFormat32bppGrayFloat:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x11]
	,_.GUID_WICPixelFormat32bppRGBA:=[0xf5c7ad2d, 0x6a8d, 0x43dd, 0xa7, 0xa8, 0xa2, 0x99, 0x35, 0x26, 0x1a, 0xe9]
	,_.GUID_WICPixelFormat32bppPRGBA:=[0x3cc4a650, 0xa527, 0x4d37, 0xa9, 0x16, 0x31, 0x42, 0xc7, 0xeb, 0xed, 0xba]
	,_.GUID_WICPixelFormat48bppRGB:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x15]
	,_.GUID_WICPixelFormat48bppBGR:=[0xe605a384, 0xb468, 0x46ce, 0xbb, 0x2e, 0x36, 0xf1, 0x80, 0xe6, 0x43, 0x13]
	,_.GUID_WICPixelFormat64bppRGBA:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x16]
	,_.GUID_WICPixelFormat64bppBGRA:=[ 0x1562ff7c, 0xd352, 0x46f9, 0x97, 0x9e, 0x42, 0x97, 0x6b, 0x79, 0x22, 0x46]
	 _.GUID_WICPixelFormat64bppPRGBA:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x17]
	,_.GUID_WICPixelFormat64bppPBGRA:=[0x8c518e8e, 0xa4ec, 0x468b, 0xae, 0x70, 0xc9, 0xa3, 0x5a, 0x9c, 0x55, 0x30]
	,_.GUID_WICPixelFormat16bppGrayFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x13]
	,_.GUID_WICPixelFormat32bppBGR101010:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x14]
	,_.GUID_WICPixelFormat48bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x12]
	,_.GUID_WICPixelFormat48bppBGRFixedPoint:=[0x49ca140e, 0xcab6, 0x493b, 0x9d, 0xdf, 0x60, 0x18, 0x7c, 0x37, 0x53, 0x2a]
	,_.GUID_WICPixelFormat96bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x18]
	,_.GUID_WICPixelFormat128bppRGBAFloat:=[ 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x19]
	,_.GUID_WICPixelFormat128bppPRGBAFloat:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1a]
	,_.GUID_WICPixelFormat128bppRGBFloat:=[  0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1b]
	,_.GUID_WICPixelFormat32bppCMYK:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1c]
	,_.GUID_WICPixelFormat64bppRGBAFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1d]
	,_.GUID_WICPixelFormat64bppBGRAFixedPoint:=[0x356de33c, 0x54d2, 0x4a23, 0xbb, 0x4, 0x9b, 0x7b, 0xf9, 0xb1, 0xd4, 0x2d]
	 _.GUID_WICPixelFormat64bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x40]
	,_.GUID_WICPixelFormat128bppRGBAFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1e]
	,_.GUID_WICPixelFormat128bppRGBFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x41]
	,_.GUID_WICPixelFormat64bppRGBAHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3a]
	,_.GUID_WICPixelFormat64bppRGBHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x42]
	,_.GUID_WICPixelFormat48bppRGBHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3b]
	,_.GUID_WICPixelFormat32bppRGBE:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3d]
	,_.GUID_WICPixelFormat16bppGrayHalf:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3e]
	,_.GUID_WICPixelFormat32bppGrayFixedPoint:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3f]
	,_.GUID_WICPixelFormat32bppRGBA1010102:=[0x25238D72, 0xFCF9, 0x4522, 0xb5, 0x14, 0x55, 0x78, 0xe5, 0xad, 0x55, 0xe0]
	,_.GUID_WICPixelFormat32bppRGBA1010102XR:=[0x00DE6B9A, 0xC101, 0x434b, 0xb5, 0x02, 0xd0, 0x16, 0x5e, 0xe1, 0x12, 0x2c]
	,_.GUID_WICPixelFormat64bppCMYK:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1f]
	,_.GUID_WICPixelFormat24bpp3Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x20]
	 _.GUID_WICPixelFormat32bpp4Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x21]
	,_.GUID_WICPixelFormat40bpp5Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x22]
	,_.GUID_WICPixelFormat48bpp6Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x23]
	,_.GUID_WICPixelFormat56bpp7Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x24]
	,_.GUID_WICPixelFormat64bpp8Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x25]
	,_.GUID_WICPixelFormat48bpp3Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x26]
	,_.GUID_WICPixelFormat64bpp4Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x27]
	,_.GUID_WICPixelFormat80bpp5Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x28]
	,_.GUID_WICPixelFormat96bpp6Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x29]
	,_.GUID_WICPixelFormat112bpp7Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2a]
	,_.GUID_WICPixelFormat128bpp8Channels:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2b]
	,_.GUID_WICPixelFormat40bppCMYKAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2c]
	,_.GUID_WICPixelFormat80bppCMYKAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2d]
	,_.GUID_WICPixelFormat32bpp3ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2e]
	 _.GUID_WICPixelFormat40bpp4ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2f]
	,_.GUID_WICPixelFormat48bpp5ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x30]
	,_.GUID_WICPixelFormat56bpp6ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x31]
	,_.GUID_WICPixelFormat64bpp7ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x32]
	,_.GUID_WICPixelFormat72bpp8ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x33]
	,_.GUID_WICPixelFormat64bpp3ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x34]
	,_.GUID_WICPixelFormat80bpp4ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x35]
	,_.GUID_WICPixelFormat96bpp5ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x36]
	,_.GUID_WICPixelFormat112bpp6ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x37]
	,_.GUID_WICPixelFormat128bpp7ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x38]
	,_.GUID_WICPixelFormat144bpp8ChannelsAlpha:=[0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x39]

	}
	if _.haskey(name){
		p:=_[name]
		VarSetCapacity(GUID,16)
		,NumPut(p.1+(p.2<<32)+(p.3<<48),GUID,0,"int64")
		,NumPut(p.4+(p.5<<8)+(p.6<<16)+(p.7<<24)+(p.8<<32)+(p.9<<40)+(p.10<<48)+(p.11<<56),GUID,8,"int64")
		return &GUID
	}else return name
}

WIC_hr(a){
	static init:=1,err:={0x8000FFFF:"Catastrophic failure error.",0x80004001:"Not implemented error.",0x8007000E:"Out of memory error.",0x80070057:"One or more arguments are not valid error.",0x80004002:"Interface not supported error.",0x80004003:"Pointer not valid error.",0x80070006:"Handle not valid error.",0x80004004:"Operation aborted error.",0x80004005:"Unspecified error.",0x80070005:"General access denied error.",0x800401E5:"The object identified by this moniker could not be found."}
	if init{
		init:=0
		 err[0x80004005]:="WINCODEC_ERR_GENERIC_ERROR"
		,err[0x80070057]:="WINCODEC_ERR_INVALIDPARAMETER"
		,err[0x8007000E]:="WINCODEC_ERR_OUTOFMEMORY"
		,err[0x80004001]:="WINCODEC_ERR_NOTIMPLEMENTED"
		,err[0x80004004]:="WINCODEC_ERR_ABORTED"
		,err[0x80070005]:="WINCODEC_ERR_ACCESSDENIED"
		,err[0x88982f04]:="WINCODEC_ERR_WRONGSTATE"
		,err[0x88982f05]:="WINCODEC_ERR_VALUEOUTOFRANGE"
		,err[0x88982f07]:="WINCODEC_ERR_UNKNOWNIMAGEFORMAT"
		,err[0x88982f0B]:="WINCODEC_ERR_UNSUPPORTEDVERSION"
		,err[0x88982f0C]:="WINCODEC_ERR_NOTINITIALIZED"
		,err[0x88982f0D]:="WINCODEC_ERR_ALREADYLOCKED"
		,err[0x88982f40]:="WINCODEC_ERR_PROPERTYNOTFOUND"
		,err[0x88982f41]:="WINCODEC_ERR_PROPERTYNOTSUPPORTED"
		,err[0x88982f42]:="WINCODEC_ERR_PROPERTYSIZE"
		,err[0x88982f43]:="WINCODEC_ERR_CODECPRESENT"
		,err[0x88982f44]:="WINCODEC_ERR_CODECNOTHUMBNAIL"
		,err[0x88982f45]:="WINCODEC_ERR_PALETTEUNAVAILABLE"
		,err[0x88982f46]:="WINCODEC_ERR_CODECTOOMANYSCANLINES"
		,err[0x88982f48]:="WINCODEC_ERR_INTERNALERROR"
		,err[0x88982f49]:="WINCODEC_ERR_SOURCERECTDOESNOTMATCHDIMENSIONS"
		,err[0x88982f50]:="WINCODEC_ERR_COMPONENTNOTFOUND"
		 err[0x88982f51]:="WINCODEC_ERR_IMAGESIZEOUTOFRANGE"
		,err[0x88982f52]:="WINCODEC_ERR_TOOMUCHMETADATA"
		,err[0x88982f60]:="WINCODEC_ERR_BADIMAGE"
		,err[0x88982f61]:="WINCODEC_ERR_BADHEADER"
		,err[0x88982f62]:="WINCODEC_ERR_FRAMEMISSING"
		,err[0x88982f63]:="WINCODEC_ERR_BADMETADATAHEADER"
		,err[0x88982f70]:="WINCODEC_ERR_BADSTREAMDATA"
		,err[0x88982f71]:="WINCODEC_ERR_STREAMWRITE"
		,err[0x88982f72]:="WINCODEC_ERR_STREAMREAD"
		,err[0x88982f73]:="WINCODEC_ERR_STREAMNOTAVAILABLE"
		,err[0x88982f80]:="WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT"
		,err[0x88982f81]:="WINCODEC_ERR_UNSUPPORTEDOPERATION"
		,err[0x88982f8A]:="WINCODEC_ERR_INVALIDREGISTRATION"
		,err[0x88982f8B]:="WINCODEC_ERR_COMPONENTINITIALIZEFAILURE"
		,err[0x88982f8C]:="WINCODEC_ERR_INSUFFICIENTBUFFER"
		,err[0x88982f8D]:="WINCODEC_ERR_DUPLICATEMETADATAPRESENT"
		,err[0x88982f8E]:="WINCODEC_ERR_PROPERTYUNEXPECTEDTYPE"
		,err[0x88982f8F]:="WINCODEC_ERR_UNEXPECTEDSIZE"
		,err[0x88982f90]:="WINCODEC_ERR_INVALIDQUERYREQUEST"
		,err[0x88982f91]:="WINCODEC_ERR_UNEXPECTEDMETADATATYPE"
		,err[0x88982f92]:="WINCODEC_ERR_REQUESTONLYVALIDATMETADATAROOT"
		,err[0x88982f93]:="WINCODEC_ERR_INVALIDQUERYCHARACTER"
	}	
	if a && (a&=0xFFFFFFFF)
        { 
	   if err.haskey(a)
              return err[a]
        }
	return a
}

41 (изменено: teadrinker, 2019-12-25 19:16:53)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Этот код даёт задержку, но неправильную (мой код выше определяет, как 100), и теперь с изображением что-то случилось. Приложил видео.
Вообще по идее нужно к каждому кадру задержку писать. В принципе, мой код работает, он, оказалось, лишь чуть-чуть медленнее твоего, я просто проверял на больших размерах изображения. Сейчас у меня так выглядит (добавил твой вариант записи задержки, но на каждый кадр), вроде работает:

#NoEnv
SetBatchLines, -1

file := "mytest.gif"
x := 340, y := 200, w := 600, h := 400
fps := 25

WICPixelFormat32bppBGRA := "{6FDDC324-4E03-4BFE-B185-3D77768DC90F}"
WICPixelFormat24bppBGR  := "{6FDDC324-4E03-4BFE-B185-3D77768DC90C}"
CLSIDFromString(WICPixelFormat32bppBGRA, GUID_WICPixelFormat32bppBGRA)
CLSIDFromString(WICPixelFormat24bppBGR, GUID_WICPixelFormat24bppBGR)
Return

$F1::
Device := IDirect3DDevice9.CreateFromIDirect3D9()
Surface := Device.CreateOffscreenPlainSurface()
ImagingFactory := IWICImagingFactory.Create()

Stream := ImagingFactory.CreateStream()
Stream.InitializeFromFilename(file)

GifEncoder := ImagingFactory.CreateEncoder(ContainerFormatGif := "{1F8A5601-7D4D-4CBD-9C82-1BC8D4EEB9A5}")
GifEncoder.Initialize(Stream.ptr, WICBitmapEncoderNoCache := 0x2)

VarSetCapacity(PROPVARIANT, A_PtrSize*2+8, 0)
NumPut(VT_UI2 := 0x12, PROPVARIANT, 0, "UShort")

estimatedDelay := 1000/fps
start := timeElapsed := A_TickCount
Loop 100 {
   if (A_Index > 1) {
      shortSleep := false
      while (delay := A_TickCount - timeElapsed) < estimatedDelay {
         ( A_Index = 1 && DllCall("Winmm\timeBeginPeriod", "UInt", 3) = 0 && shortSleep := true )
         if shortSleep
            DllCall("Sleep", "UInt", 1)
         else if (estimatedDelay - delay > 10)
            Sleep, 10
         else
            break
      }
      ( shortSleep && DllCall("Winmm\timeEndPeriod", "UInt", 3) )
      , timeElapsed += delay
      , NumPut(delay//10, PROPVARIANT, 8, "UShort")
   }
   Device.GetFrontBufferData(0, Surface.ptr)
   , Surface.LockRect(D3DLOCKED_RECT, x, y, w, h)
   , Frame := GifEncoder.CreateNewFrame(Options := 0)
   , Frame.Initialize(Options.ptr)
   , Frame.SetSize(w, h)
   , FormatConverter := ImagingFactory.CreateFormatConverter()
   , pitch := NumGet(D3DLOCKED_RECT, 0, "Int"), pBits := NumGet(D3DLOCKED_RECT, A_PtrSize, "Ptr")
   , Bitmap := ImagingFactory.CreateBitmapFromMemory(w, h, &GUID_WICPixelFormat32bppBGRA, pitch, pitch*h, pBits)
   , FormatConverter.Initialize( Bitmap.ptr, &GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeNone := 0
                               , 0, 0, WICBitmapPaletteTypeMedianCut := 0x1 )
   , Frame.SetPixelFormat(&GUID_WICPixelFormat24bppBGR)
   , Frame.WriteSource(Bitmap.ptr, w, h)
   , Surface.UnlockRect()
   
   , MetadataQueryWriter := Frame.GetMetadataQueryWriter()
   , Frame.Commit()
   , MetadataQueryWriter.SetMetadataByName("/grctlext/Delay", &PROPVARIANT)
   , MetadataQueryWriter := ""
}
GifEncoder.Commit()
Device := ImagingFactory := Stream := GifEncoder := Options := Frame := FormatConverter := Bitmap := ""

MsgBox, % "Снято 100 кадров за " . A_TickCount - start . " мс"
Return

CLSIDFromString(IID, ByRef CLSID) {
   VarSetCapacity(CLSID, 16, 0)
   if res := DllCall("ole32\CLSIDFromString", "WStr", IID, "Ptr", &CLSID)
      throw Exception("CLSIDFromString failed. Error: " . Format("{:#x}", res))
   Return &CLSID
}

class InterfaceBase {
   __New(ptr) {
      this.ptr := ptr
   }
   
   __Delete() {
      ObjRelease(this.ptr)
   }
   
   VTable(idx) {
      Return NumGet(NumGet(this.ptr + 0) + A_PtrSize*idx)
   }
   
   IsError(method, result, exc := true) {
      if (result = 0)
         Return 0
      this.error := method . " failed. Result: " . (result = "" ? "No result" : Format("{:#x}", result & 0xFFFFFFFF))
      if !exc
         Return this.error
      throw Exception(this.error)
   }
}

class IDirect3D9 extends InterfaceBase {
   Create(D3D_SDK_VERSION := 32) {
      hLib := DllCall("LoadLibrary", "Str", "d3d9", "Ptr")
      if !pIDirect3D9 := DllCall("d3d9\Direct3DCreate9", "UInt", D3D_SDK_VERSION)
         throw Exception("Direct3DCreate9 failed")
      Return new IDirect3D9(pIDirect3D9)
   }
   
   GetAdapterDisplayMode(Adapter, ByRef D3DDISPLAYMODE) {
      VarSetCapacity(D3DDISPLAYMODE, 16, 0)
      hr := DllCall(this.VTable(8), "Ptr", this.ptr, "UInt", Adapter, "Ptr", &D3DDISPLAYMODE)
      this.IsError("IDirect3D9::GetAdapterDisplayMode", hr)
   }
   
   CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters) {
      hr := DllCall(this.VTable(16), "Ptr", this.ptr, "UInt", Adapter, "UInt", DeviceType
                                   , "Ptr", hFocusWindow, "UInt", BehaviorFlags
                                   , "Ptr", pPresentationParameters, "PtrP", pIDirect3DDevice9)
      this.IsError("IDirect3D9::CreateDevice", hr)
      Return new IDirect3DDevice9(pIDirect3DDevice9)
   }
}

class IDirect3DDevice9 extends InterfaceBase {
   CreateFromIDirect3D9() {
      static D3DADAPTER_DEFAULT := 0, D3DSWAPEFFECT_DISCARD := 1
           , D3DDEVTYPE_HAL := 1, D3DCREATE_SOFTWARE_VERTEXPROCESSING := 0x20
           , Windowed := true, BackBufferCount := 1
      
      Direct3D9 := IDirect3D9.Create()
      Direct3D9.GetAdapterDisplayMode(D3DADAPTER_DEFAULT, D3DDISPLAYMODE)
      
      VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0)
      BackBufferWidth  := NumGet(D3DDISPLAYMODE, 0, "UInt")
      BackBufferHeight := NumGet(D3DDISPLAYMODE, 4, "UInt")
      NumPut(BackBufferWidth, D3DPRESENT_PARAMETERS, 0)
      NumPut(BackBufferHeight, D3DPRESENT_PARAMETERS, 4)
      NumPut(BackBufferCount, D3DPRESENT_PARAMETERS, 12)
      NumPut(D3DSWAPEFFECT_DISCARD, D3DPRESENT_PARAMETERS, 24)
      NumPut(Windowed, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)
      
      Device := Direct3D9.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 0, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3DPRESENT_PARAMETERS)
      Device.width := BackBufferWidth
      Device.height := BackBufferHeight
      Return Device
   }
   
   CreateOffscreenPlainSurface() {
      static D3DFMT_A8R8G8B8 := 21, D3DPOOL_SYSTEMMEM := 2
      hr := DllCall(this.VTable(36), "Ptr", this.ptr, "UInt", this.width, "UInt", this.height
                                   , "UInt", D3DFMT_A8R8G8B8, "UInt", D3DPOOL_SYSTEMMEM
                                   , "PtrP", pIDirect3DSurface9, "Ptr", 0)
      this.IsError("IDirect3DDevice9::CreateOffscreenPlainSurface", hr)
      Return new IDirect3DSurface9(pIDirect3DSurface9)
   }
   
   GetFrontBufferData(iSwapChain, pDestSurface) {
      hr := DllCall(this.VTable(33), "Ptr", this.ptr, "UInt", iSwapChain, "Ptr", pDestSurface)
      this.IsError("IDirect3DDevice9::GetFrontBufferData", hr)
   }
}

class IDirect3DSurface9 extends InterfaceBase {
   LockRect(ByRef D3DLOCKED_RECT, x := "", y := "", w := "", h := "", flags := 0) {
      VarSetCapacity(D3DLOCKED_RECT, A_PtrSize*2, 0)
      if (x != "") {
         VarSetCapacity(RECT, 16, 0)
         NumPut(x, RECT), NumPut(y, RECT, 4), NumPut(x + w, RECT, 8), NumPut(y + h, RECT, 12, "UInt")
      }
      hr := DllCall(this.VTable(13), "Ptr", this.ptr, "Ptr", &D3DLOCKED_RECT, "Ptr", x = "" ? 0 : &RECT, "UInt", flags)
      this.IsError("IDirect3DSurface9::LockRect", hr)
   }
   
   UnlockRect() {
      hr := DllCall(this.VTable(14), "Ptr", this.ptr)
      this.IsError("IDirect3DSurface9::LockRect", hr)
   }
}

class IWICImagingFactory extends InterfaceBase {
   Create() {
      static CLSID_WICImagingFactory := "{CACAF262-9370-4615-A13B-9F5539DA4C0A}"
           , IID_IWICImagingFactory  := "{EC5EC8A9-C395-4314-9C77-54D7A935FF70}"
      if !pIWICImagingFactory := ComObjCreate(CLSID_WICImagingFactory, IID_IWICImagingFactory)
         throw Exception("Can't create IWICImagingFactory")
      Return new IWICImagingFactory(pIWICImagingFactory)
   }
   
   CreateEncoder(ContainerFormatGUID, pguidVendor := 0) {
      if (ContainerFormatGUID + 0)
         pGUID := ContainerFormatGUID
      else
         pGUID := CLSIDFromString(ContainerFormatGUID, GUID)
      hr := DllCall(this.VTable(8), "Ptr", this.ptr, "Ptr", pGUID, "Ptr", pguidVendor, "PtrP", pIWICBitmapEncoder)
      this.IsError("IWICImagingFactory::CreateEncoder", hr)
      Return new IWICBitmapEncoder(pIWICBitmapEncoder)
   }
   
   CreateFormatConverter() {
      hr := DllCall(this.VTable(10), "Ptr", this.ptr, "PtrP", pIWICFormatConverter)
      this.IsError("IWICImagingFactory::CreateFormatConverter", hr)
      Return new IWICFormatConverter(pIWICFormatConverter)
   }
   
   CreateStream() {
      hr := DllCall(this.VTable(14), "Ptr", this.ptr, "PtrP", pIWICStream)
      this.IsError("IWICImagingFactory::CreateStream", hr)
      Return new IWICStream(pIWICStream)
   }
   
   CreateBitmapFromMemory(width, height, pixelFormat, cbStride, cbBufferSize, pbBuffer) {
      if (pixelFormat + 0)
         pGUID := pixelFormat
      else
         pGUID := CLSIDFromString(pixelFormat, GUID)
      hr := DllCall(this.VTable(20), "Ptr", this.ptr, "UInt", width, "UInt", height, "Ptr", pGUID
                                   , "UInt", cbStride, "UInt", cbBufferSize, "Ptr", pbBuffer, "PtrP", pIWICBitmap)
      this.IsError("IWICImagingFactory::CreateBitmapFromMemory", hr)
      Return new IWICBitmap(pIWICBitmap)
   }
}

class IWICBitmapEncoder extends InterfaceBase {
   Initialize(pIStream, cacheOption) {
      hr := DllCall(this.VTable(3), "Ptr", this.ptr, "Ptr", pIStream, "Int", cacheOption)
      this.IsError("IWICBitmapEncoder::Initialize", hr)
   }
   
   CreateNewFrame(ByRef pIEncoderOptions := 0) {
      hr := DllCall(this.VTable(10), "Ptr", this.ptr, "PtrP", pIWICBitmapFrameEncode, "PtrP", pIEncoderOptions)
      this.IsError("IWICBitmapEncoder::CreateNewFrame", hr)
      ( pIEncoderOptions && pIEncoderOptions := new IPropertyBag2(pIEncoderOptions) )
      Return new IWICBitmapFrameEncode(pIWICBitmapFrameEncode)
   }
   
   Commit() {
      hr := DllCall(this.VTable(11), "Ptr", this.ptr)
      this.IsError("IWICBitmapEncoder::Commit", hr)
   }
}

class IPropertyBag2 extends InterfaceBase {
   Write(cProperties, pPropBag, pvarValue) {
      hr := DllCall(this.VTable(4), "Ptr", this.ptr, "UInt", cProperties, "Ptr", pPropBag, "Ptr", pvarValue)
      this.IsError("IPropertyBag2::Write", hr)
   }
}

class IWICFormatConverter extends InterfaceBase {
   Initialize(pISource, dstFormat, dither, pIPalette, alphaThresholdPercent, paletteTranslate) {
      if (dstFormat + 0)
         pGUID := dstFormat
      else
         pGUID := CLSIDFromString(dstFormat, GUID)
      hr := DllCall(this.VTable(8), "Ptr", this.ptr, "Ptr", pISource, "Ptr", pGUID, "UInt", dither
                                  , "Ptr", pIPalette, "Double", alphaThresholdPercent, "UInt", paletteTranslate)
      this.IsError("IWICFormatConverter::Initialize", hr)
   }
   
   CanConvert(srcPixelFormat, dstPixelFormat) {
      if (srcPixelFormat + 0)
         pSrcGUID := srcPixelFormat
      else
         pSrcGUID := CLSIDFromString(srcPixelFormat, srcGUID)
      if (dstPixelFormat + 0)
         pDstGUID := dstPixelFormat
      else
         pDstGUID := CLSIDFromString(dstPixelFormat, dstGUID)
      hr := DllCall(this.VTable(9), "Ptr", this.ptr, "Ptr", pSrcGUID, "Ptr", pDstGUID, "UIntP", CanConvert)
      this.IsError("IWICFormatConverter::CanConvert", hr)
      Return CanConvert
   }
}

class IWICStream extends InterfaceBase {
   InitializeFromFilename(fileName, access := 0x40000000) {  ; GENERIC_WRITE := 0x40000000
      hr := DllCall(this.VTable(15), "Ptr", this.ptr, "Str", fileName, "UInt", access)
      this.IsError("IWICStream::InitializeFromFilename", hr)
   }
}

class IWICBitmap extends InterfaceBase {
}

class IWICBitmapFrameEncode extends InterfaceBase {
   Initialize(pIEncoderOptions := 0) {
      hr := DllCall(this.VTable(3), "Ptr", this.ptr, "Ptr", pIEncoderOptions)
      this.IsError("IWICBitmapFrameEncode::Initialize", hr)
   }
   
   SetSize(width, height) {
      hr := DllCall(this.VTable(4), "Ptr", this.ptr, "UInt", width, "UInt", height)
      this.IsError("IWICBitmapFrameEncode::SetSize", hr)
   }
   
   SetPixelFormat(pixelFormat) {
      if (pixelFormat + 0)
         pGUID := pixelFormat
      else
         pGUID := CLSIDFromString(pixelFormat, GUID)
      hr := DllCall(this.VTable(6), "Ptr", this.ptr, "Ptr", pGUID)
      this.IsError("IWICBitmapFrameEncode::SetSize", hr)
   }
   
   WriteSource(pIBitmapSource, width, height) {
      static RECT, _ := VarSetCapacity(RECT, 16, 0)
      NumPut(width, RECT, 8), NumPut(height, RECT, 12, "UInt")
      hr := DllCall(this.VTable(11), "Ptr", this.ptr, "Ptr", pIBitmapSource, "Ptr", &RECT)
      this.IsError("IWICBitmapFrameEncode::WriteSource", hr)
   }
   
   Commit() {
      hr := DllCall(this.VTable(12), "Ptr", this.ptr)
      this.IsError("IWICBitmapFrameEncode::Commit", hr)
   }
   
   GetMetadataQueryWriter() {
      hr := DllCall(this.VTable(13), "Ptr", this.ptr, "PtrP", pMetadataQueryWriter)
      this.IsError("IWICBitmapFrameEncode::GetMetadataQueryWriter", hr)
      Return new IWICMetadataQueryWriter(pMetadataQueryWriter)
   }
}

class IWICMetadataQueryWriter extends InterfaceBase {
   SetMetadataByName(wzName, pvarValue) {
      hr := DllCall(this.VTable(7), "Ptr", this.ptr, "Str", wzName, "Ptr", pvarValue)
      this.IsError("IWICMetadataQueryWriter::SetMetadataByName", hr)
   }
}
Post's attachments

test.mp4 1.5 mb, 1 downloads since 2019-12-25 

You don't have the permssions to download the attachments of this post.
Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

42 (изменено: teadrinker, 2019-12-25 13:11:29)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Только когда размер делаешь больше, получается заметно медленнее, чем 25 кадров в секунду, учитывая, что у меня hardware acceleration на семёрке отсутствует.
Вот если бы с установкой качества разобраться, пока не понял, как на AHK перевести. Это, правда, для jpeg, для gif аналога не нашёл.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

43

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

teadrinker пишет:

Только когда размер делаешь больше, получается заметно медленнее, чем 25 кадров в секунду

Наверное правильней сохранять в память скриншоты, которые уже потом прогонять через wic.

teadrinker пишет:

теперь с изображением что-то случилось

Это видно из-за конвертации в GUID_WICPixelFormat8bppIndexed.

teadrinker пишет:

Сейчас у меня так выглядит

У меня дальше 2 итерации скрипт не идет.
И глобальные метаданные тоже стоит заполнять, без них гифка получается не зациклена.

44

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

teadrinker пишет:

Вот если бы с установкой качества разобраться, пока не понял, как на AHK перевести.

Перевести-то, можно, но:

The GIF encoder does not support any basic WIC options and does not provide custom encoder options. If an encoder option is in the IPropertyBag2 option list, it is ignored.

https://docs.microsoft.com/en-us/window … t-overview

45

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Malcev пишет:

У меня дальше 2 итерации скрипт не идет.

Подправил, у меня просто ситуация, когда задержка меньше ожидаемой, никогда не возникала.

Malcev пишет:

Перевести-то, можно, но

А, это я как-то пропустил. Тогда нет возможности снизить размер файла? Gif выходит в несколько раз тяжелее, чем видео.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

46

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Malcev пишет:
NumPut(asc("N"), pElems, 0, "uchar")
NumPut(asc("E"), pElems, 1, "uchar")
NumPut(asc("T"), pElems, 2, "uchar")
NumPut(asc("S"), pElems, 3, "uchar")
NumPut(asc("C"), pElems, 4, "uchar")
NumPut(asc("A"), pElems, 5, "uchar")
NumPut(asc("P"), pElems, 6, "uchar")
NumPut(asc("E"), pElems, 7, "uchar")
NumPut(asc("2"), pElems, 8, "uchar")
NumPut(asc("."), pElems, 9, "uchar")
NumPut(asc("0"), pElems, 10, "uchar")

Вместо этого StrPut()?

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

47 (изменено: Malcev, 2019-12-25 20:31:51)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Не знаю, не пробовал.
Поправил предыдущий код. Заменил:

   IWICPalette_InitializeFromBitmap(pPalette, Bitmap, 256, 1)
   IWICImagingFactory_CreateFormatConverter(wic, FormatConverter)
   IWICFormatConverter_Initialize(FormatConverter, bitmap, WIC_GUID(GUID, "GUID_WICPixelFormat8bppIndexed"), WICBitmapDitherTypeErrorDiffusion := 0x00000008, pPalette, 0, WICBitmapPaletteTypeMedianCut := 1)

Теперь благодаря WICBitmapDitherTypeErrorDiffusion брака нету.
Размер можно контролировать уменьшением fps вкупе с уменьшением количества цветов в палитре:

IWICPalette_InitializeFromBitmap(pPalette, Bitmap, 256, 1)

48

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Сейчас хорошо. Но размер файла всё равно огромный. Попробовал уменьшить количество цветов до 128 — размер изменился только на 10%.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

49

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

А что даёт "NETSCAPE2.0"?

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

50

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

http://www.vurdalakov.net/misc/gif/nets … -extension

51

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Ага, уже это читаю.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

52 (изменено: teadrinker, 2019-12-26 15:58:53)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Добавил буферизацию, вроде работает.

#NoEnv
SetBatchLines, -1

file := "mytest.gif"
x := 0, y := 0, w := 500, h := 300
fps := 25
colorCount := 128

ContainerFormatGif        := "{1F8A5601-7D4D-4CBD-9C82-1BC8D4EEB9A5}"
WICPixelFormat32bppBGRA   := "{6FDDC324-4E03-4BFE-B185-3D77768DC90F}"
WICPixelFormat8bppIndexed := "{6FDDC324-4E03-4BFE-B185-3D77768DC904}"
CLSIDFromString(WICPixelFormat32bppBGRA  , GUID_WICPixelFormat32bppBGRA)
CLSIDFromString(WICPixelFormat8bppIndexed, GUID_WICPixelFormat8bppIndexed)
Return

$F1::
hHeap := DllCall("GetProcessHeap", "Ptr")
DataBuff := []

Device := IDirect3DDevice9.CreateFromIDirect3D9()
Surface := Device.CreateOffscreenPlainSurface()
ImagingFactory := IWICImagingFactory.Create()

Stream := ImagingFactory.CreateStream()
Stream.InitializeFromFilename(file)

GifEncoder := ImagingFactory.CreateEncoder(ContainerFormatGif)
GifEncoder.Initialize(Stream.ptr, WICBitmapEncoderNoCache := 0x2)

MetadataQueryWriter := GifEncoder.GetMetadataQueryWriter()
VarSetCapacity(PROPVARIANT, A_PtrSize*2+8, 0)

VarSetCapacity(strBuff, 11, 0)
StrPut("NETSCAPE2.0", &strBuff, "cp0")
NumPut(VT_UI1 := 0x11|VT_VECTOR := 0x1000, PROPVARIANT, "UShort")
NumPut(11, PROPVARIANT, 8, "UInt")
NumPut(&strBuff, PROPVARIANT, 8+A_PtrSize)
MetadataQueryWriter.SetMetadataByName("/appext/Application", &PROPVARIANT)

VarSetCapacity(numBuff, 5, 0)
NumPut(3, numBuff)
NumPut(1, numBuff, 1, "UChar")
NumPut(5, PROPVARIANT, 8, "UInt")
NumPut(&numBuff, PROPVARIANT, 8+A_PtrSize)
MetadataQueryWriter.SetMetadataByName("/appext/Data", &PROPVARIANT)
MetadataQueryWriter := ""

NumPut(VT_UI2 := 0x12, PROPVARIANT, "UShort")

delay := estimatedDelay := 1000//fps
startGrabbing := timeElapsed := A_TickCount
Loop 100 {
   Device.GetFrontBufferData(0, Surface.ptr)
   Surface.LockRect(D3DLOCKED_RECT, x, y, w, h)
   pitch := NumGet(D3DLOCKED_RECT, 0, "Int")
   pBits := NumGet(D3DLOCKED_RECT, A_PtrSize, "Ptr")
   newPitch := w*4, size := newPitch*h
   pHeap := DllCall("HeapAlloc", "Ptr", hHeap, "UInt", HEAP_ZERO_MEMORY := 0x8, "Ptr", size, "Ptr")
   Loop % h
      DllCall("RtlCopyMemory", "Ptr", pHeap + (A_Index - 1)*newPitch, "Ptr", pBits + (A_Index - 1)*pitch, "Ptr", newPitch)
   DataBuff.Push([pHeap, delay])
   Surface.UnlockRect()
   
   if (A_Index = 1)
      continue
   
   delay := A_TickCount - timeElapsed
   diff := estimatedDelay + diff - delay
   if (diff > 0) {
      DllCall("Winmm\timeBeginPeriod", "UInt", 3)
      DllCall("Sleep", "UInt", diff)
      DllCall("Winmm\timeEndPeriod", "UInt", 3)
   }
   delay := A_TickCount - timeElapsed
   diff := estimatedDelay - delay
   timeElapsed += delay
}
endGrabbing := A_TickCount - startGrabbing
Device := Surface := ""

startSaving := A_TickCount
for k, v in DataBuff {
   pData := v[1]
   
   Bitmap := ImagingFactory.CreateBitmapFromMemory(w, h, &GUID_WICPixelFormat32bppBGRA, newPitch, size, pData)
   DllCall("HeapFree", "Ptr", hHeap, "UInt", 0, "Ptr", pData)
   Palette := ImagingFactory.CreatePalette()
   Palette.InitializeFromBitmap(Bitmap.ptr, colorCount, true)
   FormatConverter := ImagingFactory.CreateFormatConverter()
   FormatConverter.Initialize( Bitmap.ptr, &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeErrorDiffusion := 0x8
                             , Palette.ptr, 0, WICBitmapPaletteTypeMedianCut := 0x1 )
   Frame := GifEncoder.CreateNewFrame()
   Frame.Initialize()
   Frame.WriteSource(FormatConverter.ptr, w, h)
   
   MetadataQueryWriter := Frame.GetMetadataQueryWriter()
   Frame.Commit(), Frame := FormatConverter := Palette := Bitmap := ""
   NumPut(Round(v[2]/10), PROPVARIANT, 8, "UInt")
   MetadataQueryWriter.SetMetadataByName("/grctlext/Delay", &PROPVARIANT)
   MetadataQueryWriter := ""
}
GifEncoder.Commit()
ImagingFactory := Stream := GifEncoder := ""

MsgBox, % "Снято 100 кадров за " . endGrabbing . " мс, обработано за " . A_TickCount - startSaving . " мс"
Return
   
CLSIDFromString(IID, ByRef CLSID) {
   VarSetCapacity(CLSID, 16, 0)
   if res := DllCall("ole32\CLSIDFromString", "WStr", IID, "Ptr", &CLSID)
      throw Exception("CLSIDFromString failed. Error: " . Format("{:#x}", res))
   Return &CLSID
}

class InterfaceBase {
   __New(ptr) {
      this.ptr := ptr
   }
   
   __Delete() {
      ObjRelease(this.ptr)
   }
   
   VTable(idx) {
      Return NumGet(NumGet(this.ptr + 0) + A_PtrSize*idx)
   }
   
   IsError(method, result, exc := true) {
      if (result = 0)
         Return 0
      this.error := method . " failed. Result: " . (result = "" ? "No result" : Format("{:#x}", result & 0xFFFFFFFF))
      if !exc
         Return this.error
      throw Exception(this.error)
   }
}

class IDirect3D9 extends InterfaceBase {
   Create(D3D_SDK_VERSION := 32) {
      hLib := DllCall("LoadLibrary", "Str", "d3d9", "Ptr")
      if !pIDirect3D9 := DllCall("d3d9\Direct3DCreate9", "UInt", D3D_SDK_VERSION)
         throw Exception("Direct3DCreate9 failed")
      Return new IDirect3D9(pIDirect3D9)
   }
   
   GetAdapterDisplayMode(Adapter, ByRef D3DDISPLAYMODE) {
      VarSetCapacity(D3DDISPLAYMODE, 16, 0)
      hr := DllCall(this.VTable(8), "Ptr", this.ptr, "UInt", Adapter, "Ptr", &D3DDISPLAYMODE)
      this.IsError("IDirect3D9::GetAdapterDisplayMode", hr)
   }
   
   CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters) {
      hr := DllCall(this.VTable(16), "Ptr", this.ptr, "UInt", Adapter, "UInt", DeviceType
                                   , "Ptr", hFocusWindow, "UInt", BehaviorFlags
                                   , "Ptr", pPresentationParameters, "PtrP", pIDirect3DDevice9)
      this.IsError("IDirect3D9::CreateDevice", hr)
      Return new IDirect3DDevice9(pIDirect3DDevice9)
   }
}

class IDirect3DDevice9 extends InterfaceBase {
   CreateFromIDirect3D9() {
      static D3DADAPTER_DEFAULT := 0, D3DSWAPEFFECT_DISCARD := 1
           , D3DDEVTYPE_HAL := 1, D3DCREATE_SOFTWARE_VERTEXPROCESSING := 0x20
           , Windowed := true, BackBufferCount := 1
      
      Direct3D9 := IDirect3D9.Create()
      Direct3D9.GetAdapterDisplayMode(D3DADAPTER_DEFAULT, D3DDISPLAYMODE)
      
      VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0)
      BackBufferWidth  := NumGet(D3DDISPLAYMODE, 0, "UInt")
      BackBufferHeight := NumGet(D3DDISPLAYMODE, 4, "UInt")
      NumPut(BackBufferWidth, D3DPRESENT_PARAMETERS, 0)
      NumPut(BackBufferHeight, D3DPRESENT_PARAMETERS, 4)
      NumPut(BackBufferCount, D3DPRESENT_PARAMETERS, 12)
      NumPut(D3DSWAPEFFECT_DISCARD, D3DPRESENT_PARAMETERS, 24)
      NumPut(Windowed, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)
      
      Device := Direct3D9.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 0, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3DPRESENT_PARAMETERS)
      Device.width := BackBufferWidth
      Device.height := BackBufferHeight
      Return Device
   }
   
   CreateOffscreenPlainSurface() {
      static D3DFMT_A8R8G8B8 := 21, D3DPOOL_SYSTEMMEM := 2
      hr := DllCall(this.VTable(36), "Ptr", this.ptr, "UInt", this.width, "UInt", this.height
                                   , "UInt", D3DFMT_A8R8G8B8, "UInt", D3DPOOL_SYSTEMMEM
                                   , "PtrP", pIDirect3DSurface9, "Ptr", 0)
      this.IsError("IDirect3DDevice9::CreateOffscreenPlainSurface", hr)
      Return new IDirect3DSurface9(pIDirect3DSurface9)
   }
   
   GetFrontBufferData(iSwapChain, pDestSurface) {
      hr := DllCall(this.VTable(33), "Ptr", this.ptr, "UInt", iSwapChain, "Ptr", pDestSurface)
      this.IsError("IDirect3DDevice9::GetFrontBufferData", hr)
   }
}

class IDirect3DSurface9 extends InterfaceBase {
   LockRect(ByRef D3DLOCKED_RECT, x := "", y := "", w := "", h := "", flags := 0) {
      VarSetCapacity(D3DLOCKED_RECT, A_PtrSize*2, 0)
      if (x != "") {
         VarSetCapacity(RECT, 16, 0)
         NumPut(x, RECT), NumPut(y, RECT, 4), NumPut(x + w, RECT, 8), NumPut(y + h, RECT, 12, "UInt")
      }
      hr := DllCall(this.VTable(13), "Ptr", this.ptr, "Ptr", &D3DLOCKED_RECT, "Ptr", x = "" ? 0 : &RECT, "UInt", flags)
      this.IsError("IDirect3DSurface9::LockRect", hr)
   }
   
   UnlockRect() {
      hr := DllCall(this.VTable(14), "Ptr", this.ptr)
      this.IsError("IDirect3DSurface9::LockRect", hr)
   }
}

class IWICImagingFactory extends InterfaceBase {
   Create() {
      static CLSID_WICImagingFactory := "{CACAF262-9370-4615-A13B-9F5539DA4C0A}"
           , IID_IWICImagingFactory  := "{EC5EC8A9-C395-4314-9C77-54D7A935FF70}"
      if !pIWICImagingFactory := ComObjCreate(CLSID_WICImagingFactory, IID_IWICImagingFactory)
         throw Exception("Can't create IWICImagingFactory")
      Return new IWICImagingFactory(pIWICImagingFactory)
   }
   
   CreateEncoder(ContainerFormatGUID, pguidVendor := 0) {
      if (ContainerFormatGUID + 0)
         pGUID := ContainerFormatGUID
      else
         pGUID := CLSIDFromString(ContainerFormatGUID, GUID)
      hr := DllCall(this.VTable(8), "Ptr", this.ptr, "Ptr", pGUID, "Ptr", pguidVendor, "PtrP", pIWICBitmapEncoder)
      this.IsError("IWICImagingFactory::CreateEncoder", hr)
      Return new IWICBitmapEncoder(pIWICBitmapEncoder)
   }
   
   CreatePalette() {
      hr := DllCall(this.VTable(9), "Ptr", this.ptr, "PtrP", pIWICPalette)
      this.IsError("IWICImagingFactory::CreatePalette", hr)
      Return new IWICPalette(pIWICPalette)
   }
   
   CreateFormatConverter() {
      hr := DllCall(this.VTable(10), "Ptr", this.ptr, "PtrP", pIWICFormatConverter)
      this.IsError("IWICImagingFactory::CreateFormatConverter", hr)
      Return new IWICFormatConverter(pIWICFormatConverter)
   }
   
   CreateStream() {
      hr := DllCall(this.VTable(14), "Ptr", this.ptr, "PtrP", pIWICStream)
      this.IsError("IWICImagingFactory::CreateStream", hr)
      Return new IWICStream(pIWICStream)
   }
   
   CreateBitmapFromMemory(width, height, pixelFormat, cbStride, cbBufferSize, pbBuffer) {
      if (pixelFormat + 0)
         pGUID := pixelFormat
      else
         pGUID := CLSIDFromString(pixelFormat, GUID)
      hr := DllCall(this.VTable(20), "Ptr", this.ptr, "UInt", width, "UInt", height, "Ptr", pGUID
                                   , "UInt", cbStride, "UInt", cbBufferSize, "Ptr", pbBuffer, "PtrP", pIWICBitmap)
      this.IsError("IWICImagingFactory::CreateBitmapFromMemory", hr)
      Return new IWICBitmap(pIWICBitmap)
   }
}

class IWICPalette extends InterfaceBase {
   InitializeFromBitmap(pISurface, cCount, fAddTransparentColor) {
      hr := DllCall(this.VTable(5), "Ptr", this.ptr, "Ptr", pISurface, "UInt", cCount, "UInt", fAddTransparentColor)
      this.IsError("IWICPalette::InitializeFromBitmap", hr)
   }
}

class IWICBitmapEncoder extends InterfaceBase {
   Initialize(pIStream, cacheOption) {
      hr := DllCall(this.VTable(3), "Ptr", this.ptr, "Ptr", pIStream, "Int", cacheOption)
      this.IsError("IWICBitmapEncoder::Initialize", hr)
   }
   
   CreateNewFrame() {
      hr := DllCall(this.VTable(10), "Ptr", this.ptr, "PtrP", pIWICBitmapFrameEncode, "PtrP", 0)
      this.IsError("IWICBitmapEncoder::CreateNewFrame", hr)
      Return new IWICBitmapFrameEncode(pIWICBitmapFrameEncode)
   }
   
   Commit() {
      hr := DllCall(this.VTable(11), "Ptr", this.ptr)
      this.IsError("IWICBitmapEncoder::Commit", hr)
   }
   
   GetMetadataQueryWriter() {
      hr := DllCall(this.VTable(12), "Ptr", this.ptr, "PtrP", pIWICMetadataQueryWriter)
      this.IsError("IWICBitmapEncoder::GetMetadataQueryWriter", hr)
      Return new IWICMetadataQueryWriter(pIWICMetadataQueryWriter)
   }
}

class IPropertyBag2 extends InterfaceBase {
   Write(cProperties, pPropBag, pvarValue) {
      hr := DllCall(this.VTable(4), "Ptr", this.ptr, "UInt", cProperties, "Ptr", pPropBag, "Ptr", pvarValue)
      this.IsError("IPropertyBag2::Write", hr)
   }
}

class IWICFormatConverter extends InterfaceBase {
   Initialize(pISource, dstFormat, dither, pIPalette, alphaThresholdPercent, paletteTranslate) {
      if (dstFormat + 0)
         pGUID := dstFormat
      else
         pGUID := CLSIDFromString(dstFormat, GUID)
      hr := DllCall(this.VTable(8), "Ptr", this.ptr, "Ptr", pISource, "Ptr", pGUID, "UInt", dither
                                  , "Ptr", pIPalette, "Double", alphaThresholdPercent, "UInt", paletteTranslate)
      this.IsError("IWICFormatConverter::Initialize", hr)
   }
   
   CanConvert(srcPixelFormat, dstPixelFormat) {
      if (srcPixelFormat + 0)
         pSrcGUID := srcPixelFormat
      else
         pSrcGUID := CLSIDFromString(srcPixelFormat, srcGUID)
      if (dstPixelFormat + 0)
         pDstGUID := dstPixelFormat
      else
         pDstGUID := CLSIDFromString(dstPixelFormat, dstGUID)
      hr := DllCall(this.VTable(9), "Ptr", this.ptr, "Ptr", pSrcGUID, "Ptr", pDstGUID, "UIntP", CanConvert)
      this.IsError("IWICFormatConverter::CanConvert", hr)
      Return CanConvert
   }
}

class IWICStream extends InterfaceBase {
   InitializeFromFilename(fileName, access := 0x40000000) {  ; GENERIC_WRITE := 0x40000000
      hr := DllCall(this.VTable(15), "Ptr", this.ptr, "Str", fileName, "UInt", access)
      this.IsError("IWICStream::InitializeFromFilename", hr)
   }
}

class IWICBitmap extends InterfaceBase {
}

class IWICBitmapFrameEncode extends InterfaceBase {
   Initialize(pIEncoderOptions := 0) {
      hr := DllCall(this.VTable(3), "Ptr", this.ptr, "Ptr", pIEncoderOptions = 0 ? 0 : pIEncoderOptions)
      this.IsError("IWICBitmapFrameEncode::Initialize", hr)
   }
   
   SetSize(width, height) {
      hr := DllCall(this.VTable(4), "Ptr", this.ptr, "UInt", width, "UInt", height)
      this.IsError("IWICBitmapFrameEncode::SetSize", hr)
   }
   
   SetPixelFormat(pixelFormat) {
      if (pixelFormat + 0)
         pGUID := pixelFormat
      else
         pGUID := CLSIDFromString(pixelFormat, GUID)
      hr := DllCall(this.VTable(6), "Ptr", this.ptr, "Ptr", pGUID)
      this.IsError("IWICBitmapFrameEncode::SetSize", hr)
   }
   
   WriteSource(pIBitmapSource, width, height) {
      static RECT, _ := VarSetCapacity(RECT, 16, 0)
      NumPut(width, RECT, 8), NumPut(height, RECT, 12, "UInt")
      hr := DllCall(this.VTable(11), "Ptr", this.ptr, "Ptr", pIBitmapSource, "Ptr", &RECT)
      this.IsError("IWICBitmapFrameEncode::WriteSource", hr)
   }
   
   Commit() {
      hr := DllCall(this.VTable(12), "Ptr", this.ptr)
      this.IsError("IWICBitmapFrameEncode::Commit", hr)
   }
   
   GetMetadataQueryWriter() {
      hr := DllCall(this.VTable(13), "Ptr", this.ptr, "PtrP", pMetadataQueryWriter)
      this.IsError("IWICBitmapFrameEncode::GetMetadataQueryWriter", hr)
      Return new IWICMetadataQueryWriter(pMetadataQueryWriter)
   }
}

class IWICMetadataQueryWriter extends InterfaceBase {
   SetMetadataByName(wzName, pvarValue) {
      hr := DllCall(this.VTable(7), "Ptr", this.ptr, "Str", wzName, "Ptr", pvarValue)
      this.IsError("IWICMetadataQueryWriter::SetMetadataByName", hr)
   }
}

Не глянешь, правильно метадата записалась? У меня и раньше зацикливалось.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

53

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Не зацикливается.

54

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

А, понял, кажется, подправил.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

55

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

А вот сейчас зацикливается.

56

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Но всё равно с размером беда.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

57 (изменено: Malcev, 2019-12-26 20:34:29)

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Можно кодировать сторонним кодировщиком, который поддерживает LZW, либо написать алгоритм сжатия самому.

58

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Да, пожалуй, займусь на выходных.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg

59

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Вот неплохой кодировщик.
http://www.lcdf.org/gifsicle/
С lossy=200, уменьшил 35MB gif до 8MB.

60

Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC

Попробую.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Skype dmitry_fiveg