コード例 #1
0
        private static void ExportR16ToDDS(BinaryReader sourceReader, Stream destination, DDSConvertParameters @params)
        {
            DDSConvertParameters bgraParams = new DDSConvertParameters();

            @params.CopyTo(bgraParams);
            bgraParams.RGBBitCount = 32;
            bgraParams.RBitMask    = 0xFF0000;
            bgraParams.GBitMask    = 0xFF00;
            bgraParams.BBitMask    = 0xFF;
            bgraParams.ABitMask    = 0xFF000000;
            ExportDDSHeader(destination, bgraParams);

            long pixelCount = @params.BitMapDepth * @params.Height * @params.Width;

            for (int i = 0; i < pixelCount; i++)
            {
                ushort pixel = sourceReader.ReadUInt16();
                float  f     = Half.ToHalf(pixel);
                byte   R     = (byte)Math.Ceiling(f * 255.0);
                destination.WriteByte(0);                       // B
                destination.WriteByte(0);                       // G
                destination.WriteByte(R);                       // R
                destination.WriteByte(0xFF);                    // A
            }
        }
コード例 #2
0
        private static void ExportARGB32ToDDS(BinaryReader sourceReader, Stream destination, DDSConvertParameters @params)
        {
            DDSConvertParameters bgraParams = new DDSConvertParameters();

            @params.CopyTo(bgraParams);
            bgraParams.RBitMask = 0xFF0000;
            bgraParams.GBitMask = 0xFF00;
            bgraParams.BBitMask = 0xFF;
            bgraParams.ABitMask = 0xFF000000;
            ExportDDSHeader(destination, bgraParams);

            long pixelCount = @params.BitMapDepth * @params.Height * @params.Width;

            for (int i = 0; i < pixelCount; i++)
            {
                byte A = sourceReader.ReadByte();
                byte R = sourceReader.ReadByte();
                byte G = sourceReader.ReadByte();
                byte B = sourceReader.ReadByte();
                destination.WriteByte(B);                     // B
                destination.WriteByte(G);                     // G
                destination.WriteByte(R);                     // R
                destination.WriteByte(A);                     // A
            }
        }
コード例 #3
0
        private static void ExportRGBA16ToDDS(BinaryReader sourceReader, Stream destination, DDSConvertParameters @params)
        {
            DDSConvertParameters bgraParams = new DDSConvertParameters();

            @params.CopyTo(bgraParams);
            bgraParams.RBitMask = 0xF00;
            bgraParams.BBitMask = 0xF;
            ExportDDSHeader(destination, bgraParams);

            long pixelCount = @params.BitMapDepth * @params.Height * @params.Width;

            for (int i = 0; i < pixelCount; i++)
            {
                int pixel = sourceReader.ReadUInt16();
                int c1    = (0x00F0 & pixel) >> 4;                  // B
                int c2    = (0x0F00 & pixel) >> 4;                  // G
                destination.WriteByte((byte)(c1 | c2));
                c1 = (0xF000 & pixel) >> 12;                        // R
                c2 = (0x000F & pixel) << 4;                         // A
                destination.WriteByte((byte)(c1 | c2));
            }
        }