Set of web tools to convert and manipulate fxi, g1r and g1m files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
G1rFxiTools/PicViewer/converter.php

86 lines
2.1 KiB

<?php
ini_set("display_errors",1);
if(isset($_FILES['file']['name']) && !empty($_FILES['file']['name']))
{
require_once('../common/functions.php');
//detection du format
$format = strtolower(substr($_FILES['file']['name'],-3));
//get size
if(!is_numeric($_POST['size']) || $_POST['size']<1 || $_POST['size']>9)
{
$size=3;
}
else $size=$_POST['size'];
//get colors
if(isset($_POST['blackAndWhite']) && $format=="fxi")
{
$colors =array(array(0,0,0),array(0, 0, 0),array(0, 0, 0),array(255, 255, 255)) ;
//0 = rouge
//1 = bleu
//2 = vert
//3 = white
}
elseif($format=="fxi")
// else
{
$colors =array(array(255,0,0),array(0, 0, 255),array(0, 128, 0),array(255, 255, 255));
//0 = rouge => black
//1 = bleu => black
//2 = vert => black
//3 = white => white
}
else
{
$colors =array(array(0,0,0),array(255, 255, 255),array(255, 255, 255),array(255, 255, 255)) ;
}
//getfile
$InFile = file_get_contents($_FILES['file']['tmp_name']);
$InFileSize = strlen($InFile);
if($format == 'fxi')
{
//decode fxi & to hex
$InFile = fxiDecode($InFile);
//search for pic block
for($i = 0 ; $i < $InFileSize*2; $i+=2)
{
if(substr($InFile, $i, 6) == "494d47" && substr($InFile,$i+8,4)=="5043")
{
$pics ="";
for($j = $i+96 ; $j < $i+8224+96; $j++)
{
$pics.=$InFile[$j];
}
$picsArray = getFxiPic($pics);
writePics($picsArray, $colors, $size);
exit;
}
}
}
elseif($format == 'g1r' || $format == 'g1m' || $format == 'g2m')
{
//to hex
$InFile = bin2hex($InFile);
//search for pic block
for($i = 0 ; $i < $InFileSize*2; $i+=2)
{
if(substr($InFile, $i, 16) == "5049435455524520" && substr($InFile,$i+18,46)=="00000000000000000000016d61696e0000000050494354" && substr($InFile,$i+66,22)=="0000000700000800000000")
{
$pics ="";
for($j = $i+88 ; $j < $i+4096+88; $j++)
{
$pics.=$InFile[$j];
}
$picsArray = getG1mPic($pics);
writePics($picsArray, $colors, $size);
exit;
}
}
echo "Aucune image trouvée";exit;
}
}
else
{
header('Location : ../');
}
?>