[4de1c7]: / app / resources / LeapSDK / v3_python27 / src / ImageData.cs

Download this file

105 lines (95 with data), 3.8 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
103
104
/******************************************************************************\
* Copyright (C) 2012-2016 Leap Motion, Inc. All rights reserved. *
* Leap Motion proprietary and confidential. Not for distribution. *
* Use subject to the terms of the Leap Motion SDK Agreement available at *
* https://developer.leapmotion.com/sdk_agreement, or another agreement *
* between Leap Motion and you, your company or other organization. *
\******************************************************************************/
namespace LeapInternal
{
using System;
using System.Runtime.InteropServices;
using Leap;
public class ImageData : PooledObject
{
public bool isComplete = false;
public byte[] pixelBuffer;
private GCHandle _bufferHandle;
private bool _isPinned = false;
private object locker = new object();
public UInt64 index;
public Int64 frame_id;
public Int64 timestamp;
public eLeapImageType type;
public eLeapImageFormat format;
public UInt32 bpp;
public UInt32 width;
public UInt32 height;
public float RayOffsetX = .5f;
public float RayOffsetY = .5f;
public float RayScaleX = 0.125f;
public float RayScaleY = 0.125f;
public int DistortionSize;
public UInt64 DistortionMatrixKey;
public DistortionData DistortionData;
public ImageData(){}
public ImageData(UInt64 bufferLength, UInt64 index){
pixelBuffer = new byte[bufferLength];
this.index = index;
}
public void CompleteImageData(eLeapImageType type,
eLeapImageFormat format,
UInt32 bpp,
UInt32 width,
UInt32 height,
Int64 timestamp,
Int64 frame_id,
float x_offset,
float y_offset,
float x_scale,
float y_scale,
DistortionData distortionData,
int distortion_size,
UInt64 distortion_matrix_version){
lock(locker){
this.type = type;
this.format = format;
this.bpp = bpp;
this.width = width;
this.height = height;
this.timestamp = timestamp;
this.frame_id = frame_id;
this.DistortionData = distortionData;
this.DistortionSize = distortion_size;
this.DistortionMatrixKey = distortion_matrix_version;
isComplete = true;
}
}
public override void CheckIn ()
{
base.CheckIn();
this.unPinHandle();
this.index = 0;
this.isComplete = false;
}
public IntPtr getPinnedHandle(){
if(pixelBuffer == null)
return IntPtr.Zero;
lock(locker){
if(!_isPinned){
_bufferHandle = GCHandle.Alloc(pixelBuffer, GCHandleType.Pinned);
_isPinned = true;
}
}
return _bufferHandle.AddrOfPinnedObject();
}
public void unPinHandle(){
lock(locker){
if(_isPinned){
_bufferHandle.Free();
_isPinned = false;
}
}
}
}
}