Ejemplo n.º 1
0
        public void Read(BinaryReader reader)
        {
            Size              = reader.ReadUInt32();
            HeaderFlags       = reader.ReadUInt32();
            Height            = reader.ReadUInt32();
            Width             = reader.ReadUInt32();
            PitchOrLinearSize = reader.ReadUInt32();
            Depth             = reader.ReadUInt32();
            MipMapCount       = reader.ReadUInt32();
            Reserved1_0       = reader.ReadUInt32();
            Reserved1_1       = reader.ReadUInt32();
            Reserved1_2       = reader.ReadUInt32();
            Reserved1_3       = reader.ReadUInt32();
            Reserved1_4       = reader.ReadUInt32();
            Reserved1_5       = reader.ReadUInt32();
            Reserved1_6       = reader.ReadUInt32();
            Reserved1_7       = reader.ReadUInt32();
            Reserved1_8       = reader.ReadUInt32();
            Reserved1_9       = reader.ReadUInt32();
            Reserved1_10      = reader.ReadUInt32();

            PixelFormat = new DdsPixelFormat();

            PixelFormat.Read(reader);

            SurfaceFlags = reader.ReadUInt32();
            CubemapFlags = reader.ReadUInt32();
            Reserved2_0  = reader.ReadUInt32();
            Reserved2_1  = reader.ReadUInt32();
            Reserved2_2  = reader.ReadUInt32();
        }
Ejemplo n.º 2
0
    public DdsHeader(DdsSaveConfig config, int width, int height) {
      PixelFormat = new DdsPixelFormat(config.FileFormat);

      bool isCompressed = config.FileFormat == FileFormat.DXT1
                       || config.FileFormat == FileFormat.DXT3
                       || config.FileFormat == FileFormat.DXT5;
      //
      // Compute mip map count..
      //
      int mipCount = config.GenerateMipMaps ? CountMipMaps(width, height) : 1;

      Size = 18 * 4 + PixelFormat.Size + 5 * 4;

      Width  = (uint)width;
      Height = (uint)height;

      MipMapCount = mipCount == 1 ? 0 : (uint)mipCount;

      HeaderFlags = (uint)(Constants.HeaderFlags.Texture | (isCompressed ? Constants.HeaderFlags.LinearSize : Constants.HeaderFlags.Pitch)
                                                         | (mipCount > 1 ? Constants.HeaderFlags.MipMap     : Constants.HeaderFlags.None));

      SurfaceFlags = (uint)(Constants.SurfaceFlags.Texture | (mipCount > 1 ? Constants.SurfaceFlags.MipMap : Constants.SurfaceFlags.None));

      if (isCompressed) {
        //
        // Compresssed textures have the linear flag set.  So pitchOrLinearSize
        // needs to contain the entire size of the DXT block.
        //
        int blockCount = (width + 3) / 4 * ((height + 3) / 4);

        int blockSize = config.FileFormat == FileFormat.Unknown ? 8 : 16;

        PitchOrLinearSize = (uint)(blockCount * blockSize);
      }
      else {
        //
        // Non-compressed textures have the pitch flag set. So pitchOrLinearSize
        // needs to contain the row pitch of the main image.
        //
        int pixelWidth = 0;

        switch(config.FileFormat) {
          case FileFormat.A8R8G8B8:
          case FileFormat.X8R8G8B8:
          case FileFormat.A8B8G8R8:
          case FileFormat.X8B8G8R8: {
            pixelWidth = 4;

            break;
          }
          case FileFormat.R8G8B8: {
            pixelWidth = 3;

            break;
          }
          case FileFormat.A1R5G5B5:
          case FileFormat.A4R4G4B4:
          case FileFormat.R5G6B5: {
            pixelWidth = 2;

            break;
          }
          case FileFormat.G8: {
            pixelWidth = 1;

            break;
          }
        }

        PitchOrLinearSize = (uint)(width * pixelWidth);
      }
    }
