//Map IPC format-> External format public static T IpcPixelFormatToExternalFormat <T>(IpcPixelFormat ipcPixelFormat, Dictionary <IpcPixelFormatDefault, T> dictionary) { if (!(ipcPixelFormat is IpcPixelFormatDefault)) { throw new NotSupportedException("Custom IpcPixelFormats are currently not supported for" + typeof(T)); } if (dictionary.TryGetValue((IpcPixelFormatDefault)ipcPixelFormat, out var pixelFormat)) { return(pixelFormat); } throw new NotSupportedException("Type: " + ipcPixelFormat.IpcPixelFormatType + " is not supported by " + typeof(T).FullName); }
public IpcImageFileMapped(int width, int height, IpcPixelFormat ipcPixelFormat, int stride = 0) { Height = height; Width = width; IpcPixelFormat = ipcPixelFormat; //Calculates stride if (stride <= 0) { Stride = (int)Math.Ceiling(width * BytesPerPixel); } else if (stride > 0 && stride < width * ipcPixelFormat.BytesPerPixel) { throw new ArgumentOutOfRangeException(@"Stride must be greater or equal to Width in memory."); } else if (stride <= width * ipcPixelFormat.BytesPerPixel) { Stride = stride; } _bufferSize = height * Stride; CreateFileMappedMemory(_bufferSize); }
public static T IpcPixelFormatToExternalFormatReverseLookup <T>(IpcPixelFormat ipcPixelFormat, Dictionary <T, IpcPixelFormatDefault> dictionary) where T : IEquatable <T> { try { return(dictionary.First(x => x.Value.Equals(ipcPixelFormat)).Key); } catch { throw new NotSupportedException("Type: " + ipcPixelFormat.IpcPixelFormatType + " is not supported by " + typeof(T)); } }
public static MatType GetOpenCvMatType(this IpcPixelFormat pixelFormat) => ExtUtil.IpcPixelFormatToExternalFormat(pixelFormat, IpcPixelToFormatMatTypeDictionary);
public static System.Drawing.Imaging.PixelFormat ToDrawingPixelFormat(this IpcPixelFormat ipcPixelFormat) => ExtUtil.IpcPixelFormatToExternalFormat(ipcPixelFormat, IpcPixelFormatToDrawingPixelFormatDictionary);
public static NativeMethods.BI ToGdiBiFormat(this IpcPixelFormat ipcPixelFormat) => ExtUtil.IpcPixelFormatToExternalFormat(ipcPixelFormat, IpcPixelFormatToGdiBiDictionary);
//Extensions public static PixelFormat ToMediaPixelFormat(this IpcPixelFormat ipcPixelFormat) => ExtUtil.IpcPixelFormatToExternalFormat(ipcPixelFormat, IpcPixelFormatToMediaPixelFormatDictionary);