Ejemplo n.º 1
0
 public void Deserialize(Stream input, Endian endian)
 {
     this.Size         = input.ReadValueU32(endian);
     this.Flags        = input.ReadValueEnum <PixelFormatFlags>(endian);
     this.FourCC       = input.ReadValueU32(endian);
     this.RGBBitCount  = input.ReadValueU32(endian);
     this.RedBitMask   = input.ReadValueU32(endian);
     this.GreenBitMask = input.ReadValueU32(endian);
     this.BlueBitMask  = input.ReadValueU32(endian);
     this.AlphaBitMask = input.ReadValueU32(endian);
 }
Ejemplo n.º 2
0
Archivo: DDS.cs Proyecto: Aggror/Stride
 /// <summary>
 /// Initializes a new instance of the <see cref="DDSPixelFormat" /> struct.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <param name="fourCC">The four CC.</param>
 /// <param name="rgbBitCount">The RGB bit count.</param>
 /// <param name="rBitMask">The r bit mask.</param>
 /// <param name="gBitMask">The g bit mask.</param>
 /// <param name="bBitMask">The b bit mask.</param>
 /// <param name="aBitMask">A bit mask.</param>
 public DDSPixelFormat(PixelFormatFlags flags, int fourCC, int rgbBitCount, uint rBitMask, uint gBitMask, uint bBitMask, uint aBitMask)
 {
     Size        = Utilities.SizeOf <DDSPixelFormat>();
     Flags       = flags;
     FourCC      = fourCC;
     RGBBitCount = rgbBitCount;
     RBitMask    = rBitMask;
     GBitMask    = gBitMask;
     BBitMask    = bBitMask;
     ABitMask    = aBitMask;
 }
Ejemplo n.º 3
0
 public PixelFormat(PixelFormatFlags flags, FourCC formatCode)
 {
     Size         = (uint)MemoryHelper.SizeOf <PixelFormat>();
     Flags        = flags;
     FourCC       = formatCode;
     RGBBitCount  = 0;
     RedBitMask   = 0;
     GreenBitMask = 0;
     BlueBitMask  = 0;
     AlphaBitMask = 0;
 }
Ejemplo n.º 4
0
 public PixelFormatInfo(
     int bitsPerPixel,
     ColorModel model,
     ColorChannel[] channels,
     PixelFormatFlags flags = PixelFormatFlags.None)
 {
     BitsPerPixel = bitsPerPixel;
     ColorModel   = model;
     Channels     = channels;
     Flags        = flags;
 }
