Пример #1
0
 public NativeHelpers()
 {
     this.TL = new TraceLogger("NativeHelpers");
     //this.TL.Enabled = RegistryCommonCode.GetBool("Trace Util", false);
     this.TL.Enabled = false;
     try
     {
         StringBuilder stringBuilder = new StringBuilder(260);
         string        lpFileName    = !NativeHelpers.Is64Bit() ? Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + "\\ASCOM\\VideoUtilities\\ASCOM.NativeVideo32.dll" : Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86) + "\\ASCOM\\VideoUtilities\\ASCOM.NativeVideo64.dll";
         this.TL.LogMessage("New", "Loading NativeHelpers library DLL: " + lpFileName);
         this.VideoDllHandle = NativeHelpers.LoadLibrary(lpFileName);
         int lastWin32Error = Marshal.GetLastWin32Error();
         if (this.VideoDllHandle != IntPtr.Zero)
         {
             this.TL.LogMessage("New", "Loaded NativeHelpers library OK");
             this.TL.LogMessage("NativeHelpers", "Created");
         }
         else
         {
             this.TL.LogMessage("New", "Error loading NativeHelpers library: " + lastWin32Error.ToString("X8"));
             throw new HelperException("Error code returned from LoadLibrary when loading NativeHelpers library: " + lastWin32Error.ToString("X8"));
         }
     }
     catch (Exception ex)
     {
         this.TL.LogMessageCrLf("NativeHelpers ctor", ex.ToString());
     }
 }
Пример #2
0
        public byte[] GetDisplayBitmapBytes()
        {
            if (sensorType == SensorType.Monochrome)
            {
                if (intPixelArray != null)
                {
                    return(NativeHelpers.PrepareBitmapForDisplay(intPixelArray, imageWidth, imageHeight, GetFlipMode()));
                }
                else if (objPixelArray != null)
                {
                    return(NativeHelpers.PrepareBitmapForDisplay(objPixelArray, imageWidth, imageHeight, GetFlipMode()));
                }
            }
            else if (sensorType == SensorType.Color)
            {
                if (intColourPixelArray != null)
                {
                    return(NativeHelpers.PrepareColourBitmapForDisplay(intColourPixelArray, imageWidth, imageHeight, GetFlipMode()));
                }
                else if (objColourPixelArray != null)
                {
                    return(NativeHelpers.PrepareColourBitmapForDisplay(objColourPixelArray, imageWidth, imageHeight, GetFlipMode()));
                }
            }
            else
            {
                throw new NotSupportedException(string.Format("Sensor type {0} is not currently supported.", sensorType));
            }

            return(null);
        }
Пример #3
0
        internal byte[] GetBitmapBytes(Bitmap bitmap)
        {
            byte[] bitmapBytes = new byte[bitmap.Width * bitmap.Height * 3 + 40 + 14 + 1];
            IntPtr hbitmap     = bitmap.GetHbitmap();

            try
            {
                this.GetBitmapBytes(bitmap.Width, bitmap.Height, hbitmap, ref bitmapBytes);
            }
            finally
            {
                NativeHelpers.DeleteObject(hbitmap);
            }
            return(bitmapBytes);
        }
Пример #4
0
        internal object GetMonochromePixelsFromBitmap(Bitmap bitmap, LumaConversionMode conversionMode, FlipMode flipMode, out byte[] rawBitmapBytes)
        {
            int[,] bitmapPixels = new int[bitmap.Width, bitmap.Height];
            rawBitmapBytes      = new byte[bitmap.Width * bitmap.Height * 3 + 40 + 14 + 1];
            IntPtr hbitmap = bitmap.GetHbitmap();

            try
            {
                this.GetMonochromePixelsFromBitmap(bitmap.Width, bitmap.Height, 8, flipMode, hbitmap, ref bitmapPixels, ref rawBitmapBytes, (int)conversionMode);
            }
            finally
            {
                NativeHelpers.DeleteObject(hbitmap);
            }
            return((object)bitmapPixels);
        }
Пример #5
0
        internal object GetColourPixelsFromBitmap(Bitmap bitmap, FlipMode flipMode, out byte[] rawBitmapBytes)
        {
            int[,,] bitmapPixels = new int[bitmap.Width, bitmap.Height, 3];
            rawBitmapBytes       = new byte[bitmap.Width * bitmap.Height * 3 + 40 + 14 + 1];
            IntPtr hbitmap = bitmap.GetHbitmap();

            try
            {
                this.GetColourPixelsFromBitmap(bitmap.Width, bitmap.Height, 8, flipMode, hbitmap, ref bitmapPixels, ref rawBitmapBytes);
            }
            finally
            {
                NativeHelpers.DeleteObject(hbitmap);
            }
            return((object)bitmapPixels);
        }
Пример #6
0
        public object GetImageArray(Bitmap bmp, SensorType sensorType, LumaConversionMode conversionMode, out byte[] bitmapBytes)
        {
            this.imageWidth  = bmp.Width;
            this.imageHeight = bmp.Height;

            if (sensorType == SensorType.Monochrome)
            {
                return(NativeHelpers.GetMonochromePixelsFromBitmap(bmp, conversionMode, GetFlipMode(), out bitmapBytes));
            }
            else if (sensorType == SensorType.Color)
            {
                return(NativeHelpers.GetColourPixelsFromBitmap(bmp, GetFlipMode(), out bitmapBytes));
            }
            else
            {
                throw new NotSupportedException(string.Format("Sensor type {0} is not currently supported.", sensorType));
            }
        }
