Post Pacific  

Go Back   Post Pacific > Lineage 2 > Lineage 2 General
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 05.03.2006, 15:42   #1
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default [SHARE] for your website

[php:1:22293f1ffe]
<?

$filename='./5.dds'; // $_GET['ddsfile']

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;
}


$file = fopen($filename,'rb');
$dds = fread($file,4);

if ($dds!=='DDS ')
{
die();
}

//DDS header
$hdrSize = readInt($file);
$hdrFlags = readInt($file);
$imgHeight = readInt($file);
$imgWidth = readInt($file);
$imgPitch = readShort($file);


//DXT1 header

fseek($file, 84);

$dxt1 = fread($file,4);

//echo 'Header Size: '.$hdrSize.'
';
//echo 'Header Flags: '.$hdrFlags.'
';
//echo 'Image Width: '.$imgWidth.'
';
//echo 'Image Height: '.$imgHeight.'
';
//echo 'Image Pitch: '.$imgPitch.'
';
//echo 'Image Format: '.$dxt1.'
';

if ($dxt1!=='DXT1')
{
die();
}


//here we go
fseek($file, 128);


header ("Content-type: image/png");
$img=imagecreatetruecolor($imgWidth,$imgHeight);


for ($y=0; $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);
}
}
}
}

//output
imagepng($img);

?>
[/php:1:22293f1ffe]
humordwarf is offline  
Old 05.03.2006, 15:45   #2
Metalmurphy
Архивный участник
 
Join Date: Feb 2005
Posts: 766
Default



If im correct this is to allows us to show dss files, obviously for crests isnt it? xD

Thumbs up

one of the most usefull shares yet!!
Metalmurphy is offline  
Old 05.03.2006, 17:16   #3
drzoom
Архивный участник
 
Join Date: Aug 2005
Posts: 428
Default

Cool! Thks, humordwarf!
drzoom is offline  
Old 05.03.2006, 17:26   #4
Xoleum
Архивный участник
 
Join Date: Jan 2006
Posts: 125
Default

What is this for? Sorry for my n00bish question.
Xoleum is offline  
Old 05.03.2006, 17:27   #5
Metalmurphy
Архивный участник
 
Join Date: Feb 2005
Posts: 766
Default

I just said whats it for Xoleum...
Metalmurphy is offline  
Old 05.03.2006, 17:51   #6
Truffe
Архивный участник
 
Join Date: May 2005
Posts: 944
Default

Humordwarf, did I mentionned thou were awesome ?
Truffe is offline  
Old 05.03.2006, 19:30   #7
Xoleum
Архивный участник
 
Join Date: Jan 2006
Posts: 125
Default

Quote:
Originally Posted by Metalmurphy
I just said whats it for Xoleum...
And what is a dss?
Xoleum is offline  
Old 05.03.2006, 19:36   #8
toolpunk
Архивный участник
 
Join Date: May 2005
Posts: 2,033
Default

afaik its a file format...
toolpunk is offline  
Old 05.03.2006, 20:53   #9
Metalmurphy
Архивный участник
 
Join Date: Feb 2005
Posts: 766
Default

Texture file format used by Unreal Engine. In c1 crests were saved as bmp. in C3/C4 they are saved as dss and my guess is becouse of the crest in pledge shields feature.
Metalmurphy is offline  
Old 06.03.2006, 00:25   #10
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default

lol
DDS - DirectDraw Surface
DXT1 - the smallest variation of S3TC, storing 16 input pixels in 64 bits of output, consisting of two 16-bit RGB 5:6:5 color values and a 4x4 two bit lookup table
humordwarf is offline  
Old 06.03.2006, 04:03   #11
GMan
Архивный участник
 
Join Date: Sep 2005
Posts: 198
Default

I added the code to get clan crest from DB and some error text to the 2 die statments

[php:1:f062ecfb0d]<?
$ms_server = "SERVER";
$ms_user = "USERNAME";
$ms_password = "PASSWORD";
$ms_lin2world = "lin2world";
$ms_con = mssql_connect($ms_server, $ms_user, $ms_password);
mssql_select_db($ms_lin2world, $ms_con);
$sql = "SELECT bitmap
FROM Pledge_Crest
WHERE (crest_id =
(SELECT crest_id
FROM pledge
WHERE name = '".mysql_escape_string($_GET['clan_name'])."')) OR
(crest_id =
(SELECT crest_id
FROM pledge
WHERE pledge_id = '".mysql_escape_string($_GET['clan_id'])."'))";
$ms_query = mssql_query($sql, $ms_con);
$clan_crest = mssql_fetch_array($ms_query);
$rnd_file = tmpfile();
fwrite($rnd_file, $clan_crest['bitmap']);
fseek($rnd_file, 0);

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;
}


$file = &$rnd_file; //fopen($filename,'rb');
$dds = fread($file,4);

if ($dds!=='DDS ')
{
die("Error: not DDS");
}

//DDS header
$hdrSize = readInt($file);
$hdrFlags = readInt($file);
$imgHeight = readInt($file);
$imgWidth = readInt($file);
$imgPitch = readShort($file);


//DXT1 header

fseek($file, 84);

$dxt1 = fread($file,4);

//echo 'Header Size: '.$hdrSize.'
';
//echo 'Header Flags: '.$hdrFlags.'
';
//echo 'Image Width: '.$imgWidth.'
';
//echo 'Image Height: '.$imgHeight.'
';
//echo 'Image Pitch: '.$imgPitch.'
';
//echo 'Image Format: '.$dxt1.'
';

if ($dxt1!=='DXT1')
{
die("Error: not DX1 format");
}


//here we go
fseek($file, 128);


header ("Content-type: image/png");
$img=imagecreatetruecolor($imgWidth,$imgHeight);


for ($y=0; $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);
}
}
}
}

//output
imagepng($img);

?>[/php:1:f062ecfb0d]

call like
crest.php?clan_name=gm or crest.php?clan_id=1
changing gm or 1 to the clan name or id
also can be in normal img tag

[img]crest.php?clan_name=gm[/img]

have not really checked for security holes so dont blame me if your DB wipes out but by all means it wont do that
GMan is offline  
Old 06.03.2006, 05:35   #12
lich
Архивный участник
 
Join Date: Jul 2005
Posts: 96
Default

It's a good idea to save crests in flies instead of getting it from base every time
lich is offline  
Old 06.03.2006, 17:31   #13
Metalmurphy
Архивный участник
 
Join Date: Feb 2005
Posts: 766
Default

Do you realise how often ppl change clan crests?
Metalmurphy is offline  
Old 08.03.2006, 03:46   #14
Shawnmb
Архивный участник
 
Join Date: Feb 2005
Posts: 307
Default

If you set up your database server properly you wouldn't see a negative performance impact with this unless someone was flooding it, might be a good idea to add flood prevention to the page later.
Shawnmb is offline  
Old 16.02.2007, 11:05   #15
AgeNT2005
Архивный участник
 
Join Date: Aug 2005
Posts: 10
Default

Prompt if you please that necessary to change in order to they showed pledge crest for C4.
I please forgiveness for the poor English, I use translator.
AgeNT2005 is offline  
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 22:20.