Skip to content

Commit 8332c99

Browse files
committed
Correctly marshal the inner struct
1 parent e64780c commit 8332c99

2 files changed

Lines changed: 45 additions & 23 deletions

File tree

binding/Binding/Definitions.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -330,29 +330,13 @@ public enum SKTransferFunctionBehavior {
330330
}
331331

332332

333-
[StructLayout(LayoutKind.Sequential)]
333+
[StructLayout (LayoutKind.Sequential)]
334334
internal unsafe struct SKCodecOptionsInternal {
335335
public SKZeroInitialized fZeroInitialized;
336336
public SKRectI* fSubset;
337337
public int fFrameIndex;
338338
public int fPriorFrame;
339339
public SKTransferFunctionBehavior fPremulBehavior;
340-
341-
public static unsafe SKCodecOptionsInternal FromManaged (ref SKCodecOptions managed)
342-
{
343-
var nativeOptions = new SKCodecOptionsInternal {
344-
fZeroInitialized = managed.ZeroInitialized,
345-
fSubset = null,
346-
fFrameIndex = managed.FrameIndex,
347-
fPriorFrame = managed.PriorFrame,
348-
fPremulBehavior = managed.PremulBehavior,
349-
};
350-
if (managed.HasSubset) {
351-
var subset = managed.Subset.Value;
352-
nativeOptions.fSubset = ⊂
353-
}
354-
return nativeOptions;
355-
}
356340
}
357341

358342
public struct SKCodecOptions {

binding/Binding/SKCodec.cs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,22 @@ public SKCodecResult GetPixels (SKImageInfo info, IntPtr pixels, int rowBytes, S
113113
if (pixels == IntPtr.Zero)
114114
throw new ArgumentNullException (nameof (pixels));
115115

116-
var nOptions = SKCodecOptionsInternal.FromManaged (ref options);
117116
var nInfo = SKImageInfoNative.FromManaged (ref info);
118117

119-
return SkiaApi.sk_codec_get_pixels (Handle, ref nInfo, pixels, (IntPtr)rowBytes, ref nOptions);
118+
unsafe {
119+
var nOptions = new SKCodecOptionsInternal {
120+
fZeroInitialized = options.ZeroInitialized,
121+
fSubset = null,
122+
fFrameIndex = options.FrameIndex,
123+
fPriorFrame = options.PriorFrame,
124+
fPremulBehavior = options.PremulBehavior,
125+
};
126+
if (options.HasSubset) {
127+
var subset = options.Subset.Value;
128+
nOptions.fSubset = ⊂
129+
}
130+
return SkiaApi.sk_codec_get_pixels (Handle, ref nInfo, pixels, (IntPtr)rowBytes, ref nOptions);
131+
}
120132
}
121133

122134
[Obsolete ("The Index8 color type and color table is no longer supported. Use GetPixels(SKImageInfo, IntPtr, int, SKCodecOptions) instead.")]
@@ -176,10 +188,23 @@ public SKCodecResult StartIncrementalDecode (SKImageInfo info, IntPtr pixels, in
176188
if (pixels == IntPtr.Zero)
177189
throw new ArgumentNullException (nameof (pixels));
178190

179-
var nOptions = SKCodecOptionsInternal.FromManaged (ref options);
180191
var nInfo = SKImageInfoNative.FromManaged (ref info);
181192

182-
return SkiaApi.sk_codec_start_incremental_decode (Handle, ref nInfo, pixels, (IntPtr)rowBytes, ref nOptions);
193+
unsafe {
194+
var nOptions = new SKCodecOptionsInternal {
195+
fZeroInitialized = options.ZeroInitialized,
196+
fSubset = null,
197+
fFrameIndex = options.FrameIndex,
198+
fPriorFrame = options.PriorFrame,
199+
fPremulBehavior = options.PremulBehavior,
200+
};
201+
if (options.HasSubset) {
202+
var subset = options.Subset.Value;
203+
nOptions.fSubset = ⊂
204+
}
205+
206+
return SkiaApi.sk_codec_start_incremental_decode (Handle, ref nInfo, pixels, (IntPtr)rowBytes, ref nOptions);
207+
}
183208
}
184209

185210
public SKCodecResult StartIncrementalDecode (SKImageInfo info, IntPtr pixels, int rowBytes)
@@ -212,10 +237,23 @@ public SKCodecResult StartScanlineDecode (SKImageInfo info, SKCodecOptions optio
212237

213238
public SKCodecResult StartScanlineDecode (SKImageInfo info, SKCodecOptions options)
214239
{
215-
var nOptions = SKCodecOptionsInternal.FromManaged (ref options);
216240
var nInfo = SKImageInfoNative.FromManaged (ref info);
217241

218-
return SkiaApi.sk_codec_start_scanline_decode (Handle, ref nInfo, ref nOptions);
242+
unsafe {
243+
var nOptions = new SKCodecOptionsInternal {
244+
fZeroInitialized = options.ZeroInitialized,
245+
fSubset = null,
246+
fFrameIndex = options.FrameIndex,
247+
fPriorFrame = options.PriorFrame,
248+
fPremulBehavior = options.PremulBehavior,
249+
};
250+
if (options.HasSubset) {
251+
var subset = options.Subset.Value;
252+
nOptions.fSubset = ⊂
253+
}
254+
255+
return SkiaApi.sk_codec_start_scanline_decode (Handle, ref nInfo, ref nOptions);
256+
}
219257
}
220258

221259
public SKCodecResult StartScanlineDecode (SKImageInfo info)

0 commit comments

Comments
 (0)