public static unsafe byte[] ConvertToBytes <TIn>( this IImageFormatter <TIn, IntPtr> Formatter, [In] ref ImageBuffer <TIn> In, PixelFlags Options = DefaultOptions) { if (null == Formatter) { throw new NullReferenceException("Formatter was null"); } if (In.Dimensions.ByteCount == 0) { return(null); } int Size = Formatter.CalculateByteSize(ref In); if (Size <= 0) { return(null); } byte[] Buf = new byte[Size]; fixed(byte *ptr = Buf) { var O = new ImageBuffer <IntPtr>((IntPtr)ptr, In.Dimensions / Options, (uint)Size); if (!Formatter.Convert(ref In, ref O)) { Buf = null; } } return(Buf); }
public PixelFormatDescriptor(byte colorBits, byte depthBits) { nSize = 40; nVersion = 1; dwFlags = PixelFlags.DoubleBuffer | PixelFlags.DrawToWindow | PixelFlags.SupportOpenGL; iPixelType = 0; cColorBits = colorBits; cRedBits = 0; cRedShift = 0; cGreenBits = 0; cGreenShift = 0; cBlueBits = 0; cBlueShift = 0; cAlphaBits = 0; cAlphaShift = 0; cAccumBits = 0; cAccumRedBits = 0; cAccumGreenBits = 0; cAccumBlueBits = 0; cAccumAlphaBits = 0; cDepthBits = depthBits; cStencilBits = 0; cAuxBuffers = 0; iLayerType = 0; bReserved = 0; dwLayerMask = 0; dwVisibleMask = 0; dwDamageMask = 0; }
public static bool Convert <TIn, TOut>( this IImageFormatter <TIn, TOut> Formatter, [In] ref ImageBuffer <TIn> In, [In, Out] ref TOut Out, uint Length, PixelFlags Options = DefaultOptions) { return(Convert <TIn, TOut>(Formatter, ref In, ref Out, 0u, Length, Options)); }
public ImageDimensions(PixelFlags Flags, uint Width, uint Height, uint Depth) { if (Width == 0) { throw new ArgumentException("Cannot be zero", "Width"); } if (Height == 0) { throw new ArgumentException("Cannot be zero", "Height"); } if (Depth == 0) { throw new ArgumentException("Cannot be zero", "Depth"); } if (((Depth * (ulong)Width * Height) << 2) >= (uint)int.MaxValue) { throw new ArgumentException("Product of Width, Height and Depth is too large"); } this.PackB = 0; this.PackA = 0; this.Width = Width; this.Height = Height; this.Depth = Depth; this.Flags = Flags & PixelFlagsUtility.Valid; }
public static byte GetOffsets(this PixelFlags Flags, out Channel First, out Channel Second, out Channel Third, out Channel Fourth) { sbyte a = (sbyte)Channel.Alpha, r = (sbyte)Channel.Red, g = (sbyte)Channel.Green, b = (sbyte)Channel.Blue, swap; byte ret;; if (0 != (Flags & PixelFlags.SwapRB)) { swap = r; r = b; b = swap; } if (0 != (Flags & PixelFlags.SwapAG)) { swap = a; a = g; g = swap; } if (0 != (Flags & PixelFlags.SwapAR)) { swap = a; a = r; r = swap; } if (0 != (Flags & PixelFlags.SwapRG)) { swap = r; r = g; g = swap; } if (0 != (Flags & PixelFlags.SwapGB)) { swap = g; g = b; b = swap; } if (0 != (Flags & PixelFlags.SwapBA)) { swap = b; b = a; a = swap; } if (0 != (Flags & PixelFlags.NoTransparency)) { --a; --r; --g; --b; if (-1 == a) { a = r; r = g; g = b; b = -1; } else if (-1 == r) { r = g; g = b; b = -1; } else if (-1 == g) { g = b; b = -1; } ret = 3; } else { ret = 4; } First = (Channel)a; Second = (Channel)r; Third = (Channel)g; Fourth = (Channel)b; return(ret); }
private ImageDimensions(ref ImageDimensions L, PixelFlags R) { this.PackB = L.PackB; this.PackA = L.PackA; this.Width = L.Width; this.Height = L.Height; this.Depth = L.Depth; this.Flags = R & PixelFlagsUtility.Valid; }
public static bool Convert <TIn, TOut>( this IImageFormatter <TIn, TOut[]> Formatter, [In] ref ImageBuffer <TIn> In, TOut[] Out, PixelFlags Options = DefaultOptions) { return(Formatter.Convert <TIn, TOut[]>( In: ref In, Out: ref Out, Offset: 0u, Length: (uint)Out.Length, Options: Options)); }
public ImageDimensions(PixelFlags Flags, uint Square) { if (Square == 0) { throw new ArgumentException("Cannot be zero", "Square"); } if ((((ulong)Square * Square) << 2) >= (uint)int.MaxValue) { throw new ArgumentException("Too large", "Square"); } this.PackB = 0; this.PackA = 0; this.Width = Square; this.Height = Square; this.Depth = 1; this.Flags = Flags; }
public static bool Convert <TIn, TOut>( this IImageFormatter <TIn, TOut> Formatter, [In] ref ImageBuffer <TIn> In, [In, Out] ref TOut Out, uint Offset, uint Length, PixelFlags Options = DefaultOptions) { if (null == Formatter) { throw new NullReferenceException("Formatter was null"); } var OutBuf = new ImageBuffer <TOut>(Out, In.Dimensions / Options, Offset, Length); try { return(Formatter.Convert(ref In, ref OutBuf)); } finally { Out = OutBuf.Buffer; } }
public ImageDimensions(uint Width, uint Height) { if (Width == 0) { throw new ArgumentException("Cannot be zero", "Width"); } if (Height == 0) { throw new ArgumentException("Cannot be zero", "Height"); } if ((((ulong)Width * Height) << 2) >= (uint)int.MaxValue) { throw new ArgumentException("Product of Width and Height is too large"); } this.PackB = 0; this.PackA = 0; this.Width = Width; this.Height = Height; this.Depth = 1; this.Flags = 0; }
public static PixelFlags SlashSet(PixelFlags Flags) { return((PixelFlags)((~((uint)(Flags & Valid)) >> 17) << 1) | (Flags & Valid)); }
public static PixelFlags SlashRemove(PixelFlags Flags) { return(PixelFlags.InheritFromOther | (PixelFlags)((uint)(Flags & Valid) >> 16)); }
public static PixelFlags SlashAdd(PixelFlags Flags) { return(PixelFlags.InheritFromOther | (Flags & Valid)); }