Ejemplo n.º 5
0
 public PixelFormat(PixelFormatFlags flags, FourCC formatCode, uint colorBitCount, uint redMask, uint greenMask, uint blueMask, uint alphaMask)
 {
     Size         = (uint)MemoryHelper.SizeOf <PixelFormat>();
     Flags        = flags;
     FourCC       = formatCode;
     RGBBitCount  = colorBitCount;
     RedBitMask   = redMask;
     GreenBitMask = greenMask;
     BlueBitMask  = blueMask;
     AlphaBitMask = alphaMask;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PixelFormat" /> struct.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <param name="fourCC">The four CC.</param>
 /// <param name="rgbBitCount">The RGB bit count.</param>
 /// <param name="rBitMask">The r bit mask.</param>
 /// <param name="gBitMask">The g bit mask.</param>
 /// <param name="bBitMask">The b bit mask.</param>
 /// <param name="aBitMask">A bit mask.</param>
 public PixelFormat(PixelFormatFlags flags, int fourCC, int rgbBitCount, uint rBitMask, uint gBitMask,
                    uint bBitMask, uint aBitMask)
 {
     Size        = 32;
     Flags       = flags;
     FourCC      = fourCC;
     RGBBitCount = rgbBitCount;
     RBitMask    = rBitMask;
     GBitMask    = gBitMask;
     BBitMask    = bBitMask;
     ABitMask    = aBitMask;
 }
Ejemplo n.º 7
0
            /// <summary>Create the pixel format.</summary>
            /// <param name="format"></param>
            public PixelFormat(Format format)
            {
                if (format.IsCompressed)
                {
                    Flags  = PixelFormatFlags.FourCC;
                    FourCC = FormatFourCCs[format];

                    RGBBitCount = 0;
                    RBitMask    = GBitMask = BBitMask = ABitMask = 0;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
Ejemplo n.º 8
0
 public void Parse(Stream s)
 {
     BinaryReader r = new BinaryReader(s);
     uint size = r.ReadUInt32();
     if (size != this.size) throw new InvalidDataException(string.Format("Expected size: 0x{0:X8}, read 0x{1:X8}", this.size, size));
     //this.pixelFormatFlag = (PixelFormatFlags)r.ReadUInt32();
     //if ((this.pixelFormatFlag & PixelFormatFlags.FourCC) != PixelFormatFlags.FourCC) throw new InvalidDataException("Bad pixel format flag");
     uint pixelFormatFlag = r.ReadUInt32();
     if (!Enum.IsDefined(typeof(PixelFormatFlags), pixelFormatFlag)) throw new InvalidDataException("Bad pixel format flag"); else this.pixelFormatFlag = (PixelFormatFlags) pixelFormatFlag;
     uint fourCC = r.ReadUInt32();
     if (!Enum.IsDefined(typeof(FourCC), fourCC)) throw new InvalidDataException(string.Format("Unexpected data, read 0x{0:X8}", fourCC)); else this.fourcc = (FourCC)fourCC;
     this.RGBBitCount = r.ReadUInt32();
     this.redBitMask = r.ReadUInt32();
     this.greenBitMask = r.ReadUInt32();
     this.blueBitMask = r.ReadUInt32();
     this.alphaBitMask = r.ReadUInt32();
 }
Ejemplo n.º 9
0
            /// <summary>Read the pixel format.</summary>
            /// <param name="reader"></param>
            public PixelFormat(BinaryReader reader)
            {
                int size = reader.ReadInt32();

                if (size != Size)
                {
                    throw new InvalidDataException();
                }
                Flags = (PixelFormatFlags)reader.ReadInt32();
                var fourcc = reader.ReadBytes(4);

                FourCC      = Encoding.ASCII.GetString(fourcc);
                RGBBitCount = reader.ReadInt32();
                RBitMask    = reader.ReadInt32();
                GBitMask    = reader.ReadInt32();
                BBitMask    = reader.ReadInt32();
                ABitMask    = reader.ReadInt32();
            }
Ejemplo n.º 10
0
 public PixelFormatDescription(string name,
                               PixelFormat format,
                               byte elemBytes,
                               PixelFormatFlags flags,
                               PixelComponentType componentType,
                               byte componentCount,
                               byte rbits,
                               byte gbits,
                               byte bbits,
                               byte abits,
                               uint rmask,
                               uint gmask,
                               uint bmask,
                               uint amask,
                               byte rshift,
                               byte gshift,
                               byte bshift,
                               byte ashift)
 {
     this.name           = name;
     this.format         = format;
     this.elemBytes      = elemBytes;
     this.flags          = flags;
     this.componentType  = componentType;
     this.componentCount = componentCount;
     this.rbits          = rbits;
     this.gbits          = gbits;
     this.bbits          = bbits;
     this.abits          = abits;
     this.rmask          = rmask;
     this.gmask          = gmask;
     this.bmask          = bmask;
     this.amask          = amask;
     this.rshift         = rshift;
     this.gshift         = gshift;
     this.bshift         = bshift;
 }
Ejemplo n.º 11
0
        public void Parse(Stream s)
        {
            BinaryReader r    = new BinaryReader(s);
            uint         size = r.ReadUInt32();

            if (size != this.size)
            {
                throw new InvalidDataException(string.Format("Expected size: 0x{0:X8}, read 0x{1:X8}", this.size, size));
            }
            //this.pixelFormatFlag = (PixelFormatFlags)r.ReadUInt32();
            //if ((this.pixelFormatFlag & PixelFormatFlags.FourCC) != PixelFormatFlags.FourCC) throw new InvalidDataException("Bad pixel format flag");
            uint pixelFormatFlag = r.ReadUInt32();

            if (!Enum.IsDefined(typeof(PixelFormatFlags), pixelFormatFlag))
            {
                throw new InvalidDataException("Bad pixel format flag");
            }
            else
            {
                this.pixelFormatFlag = (PixelFormatFlags)pixelFormatFlag;
            }
            uint fourCC = r.ReadUInt32();

            if (!Enum.IsDefined(typeof(FourCC), fourCC))
            {
                throw new InvalidDataException(string.Format("Unexpected data, read 0x{0:xX8}", fourCC));
            }
            else
            {
                this.fourcc = (FourCC)fourCC;
            }
            this.RGBBitCount  = r.ReadUInt32();
            this.redBitMask   = r.ReadUInt32();
            this.greenBitMask = r.ReadUInt32();
            this.blueBitMask  = r.ReadUInt32();
            this.alphaBitMask = r.ReadUInt32();
        }
Ejemplo n.º 12
0
			public PixelFormatDescription( string name, PixelFormat format, byte elemBytes, PixelFormatFlags flags,
			                               PixelComponentType componentType, byte componentCount, byte rbits, byte gbits,
			                               byte bbits, byte abits, uint rmask, uint gmask, uint bmask, uint amask, byte rshift,
			                               byte gshift, byte bshift, byte ashift )
			{
				this.name = name;
				this.format = format;
				this.elemBytes = elemBytes;
				this.flags = flags;
				this.componentType = componentType;
				this.componentCount = componentCount;
				this.rbits = rbits;
				this.gbits = gbits;
				this.bbits = bbits;
				this.abits = abits;
				this.rmask = rmask;
				this.gmask = gmask;
				this.bmask = bmask;
				this.amask = amask;
				this.rshift = rshift;
				this.gshift = gshift;
				this.bshift = bshift;
				this.ashift = ashift;
			}
Ejemplo n.º 13
0
        static private PixelFormatFlags GetPixelFormatFlagsFromGuid(Guid pixelFormatGuid)
        {
            PixelFormatFlags result = PixelFormatFlags.BitsPerPixelUndefined;

            if (pixelFormatGuid.CompareTo(WICPixelFormatPhotonFirst) >= 0 &&
                pixelFormatGuid.CompareTo(WICPixelFormatPhotonLast) <= 0)
            {
                byte[] b = pixelFormatGuid.ToByteArray();

                switch (b[15])
                {
                case 0x1D:      // GUID_WICPixelFormat64bppRGBAFixedPoint
                    result = PixelFormatFlags.ChannelOrderARGB | PixelFormatFlags.IsScRGB;
                    break;

                case 0x1E:      // GUID_WICPixelFormat128bppRGBAFixedPoint
                    result = PixelFormatFlags.ChannelOrderARGB | PixelFormatFlags.IsScRGB;
                    break;

                case 0x1F:      // GUID_WICPixelFormat64bppCMYK
                    result = PixelFormatFlags.IsCMYK;
                    break;

                case 0x20:      // GUID_WICPixelFormat24bpp3Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x21:      // GUID_WICPixelFormat32bpp4Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x22:      // GUID_WICPixelFormat40bpp5Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x23:      // GUID_WICPixelFormat48bpp6Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x24:      // GUID_WICPixelFormat56bpp7Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x25:      // GUID_WICPixelFormat64bpp8Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x26:      // GUID_WICPixelFormat48bpp3Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x27:      // GUID_WICPixelFormat64bpp4Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x28:      // GUID_WICPixelFormat80bpp5Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x29:      // GUID_WICPixelFormat96bpp6Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x2A:      // GUID_WICPixelFormat112bpp7Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x2B:      // GUID_WICPixelFormat128bpp8Channels
                    result = PixelFormatFlags.IsNChannel;
                    break;

                case 0x2C:      // GUID_WICPixelFormat40bppCMYKAlpha
                    result = PixelFormatFlags.IsCMYK | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x2D:      // GUID_WICPixelFormat80bppCMYKAlpha
                    result = PixelFormatFlags.IsCMYK | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x2E:      // GUID_WICPixelFormat32bpp3ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x2F:      // GUID_WICPixelFormat40bpp4ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x30:      // GUID_WICPixelFormat48bpp5ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x31:      // GUID_WICPixelFormat56bpp6ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x32:      // GUID_WICPixelFormat64bpp7ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x33:      // GUID_WICPixelFormat72bpp8ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x34:      // GUID_WICPixelFormat64bpp3ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x35:      // GUID_WICPixelFormat80bpp4ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x36:      // GUID_WICPixelFormat96bpp5ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x37:      // GUID_WICPixelFormat112bpp6ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x38:      // GUID_WICPixelFormat128bpp7ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x39:      // GUID_WICPixelFormat144bpp8ChannelsAlpha
                    result = PixelFormatFlags.IsNChannel | PixelFormatFlags.NChannelAlpha;
                    break;

                case 0x3A:      // GUID_WICPixelFormat64bppRGBAHalf
                    result = PixelFormatFlags.ChannelOrderARGB | PixelFormatFlags.IsScRGB;
                    break;

                case 0x3B:      // GUID_WICPixelFormat48bppRGBHalf
                    result = PixelFormatFlags.ChannelOrderRGB | PixelFormatFlags.IsScRGB;
                    break;

                case 0x3D:      // GUID_WICPixelFormat32bppRGBE
                    result = PixelFormatFlags.ChannelOrderRGB | PixelFormatFlags.IsScRGB;
                    break;

                case 0x3E:      // GUID_WICPixelFormat16bppGrayHalf
                    result = PixelFormatFlags.IsGray | PixelFormatFlags.IsScRGB;
                    break;

                case 0x3F:      // GUID_WICPixelFormat32bppGrayFixedPoint
                    result = PixelFormatFlags.IsGray | PixelFormatFlags.IsScRGB;
                    break;

                case 0x40:      // GUID_WICPixelFormat64bppRGBFixedPoint
                    result = PixelFormatFlags.IsScRGB | PixelFormatFlags.ChannelOrderRGB;
                    break;

                case 0x41:      // GUID_WICPixelFormat128bppRGBFixedPoint
                    result = PixelFormatFlags.IsScRGB | PixelFormatFlags.ChannelOrderRGB;
                    break;

                case 0x42:      // GUID_WICPixelFormat64bppRGBHalf
                    result = PixelFormatFlags.IsScRGB | PixelFormatFlags.ChannelOrderRGB;
                    break;
                }
            }

            return(result);
        }
Ejemplo n.º 14
0
 public void Deserialize(Stream input, Endian endian)
 {
     this.Size = input.ReadValueU32(endian);
     this.Flags = input.ReadValueEnum<PixelFormatFlags>(endian);
     this.FourCC = input.ReadValueU32(endian);
     this.RGBBitCount = input.ReadValueU32(endian);
     this.RedBitMask = input.ReadValueU32(endian);
     this.GreenBitMask = input.ReadValueU32(endian);
     this.BlueBitMask = input.ReadValueU32(endian);
     this.AlphaBitMask = input.ReadValueU32(endian);
 }
Ejemplo n.º 15
0
        public void Initialise(FileFormat fileFormat)
        {
            this.Size = this.GetSize();
            
            switch (fileFormat)
            {
                case FileFormat.DXT1:
                {
                    this.Flags = PixelFormatFlags.FourCC;
                    this.RGBBitCount = 0;
                    this.RedBitMask = 0;
                    this.GreenBitMask = 0;
                    this.BlueBitMask = 0;
                    this.AlphaBitMask = 0;
                    this.FourCC = 0x31545844; // "DXT1"
                    break;
                }

                case FileFormat.DXT3:
                {
                    this.Flags = PixelFormatFlags.FourCC;
                    this.RGBBitCount = 0;
                    this.RedBitMask = 0;
                    this.GreenBitMask = 0;
                    this.BlueBitMask = 0;
                    this.AlphaBitMask = 0;
                    this.FourCC = 0x33545844; // "DXT3"
                    break;
                }

                case FileFormat.DXT5:
                {
                    this.Flags = PixelFormatFlags.FourCC;
                    this.RGBBitCount = 0;
                    this.RedBitMask = 0;
                    this.GreenBitMask = 0;
                    this.BlueBitMask = 0;
                    this.AlphaBitMask = 0;
                    this.FourCC = 0x35545844; // "DXT5"
                    break;
                }

                case FileFormat.A8R8G8B8:
                {
                    Flags = PixelFormatFlags.RGBA;
                    RGBBitCount = 32;
                    FourCC = 0;
                    RedBitMask = 0x00FF0000;
                    GreenBitMask = 0x0000FF00;
                    BlueBitMask = 0x000000FF;
                    AlphaBitMask = 0xFF000000;
                    break;
                }

                case FileFormat.X8R8G8B8:
                {
                    Flags = PixelFormatFlags.RGB;
                    RGBBitCount = 32;
                    FourCC = 0;
                    RedBitMask = 0x00FF0000;
                    GreenBitMask = 0x0000FF00;
                    BlueBitMask = 0x000000FF;
                    AlphaBitMask = 0x00000000;
                    break;
                }

                case FileFormat.A8B8G8R8:
                {
                    Flags = PixelFormatFlags.RGBA;
                    RGBBitCount = 32;
                    FourCC = 0;
                    RedBitMask = 0x000000FF;
                    GreenBitMask = 0x0000FF00;
                    BlueBitMask = 0x00FF0000;
                    AlphaBitMask = 0xFF000000;
                    break;
                }

                case FileFormat.X8B8G8R8:
                {
                    Flags = PixelFormatFlags.RGB;
                    RGBBitCount = 32;
                    FourCC = 0;
                    RedBitMask = 0x000000FF;
                    GreenBitMask = 0x0000FF00;
                    BlueBitMask = 0x00FF0000;
                    AlphaBitMask = 0x00000000;
                    break;
                }

                case FileFormat.A1R5G5B5:
                {
                    Flags = PixelFormatFlags.RGBA;
                    RGBBitCount = 16;
                    FourCC = 0;
                    RedBitMask = 0x00007C00;
                    GreenBitMask = 0x000003E0;
                    BlueBitMask = 0x0000001F;
                    AlphaBitMask = 0x00008000;
                    break;
                }

                case FileFormat.A4R4G4B4:
                {
                    Flags = PixelFormatFlags.RGBA;
                    RGBBitCount = 16;
                    FourCC = 0;
                    RedBitMask = 0x00000F00;
                    GreenBitMask = 0x000000F0;
                    BlueBitMask = 0x0000000F;
                    AlphaBitMask = 0x0000F000;
                    break;
                }

                case FileFormat.R8G8B8:
                {
                    Flags = PixelFormatFlags.RGB;
                    FourCC = 0;
                    RGBBitCount = 24;
                    RedBitMask = 0x00FF0000;
                    GreenBitMask = 0x0000FF00;
                    BlueBitMask = 0x000000FF;
                    AlphaBitMask = 0x00000000;
                    break;
                }

                case FileFormat.R5G6B5:
                {
                    Flags = PixelFormatFlags.RGB;
                    FourCC = 0;
                    RGBBitCount = 16;
                    RedBitMask = 0x0000F800;
                    GreenBitMask = 0x000007E0;
                    BlueBitMask = 0x0000001F;
                    AlphaBitMask = 0x00000000;
                    break;
                }

                default:
                {
                    throw new NotSupportedException();
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Checks for correct pixel format. If wrong, an 
        /// <see cref="ArgumentException"/> is thrown.
        /// </summary>
        /// <param name="supportedPixelFormats">The supported pixel formats.
        /// </param>
        /// <param name="format">The pixel format to check.</param>
        /// <exception cref="NotSupportedException">
        /// No supported pixel format.</exception>
        public static void CheckPixelFormat(
            PixelFormatFlags supportedPixelFormats,
            PixelFormat format)
        {
            string errorMsg = "No supported source pixel format.";
            switch (supportedPixelFormats)
            {
                case PixelFormatFlags.None:
                    errorMsg = "No supported pixel format.";
                    break;
                case PixelFormatFlags.Format8BppIndexed:
                    errorMsg = "Source image can be grayscale (8 bpp) image only.";
                    break;
                case PixelFormatFlags.Format24BppRgb:
                    errorMsg = "Source image can be color (24 bpp) image only.";
                    break;
                case (PixelFormatFlags.Format32BppArgb | PixelFormatFlags.Format32BppRgb):
                    errorMsg = "Source image can be color (32 bpp) image only.";
                    break;
                case PixelFormatFlags.Format24And8Bpp:
                    errorMsg = "Source image can be color (24 bpp) image" +
                        " or grayscale (8 bpp) image only.";
                    break;
                case PixelFormatFlags.Format32And8Bpp:
                    errorMsg = "Source image can be color (32 bpp) image" +
                        " or grayscale (8 bpp) image only.";
                    break;
                case PixelFormatFlags.Color:
                    errorMsg = "Source image can be color (24 or 32 bpp) image only.";
                    break;
                case PixelFormatFlags.All:
                    errorMsg = "Source image can be color (24 or 32 bpp) image" +
                        " or grayscale (8 bpp) image only.";
                    break;
            }

            PixelFormatFlags flags;
            switch (format)
            {
                case PixelFormat.Format8bppIndexed:
                    flags = PixelFormatFlags.Format8BppIndexed;
                    break;
                case PixelFormat.Format24bppRgb:
                    flags = PixelFormatFlags.Format24BppRgb;
                    break;
                case PixelFormat.Format32bppArgb:
                    flags = PixelFormatFlags.Format32BppArgb;
                    break;
                case PixelFormat.Format32bppRgb:
                    flags = PixelFormatFlags.Format32BppRgb;
                    break;
                default:
                    flags = PixelFormatFlags.None;
                    break;
            }

            if ((flags & supportedPixelFormats) == 0)
            {
                throw new NotSupportedException(errorMsg);
            }
        }
Ejemplo n.º 17
0
 /// <summary>Read the pixel format.</summary>
 /// <param name="reader"></param>
 public PixelFormat(BinaryReader reader)
 {
     int size = reader.ReadInt32();
     if (size != Size)
         throw new InvalidDataException();
     Flags = (PixelFormatFlags)reader.ReadInt32();
     var fourcc = reader.ReadBytes(4);
     FourCC = Encoding.ASCII.GetString(fourcc);
     RGBBitCount = reader.ReadInt32();
     RBitMask = reader.ReadInt32();
     GBitMask = reader.ReadInt32();
     BBitMask = reader.ReadInt32();
     ABitMask = reader.ReadInt32();
 }
Ejemplo n.º 18
0
            /// <summary>Create the pixel format.</summary>
            /// <param name="format"></param>
            public PixelFormat(Format format)
            {
                if (format.IsCompressed) {
                    Flags = PixelFormatFlags.FourCC;
                    FourCC = FormatFourCCs[format];

                    RGBBitCount = 0;
                    RBitMask = GBitMask = BBitMask = ABitMask = 0;
                } else
                    throw new NotImplementedException();
            }
Ejemplo n.º 19
0
        /// <summary>
        /// Checks for correct pixel format. If wrong, an
        /// <see cref="ArgumentException"/> is thrown.
        /// </summary>
        /// <param name="supportedPixelFormats">The supported pixel formats.
        /// </param>
        /// <param name="format">The pixel format to check.</param>
        /// <exception cref="NotSupportedException">
        /// No supported pixel format.</exception>
        public static void CheckPixelFormat(
            PixelFormatFlags supportedPixelFormats,
            PixelFormat format)
        {
            string errorMsg = "No supported source pixel format.";

            switch (supportedPixelFormats)
            {
            case PixelFormatFlags.None:
                errorMsg = "No supported pixel format.";
                break;

            case PixelFormatFlags.Format8BppIndexed:
                errorMsg = "Source image can be grayscale (8 bpp) image only.";
                break;

            case PixelFormatFlags.Format24BppRgb:
                errorMsg = "Source image can be color (24 bpp) image only.";
                break;

            case (PixelFormatFlags.Format32BppArgb | PixelFormatFlags.Format32BppRgb):
                errorMsg = "Source image can be color (32 bpp) image only.";
                break;

            case PixelFormatFlags.Format24And8Bpp:
                errorMsg = "Source image can be color (24 bpp) image" +
                           " or grayscale (8 bpp) image only.";
                break;

            case PixelFormatFlags.Format32And8Bpp:
                errorMsg = "Source image can be color (32 bpp) image" +
                           " or grayscale (8 bpp) image only.";
                break;

            case PixelFormatFlags.Color:
                errorMsg = "Source image can be color (24 or 32 bpp) image only.";
                break;

            case PixelFormatFlags.All:
                errorMsg = "Source image can be color (24 or 32 bpp) image" +
                           " or grayscale (8 bpp) image only.";
                break;
            }

            PixelFormatFlags flags;

            switch (format)
            {
            case PixelFormat.Format8bppIndexed:
                flags = PixelFormatFlags.Format8BppIndexed;
                break;

            case PixelFormat.Format24bppRgb:
                flags = PixelFormatFlags.Format24BppRgb;
                break;

            case PixelFormat.Format32bppArgb:
                flags = PixelFormatFlags.Format32BppArgb;
                break;

            case PixelFormat.Format32bppRgb:
                flags = PixelFormatFlags.Format32BppRgb;
                break;

            default:
                flags = PixelFormatFlags.None;
                break;
            }

            if ((flags & supportedPixelFormats) == 0)
            {
                throw new NotSupportedException(errorMsg);
            }
        }
Ejemplo n.º 20
0
Archivo: DDS.cs Proyecto: cg123/xenko
 /// <summary>
 /// Initializes a new instance of the <see cref="DDSPixelFormat" /> struct.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <param name="fourCC">The four CC.</param>
 /// <param name="rgbBitCount">The RGB bit count.</param>
 /// <param name="rBitMask">The r bit mask.</param>
 /// <param name="gBitMask">The g bit mask.</param>
 /// <param name="bBitMask">The b bit mask.</param>
 /// <param name="aBitMask">A bit mask.</param>
 public DDSPixelFormat(PixelFormatFlags flags, int fourCC, int rgbBitCount, uint rBitMask, uint gBitMask, uint bBitMask, uint aBitMask)
 {
     Size = Utilities.SizeOf<DDSPixelFormat>();
     Flags = flags;
     FourCC = fourCC;
     RGBBitCount = rgbBitCount;
     RBitMask = rBitMask;
     GBitMask = gBitMask;
     BBitMask = bBitMask;
     ABitMask = aBitMask;
 }
Ejemplo n.º 21
0
        public void Initialise(FileFormat fileFormat)
        {
            this.Size = this.GetSize();

            switch (fileFormat)
            {
            case FileFormat.DXT1:
            {
                this.Flags        = PixelFormatFlags.FourCC;
                this.RGBBitCount  = 0;
                this.RedBitMask   = 0;
                this.GreenBitMask = 0;
                this.BlueBitMask  = 0;
                this.AlphaBitMask = 0;
                this.FourCC       = 0x31545844; // "DXT1"
                break;
            }

            case FileFormat.DXT3:
            {
                this.Flags        = PixelFormatFlags.FourCC;
                this.RGBBitCount  = 0;
                this.RedBitMask   = 0;
                this.GreenBitMask = 0;
                this.BlueBitMask  = 0;
                this.AlphaBitMask = 0;
                this.FourCC       = 0x33545844; // "DXT3"
                break;
            }

            case FileFormat.DXT5:
            {
                this.Flags        = PixelFormatFlags.FourCC;
                this.RGBBitCount  = 0;
                this.RedBitMask   = 0;
                this.GreenBitMask = 0;
                this.BlueBitMask  = 0;
                this.AlphaBitMask = 0;
                this.FourCC       = 0x35545844; // "DXT5"
                break;
            }

            case FileFormat.A8R8G8B8:
            {
                Flags        = PixelFormatFlags.RGBA;
                RGBBitCount  = 32;
                FourCC       = 0;
                RedBitMask   = 0x00FF0000;
                GreenBitMask = 0x0000FF00;
                BlueBitMask  = 0x000000FF;
                AlphaBitMask = 0xFF000000;
                break;
            }

            case FileFormat.X8R8G8B8:
            {
                Flags        = PixelFormatFlags.RGB;
                RGBBitCount  = 32;
                FourCC       = 0;
                RedBitMask   = 0x00FF0000;
                GreenBitMask = 0x0000FF00;
                BlueBitMask  = 0x000000FF;
                AlphaBitMask = 0x00000000;
                break;
            }

            case FileFormat.A8B8G8R8:
            {
                Flags        = PixelFormatFlags.RGBA;
                RGBBitCount  = 32;
                FourCC       = 0;
                RedBitMask   = 0x000000FF;
                GreenBitMask = 0x0000FF00;
                BlueBitMask  = 0x00FF0000;
                AlphaBitMask = 0xFF000000;
                break;
            }

            case FileFormat.X8B8G8R8:
            {
                Flags        = PixelFormatFlags.RGB;
                RGBBitCount  = 32;
                FourCC       = 0;
                RedBitMask   = 0x000000FF;
                GreenBitMask = 0x0000FF00;
                BlueBitMask  = 0x00FF0000;
                AlphaBitMask = 0x00000000;
                break;
            }

            case FileFormat.A1R5G5B5:
            {
                Flags        = PixelFormatFlags.RGBA;
                RGBBitCount  = 16;
                FourCC       = 0;
                RedBitMask   = 0x00007C00;
                GreenBitMask = 0x000003E0;
                BlueBitMask  = 0x0000001F;
                AlphaBitMask = 0x00008000;
                break;
            }

            case FileFormat.A4R4G4B4:
            {
                Flags        = PixelFormatFlags.RGBA;
                RGBBitCount  = 16;
                FourCC       = 0;
                RedBitMask   = 0x00000F00;
                GreenBitMask = 0x000000F0;
                BlueBitMask  = 0x0000000F;
                AlphaBitMask = 0x0000F000;
                break;
            }

            case FileFormat.R8G8B8:
            {
                Flags        = PixelFormatFlags.RGB;
                FourCC       = 0;
                RGBBitCount  = 24;
                RedBitMask   = 0x00FF0000;
                GreenBitMask = 0x0000FF00;
                BlueBitMask  = 0x000000FF;
                AlphaBitMask = 0x00000000;
                break;
            }

            case FileFormat.R5G6B5:
            {
                Flags        = PixelFormatFlags.RGB;
                FourCC       = 0;
                RGBBitCount  = 16;
                RedBitMask   = 0x0000F800;
                GreenBitMask = 0x000007E0;
                BlueBitMask  = 0x0000001F;
                AlphaBitMask = 0x00000000;
                break;
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Ejemplo n.º 22
0
 public PixelFormat(PixelFormatFlags flags, int fourCC, int rgbBitCount, uint rBitMask, uint gBitMask, uint bBitMask, uint aBitMask)
 {
     Size = Marshal.SizeOf(typeof(PixelFormat));
     Flags = flags;
     FourCC = fourCC;
     RGBBitCount = rgbBitCount;
     RBitMask = rBitMask;
     GBitMask = gBitMask;
     BBitMask = bBitMask;
     ABitMask = aBitMask;
 }