display-name: "Images/DDS"

file-format image-DDS
{
	unsigned32 dwMagic == 0x20534444

	//DDSURFACEDESC2
	unsigned32 dwSize  //Size of structure. This member must be set to 124.
	unsigned32 dwFlags  //Flags to indicate valid fields. Always include DDSD_CAPS, DDSD_PIXELFORMAT, DDSD_WIDTH, DDSD_HEIGHT.
	unsigned32 dwHeight  //Height of the main image in pixels
	unsigned32 dwWidth  //Width of the main image in pixels
	unsigned32 dwPitchOrLinearSize  //For uncompressed formats, this is the number of bytes per scan line (unsigned32> aligned) for the main image. dwFlags should include DDSD_PITCH in this case. For compressed formats, this is the total number of bytes for the main image. dwFlags should be include DDSD_LINEARSIZE in this case.
	unsigned32 dwDepth  //For volume textures, this is the depth of the volume. dwFlags should include DDSD_DEPTH in this case.
	unsigned32 dwMipMapCount  //For items with mipmap levels, this is the total number of levels in the mipmap chain of the main image. dwFlags should include DDSD_MIPMAPCOUNT in this case.
	unsigned32[11] dwReserved1  //Unused

	//DDPIXELFORMAT
	unsigned32 dwSize  //Size of structure. This member must be set to 32.
	unsigned32 dwFlags  //Flags to indicate valid fields. Uncompressed formats will usually use DDPF_RGB to indicate an RGB format, while compressed formats will use DDPF_FOURCC with a four-character code.
	unsigned32 dwFourCC  //This is the four-character code for compressed formats. dwFlags should include DDPF_FOURCC in this case. For DXTn compression, this is set to "DXT1", "DXT2", "DXT3", "DXT4", or "DXT5".
	unsigned32 dwRGBBitCount  //For RGB formats, this is the total number of bits in the format. dwFlags should include DDPF_RGB in this case. This value is usually 16, 24, or 32. For A8R8G8B8, this value would be 32.

	unsigned32 dwRBitMask
 	unsigned32 dwGBitMask
 	unsigned32 dwBBitMask  //For RGB formats, these three fields contain the masks for the red, green, and blue channels. For A8R8G8B8, these values would be 0x00ff0000, 0x0000ff00, and 0x000000ff respectively.
	unsigned32 dwRGBAlphaBitMask  //For RGB formats, this contains the mask for the alpha channel, if any. dwFlags should include DDPF_ALPHAPIXELS in this case. For A8R8G8B8, this value would be 0xff000000.

	//DDCAPS2	
	unsigned32 dwCaps1   //DDS files should always include DDSCAPS_TEXTURE. If the file contains mipmaps, DDSCAPS_MIPMAP should be set. For any .dds file with more than one main surface, such as a mipmaps, cubic environment map, or volume texture, DDSCAPS_COMPLEX should also be set.
	unsigned32 dwCaps2   //For cubic environment maps, DDSCAPS2_CUBEMAP should be included as well as one or more faces of the map (DDSCAPS2_CUBEMAP_POSITIVEX, DDSCAPS2_CUBEMAP_NEGATIVEX, DDSCAPS2_CUBEMAP_POSITIVEY, DDSCAPS2_CUBEMAP_NEGATIVEY, DDSCAPS2_CUBEMAP_POSITIVEZ, DDSCAPS2_CUBEMAP_NEGATIVEZ). For volume textures, DDSCAPS2_VOLUME should be included.
	unsigned32[2] Reserved	 // Unused


	unsigned32 dwReserved2  // Unused

	width: dwWidth
	height: dwHeight

	if ((dwFlags & 0x00000004) != 0) //fourCC
	{
		S3TCType: 0

		if (dwFourCC == 0x31545844)
		{
			S3TCType = 1
		}
		else if (dwFourCC == 0x32545844)
		{
			S3TCType = 2
		}
		else if (dwFourCC == 0x33545844)
		{
			S3TCType = 3
		}
		else if (dwFourCC == 0x34545844)
		{
			S3TCType = 4
		}
		else if (dwFourCC == 0x35545844)
		{
			S3TCType = 5
		}

		if (S3TCType != 0)
		{
			compressed [file.remaining-bytes]  "S3TC"
			{
				image
				{
					format: "R8G8B8A8"
				}
			}
		}
	}	
}


if (file.name like "*.*")
{
	interpret-as "image-DDS"
}