HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

BLP -> JPG -> BLP

05-04-2005, 05:17 PM#1
Vexorian
Completelly new to image files.

I only have one question, I read the specifications file's stuff about blps, but I have no clue about the mipmaps and the 15 things and that stuff, I would really need a way to just extract a jpg from a blp and inserting one into a blp.

Only need to know where the mipmap size/offset stuff go in a jpg file. and where is the data and all that stuff
05-04-2005, 10:19 PM#2
BlacKDicK
Here is some help. I´m a bit lazy to write something better right now. :8
Code:
// BlpSample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


#define BLP_MAX_MIPMAPS 16
#define DesiredMipMap 0

struct BLP_HEADER{
	DWORD BlpId;
	BOOL  IsPal;
	DWORD UnkA;
	DWORD Width;
	DWORD Height;
	DWORD UnkB;
	DWORD UnkC;
};


int _tmain(int argc, _TCHAR* argv[])
{
	LPCSTR FileName = "c:\\HeroTinkerTank.blp";
	HANDLE hFile = CreateFileA(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
	if (hFile != INVALID_HANDLE_VALUE)
	{
		BLP_HEADER BlpHeader;
		DWORD BytesReturned;
		ReadFile(hFile, &BlpHeader, sizeof(BLP_HEADER), &BytesReturned, NULL);
		if (BlpHeader.IsPal == FALSE)
		{
			DWORD MipMapOffset[BLP_MAX_MIPMAPS];
			DWORD MipMapSize[BLP_MAX_MIPMAPS];
			DWORD JpegHeaderSize;
			ReadFile(hFile, &MipMapOffset, sizeof(DWORD) * BLP_MAX_MIPMAPS, &BytesReturned, NULL);
			ReadFile(hFile, &MipMapSize, sizeof(DWORD) * BLP_MAX_MIPMAPS, &BytesReturned, NULL);
			ReadFile(hFile, &JpegHeaderSize, sizeof(DWORD), &BytesReturned, NULL);
			BYTE* JpegHeader = new BYTE[JpegHeaderSize];
			BYTE* MipMapData = new BYTE[MipMapSize[DesiredMipMap]];
			ReadFile(hFile, JpegHeader, JpegHeaderSize, &BytesReturned, NULL);
			SetFilePointer(hFile, MipMapOffset[DesiredMipMap], NULL, FILE_BEGIN);
			ReadFile(hFile, MipMapData, MipMapSize[DesiredMipMap], &BytesReturned, NULL);
			HANDLE hTarget = CreateFileA("c:\\HeroTinkerTank.jpg", GENERIC_WRITE, FILE_SHARE_READ, 
				NULL, CREATE_ALWAYS, NULL, NULL);
			if (hTarget !=INVALID_HANDLE_VALUE)
			{
				WriteFile(hTarget, JpegHeader, JpegHeaderSize, &BytesReturned, NULL);
				WriteFile(hTarget, MipMapData, MipMapSize[DesiredMipMap], &BytesReturned, NULL);
				CloseHandle(hTarget);
			}else{
				printf("Oops, unable to open target file\n");
			}
			delete MipMapData;
			delete JpegHeader;
		}else{
			printf("File is not a JPEG based BLP\n");
		}
		CloseHandle(hFile);
	}else{
		printf("Unable to open %s\n", FileName);
	}
	return 0;
}
08-19-2005, 07:17 PM#3
Vexorian
I didn't note this uddate till last wednesday.

I was unable to compile it, but I understood it.

The jpeg file only needs the header and the mipmap 0 after the header. Well that's what I understand from the code.

But when I do that, the result jpg image has weird colors, I seriously ignore any reason for this, but it seems the first channel is swapped with the 3rd chanel.

I am totally clueless about this
01-02-2006, 08:04 PM#4
PitzerMike
Might the byte order be the problem?