Platinum Partner

Quake LMP Parser

Canvas LMP (Quake QPic) parser.
Usage: LMPOpen (file name, canvas element, X pos on canvas, Y pos on canvas, path to palette, subrectangle X, subrectangle Y, subrectangle width, subrectangle height).

function LMPOpen(LMPFileName,LMPTarget,LMPX,LMPY,LMPPaletteFilename,LMPSubX,LMPSubY,LMPSubW,LMPSubH)
{
	if (document.getElementById(LMPTarget) == null) return;
	if (LMPFileName == null) return;
	
	//LMP file request
	var LMPRequest = new XMLHttpRequest();
	LMPRequest.open('GET',LMPFileName,false);
	LMPRequest.overrideMimeType('text/plain;charset=x-user-defined');
	LMPRequest.send(null);
	var LMPFile;
	LMPFile = LMPRequest.responseText;
	LMPRequest.abort();
	
	//Parsing
	var LMPOfs = 0;
	var LMPWidth = 0;
	var LMPHeight = 0;
	
	//Width and height
	LMPWidth = parseInt(
		'0x' + (LMPFile.charCodeAt(LMPOfs+3)&255).toString(16) + 
		(LMPFile.charCodeAt(LMPOfs+2)&255).toString(16) + 
		(LMPFile.charCodeAt(LMPOfs+1)&255).toString(16) + 
		(LMPFile.charCodeAt(LMPOfs)&255).toString(16))
	LMPOfs+=4;
	LMPHeight = parseInt(
		'0x' + (LMPFile.charCodeAt(LMPOfs+3)&255).toString(16) + 
		(LMPFile.charCodeAt(LMPOfs+2)&255).toString(16) + 
		(LMPFile.charCodeAt(LMPOfs+1)&255).toString(16) + 
		(LMPFile.charCodeAt(LMPOfs)&255).toString(16))
	LMPOfs+=4;
	
	//Pixels
	var LMPContext = document.getElementById(LMPTarget).getContext('2d');
	var LMPImageData = LMPContext.createImageData(LMPWidth,LMPHeight);
	//Palette
	var LMPPal;
	var LMPNumColors;
	if (LMPFile[LMPOfs+LMPWidth*LMPHeight] == null)
	{
		var LMPPalRequest = new XMLHttpRequest();
		LMPPalRequest.open('GET',LMPPaletteFilename || 'palette.lmp',false);
		LMPPalRequest.overrideMimeType('text/plain;charset=x-user-defined');
		LMPPalRequest.send(null);
		if ((LMPPalRequest.status == 200) || (LMPPalRequest.status == 0))
			LMPPal = LMPPalRequest.responseText;
		LMPPalRequest.abort();
		LMPNumColors = parseInt(LMPPal.length/3);
	}
	else
	{
		LMPNumColors = LMPFile.charCodeAt(LMPOfs+LMPWidth*LMPHeight)&255;
		if (LMPFile.charCodeAt(1+LMPOfs+LMPWidth*LMPHeight)&255 > 0)
			LMPNumColors = 256;
		LMPPal = LMPFile.substr(2+LMPOfs+LMPWidth*LMPHeight,LMPNumColors*3);
	}
	var LMPColors = [];
	var LMPQPalOfs = 0;
	var iClr = 0;
	for (iClr=0;iClr
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}