Click here to Skip to main content
15,867,308 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Maximum limit of char array? Pin
jannathali6-Apr-10 22:38
jannathali6-Apr-10 22:38 
GeneralRe: Maximum limit of char array? Pin
«_Superman_»6-Apr-10 22:42
professional«_Superman_»6-Apr-10 22:42 
GeneralRe: Maximum limit of char array? Pin
CPallini6-Apr-10 22:48
mveCPallini6-Apr-10 22:48 
AnswerRe: Maximum limit of char array? Pin
Cedric Moonen7-Apr-10 0:12
Cedric Moonen7-Apr-10 0:12 
AnswerRe: Maximum limit of char array? Pin
Rajesh R Subramanian7-Apr-10 0:18
professionalRajesh R Subramanian7-Apr-10 0:18 
QuestionMSXML Issue [modified] Pin
002comp6-Apr-10 19:07
002comp6-Apr-10 19:07 
AnswerRe: MSXML Issue Pin
CPallini6-Apr-10 21:41
mveCPallini6-Apr-10 21:41 
QuestionNeed to read big-endian file (Windows) Pin
o m n i6-Apr-10 15:06
o m n i6-Apr-10 15:06 
I have a bunch of DXT5 DDS files, but information on the format is so sparse I have no idea how to write something to convert them. I have the following code as part of a library and this converts it to a format I can use, but I can't understand what I need to change to make it read the files as big endian.
If anyone could at least explain how the the *src variable is being used so I could determine where I need to convert stuff that would help, I currently don't get how values are being derived from it.

//-----------------------------------------------------------------------------------------------------
// DecompressDXT5(vlByte *src, vlByte *dst, vlUInt uiWidth, vlUInt uiHeight)
//
// Converts data from the DXT5 to RGBA8888 format. Data is read from *src
// and written to *dst. Width and height are needed to it knows how much data to process
//-----------------------------------------------------------------------------------------------------
vlBool CVTFFile::DecompressDXT5(vlByte *src, vlByte *dst, vlUInt uiWidth, vlUInt uiHeight)
{
	vlUInt		x, y, i, j, k, Select;
	vlByte		*Temp;
	Colour565	*color_0, *color_1;
	Colour8888	colours[4], *col;
	vlUInt		bitmask, Offset;
	vlByte		alphas[8], *alphamask;
	vlUInt		bits;

	vlByte nBpp = 4;						// bytes per pixel (4 channels (RGBA))
	vlByte nBpc = 1;						// bytes per channel (1 byte per channel)
	vlUInt iBps = nBpp * nBpc * uiWidth;		// bytes per scanline

	Temp = src;

	for (y = 0; y < uiHeight; y += 4)
	{
		for (x = 0; x < uiWidth; x += 4)
		{
			//if (y >= uiHeight || x >= uiWidth)
			//		break;

			alphas[0] = Temp[0];
			alphas[1] = Temp[1];
			alphamask = Temp + 2;
			Temp += 8;
			color_0 = ((Colour565*)Temp);
			color_1 = ((Colour565*)(Temp+2));
			bitmask = ((vlUInt*)Temp)[1];
			Temp += 8;

			colours[0].r = color_0->nRed << 3;
			colours[0].g = color_0->nGreen << 2;
			colours[0].b = color_0->nBlue << 3;
			colours[0].a = 0xFF;

			colours[1].r = color_1->nRed << 3;
			colours[1].g = color_1->nGreen << 2;
			colours[1].b = color_1->nBlue << 3;
			colours[1].a = 0xFF;

			// Four-color block: derive the other two colors.    
			// 00 = color_0, 01 = color_1, 10 = color_2, 11 = color_3
			// These 2-bit codes correspond to the 2-bit fields 
			// stored in the 64-bit block.
			colours[2].b = (2 * colours[0].b + colours[1].b + 1) / 3;
			colours[2].g = (2 * colours[0].g + colours[1].g + 1) / 3;
			colours[2].r = (2 * colours[0].r + colours[1].r + 1) / 3;
			colours[2].a = 0xFF;

			colours[3].b = (colours[0].b + 2 * colours[1].b + 1) / 3;
			colours[3].g = (colours[0].g + 2 * colours[1].g + 1) / 3;
			colours[3].r = (colours[0].r + 2 * colours[1].r + 1) / 3;
			colours[3].a = 0xFF;

			k = 0;
			for (j = 0; j < 4; j++)
			{
				for (i = 0; i < 4; i++, k++)
				{
					Select = (bitmask & (0x03 << k*2)) >> k*2;
					col = &colours[Select];

					// only put pixels out < width or height
					if (((x + i) < uiWidth) && ((y + j) < uiHeight)) {
						Offset = (y + j) * iBps + (x + i) * nBpp;
						dst[Offset + 0] = col->r;
						dst[Offset + 1] = col->g;
						dst[Offset + 2] = col->b;
					}
				}
			}

			// 8-alpha or 6-alpha block?    
			if (alphas[0] > alphas[1])
			{ 
				// 8-alpha block:  derive the other six alphas.    
				// Bit code 000 = alpha_0, 001 = alpha_1, others are interpolated.
				alphas[2] = (6 * alphas[0] + 1 * alphas[1] + 3) / 7;	// bit code 010
				alphas[3] = (5 * alphas[0] + 2 * alphas[1] + 3) / 7;	// bit code 011
				alphas[4] = (4 * alphas[0] + 3 * alphas[1] + 3) / 7;	// bit code 100
				alphas[5] = (3 * alphas[0] + 4 * alphas[1] + 3) / 7;	// bit code 101
				alphas[6] = (2 * alphas[0] + 5 * alphas[1] + 3) / 7;	// bit code 110
				alphas[7] = (1 * alphas[0] + 6 * alphas[1] + 3) / 7;	// bit code 111  
			}    
			else
			{  
				// 6-alpha block.    
				// Bit code 000 = alpha_0, 001 = alpha_1, others are interpolated.
				alphas[2] = (4 * alphas[0] + 1 * alphas[1] + 2) / 5;	// Bit code 010
				alphas[3] = (3 * alphas[0] + 2 * alphas[1] + 2) / 5;	// Bit code 011
				alphas[4] = (2 * alphas[0] + 3 * alphas[1] + 2) / 5;	// Bit code 100
				alphas[5] = (1 * alphas[0] + 4 * alphas[1] + 2) / 5;	// Bit code 101
				alphas[6] = 0x00;										// Bit code 110
				alphas[7] = 0xFF;										// Bit code 111
			}

			// Note: Have to separate the next two loops,
			//	it operates on a 6-byte system.

			// First three bytes
			bits = *((int*)alphamask);
			for (j = 0; j < 2; j++)
			{
				for (i = 0; i < 4; i++)
				{
					// only put pixels out < width or height
					if (((x + i) < uiWidth) && ((y + j) < uiHeight)) {
						Offset = (y + j) * iBps + (x + i) * nBpp + 3;
							dst[Offset] = alphas[bits & 0x07];
					}
					bits >>= 3;
				}
			}

			// Last three bytes
			bits = *((int*)&alphamask[3]);
			for (j = 2; j < 4; j++)
			{
				for (i = 0; i < 4; i++)
				{
					// only put pixels out < width or height
					if (((x + i) < uiWidth) && ((y + j) < uiHeight)) {
						Offset = (y + j) * iBps + (x + i) * nBpp + 3;
							dst[Offset] = alphas[bits & 0x07];
					}
					bits >>= 3;
				}
			}
		}
	}
	return vlTrue;
}

