public static function Create($filename, $imgid = 0) { $f = fopen($filename, "rb") or die("Cannot open file " . $filename . "\n"); $filesize = filesize($filename); if ($filesize < 16) { die("File " . $filename . " is too small for a BLP file\n"); } $data = fread($f, $filesize); fclose($f); if (substr($data, 0, 4) != "BLP2") { die("File " . $filename . " has incorrect/unsupported magic bytes\n"); } $header = unpack("Vformat/Ctype/CalphaBits/CalphaType/Cmips/Vwidth/Vheight", substr($data, 4, 16)); $header["mipsOffs"] = unpack("V16", substr($data, 20, 64)); $header["mipsSize"] = unpack("V16", substr($data, 84, 64)); $debugstr = "\nheader = " . print_r($header, true) . "\n"; if ($header["format"] != 1) { die("File " . $filename . " has unsupported format" . $debugstr); } //print_r($debugstr); $offs = $header["mipsOffs"][$imgid + 1]; $size = $header["mipsSize"][$imgid + 1]; while ($imgid > 0) { $header["width"] /= 2; $header["height"] /= 2; $imgid--; } if ($size == 0) { die("File " . $filename . " contains zeroes in a mips table" . $debugstr); } if ($offs + $size > $filesize) { die("File " . $filename . " is corrupted/incomplete" . $debugstr); } if ($header["type"] == 1) { $img = BLP2Image::icfb1($header["width"], $header["height"], substr($data, 148, 1024), substr($data, $offs, $size)); } elseif ($header["type"] == 2) { $img = BLP2Image::icfb2($header["width"], $header["height"], substr($data, $offs, $size), $header["alphaBits"], $header["alphaType"]); } elseif ($header["type"] == 3) { $img = BLP2Image::icfb3($header["width"], $header["height"], substr($data, $offs, $size)); } else { die("File " . $filename . " has unsupported type" . $debugstr); } if ($img) { return $img; } else { die($debugstr); } }
public static function Extract($Filename, $Format) { ImageGenerator::Status("Reading icons list from {$Filename}...\n"); ImageGenerator::Status("Looking for icons in " . ImageGenerator::$DataDir . "...\n"); $UnpackedDBC = ImageGenerator::Unpack($Filename, $Format); $Count = count($UnpackedDBC); ImageGenerator::Status($Count . " icons found\n"); $CurrentIcon = 0; $Status = array(); $LastFile = array(); foreach ($UnpackedDBC as $Row) { $SourceFileName = strtolower(str_replace("\\", "/", $Row[1])); if (strpos($SourceFileName, "/") === FALSE) { $SourceFileName = "/interface/icons/" . $SourceFileName; } $Source = ImageGenerator::$DataDir . ImageGenerator::$Patch . '/' . $SourceFileName . ".blp"; $SourceStat = @stat($Source); if ($Row[1] == "") { echo " "; } else { if ($SourceStat == NULL || $SourceStat['size'] == 0) { $Message = "Not Found"; $Status[$Message] = isset($Status[$Message]) ? $Status[$Message] + 1 : 1; $LastFile[$Message][] = $Source; echo "-"; } else { $DestFileName = strtolower(substr(strrchr($SourceFileName, "/"), 1)); $DestStat = @stat(ImageGenerator::$DirArray['large'] . $DestFileName . ".jpg"); if ($DestStat != NULL && $DestStat['mtime'] >= $SourceStat['mtime']) { $Message = "Already up-to-date"; $Status[$Message] = isset($Status[$Message]) ? $Status[$Message] + 1 : 1; $LastFile[$Message][0] = "..."; $LastFile[$Message][1] = $Source; echo "."; } else { $Image = BLP2Image::Create($Source); ImageGenerator::ReSave(ImageGenerator::$DirArray['large'] . $DestFileName . ".jpg", $Image, 56, 56); ImageGenerator::ReSave(ImageGenerator::$DirArray['medium'] . $DestFileName . ".jpg", $Image, 36, 36); ImageGenerator::ReSave(ImageGenerator::$DirArray['small'] . $DestFileName . ".jpg", $Image, 18, 18); ImageGenerator::ReSave(ImageGenerator::$DirArray['tiny'] . $DestFileName . ".gif", $Image, 15, 15); echo "+"; } } } $CurrentIcon++; if ($CurrentIcon % 60 == 0) { ImageGenerator::Status(" " . $CurrentIcon . "/" . $Count . " (" . round(100 * $CurrentIcon / $Count) . "%)\n"); } } if ($CurrentIcon % 60 != 0) { ImageGenerator::Status(" " . $CurrentIcon . "/" . $Count . " (100%)\n"); } echo "Done\n"; if (count($Status) > 0) { echo "Status:\n"; foreach ($Status as $S => $Row) { echo " " . $S . ": " . $Row . "\n"; } } echo "\n\n\n"; }
public static function GenerateWorld() { MapsGenerator::Status("Reading subzones list...\n"); $UnpackedDBC = MapsGenerator::Unpack("WorldMapOverlay.dbc", "nixxxxxxsiiiixxxx"); $WMO = array(); foreach ($UnpackedDBC as $Row) { if ($Row[2]) { $WMO[$Row[1]][] = array("name" => strtolower($Row[2]), "width" => $Row[3], "height" => $Row[4], "left" => $Row[5], "top" => $Row[6]); } } MapsGenerator::Status(count($UnpackedDBC) . "\n"); MapsGenerator::Status("Reading zones list...\n"); $UnpackedDBC = MapsGenerator::Unpack("WorldMapArea.dbc", "nxisxxxxxxx"); MapsGenerator::Status(count($UnpackedDBC) . "\n"); $Count = 0; foreach ($UnpackedDBC as $Row) { $Count++; if ($Row[1]) { $zid = $Row[0]; $MapID = $Row[1]; $MapName = $Row[2]; MapsGenerator::Status($MapName . "[" . $MapID . "]"); $MapName = strtolower($MapName); $Map = imagecreatetruecolor(1024, 768); $MapFG = imagecreatetruecolor(1024, 768); imagesavealpha($MapFG, true); imagealphablending($MapFG, false); $bgcolor = imagecolorallocatealpha($MapFG, 0, 0, 0, 127); imagefilledrectangle($MapFG, 0, 0, 1023, 767, $bgcolor); imagecolordeallocate($MapFG, $bgcolor); imagealphablending($MapFG, true); echo "."; $prefix = MapsGenerator::$DirArray['WorldMap'] . $MapName . "/" . $MapName; if (@stat($prefix . "1.blp") == NULL) { $prefix = $prefix . "1_"; } if (@stat($prefix . "1.blp") == NULL) { MapsGenerator::Status(" not found.\n"); continue; } for ($i = 0; $i < 12; $i++) { $Image = BLP2Image::Create($prefix . ($i + 1) . ".blp"); imagecopyresampled($Map, $Image, 256 * ($i % 4), 256 * intval($i / 4), 0, 0, 256, 256, imagesx($Image), imagesy($Image)); imagedestroy($Image); } echo "."; if (isset($wmo[$zid])) { foreach ($wmo[$zid] as $Row) { $i = 1; $y = 0; while ($y < $Row["height"]) { $x = 0; while ($x < $Row["width"]) { $Image = BLP2Image::Create(MapsGenerator::$DirArray['WorldMap'] . $MapName . "/" . $Row["name"] . $i . ".blp"); imagecopy($MapFG, $Image, $Row["left"] + $x, $Row["top"] + $y, 0, 0, imagesx($Image), imagesy($Image)); imagedestroy($Image); $x += 256; $i++; } $y += 256; } } echo "."; if (isset($outtmpdir)) { $tmp = imagecreate(1000, 1000); $cbg = imagecolorallocate($tmp, 255, 255, 255); $cfg = imagecolorallocate($tmp, 0, 0, 0); for ($y = 0; $y < 1000; $y++) { for ($x = 0; $x < 1000; $x++) { $a = imagecolorat($MapFG, $x * MapsGenerator::$BLPMapWidth / 1000, $y * MapsGenerator::$BLPMapHeight / 1000) >> 24; imagesetpixel($tmp, $x, $y, $a < 30 ? $cfg : $cbg); } } imagepng($tmp, $outtmpdir . $MapID . ".png"); imagecolordeallocate($tmp, $cbg); imagecolordeallocate($tmp, $cfg); imagedestroy($tmp); echo "."; } } for ($y = 0; $y < imagesy($MapFG); $y++) { for ($x = 0; $x < imagesx($MapFG); $x++) { $c = imagecolorat($MapFG, $x, $y); if ($c >> 24 < 127 && $c >> 24 > 0) { $c &= 0xffffff; imagesetpixel($MapFG, $x, $y, $c); } } } imagecopy($Map, $MapFG, 0, 0, 0, 0, imagesx($MapFG), imagesy($MapFG)); imagedestroy($MapFG); $NewImage = imagecreatetruecolor(488, 325); imagecopyresampled($NewImage, $Map, 0, 0, 0, 0, 488, 325, MapsGenerator::$BLPMapWidth, MapsGenerator::$BLPMapHeight); imagejpeg($NewImage, MapsGenerator::$DirArray['NormalMap'] . $MapID . ".jpg"); imagedestroy($NewImage); $NewImage = imagecreatetruecolor(772, 515); imagecopyresampled($NewImage, $Map, 0, 0, 0, 0, 772, 515, MapsGenerator::$BLPMapWidth, MapsGenerator::$BLPMapHeight); imagejpeg($NewImage, MapsGenerator::$DirArray['ZoomMap'] . $MapID . ".jpg"); imagedestroy($NewImage); imagedestroy($Map); MapsGenerator::Status("done (" . intval($Count * 100 / count($UnpackedDBC)) . "%)\n"); } } }