Help us keep the site up! Got some change to spare? Why not donate a few bits and buy us a coffee. Image

Diablo III Tex File Format

Get your graphics formats figures out here! Got details for others? Post here!
Post Reply
User avatar
TaylorMouse
ultra-veteran
ultra-veteran
Posts: 340
Joined: Mon Sep 26, 2011 12:51 pm
Has thanked: 11 times
Been thanked: 84 times

Diablo III Tex File Format

Post by TaylorMouse »

Hi guys, been figuring out how to convert the C++ data into c#

this is for coverting the .tex files (Diablo III Tex(tures)) to dds format.

up till the code below everything was just going well ( being not a C++ guy and all)

but now I ran into a huge problem, I don't understand what is happening in the part that starts with

Code: Select all

if(nPixelSize == 8) 
In c# I have a BinaryReader object, that is used to read the bytes (and stuff) but I just can't seem to get that part of code... need help plz .

(code is originally taken from the C++ D3TEX2DDS converter)

Code: Select all

int DecodeTexPixelData(
	int nDecodeMethod, int nDecodeMethodEx, 
	uint8_t* pDst, uint8_t* pSrc, size_t nDstSize, 
	size_t nWidth, size_t nHeight, size_t nMipLevel, size_t nCalcPitch, size_t nTexPitch)
{

	//DecodeTexPixelData( nFormat, nFormat, pBuffer, pStart, nSize, nWidth ,nHeight, 0, nPitch, nPitch);

	//First Pass Decode
	uint8_t* pBuffer = NULL;
	if(nDecodeMethod <= 12 && nDecodeMethod >= 9)
	{
		size_t nPixels = ((nWidth >> nMipLevel) * (nHeight >> nMipLevel)) / 16;
		int nPixelSize = GetDecodeSize(nDecodeMethod);
		if(nPixelSize == -1)
			return 0;

		size_t nSize = nPixels * nPixelSize;
		pBuffer = (uint8_t*)malloc(nSize);



		if(nPixelSize == 8)
		{
			uint32_t* pDest = (uint32_t*)pBuffer;
			uint32_t* r = (uint32_t*)pSrc;
			uint32_t* g = (uint32_t*)(pSrc + (nPixels * 4));
			for(size_t i = nPixels; i != 0; i--)
			{
				pDest[0] = *r++;
				pDest[1] = *g++;
				pDest += 2;
			}
		}


Thnx
T.
ZeroGravity
n00b
Posts: 10
Joined: Sat Nov 26, 2011 10:29 pm
Been thanked: 7 times

Re: Diablo III Tex File Format

Post by ZeroGravity »

looks like pixels stored in 2 different sources, column 0,2,4,6,...,n and column 1,3,5,7,...n+1

Code: Select all

      if(nPixelSize == 8)
      {
         uint32_t* pDest = (uint32_t*)pBuffer;
         uint32_t* r = (uint32_t*)pSrc;                          //pixels source 1
         uint32_t* g = (uint32_t*)(pSrc + (nPixels * 4));  //pixels source 2 8bit per color+8bit alpha = 32 or 4 bytes
         for(size_t i = nPixels; i != 0; i--)
         {
            pDest[0] = *r++;                                          //place first pixel from source 1, pDest[0] = *r; r = r + 1;
            pDest[1] = *g++;                                         //place second pixel from source 2, pDest[1] = *g; g = g + 1;
            pDest += 2;                                                //increment pDest,  pDest = pDest + 2;
         }
      }
User avatar
TaylorMouse
ultra-veteran
ultra-veteran
Posts: 340
Joined: Mon Sep 26, 2011 12:51 pm
Has thanked: 11 times
Been thanked: 84 times

Re: Diablo III Tex File Format

Post by TaylorMouse »

aaaah, it starts to make sence... thnx

T.
Post Reply