Пример #7
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposedValue)
     {
         if (disposing)
         {
             if (this.TL != null)
             {
                 this.TL.Enabled = false;
                 this.TL.Dispose();
                 this.TL = (TraceLogger)null;
             }
         }
         try
         {
             NativeHelpers.FreeLibrary(this.VideoDllHandle);
         }
         catch
         {
         }
     }
     this.disposedValue = true;
 }
Пример #8
0
 public byte[] GetBitmapBytes(Bitmap bmp)
 {
     return(NativeHelpers.GetBitmapBytes(bmp));
 }
Пример #9
0
 internal int GetResultingIntegratedFrame(ref int[,] pixels)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.GetResultingIntegratedFrame32(pixels) : NativeHelpers.GetResultingIntegratedFrame64(pixels);
     return(this.rc);
 }
Пример #10
0
 internal int SetWhiteBalance(int newWhiteBalance)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.SetWhiteBalance32(newWhiteBalance) : NativeHelpers.SetWhiteBalance64(newWhiteBalance);
     return(this.rc);
 }
Пример #11
0
 internal int SetGamma(double gamma)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.SetGamma32(gamma) : NativeHelpers.SetGamma64(gamma);
     return(this.rc);
 }
Пример #12
0
 internal int GetLastAviFileError(IntPtr errorMessage)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.GetLastAviFileError32(errorMessage) : NativeHelpers.GetLastAviFileError64(errorMessage);
     return(this.rc);
 }
Пример #13
0
 internal uint GetUsedAviCompression()
 {
     this.urc = !NativeHelpers.Is64Bit() ? NativeHelpers.GetUsedAviCompression32() : NativeHelpers.GetUsedAviCompression64();
     return(this.urc);
 }
Пример #14
0
 public CameraImage()
 {
     this.nativeHelpers = new NativeHelpers();
 }
Пример #15
0
 internal int AviFileClose()
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.AviFileClose32() : NativeHelpers.AviFileClose64();
     return(this.rc);
 }
Пример #16
0
 internal int GetColourBitmapPixels(int width, int height, int bpp, FlipMode flipMode, int[,,] pixels, ref byte[] bitmapBytes)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.GetColourBitmapPixels32(width, height, bpp, flipMode, pixels, bitmapBytes) : NativeHelpers.GetColourBitmapPixels64(width, height, bpp, flipMode, pixels, bitmapBytes);
     return(this.rc);
 }
Пример #17
0
 internal int ApplyGammaBrightness(int width, int height, int bpp, ref int[,] pixelsIn, ref int[,] pixelsOut, short brightness)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.ApplyGammaBrightness32(width, height, bpp, pixelsIn, pixelsOut, brightness) : NativeHelpers.ApplyGammaBrightness64(width, height, bpp, pixelsIn, pixelsOut, brightness);
     return(this.rc);
 }
Пример #18
0
 internal int AddFrameForIntegration(ref int[,] pixels)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.AddFrameForIntegration32(pixels) : NativeHelpers.AddFrameForIntegration64(pixels);
     return(this.rc);
 }
Пример #19
0
 internal int InitFrameIntegration(int width, int height, int bpp)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.InitFrameIntegration32(width, height, bpp) : NativeHelpers.InitFrameIntegration64(width, height, bpp);
     return(this.rc);
 }
Пример #20
0
 internal int GetBitmapBytes(int width, int height, IntPtr hBitmap, ref byte[] bitmapBytes)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.GetBitmapBytes32(width, height, hBitmap, bitmapBytes) : NativeHelpers.GetBitmapBytes64(width, height, hBitmap, bitmapBytes);
     return(this.rc);
 }
Пример #21
0
 internal int CreateNewAviFile(string fileName, int width, int height, int bpp, double fps, bool showCompressionDialog)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.CreateNewAviFile32(fileName, width, height, bpp, fps, showCompressionDialog) : NativeHelpers.CreateNewAviFile64(fileName, width, height, bpp, fps, showCompressionDialog);
     return(this.rc);
 }
Пример #22
0
 internal int AviFileAddFrame(int[,] pixels)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.AviFileAddFrame32(pixels) : NativeHelpers.AviFileAddFrame64(pixels);
     return(this.rc);
 }
Пример #23
0
 internal int GetMonochromePixelsFromBitmap(int width, int height, int bpp, FlipMode flipMode, IntPtr hBitmap, ref int[,] bitmapPixels, ref byte[] bitmapBytes, int mode)
 {
     this.rc = !NativeHelpers.Is64Bit() ? NativeHelpers.GetMonochromePixelsFromBitmap32(width, height, bpp, flipMode, hBitmap, bitmapPixels, bitmapBytes, mode) : NativeHelpers.GetMonochromePixelsFromBitmap64(width, height, bpp, flipMode, hBitmap, bitmapPixels, bitmapBytes, mode);
     return(this.rc);
 }
Пример #24
0
 public AviTools()
 {
     nativeHelpers = new NativeHelpers();
 }