-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWebPDemuxer.cs
More file actions
102 lines (61 loc) · 2.33 KB
/
Copy pathWebPDemuxer.cs
File metadata and controls
102 lines (61 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using Gsemac.Drawing.Imaging.Native;
using Gsemac.Drawing.Imaging.Properties;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace Gsemac.Drawing.Imaging {
public sealed class WebPDemuxer :
IWebPDemuxer {
// Public members
public WebPDemuxer(byte[] data) {
webpDataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
webPData = new WebPData() {
bytes = webpDataHandle.AddrOfPinnedObject(),
size = new UIntPtr((uint)data.Length),
};
demuxerHandle = LibWebPDemux.WebPDemux(ref webPData);
}
public IWebPFrame GetFrame(int frameIndex) {
WebPIterator iter = new WebPIterator();
bool success = false;
try {
success = LibWebPDemux.WebPDemuxGetFrame(demuxerHandle, frameIndex, ref iter) > 0;
if (!success)
throw new ArgumentOutOfRangeException(nameof(frameIndex), ExceptionMessages.IndexOutOfRange);
return new WebPFrame(iter);
}
finally {
if (success)
LibWebPDemux.WebPDemuxReleaseIterator(ref iter);
}
}
public IEnumerable<IWebPFrame> GetFrames() {
using (IWebPEnumerator frameIterator = new WebPEnumerator(demuxerHandle)) {
while (frameIterator.MoveNext())
yield return frameIterator.Current;
}
}
public int GetI(WebPFormatFeature feature) {
return (int)LibWebPDemux.WebPDemuxGetI(demuxerHandle, feature);
}
public void Dispose() {
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
// Private members
private readonly GCHandle webpDataHandle;
private readonly WebPData webPData;
private readonly WebPDemuxerHandle demuxerHandle;
private bool disposedValue;
private void Dispose(bool disposing) {
if (!disposedValue) {
if (disposing) {
demuxerHandle.Dispose();
if (webpDataHandle.IsAllocated)
webpDataHandle.Free();
}
disposedValue = true;
}
}
}
}