AnswerRe: Need to read big-endian file (Windows) Pin
Garth J Lancaster6-Apr-10 20:05
professionalGarth J Lancaster6-Apr-10 20:05 
GeneralRe: Need to read big-endian file (Windows) Pin
o m n i11-Apr-10 18:14
o m n i11-Apr-10 18:14 
AnswerRe: Need to read big-endian file (Windows) Pin
Eugen Podsypalnikov6-Apr-10 21:39
Eugen Podsypalnikov6-Apr-10 21:39 
AnswerRe: Need to read big-endian file (Windows) Pin
Luc Pattyn6-Apr-10 23:31
sitebuilderLuc Pattyn6-Apr-10 23:31 
QuestionAfxBeginThread and ON_THREAD_MESSAGE does not work using PostThreadMessage Pin
Vaclav_6-Apr-10 14:25
Vaclav_6-Apr-10 14:25 
AnswerRe: AfxBeginThread and ON_THREAD_MESSAGE does not work using PostThreadMessage Pin
No Name No Name No Name6-Apr-10 17:56
No Name No Name No Name6-Apr-10 17:56 
AnswerRe: AfxBeginThread and ON_THREAD_MESSAGE does not work using PostThreadMessage Pin
ramana.g6-Apr-10 18:26
ramana.g6-Apr-10 18:26 
GeneralRe: AfxBeginThread and ON_THREAD_MESSAGE does not work using PostThreadMessage Pin
sthalasayanam6-Apr-10 18:43
sthalasayanam6-Apr-10 18:43 
AnswerRe: AfxBeginThread and ON_THREAD_MESSAGE does not work using PostThreadMessage Pin
Rajesh R Subramanian7-Apr-10 0:16
professionalRajesh R Subramanian7-Apr-10 0:16 
AnswerRe: AfxBeginThread and ON_THREAD_MESSAGE does not work using PostThreadMessage Pin
David Crow7-Apr-10 3:05
David Crow7-Apr-10 3:05 
AnswerRe: AfxBeginThread and ON_THREAD_MESSAGE does not work using PostThreadMessage Pin
Vaclav_7-Apr-10 6:26
Vaclav_7-Apr-10 6:26 
GeneralRe: AfxBeginThread and ON_THREAD_MESSAGE does not work using PostThreadMessage Pin
Vaclav_7-Apr-10 6:36
Vaclav_7-Apr-10 6:36 
AnswerRe: AfxBeginThread and ON_THREAD_MESSAGE does not work using PostThreadMessage Pin
Vaclav_7-Apr-10 8:01
Vaclav_7-Apr-10 8:01 
QuestionReset to computer Pin
RomTibi6-Apr-10 9:57
RomTibi6-Apr-10 9:57 
QuestionRe: Reset to computer Pin
David Crow6-Apr-10 10:04
David Crow6-Apr-10 10:04 
AnswerRe: Reset to computer Pin
RomTibi6-Apr-10 10:24
RomTibi6-Apr-10 10:24 
AnswerRe: Reset to computer Pin
David Crow6-Apr-10 10:26
David Crow6-Apr-10 10:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.