Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 19.06.2007, 10:32   #1
aralyon
Архивный участник
 
Join Date: Sep 2005
Posts: 72
Default DSS->standard format conversion

Hi, I'm looking for any conversion tool written in PHP to convert DDS files (clan/ali crests) to any standard image usable for website (bmp,jpg,gif,png...). Does anyone know about something?
aralyon is offline  
Old 19.06.2007, 11:44   #2
tpuNIsher
Архивный участник
 
Join Date: Mar 2006
Posts: 685
Default

I don't know any in php but if u want to view them, u can use nVidia dds viewer / DDS plugin and then convert through photoshop i guess.
tpuNIsher is offline  
Old 19.06.2007, 11:48   #3
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default

Quote:
Originally Posted by tpuNIsher View Post
I don't know any in php but if u want to view them, u can use nVidia dds viewer / DDS plugin and then convert through photoshop i guess.
how u think how your thing will looks for website that shows clan emblems in top-X clans online real-time ?
humordwarf is offline  
Old 19.06.2007, 12:05   #4
tpuNIsher
Архивный участник
 
Join Date: Mar 2006
Posts: 685
Default

good question :P didn't think about that.
I don't have that script done cos' i don't know how it's done, yet. But i guess it's do-able.
tpuNIsher is offline  
Old 19.06.2007, 14:51   #5
FidoW
Архивный участник
 
Join Date: Sep 2005
Posts: 1,014
Default

Of course it is.

http://www.lineage2.es/info_clanes.php?server=2

Isnt perfect, have some problems with some colors in the last line... but it works... the original source of that code i get from here somewhere, i cant found the thread... , it was more bugged, i fixed it a little.
FidoW is offline  
Old 19.06.2007, 14:55   #6
m4rk
Архивный участник
 
Join Date: Jan 2006
Posts: 607
Default

this one?
https://postpacific.loc-online.com/f...ead.php?t=3555
m4rk is offline  
Old 19.06.2007, 15:32   #7
FidoW
Архивный участник
 
Join Date: Sep 2005
Posts: 1,014
Default

Quote:
Originally Posted by m4rk View Post
yeah, that is, lol, more 1 year ago, time is fast

Is almost the same... but have some small changes... if someone can fix it...
PHP Code:
<?

####################
## humordwarf (c) ##
####################

$result = mssql_query(sprintf(SELECT_CLAN_LOGO,$id));

$clan_crest = mssql_fetch_array($result);
$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: no hay imagen DDS");

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

//DXT1 header

fseek($file, 84);

$dxt1 = fread($file,4);

if (
$dxt1!=='DXT1') die("Error: no es formato DX1");

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

header ("Content-type: image/png");
$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);
      }
    }
  }
}

imagepng($img);
?>
###############
## humordwarf (c) ##
###############
FidoW is offline  
Old 19.06.2007, 16:51   #8
ZeniMax
Архивный участник
 
Join Date: May 2006
Posts: 209
Default

Thanks its a great share but Fidow where's the define for SELECT_CLAN_LOGO?
ZeniMax is offline  
Old 19.06.2007, 20:52   #9
aralyon
Архивный участник
 
Join Date: Sep 2005
Posts: 72
Default

Thanks, I'm going to implement it ASAP
aralyon is offline  
Old 19.06.2007, 23:59   #10
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default

lol... i forgot about that my thread %)
FidoW: and u forgot to place (c) HD into ur piece of code
:-P
humordwarf is offline  
Old 20.06.2007, 00:28   #11
FidoW
Архивный участник
 
Join Date: Sep 2005
Posts: 1,014
Default

Quote:
Originally Posted by humordwarf View Post
lol... i forgot about that my thread %)
FidoW: and u forgot to place (c) HD into ur piece of code
:-P
Sorry about that, i simple forgot, but is 99,99999% your code... so.. its complety yours isnt my work at all
FidoW is offline  
Old 20.06.2007, 08:56   #12
Kenjiro
Архивный участник
 
Join Date: Apr 2006
Posts: 120
Default

Huh, i searched this for months! Thanks a lot!
Mine reworked version (without ugly file using):
PHP Code:
function dds_to_image ( $dds_crest ) {
// base work, algorithm done by HD, changes by FidoW, reworked to image by mine

  // Validate type
  
if ( substr ( $dds_crest, 0, 4 ) !== "DDS " ) {
    return ( 
false );
  }
  
  
// DDS header
  
list ( , $hdr_size ) = unpack ( "V", substr ( $dds_crest, 4, 4 ) );
  list ( , 
$hdr_flags ) = unpack ( "V", substr ( $dds_crest, 8, 4 ) );
  list ( , 
$img_height ) = unpack ( "V", substr ( $dds_crest, 12, 4 ) );
  
$img_height -= 4;
  list ( , 
$img_width ) = unpack ( "V", substr ( $dds_crest, 16, 4 ) );
  list ( , 
$img_pitch ) = unpack ( "v", substr ( $dds_crest, 20, 2 ) );

  
// Validate DXT1
  
if ( substr ( $dds_crest, 84, 4 ) !== "DXT1" ) {
    return ( 
false );
  }
  
  
// main code
  
$dds_ptr = 128;
  
$img = imagecreatetruecolor ( $img_width, $img_height );

  for ( 
$y = -1; $y < $img_height / 4; $y++ ) {
    for ( 
$x = 0; $x < $img_width / 4; $x++ ) {
      list ( , 
$color0_16 ) = unpack ( "v", substr ( $dds_crest, $dds_ptr, 2 ) );
      list ( , 
$color1_16 ) = unpack ( "v", substr ( $dds_crest, $dds_ptr + 2, 2 ) );
      
$r0 = ( $color0_16 >> 11 ) << 3;
      
$g0 = ( ( $color0_16 >> 5 ) & 0x3f ) << 2;
      
$b0 = ( $color0_16 & 31 ) << 3;
      
$r1 = ( $color1_16 >> 11 ) << 3;
      
$g1 = ( ( $color1_16 >> 5 ) & 0x3f ) << 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 );
      list ( , 
$data ) = @unpack ( "V", substr ( $dds_crest, $dds_ptr + 4, 4 ) );
      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 );
        }
      }
      
$dds_ptr += 8;
    }
  }
  return ( 
$img );
} 
could be used as:
PHP Code:
$query = "select pc.bitmap from pledge p inner join pledge_crest pc on p.crest_id=pc.crest_id where p.pledge_id=" . str_replace ( "'", "''", $_GET [ "c" ] );
$res = mssql_query ( $query, $link_world );
$array_clan_crest = mssql_fetch_array ( $res );
mssql_free_result ( $res );
imagepng ( dds_to_image ( $array_clan_crest [ "bitmap" ] ) ); 
Kenjiro is offline  
Old 20.06.2007, 18:56   #13
tpuNIsher
Архивный участник
 
Join Date: Mar 2006
Posts: 685
Default

haha this rocks, thanks HD, FiDoW, kenjiro :P
tpuNIsher is offline  
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 17:43.