Esempio n. 1
0
        internal static DdsFormat GetDdsFormat(DdsPixelFormat ddpf)
        {
            if ((ddpf.Options & DdsPixelFormatOptions.Rgb) != 0)
            {
                switch (ddpf.RgbBitCount)
                {
                case 32:
                    if (IsBitMask(ddpf, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000))
                    {
                        return(DdsFormat.R8G8B8A8UNorm);
                    }

                    if (IsBitMask(ddpf, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000))
                    {
                        return(DdsFormat.B8G8R8A8UNorm);
                    }

                    if (IsBitMask(ddpf, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000))
                    {
                        return(DdsFormat.B8G8R8X8UNorm);
                    }

                    if (IsBitMask(ddpf, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000))
                    {
                        return(DdsFormat.R10G10B10A2UNorm);
                    }

                    if (IsBitMask(ddpf, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000))
                    {
                        return(DdsFormat.R16G16UNorm);
                    }

                    if (IsBitMask(ddpf, 0xffffffff, 0x00000000, 0x00000000, 0x00000000))
                    {
                        return(DdsFormat.R32Float);
                    }

                    break;

                case 24:
                    break;

                case 16:
                    if (IsBitMask(ddpf, 0x7c00, 0x03e0, 0x001f, 0x8000))
                    {
                        return(DdsFormat.B5G5R5A1UNorm);
                    }

                    if (IsBitMask(ddpf, 0xf800, 0x07e0, 0x001f, 0x0000))
                    {
                        return(DdsFormat.B5G6R5UNorm);
                    }

                    if (IsBitMask(ddpf, 0x0f00, 0x00f0, 0x000f, 0xf000))
                    {
                        return(DdsFormat.B4G4R4A4UNorm);
                    }

                    break;
                }
            }
            else if ((ddpf.Options & DdsPixelFormatOptions.Luminance) != 0)
            {
                switch (ddpf.RgbBitCount)
                {
                case 16:
                    if (IsBitMask(ddpf, 0x0000ffff, 0x00000000, 0x00000000, 0x00000000))
                    {
                        return(DdsFormat.R16UNorm);
                    }

                    if (IsBitMask(ddpf, 0x000000ff, 0x00000000, 0x00000000, 0x0000ff00))
                    {
                        return(DdsFormat.R8G8UNorm);
                    }

                    break;

                case 8:
                    if (IsBitMask(ddpf, 0x000000ff, 0x00000000, 0x00000000, 0x00000000))
                    {
                        return(DdsFormat.R8UNorm);
                    }

                    if (IsBitMask(ddpf, 0x000000ff, 0x00000000, 0x00000000, 0x0000ff00))
                    {
                        return(DdsFormat.R8G8UNorm);
                    }

                    break;
                }
            }
            else if ((ddpf.Options & DdsPixelFormatOptions.Alpha) != 0)
            {
                if (ddpf.RgbBitCount == 8)
                {
                    return(DdsFormat.A8UNorm);
                }
            }
            else if ((ddpf.Options & DdsPixelFormatOptions.BumpDuDv) != 0)
            {
                switch (ddpf.RgbBitCount)
                {
                case 32:
                    if (IsBitMask(ddpf, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000))
                    {
                        return(DdsFormat.R8G8B8A8SNorm);
                    }

                    if (IsBitMask(ddpf, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000))
                    {
                        return(DdsFormat.R16G16SNorm);
                    }

                    break;

                case 16:
                    if (IsBitMask(ddpf, 0x00ff, 0xff00, 0x0000, 0x0000))
                    {
                        return(DdsFormat.R8G8SNorm);
                    }

                    break;
                }
            }
            else if ((ddpf.Options & DdsPixelFormatOptions.FourCC) != 0)
            {
                switch (ddpf.FourCC)
                {
                case DdsFourCC.DXT1:
                    return(DdsFormat.BC1UNorm);

                case DdsFourCC.DXT3:
                    return(DdsFormat.BC2UNorm);

                case DdsFourCC.DXT5:
                    return(DdsFormat.BC3UNorm);

                case DdsFourCC.DXT2:
                    return(DdsFormat.BC2UNorm);

                case DdsFourCC.DXT4:
                    return(DdsFormat.BC3UNorm);

                case DdsFourCC.BC4U:
                    return(DdsFormat.BC4UNorm);

                case DdsFourCC.BC4S:
                    return(DdsFormat.BC4SNorm);

                case DdsFourCC.BC5U:
                    return(DdsFormat.BC5UNorm);

                case DdsFourCC.BC5S:
                    return(DdsFormat.BC5SNorm);

                case DdsFourCC.RGBG:
                    return(DdsFormat.R8G8B8G8UNorm);

                case DdsFourCC.GRGB:
                    return(DdsFormat.G8R8G8B8UNorm);

                case DdsFourCC.YUY2:
                    return(DdsFormat.Yuy2);

                case DdsFourCC.D3DFMT_A16B16G16R16:
                    return(DdsFormat.R16G16B16A16UNorm);

                case DdsFourCC.D3DFMT_Q16W16V16U16:
                    return(DdsFormat.R16G16B16A16SNorm);

                case DdsFourCC.D3DFMT_R16F:
                    return(DdsFormat.R16Float);

                case DdsFourCC.D3DFMT_G16R16F:
                    return(DdsFormat.R16G16Float);

                case DdsFourCC.D3DFMT_A16B16G16R16F:
                    return(DdsFormat.R16G16B16A16Float);

                case DdsFourCC.D3DFMT_R32F:
                    return(DdsFormat.R32Float);

                case DdsFourCC.D3DFMT_G32R32F:
                    return(DdsFormat.R32G32Float);

                case DdsFourCC.D3DFMT_A32B32G32R32F:
                    return(DdsFormat.R32G32B32A32Float);
                }
            }

            return(DdsFormat.Unknown);
        }
Esempio n. 2
0
 private static bool IsBitMask(DdsPixelFormat ddpf, uint r, uint g, uint b, uint a)
 {
     return(ddpf.RedBitMask == r && ddpf.GreenBitMask == g && ddpf.BlueBitMask == b && ddpf.AlphaBitMask == a);
 }