Ejemplo n.º 3
0
        public DdsHeader(DdsSaveConfig config, int width, int height)
        {
            PixelFormat = new DdsPixelFormat(config.FileFormat);

            bool isCompressed = config.FileFormat == FileFormat.DXT1 ||
                                config.FileFormat == FileFormat.DXT3 ||
                                config.FileFormat == FileFormat.DXT5;
            //
            // Compute mip map count..
            //
            int mipCount = config.GenerateMipMaps ? CountMipMaps(width, height) : 1;

            Size = 18 * 4 + PixelFormat.Size + 5 * 4;

            Width  = (uint)width;
            Height = (uint)height;

            MipMapCount = mipCount == 1 ? 0 : (uint)mipCount;

            HeaderFlags = (uint)(Constants.HeaderFlags.Texture | (isCompressed ? Constants.HeaderFlags.LinearSize : Constants.HeaderFlags.Pitch)
                                 | (mipCount > 1 ? Constants.HeaderFlags.MipMap     : Constants.HeaderFlags.None));

            SurfaceFlags = (uint)(Constants.SurfaceFlags.Texture | (mipCount > 1 ? Constants.SurfaceFlags.MipMap : Constants.SurfaceFlags.None));

            if (isCompressed)
            {
                //
                // Compresssed textures have the linear flag set.  So pitchOrLinearSize
                // needs to contain the entire size of the DXT block.
                //
                int blockCount = (width + 3) / 4 * ((height + 3) / 4);

                int blockSize = config.FileFormat == FileFormat.Unknown ? 8 : 16;

                PitchOrLinearSize = (uint)(blockCount * blockSize);
            }
            else
            {
                //
                // Non-compressed textures have the pitch flag set. So pitchOrLinearSize
                // needs to contain the row pitch of the main image.
                //
                int pixelWidth = 0;

                switch (config.FileFormat)
                {
                case FileFormat.A8R8G8B8:
                case FileFormat.X8R8G8B8:
                case FileFormat.A8B8G8R8:
                case FileFormat.X8B8G8R8: {
                    pixelWidth = 4;

                    break;
                }

                case FileFormat.R8G8B8: {
                    pixelWidth = 3;

                    break;
                }

                case FileFormat.A1R5G5B5:
                case FileFormat.A4R4G4B4:
                case FileFormat.R5G6B5: {
                    pixelWidth = 2;

                    break;
                }

                case FileFormat.G8: {
                    pixelWidth = 1;

                    break;
                }
                }

                PitchOrLinearSize = (uint)(width * pixelWidth);
            }
        }
Ejemplo n.º 4
0
    public void Read(BinaryReader reader) {
      Size              = reader.ReadUInt32();
      HeaderFlags       = reader.ReadUInt32();
      Height            = reader.ReadUInt32();
      Width             = reader.ReadUInt32();
      PitchOrLinearSize = reader.ReadUInt32();
      Depth             = reader.ReadUInt32();
      MipMapCount       = reader.ReadUInt32();
      Reserved1_0       = reader.ReadUInt32();
      Reserved1_1       = reader.ReadUInt32();
      Reserved1_2       = reader.ReadUInt32();
      Reserved1_3       = reader.ReadUInt32();
      Reserved1_4       = reader.ReadUInt32();
      Reserved1_5       = reader.ReadUInt32();
      Reserved1_6       = reader.ReadUInt32();
      Reserved1_7       = reader.ReadUInt32();
      Reserved1_8       = reader.ReadUInt32();
      Reserved1_9       = reader.ReadUInt32();
      Reserved1_10      = reader.ReadUInt32();

      PixelFormat = new DdsPixelFormat();

      PixelFormat.Read(reader);

      SurfaceFlags = reader.ReadUInt32();
      CubemapFlags = reader.ReadUInt32();
      Reserved2_0  = reader.ReadUInt32();
      Reserved2_1  = reader.ReadUInt32();
      Reserved2_2  = reader.ReadUInt32();
    }