<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=14508&amp;type=atom" />
	<updated>2019-12-26T23:08:09Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=14508</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137068#p137068" />
			<content type="html"><![CDATA[<p>Попробую.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-12-26T23:08:09Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137068#p137068</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137063#p137063" />
			<content type="html"><![CDATA[<p>Вот неплохой кодировщик.<br /><a href="http://www.lcdf.org/gifsicle/">http://www.lcdf.org/gifsicle/</a><br />С lossy=200, уменьшил 35MB gif до 8MB.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-12-26T20:07:24Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137063#p137063</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137062#p137062" />
			<content type="html"><![CDATA[<p>Да, пожалуй, займусь на выходных. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-12-26T16:47:45Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137062#p137062</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137061#p137061" />
			<content type="html"><![CDATA[<p>Можно кодировать сторонним кодировщиком, который поддерживает LZW, либо написать алгоритм сжатия самому. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-12-26T16:33:07Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137061#p137061</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137060#p137060" />
			<content type="html"><![CDATA[<p>Но всё равно с размером беда.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-12-26T16:13:59Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137060#p137060</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137059#p137059" />
			<content type="html"><![CDATA[<p>А вот сейчас зацикливается.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-12-26T16:09:10Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137059#p137059</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137057#p137057" />
			<content type="html"><![CDATA[<p>А, понял, кажется, подправил.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-12-26T11:59:20Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137057#p137057</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137056#p137056" />
			<content type="html"><![CDATA[<p>Не зацикливается.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-12-26T10:54:56Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137056#p137056</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137055#p137055" />
			<content type="html"><![CDATA[<p>Добавил буферизацию, вроде работает. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br /></p><div class="codebox"><pre><code>#NoEnv
SetBatchLines, -1

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

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

$F1::
hHeap := DllCall(&quot;GetProcessHeap&quot;, &quot;Ptr&quot;)
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(&quot;NETSCAPE2.0&quot;, &amp;strBuff, &quot;cp0&quot;)
NumPut(VT_UI1 := 0x11|VT_VECTOR := 0x1000, PROPVARIANT, &quot;UShort&quot;)
NumPut(11, PROPVARIANT, 8, &quot;UInt&quot;)
NumPut(&amp;strBuff, PROPVARIANT, 8+A_PtrSize)
MetadataQueryWriter.SetMetadataByName(&quot;/appext/Application&quot;, &amp;PROPVARIANT)

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

NumPut(VT_UI2 := 0x12, PROPVARIANT, &quot;UShort&quot;)

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, &quot;Int&quot;)
   pBits := NumGet(D3DLOCKED_RECT, A_PtrSize, &quot;Ptr&quot;)
   newPitch := w*4, size := newPitch*h
   pHeap := DllCall(&quot;HeapAlloc&quot;, &quot;Ptr&quot;, hHeap, &quot;UInt&quot;, HEAP_ZERO_MEMORY := 0x8, &quot;Ptr&quot;, size, &quot;Ptr&quot;)
   Loop % h
      DllCall(&quot;RtlCopyMemory&quot;, &quot;Ptr&quot;, pHeap + (A_Index - 1)*newPitch, &quot;Ptr&quot;, pBits + (A_Index - 1)*pitch, &quot;Ptr&quot;, newPitch)
   DataBuff.Push([pHeap, delay])
   Surface.UnlockRect()
   
   if (A_Index = 1)
      continue
   
   delay := A_TickCount - timeElapsed
   diff := estimatedDelay + diff - delay
   if (diff &gt; 0) {
      DllCall(&quot;Winmm\timeBeginPeriod&quot;, &quot;UInt&quot;, 3)
      DllCall(&quot;Sleep&quot;, &quot;UInt&quot;, diff)
      DllCall(&quot;Winmm\timeEndPeriod&quot;, &quot;UInt&quot;, 3)
   }
   delay := A_TickCount - timeElapsed
   diff := estimatedDelay - delay
   timeElapsed += delay
}
endGrabbing := A_TickCount - startGrabbing
Device := Surface := &quot;&quot;

startSaving := A_TickCount
for k, v in DataBuff {
   pData := v[1]
   
   Bitmap := ImagingFactory.CreateBitmapFromMemory(w, h, &amp;GUID_WICPixelFormat32bppBGRA, newPitch, size, pData)
   DllCall(&quot;HeapFree&quot;, &quot;Ptr&quot;, hHeap, &quot;UInt&quot;, 0, &quot;Ptr&quot;, pData)
   Palette := ImagingFactory.CreatePalette()
   Palette.InitializeFromBitmap(Bitmap.ptr, colorCount, true)
   FormatConverter := ImagingFactory.CreateFormatConverter()
   FormatConverter.Initialize( Bitmap.ptr, &amp;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 := &quot;&quot;
   NumPut(Round(v[2]/10), PROPVARIANT, 8, &quot;UInt&quot;)
   MetadataQueryWriter.SetMetadataByName(&quot;/grctlext/Delay&quot;, &amp;PROPVARIANT)
   MetadataQueryWriter := &quot;&quot;
}
GifEncoder.Commit()
ImagingFactory := Stream := GifEncoder := &quot;&quot;

MsgBox, % &quot;Снято 100 кадров за &quot; . endGrabbing . &quot; мс, обработано за &quot; . A_TickCount - startSaving . &quot; мс&quot;
Return
   
CLSIDFromString(IID, ByRef CLSID) {
   VarSetCapacity(CLSID, 16, 0)
   if res := DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;WStr&quot;, IID, &quot;Ptr&quot;, &amp;CLSID)
      throw Exception(&quot;CLSIDFromString failed. Error: &quot; . Format(&quot;{:#x}&quot;, res))
   Return &amp;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 . &quot; failed. Result: &quot; . (result = &quot;&quot; ? &quot;No result&quot; : Format(&quot;{:#x}&quot;, result &amp; 0xFFFFFFFF))
      if !exc
         Return this.error
      throw Exception(this.error)
   }
}

class IDirect3D9 extends InterfaceBase {
   Create(D3D_SDK_VERSION := 32) {
      hLib := DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;d3d9&quot;, &quot;Ptr&quot;)
      if !pIDirect3D9 := DllCall(&quot;d3d9\Direct3DCreate9&quot;, &quot;UInt&quot;, D3D_SDK_VERSION)
         throw Exception(&quot;Direct3DCreate9 failed&quot;)
      Return new IDirect3D9(pIDirect3D9)
   }
   
   GetAdapterDisplayMode(Adapter, ByRef D3DDISPLAYMODE) {
      VarSetCapacity(D3DDISPLAYMODE, 16, 0)
      hr := DllCall(this.VTable(8), &quot;Ptr&quot;, this.ptr, &quot;UInt&quot;, Adapter, &quot;Ptr&quot;, &amp;D3DDISPLAYMODE)
      this.IsError(&quot;IDirect3D9::GetAdapterDisplayMode&quot;, hr)
   }
   
   CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters) {
      hr := DllCall(this.VTable(16), &quot;Ptr&quot;, this.ptr, &quot;UInt&quot;, Adapter, &quot;UInt&quot;, DeviceType
                                   , &quot;Ptr&quot;, hFocusWindow, &quot;UInt&quot;, BehaviorFlags
                                   , &quot;Ptr&quot;, pPresentationParameters, &quot;PtrP&quot;, pIDirect3DDevice9)
      this.IsError(&quot;IDirect3D9::CreateDevice&quot;, 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, &quot;UInt&quot;)
      BackBufferHeight := NumGet(D3DDISPLAYMODE, 4, &quot;UInt&quot;)
      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, &amp;D3DPRESENT_PARAMETERS)
      Device.width := BackBufferWidth
      Device.height := BackBufferHeight
      Return Device
   }
   
   CreateOffscreenPlainSurface() {
      static D3DFMT_A8R8G8B8 := 21, D3DPOOL_SYSTEMMEM := 2
      hr := DllCall(this.VTable(36), &quot;Ptr&quot;, this.ptr, &quot;UInt&quot;, this.width, &quot;UInt&quot;, this.height
                                   , &quot;UInt&quot;, D3DFMT_A8R8G8B8, &quot;UInt&quot;, D3DPOOL_SYSTEMMEM
                                   , &quot;PtrP&quot;, pIDirect3DSurface9, &quot;Ptr&quot;, 0)
      this.IsError(&quot;IDirect3DDevice9::CreateOffscreenPlainSurface&quot;, hr)
      Return new IDirect3DSurface9(pIDirect3DSurface9)
   }
   
   GetFrontBufferData(iSwapChain, pDestSurface) {
      hr := DllCall(this.VTable(33), &quot;Ptr&quot;, this.ptr, &quot;UInt&quot;, iSwapChain, &quot;Ptr&quot;, pDestSurface)
      this.IsError(&quot;IDirect3DDevice9::GetFrontBufferData&quot;, hr)
   }
}

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

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

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

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

class IPropertyBag2 extends InterfaceBase {
   Write(cProperties, pPropBag, pvarValue) {
      hr := DllCall(this.VTable(4), &quot;Ptr&quot;, this.ptr, &quot;UInt&quot;, cProperties, &quot;Ptr&quot;, pPropBag, &quot;Ptr&quot;, pvarValue)
      this.IsError(&quot;IPropertyBag2::Write&quot;, 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), &quot;Ptr&quot;, this.ptr, &quot;Ptr&quot;, pISource, &quot;Ptr&quot;, pGUID, &quot;UInt&quot;, dither
                                  , &quot;Ptr&quot;, pIPalette, &quot;Double&quot;, alphaThresholdPercent, &quot;UInt&quot;, paletteTranslate)
      this.IsError(&quot;IWICFormatConverter::Initialize&quot;, 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), &quot;Ptr&quot;, this.ptr, &quot;Ptr&quot;, pSrcGUID, &quot;Ptr&quot;, pDstGUID, &quot;UIntP&quot;, CanConvert)
      this.IsError(&quot;IWICFormatConverter::CanConvert&quot;, hr)
      Return CanConvert
   }
}

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

class IWICBitmap extends InterfaceBase {
}

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

class IWICMetadataQueryWriter extends InterfaceBase {
   SetMetadataByName(wzName, pvarValue) {
      hr := DllCall(this.VTable(7), &quot;Ptr&quot;, this.ptr, &quot;Str&quot;, wzName, &quot;Ptr&quot;, pvarValue)
      this.IsError(&quot;IWICMetadataQueryWriter::SetMetadataByName&quot;, hr)
   }
}</code></pre></div><p>Не глянешь, правильно метадата записалась? У меня и раньше зацикливалось.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-12-26T07:43:09Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137055#p137055</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137024#p137024" />
			<content type="html"><![CDATA[<p>Ага, уже это читаю. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-12-25T17:35:41Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137024#p137024</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137023#p137023" />
			<content type="html"><![CDATA[<p><a href="http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension">http://www.vurdalakov.net/misc/gif/nets … -extension</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-12-25T17:34:02Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137023#p137023</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137021#p137021" />
			<content type="html"><![CDATA[<p>А что даёт &quot;NETSCAPE2.0&quot;?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-12-25T17:14:37Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137021#p137021</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137020#p137020" />
			<content type="html"><![CDATA[<p>Сейчас хорошо. Но размер файла всё равно огромный. Попробовал уменьшить количество цветов до 128 — размер изменился только на 10%.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-12-25T17:04:28Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137020#p137020</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137019#p137019" />
			<content type="html"><![CDATA[<p>Не знаю, не пробовал.<br />Поправил предыдущий код. Заменил:<br /></p><div class="codebox"><pre><code>   IWICPalette_InitializeFromBitmap(pPalette, Bitmap, 256, 1)
   IWICImagingFactory_CreateFormatConverter(wic, FormatConverter)
   IWICFormatConverter_Initialize(FormatConverter, bitmap, WIC_GUID(GUID, &quot;GUID_WICPixelFormat8bppIndexed&quot;), WICBitmapDitherTypeErrorDiffusion := 0x00000008, pPalette, 0, WICBitmapPaletteTypeMedianCut := 1)</code></pre></div><p>Теперь благодаря WICBitmapDitherTypeErrorDiffusion брака нету.<br />Размер можно контролировать уменьшением fps вкупе с уменьшением количества цветов в палитре:<br /></p><div class="quotebox"><blockquote><p>IWICPalette_InitializeFromBitmap(pPalette, Bitmap, <strong>256</strong>, 1)</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-12-25T16:31:38Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137019#p137019</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сохранение экрана с DirectX и Windows Imaging Component WIC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=137018#p137018" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Malcev пишет:</cite><blockquote><div class="codebox"><pre><code>NumPut(asc(&quot;N&quot;), pElems, 0, &quot;uchar&quot;)
NumPut(asc(&quot;E&quot;), pElems, 1, &quot;uchar&quot;)
NumPut(asc(&quot;T&quot;), pElems, 2, &quot;uchar&quot;)
NumPut(asc(&quot;S&quot;), pElems, 3, &quot;uchar&quot;)
NumPut(asc(&quot;C&quot;), pElems, 4, &quot;uchar&quot;)
NumPut(asc(&quot;A&quot;), pElems, 5, &quot;uchar&quot;)
NumPut(asc(&quot;P&quot;), pElems, 6, &quot;uchar&quot;)
NumPut(asc(&quot;E&quot;), pElems, 7, &quot;uchar&quot;)
NumPut(asc(&quot;2&quot;), pElems, 8, &quot;uchar&quot;)
NumPut(asc(&quot;.&quot;), pElems, 9, &quot;uchar&quot;)
NumPut(asc(&quot;0&quot;), pElems, 10, &quot;uchar&quot;)</code></pre></div></blockquote></div><p>Вместо этого StrPut()?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-12-25T15:33:13Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=137018#p137018</id>
		</entry>
</feed>
