using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;

namespace Asa.Region
{
    internal static class API
    {
        [DllImport(@".\EyemLib\eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int eyemTrackFeature(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize, IntPtr ipResults, out EyemImage tpDstImg);

        internal static IntPtr StructArray2IntPtr<T>(T[] tpArray)
        {
            IntPtr ptr = Marshal.AllocHGlobal(checked(Marshal.SizeOf(typeof(T)) * tpArray.Length));
            for (int index = 0; index < tpArray.Length; index++)
                Marshal.StructureToPtr(tpArray[index], (IntPtr)(checked((long)ptr + index * Marshal.SizeOf(typeof(T)))), false);
            return ptr;
        }

        [StructLayout(LayoutKind.Sequential)]
        internal struct EyemImage
        {
            public IntPtr Handle;
            public int Width;
            public int Height;
            public int Depth;
            public int Channel;

            /*
            iDepth:
            uint8_t 取值范围[0, 255], iDepth = 0(常用,解码图像一般为此种格式)
            int8_t 取值范围[-128, 127], iDepth = 1
            uint16_t 取值范围[0, 56635], iDepth = 2(常用,点料机图像一般为此种格式)
            int16_t 取值范围[-32768, 32767], iDepth = 3
            int32_t 取值范围[-2147483648, 2147483647], iDepth = 4
            float_t 取值范围[-3.4028235E38, 3.4028235E38], iDepth = 5
            double_t 取值范围[-1.7E-308, 1.7E+308], iDepth = 6
            iChannels:
            彩色  rgb iChannels=3  argb iChannels=4
            灰度  iChannels=1
            */
        }

        [StructLayout(LayoutKind.Sequential)]
        internal struct EyemRegion
        {
            public int X;
            public int Y;
            public int Width;
            public int Height;
            public double Ratio;  //变化比例
        }

    }

}