<?php
$dbname = 'l2jdb';
$id = isset( $_GET['id'] ) ? $_GET['id'] : 0;
$type = isset( $_GET['type'] ) ? $_GET['type'] : '';
if ( $id > 0 && ( $type == 'clan' || $type == 'ally') )
{
$data = '';
switch ( $type )
{
case 'clan':
$clan = $controller->db()->getRow( "SELECT crest, isCrest FROM `$dbname`.`clan_data` WHERE clan_id = ?", array( $id ) );
if ( $clan && $clan['isCrest'] )
{
$data = $clan['crest'];
}
break;
case 'ally':
$ally = $controller->db()->getRow( "SELECT crest, isCrest FROM `$dbname`.`ally_data` WHERE ally_id = ?", array( $id ) );
if ( $ally && $ally['isCrest'] )
{
$data = $ally['crest'];
}
break;
}
if ( $data )
{
function readInt( $file )
{
$b4 = ord(fgetc($file));
$b3 = ord(fgetc($file));
$b2 = ord(fgetc($file));
$b1 = ord(fgetc($file));
return ($b1<<24)|($b2<<16)|($b3<<8)|$b4;
}
function readShort( $file )
{
$b2 = ord(fgetc($file));
$b1 = ord(fgetc($file));
return ($b1<<8)|$b2;
}
$rnd_file = tmpfile();
fwrite($rnd_file, $data);
fseek($rnd_file, 0);
$file = &$rnd_file;
$dds = fread($file,4);
if ( $dds !== 'DDS ' )
die( 'Error: no hay imagen DDS<br />'. $dds );
$hdrSize = readInt($file);
$hdrFlags = readInt($file);
$imgHeight = readInt($file)-4;
$imgWidth = readInt($file);
$imgPitch = readShort($file);
fseek($file, 84);
$dxt1 = fread($file,4);
if ($dxt1!=='DXT1') die("Error: no es formato DX1");
fseek($file, 128);
$img = imagecreatetruecolor($imgWidth, $imgHeight);
for ($y=-1; $y<$imgHeight/4; $y++)
{
for ($x=0; $x<$imgWidth/4; $x++)
{
$color0_16 = readShort($file);
$color1_16 = readShort($file);
$r0 = ($color0_16 >> 11) << 3;
$g0 = (($color0_16 >> 5) & 63) << 2;
$b0 = ($color0_16 & 31) << 3;
$r1 = ($color1_16 >> 11) << 3;
$g1 = (($color1_16 >> 5) & 63) << 2;
$b1 = ($color1_16 & 31) << 3;
$color0_32 = imagecolorallocate($img,$r0,$g0,$b0);
$color1_32 = imagecolorallocate($img,$r1,$g1,$b1);
$color01_32 = imagecolorallocate($img,$r0/2+$r1/2,$g0/2+$g1/2,$b0/2+$b1/2);
$black = imagecolorallocate($img,0,0,0);
$data = readInt($file);
for ($yy=0;$yy<4;$yy++)
{
for ($xx=0;$xx<4;$xx++)
{
$bb = $data & 3;
$data = $data >> 2;
switch ($bb)
{
case 0: $c = $color0_32; break;
case 1: $c = $color1_32; break;
case 2: $c = $color01_32; break;
default: $c = $black; break;
}
imagesetpixel($img,$x*4+$xx,$y*4+$yy,$c);
}
}
}
}
header( 'Content-type: image/jpeg' );
imagejpeg( $img );
die;
}
}
header( 'Content-Type: image/gif' );
die( "\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x90\x00\x00\xff\x00\x00\x00\x00\x00\x21\xf9\x04\x05\x10\x00\x00\x00\x2c\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x04\x01\x00\x3b" );
?>