First commit of Sprite Coder V3
This commit is contained in:
parent
33bb602821
commit
908059c17f
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
Copyright (c) 2019 Smashmaster
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -0,0 +1,587 @@
|
|||
<?php
|
||||
include('codeBasic.php');
|
||||
|
||||
|
||||
function AjoutRetourLigne($str) //ajoute à la fin de la chaine $str un retour chariot
|
||||
{
|
||||
return $str.'
|
||||
';
|
||||
}
|
||||
|
||||
|
||||
|
||||
function estTropErreur($err)
|
||||
{
|
||||
$nb=count($err);
|
||||
for ($i=0 ; $i<$nb ; $i++)
|
||||
if ($err[$i]["err"]==2 )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function uploadFile()
|
||||
{
|
||||
$nbFichier=count($_FILES['fichier']['name']);
|
||||
$nomImage = array();
|
||||
if ($_FILES['fichier']['error'][0]!=4)
|
||||
{
|
||||
/**on upload les fichiers**/
|
||||
for ($j= 0;$j<$nbFichier;$j++)
|
||||
{
|
||||
move_uploaded_file($_FILES['fichier']['tmp_name'][$j], "upload/". $_FILES['fichier']['name'][$j]);
|
||||
$extension = $_FILES['fichier']['type'][$j]; //extension est sous la forme "image/png" par exemple ...
|
||||
$extension=str_replace('image/','',$extension); //... du coup on supprime /image
|
||||
if ($extension != "png" && $extension != "gif" && $extension != "jpeg")
|
||||
/* on test si le fichier est bien une image*/
|
||||
{
|
||||
array_push($nomImage, array("ext"=>"" , "name"=>$_FILES['fichier']['name'][$j] , "err" => 2 , "msg" => "L'extension du fichier ".$_FILES['fichier']['name'][$j]." est invalide." ));
|
||||
}
|
||||
else
|
||||
array_push($nomImage, array("ext"=>$extension , "name"=>$_FILES['fichier']['name'][$j] , "err" => 0 , "msg" => "" ));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push($nomImage, array("ext"=>"" , "name"=>"" , "err" => 2 , "msg" => "Vous n'avez pas choisi de fichier." ));
|
||||
}
|
||||
return $nomImage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function errorMsg($str)
|
||||
{
|
||||
$string = "<div class='errorBox'>
|
||||
<table>
|
||||
<tr>
|
||||
<td width=30px ><img src='image/error.png'/></td>
|
||||
<td>".$str."</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>";
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function warningMsg($str)
|
||||
{
|
||||
$string = "<div class='errorBox'>
|
||||
<table>
|
||||
<tr>
|
||||
<td width=30px ><img src='image/warning.png'/></td>
|
||||
<td>".$str."</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>";
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function displayError($error)
|
||||
{
|
||||
$size = count($error);
|
||||
for ($j= 0;$j<$size;$j++)
|
||||
{
|
||||
if ( $error[$j]["err"] == 2)
|
||||
echo errorMsg($error[$j]["msg"])."<hr/>";
|
||||
else if ( $error[$j]["err"] == 1)
|
||||
echo warningMsg($error[$j]["msg"])."<hr/>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function deboguage($uploadedFile) //cette fonction teste s'i n'y a aucun bug
|
||||
{
|
||||
if ($_POST["langage"] === " ")
|
||||
array_push($uploadedFile, array( "ext"=>"" , "name"=>"" , "err" => 2 , "msg" => "Language de programmation sélectionné invalide."));
|
||||
else if ($_POST["langage"] === "Basic")
|
||||
{
|
||||
if ($_POST["calculatriceB"] === " ")
|
||||
array_push($uploadedFile, array( "ext"=>"" , "name"=>"" , "err" => 2 , "msg" => "Calculatrice sélectionné invalide."));
|
||||
|
||||
}
|
||||
else if ($_POST["langage"] === "C/C++")
|
||||
{
|
||||
if ($_POST["calculatriceC"] === " ")
|
||||
array_push($uploadedFile, array( "ext"=>"" , "name"=>"" , "err" => 2 , "msg" => "Calculatrice sélectionné invalide."));
|
||||
if ($_POST["nameC"] === "persona" && trim($_POST["namePersC"]) === "")
|
||||
{
|
||||
array_push($uploadedFile, array( "ext"=>"" , "name"=>"" , "err" => 1 , "msg" => "Nom des sprites invalide, nom par défaut sélectionné"));
|
||||
$_POST["nameC"] = "default";
|
||||
}
|
||||
if ($_POST["tabpointeurC"] === "oui" && trim($_POST["tabpointeur_name"]) === "")
|
||||
{
|
||||
array_push($uploadedFile, array( "ext"=>"" , "name"=>"" , "err" => 1 , "msg" => "Nom du tableau de pointeur invalide, nom par défaut sélectionné"));
|
||||
$_POST["tabpointeur_name"] = "pointerTab";
|
||||
}
|
||||
if ($_POST["coupeSprC"] === "oui")
|
||||
{
|
||||
if ($_POST["outil_largSprC"] < 1)
|
||||
{
|
||||
array_push($uploadedFile, array( "ext"=>"" , "name"=>"" , "err" => 1 , "msg" => "Découpage de sprite : hauteur de chaque sprite invalide (doit être supérieur à 1)"));
|
||||
$_POST["outil_largSprC"] = 16;
|
||||
}
|
||||
if ($_POST["outil_longSprC"] < 1)
|
||||
{
|
||||
array_push($uploadedFile, array( "ext"=>"" , "name"=>"" , "err" => 1 , "msg" => "Découpage de sprite : longueur de chaque sprite invalide (doit être supérieur à 1)"));
|
||||
$_POST["outil_longSprC"] = 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($_POST["langage"] !== "Lua")
|
||||
{
|
||||
array_push($uploadedFile, array( "ext"=>"" , "name"=>"" , "err" => 2 , "msg" => "Language de programmation sélectionné invalide."));
|
||||
}
|
||||
return $uploadedFile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function supprimerExtensionDansNom($nom)
|
||||
{
|
||||
$pattern = "/\.(.)*/";
|
||||
return preg_replace($pattern, "", $nom);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function convertToReadablePicture($images)
|
||||
{
|
||||
$size = count($images);
|
||||
$convertedPicture = array();
|
||||
for ($j= 0;$j<$size;$j++)
|
||||
{
|
||||
if ($images[$j]["err"] == 0)
|
||||
{
|
||||
$extension = $images[$j]["ext"];
|
||||
$name = "upload/".$images[$j]["name"];
|
||||
$im = "";
|
||||
if ($extension == "png")
|
||||
$im = imagecreatefrompng($name);
|
||||
else if ($extension == "gif")
|
||||
$im = imagecreatefromgif($name);
|
||||
else if ($extension == "jpeg")
|
||||
$im = imagecreatefromjpeg($name);
|
||||
array_push($convertedPicture,array("pict" => $im , "name" => supprimerExtensionDansNom($images[$j]["name"])));
|
||||
|
||||
}
|
||||
if ($images[$j]["name"] != "")
|
||||
unlink("upload/".$images[$j]["name"]);
|
||||
|
||||
}
|
||||
return $convertedPicture;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function codeSpriteC_nom($name, $largeur, $hauteur)
|
||||
{
|
||||
$string = "";
|
||||
if ($_POST["motcleC"]=="extern")
|
||||
$string = "extern ";
|
||||
else if ($_POST["motcleC"]=="static")
|
||||
$string = "static ";
|
||||
|
||||
if (($_POST["bitC"]=="8bit") || $_POST["calculatriceC"]=="G75/G85/G95/G35")
|
||||
$string = $string . "const unsigned char $name"."[]={";
|
||||
else if ($_POST["bitC"]=="16bit")
|
||||
$string = $string . "const color_t $name"."[".$largeur*2*$hauteur."]={";
|
||||
|
||||
if ( $_POST["retourLigneSpriteC"]=="default" )
|
||||
$string = AjoutRetourLigne($string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function creerImage_gris($im, $estClair) // 0<noir<=64 , 64<grisClair<=128
|
||||
//$estClair = true si sprite clair
|
||||
//sinon foncé
|
||||
{
|
||||
$height = imagesy($im);
|
||||
$width = imagesx($im);
|
||||
$imReturn = imagecreatetruecolor ( $width , $height );
|
||||
for ( $j=0 ; $j<$height ; $j++ )
|
||||
{
|
||||
for ( $i=0 ; $i<$width ; $i++ )
|
||||
{
|
||||
$rgb = imagecolorat($im,$i,$j);
|
||||
$cols = imagecolorsforindex($im, $rgb);
|
||||
$r = $cols['red'];
|
||||
$g = $cols['green'];
|
||||
$b = $cols['blue'];
|
||||
if ($estClair)
|
||||
{
|
||||
if (($r+$g+$b)/3 <= 64)
|
||||
imagesetpixel($imReturn, $i, $j, imagecolorallocate ($imReturn,0,0,0));
|
||||
else if (($r+$g+$b)/3 > 64 && ($r+$g+$b)/3 <= 128 )
|
||||
imagesetpixel($imReturn, $i, $j, imagecolorallocate ($imReturn,255,255,255));
|
||||
else if (($r+$g+$b)/3 > 128 && ($r+$g+$b)/3 <= 192 )
|
||||
imagesetpixel($imReturn, $i, $j, imagecolorallocate ($imReturn,0,0,0));
|
||||
else
|
||||
imagesetpixel($imReturn, $i, $j, imagecolorallocate ($imReturn,255,255,255));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (($r+$g+$b)/3 <= 64)
|
||||
imagesetpixel($imReturn, $i, $j, imagecolorallocate ($imReturn,0,0,0));
|
||||
else if (($r+$g+$b)/3 > 64 && ($r+$g+$b)/3 <= 128 )
|
||||
imagesetpixel($imReturn, $i, $j, imagecolorallocate ($imReturn,0,0,0));
|
||||
else if (($r+$g+$b)/3 > 128 && ($r+$g+$b)/3 <= 192 )
|
||||
imagesetpixel($imReturn, $i, $j, imagecolorallocate ($imReturn,255,255,255));
|
||||
else
|
||||
imagesetpixel($imReturn, $i, $j, imagecolorallocate ($imReturn,255,255,255));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $imReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function codeSpriteC_G75($x, $y, $width, $height, $im, $name,$maxwidth, $maxheight) //retourne sprite codé sous forme de string
|
||||
{
|
||||
$string = codeSpriteC_nom($name, $width, $height);
|
||||
$valeurTableauPalette = array();
|
||||
|
||||
for ( $j=$y ; $j<$y+$height ; $j++ )
|
||||
{
|
||||
if ( $_POST["retourLigneSpriteC"]=="default" )
|
||||
$string = $string . "\t";
|
||||
|
||||
for ( $i=$x ; $i<$x+$width ; $i+=8 )
|
||||
{
|
||||
$binaire = "";
|
||||
for ($k=$i ; $k<$i+8 ; $k++)
|
||||
{
|
||||
if (($k<$maxwidth && $j<$maxheight) )
|
||||
{
|
||||
$rgb = imagecolorat($im,$k,$j);
|
||||
$cols = imagecolorsforindex($im, $rgb);
|
||||
$r = $cols['red'];
|
||||
$g = $cols['green'];
|
||||
$b = $cols['blue'];
|
||||
if ( ($r+$g+$b)/3 > 127 )
|
||||
$binaire = $binaire."0";
|
||||
else
|
||||
$binaire = $binaire."1";
|
||||
}
|
||||
else
|
||||
$binaire = $binaire."1";
|
||||
}
|
||||
$hex = dechex(bindec($binaire));
|
||||
$string = $string . "0x$hex, ";
|
||||
}
|
||||
if ( $_POST["retourLigneSpriteC"]=="default" && $j<$maxheight)
|
||||
$string = AjoutRetourLigne($string);
|
||||
}
|
||||
|
||||
$string = AjoutRetourLigne( AjoutRetourLigne( $string . "};" ) );
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function nomTabPointeur($name)
|
||||
{
|
||||
$string = "";
|
||||
|
||||
if (($_POST["bitC"]=="8bit") || $_POST["calculatriceC"]=="G75/G85/G95/G35")
|
||||
$string = $string . "const unsigned char* $name"."[]={";
|
||||
else if ($_POST["bitC"]=="16bit")
|
||||
$string = $string . "const color_t* $name"."[]={";
|
||||
|
||||
if ( $_POST["retourLigne"]=="oui" )
|
||||
$string = AjoutRetourLigne($string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function genererTabPointeur($tableauPonteur,$tableauPonteurPalette)
|
||||
{
|
||||
$string ="";
|
||||
|
||||
$taille = count($tableauPonteur);
|
||||
|
||||
$string = $string . nomTabPointeur($_POST["tabpointeur_name"]);
|
||||
|
||||
for ( $i=0 ; $i<$taille ; $i++ )
|
||||
{
|
||||
if ( $_POST["retourLigne"]=="oui" )
|
||||
$string = $string . "\t";
|
||||
|
||||
$string = $string . $tableauPonteur[$i];
|
||||
if ($i != $taille-1)
|
||||
$string = $string . ", ";
|
||||
if ( $_POST["retourLigne"]=="oui" )
|
||||
$string = AjoutRetourLigne($string);
|
||||
}
|
||||
|
||||
$string = $string . "};";
|
||||
|
||||
if ($_POST["bitC"]!=="16bit" && $_POST["calculatriceC"] === "Prizm/Cg-10/Cg-20")
|
||||
{
|
||||
$string = AjoutRetourLigne(AjoutRetourLigne($string)) . "const color_t* ".$_POST["tabpointeur_name"]."_palette[]={";
|
||||
if ( $_POST["retourLigne"]=="oui" )
|
||||
$string = AjoutRetourLigne($string);
|
||||
$taille = count($tableauPonteurPalette);
|
||||
|
||||
for ( $i=0 ; $i<$taille ; $i++ )
|
||||
{
|
||||
if ( $_POST["retourLigne"]=="oui" )
|
||||
$string = $string . "\t";
|
||||
|
||||
$string = $string . $tableauPonteurPalette[$i];
|
||||
if ($i != $taille-1)
|
||||
$string = $string . ", ";
|
||||
if ( $_POST["retourLigne"]=="oui" )
|
||||
$string = AjoutRetourLigne($string);
|
||||
}
|
||||
|
||||
$string = $string . "};";
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function codeSpriteC_CG20($x, $y, $width, $height, $im, $name,$maxwidth, $maxheight) //retourne sprite codé sous forme de string
|
||||
{
|
||||
$string = codeSpriteC_nom($name, $width, $height);
|
||||
$valeurTableauPalette = array();
|
||||
|
||||
for ( $j=$y ; $j<$y+$height ; $j++ )
|
||||
{
|
||||
if ( $_POST["retourLigneSpriteC"]=="default" )
|
||||
$string = $string . "\t";
|
||||
for ( $i=$x ; $i<$x+$width ; $i++ )
|
||||
{
|
||||
if ( $i<$maxwidth && $j<$maxheight )
|
||||
{
|
||||
$rgb = imagecolorat($im,$i,$j);
|
||||
$cols = imagecolorsforindex($im, $rgb);
|
||||
$r = $cols['red'];
|
||||
$g = $cols['green'];
|
||||
$b = $cols['blue'];
|
||||
|
||||
$hex = dechex( (( (31*$r/255) & 0x1F) << 11 ) | (( (63*$g/255) & 0x3F) << 5 ) | (( (31*$b/255) & 0x1F)) );
|
||||
|
||||
if ($_POST["bitC"]=="8bit")
|
||||
{
|
||||
if (array_search ($hex,$valeurTableauPalette) === FALSE)
|
||||
array_push($valeurTableauPalette,$hex);
|
||||
$string = $string . array_search ($hex,$valeurTableauPalette);
|
||||
}
|
||||
else if ($_POST["bitC"]=="16bit")
|
||||
{
|
||||
$string = $string . "0x$hex";
|
||||
}
|
||||
|
||||
$string = $string . ", ";
|
||||
}
|
||||
}
|
||||
if ( $_POST["retourLigneSpriteC"]=="default" && $j<$maxheight-1)
|
||||
$string = AjoutRetourLigne($string);
|
||||
}
|
||||
|
||||
$string = AjoutRetourLigne( AjoutRetourLigne( $string . "};" ) );
|
||||
|
||||
if ($_POST["bitC"]!="16bit")
|
||||
{
|
||||
$taillePalette = count($valeurTableauPalette);
|
||||
|
||||
$string = $string . "const color_t ".$name."_palette[".$taillePalette."]={";
|
||||
$string = AjoutRetourLigne($string) . "\t";
|
||||
for ( $i=0 ; $i<$taillePalette ; $i++ )
|
||||
{
|
||||
$string = $string . "0x" . $valeurTableauPalette[$i];
|
||||
if ($i != $taillePalette-1)
|
||||
$string = $string . ", ";
|
||||
}
|
||||
$string = AjoutRetourLigne( AjoutRetourLigne( AjoutRetourLigne($string) . "};" ) );
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function composer_nom_sprite($i, $nbImage, $name)
|
||||
{
|
||||
if ($_POST["nameC"] === "persona")
|
||||
{
|
||||
$name = $_POST["namePersC"];
|
||||
if ($nbImage != 1)
|
||||
$name = $name."$i";
|
||||
return $name;
|
||||
}
|
||||
else
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function codeSprite($listeImage)
|
||||
{
|
||||
$nbImage = count ($listeImage);
|
||||
$string = "";
|
||||
$tableauPonteur = array();
|
||||
$tableauPonteurPalette = array();
|
||||
for ($i = 0 ; $i < $nbImage ; $i++)
|
||||
{
|
||||
$width = imagesx($listeImage[$i]["pict"]);
|
||||
$height = imagesy($listeImage[$i]["pict"]);
|
||||
|
||||
|
||||
|
||||
|
||||
if ($_POST["langage"] === "C/C++")
|
||||
{
|
||||
$name = composer_nom_sprite($i, $nbImage, $listeImage[$i]["name"]);
|
||||
$nameSav = $name;
|
||||
if ($_POST["calculatriceC"] === "Prizm/Cg-10/Cg-20")
|
||||
{
|
||||
if ($_POST["coupeSprC"] === "non")
|
||||
{
|
||||
$string = $string . codeSpriteC_CG20(0, 0, $width, $height, $listeImage[$i]["pict"], $name, $width+1, $height+1);
|
||||
array_push($tableauPonteur, $name);
|
||||
array_push($tableauPonteurPalette, $name."_palette");
|
||||
}
|
||||
else
|
||||
{
|
||||
$num = 0;
|
||||
for ($y=0 ; $y < $height ; $y += $_POST["outil_largSprC"])
|
||||
{
|
||||
for ($x=0 ; $x < $width ; $x += $_POST["outil_longSprC"])
|
||||
{
|
||||
$name = $nameSav."$num";
|
||||
$string = $string . codeSpriteC_CG20($x, $y, $_POST["outil_longSprC"], $_POST["outil_largSprC"], $listeImage[$i]["pict"], $name, $width, $height);
|
||||
array_push($tableauPonteur, $name);
|
||||
array_push($tableauPonteurPalette, $name."_palette");
|
||||
$num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($_POST["coupeSprC"] === "non")
|
||||
{
|
||||
if ($_POST["couleur75"] === "n")
|
||||
{
|
||||
$string = $string . codeSpriteC_G75(0, 0, $width, $height, $listeImage[$i]["pict"], $name, $width, $height);
|
||||
array_push($tableauPonteur, $name);
|
||||
}
|
||||
else
|
||||
{
|
||||
$string = $string . codeSpriteC_G75(0, 0, $width, $height, creerImage_gris($listeImage[$i]["pict"], true) , $name."_light", $width+1, $height+1);
|
||||
array_push($tableauPonteur, $name."_light");
|
||||
$string = $string . codeSpriteC_G75(0, 0, $width, $height, creerImage_gris($listeImage[$i]["pict"], false) , $name."_dark", $width+1, $height+1);
|
||||
array_push($tableauPonteur, $name."_dark");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$num = 0;
|
||||
for ($y=0 ; $y < $height ; $y += $_POST["outil_largSprC"])
|
||||
{
|
||||
for ($x=0 ; $x < $width ; $x += $_POST["outil_longSprC"])
|
||||
{
|
||||
if ($_POST["couleur75"] === "g")
|
||||
{
|
||||
$name = $nameSav."$num";
|
||||
$string = $string . codeSpriteC_G75($x, $y, $_POST["outil_longSprC"], $_POST["outil_largSprC"], creerImage_gris($listeImage[$i]["pict"], true) , $name."_light", $width, $height);
|
||||
array_push($tableauPonteur, $name."_light");
|
||||
$string = $string . codeSpriteC_G75($x, $y, $_POST["outil_longSprC"], $_POST["outil_largSprC"], creerImage_gris($listeImage[$i]["pict"], false) , $name."_dark", $width, $height);
|
||||
array_push($tableauPonteur, $name."_dark");
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = $nameSav."$num";
|
||||
$string = $string . codeSpriteC_G75($x, $y, $_POST["outil_longSprC"], $_POST["outil_largSprC"], $listeImage[$i]["pict"] , $name, $width, $height);
|
||||
array_push($tableauPonteur, $name);
|
||||
}
|
||||
$num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($_POST["langage"] === "Basic")
|
||||
{
|
||||
if ($_POST["coupeSprC"] === "non")
|
||||
{
|
||||
$string = $string . codeSpriteBasic(0, 0, $width, $height, $listeImage[$i]["pict"], $width, $height);
|
||||
}
|
||||
else
|
||||
{
|
||||
$num = 0;
|
||||
for ($x=0 ; $x < $width ; $x += $_POST["outil_longSprC"])
|
||||
{
|
||||
for ($y=0 ; $y < $height ; $y += $_POST["outil_largSprC"])
|
||||
{
|
||||
$string = $string . codeSpriteBasic($x, $y, $_POST["outil_longSprC"], $_POST["outil_largSprC"], $listeImage[$i]["pict"] , $width, $height);
|
||||
|
||||
$num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = composer_nom_sprite($i, $nbImage, $listeImage[$i]["name"]);
|
||||
if ($_POST["coupeSprC"] === "non")
|
||||
{
|
||||
$string = $string . codeSpriteLua(0, 0, $width, $height, $listeImage[$i]["pict"],$name, $width, $height);
|
||||
}
|
||||
else
|
||||
{
|
||||
$num = 0;
|
||||
for ($x=0 ; $x < $width ; $x += $_POST["outil_longSprC"])
|
||||
{
|
||||
for ($y=0 ; $y < $height ; $y += $_POST["outil_largSprC"])
|
||||
{
|
||||
$string = $string . codeSpriteLua($x, $y, $_POST["outil_longSprC"], $_POST["outil_largSprC"], $listeImage[$i]["pict"] , $name, $width, $height);
|
||||
|
||||
$num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST["tabpointeurC"] === "oui" && $_POST["langage"] === "C/C++")
|
||||
$string = $string . genererTabPointeur($tableauPonteur, $tableauPonteurPalette);
|
||||
return $string;
|
||||
}
|
|
@ -0,0 +1,378 @@
|
|||
<?php
|
||||
|
||||
//convertit une image en binaire, 1=pixel, 0=pas pixel(blanc)
|
||||
function GenererImageEnBinaire ($x, $y, $width, $height, $im, $contrast, $maxwidth, $maxheight)
|
||||
{
|
||||
$tabBinaire = array();
|
||||
$tabBinaireLigne = array();
|
||||
$hauteur = imagesy($im);
|
||||
$largeur = imagesx($im);
|
||||
|
||||
for ( $j=$y ; $j<$maxheight ; $j++ )
|
||||
{
|
||||
$tabBinaireLigne = array();
|
||||
for ( $i=$x ; $i<$maxwidth ; $i++ )
|
||||
{
|
||||
|
||||
$pixelrgb = imagecolorat($im,$i,$j);
|
||||
$cols = imagecolorsforindex($im, $pixelrgb);
|
||||
$r = $cols['red'];
|
||||
$g = $cols['green'];
|
||||
$b = $cols['blue'];
|
||||
|
||||
if (($r+$g+$b)/3 < 255-$contrast)
|
||||
array_push($tabBinaireLigne,"1");
|
||||
else
|
||||
array_push($tabBinaireLigne,"0");
|
||||
}
|
||||
array_push($tabBinaire,$tabBinaireLigne);
|
||||
}
|
||||
return $tabBinaire;
|
||||
}
|
||||
|
||||
function maximum($i,$j)
|
||||
{
|
||||
if ($i>$j)
|
||||
return $i;
|
||||
else
|
||||
return $j;
|
||||
|
||||
}
|
||||
|
||||
function nbPixelInutilise_c_bg($pict,$i,$j,$height,$width)
|
||||
{
|
||||
$longueur = 0;
|
||||
while ($pict[$i][$j]!='0' && $j>=1 && $i<$height-1)
|
||||
{
|
||||
$i++;
|
||||
$j--;
|
||||
if ($pict[$i][$j]=='1')
|
||||
$longueur++;
|
||||
}
|
||||
return $longueur;
|
||||
|
||||
}
|
||||
|
||||
function tracer_c_bg($pict,$i,$j,$height,$width)
|
||||
{
|
||||
while ($j>=0 && $i<$height && $pict[$i][$j]!='0' )
|
||||
{
|
||||
$pict[$i][$j] = '2';
|
||||
$i++;
|
||||
$j--;
|
||||
}
|
||||
return $pict;
|
||||
|
||||
}
|
||||
|
||||
function nbPixelInutilise_c_b($pict,$i,$j,$height,$width)
|
||||
{
|
||||
$longueur = 0;
|
||||
while ($pict[$i][$j]!='0' && $i<$height-1)
|
||||
{
|
||||
$i++;
|
||||
if ($pict[$i][$j]=='1')
|
||||
$longueur++;
|
||||
}
|
||||
return $longueur;
|
||||
|
||||
}
|
||||
|
||||
function tracer_c_b($pict,$i,$j,$height,$width)
|
||||
{
|
||||
while ($i<$height && $pict[$i][$j]!='0')
|
||||
{
|
||||
$pict[$i][$j] = '2';
|
||||
$i++;
|
||||
}
|
||||
return $pict;
|
||||
|
||||
}
|
||||
|
||||
function nbPixelInutilise_c_bd($pict,$i,$j,$height,$width)
|
||||
{
|
||||
$longueur = 0;
|
||||
while ($pict[$i][$j]!='0' && $i<$height-1 && $j<$width-1)
|
||||
{
|
||||
$j++;
|
||||
$i++;
|
||||
if ($pict[$i][$j]=='1')
|
||||
$longueur++;
|
||||
}
|
||||
return $longueur;
|
||||
|
||||
}
|
||||
|
||||
function tracer_c_bd($pict,$i,$j,$height,$width)
|
||||
{
|
||||
while ( $i<$height && $j<$width && $pict[$i][$j]!='0')
|
||||
{
|
||||
$pict[$i][$j] = '2';
|
||||
$i++;
|
||||
$j++;
|
||||
}
|
||||
return $pict;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function nbPixelInutilise_c_d($pict,$i,$j,$height,$width)
|
||||
{
|
||||
$longueur = 0;
|
||||
while ($pict[$i][$j]!='0' && $j<$width-1)
|
||||
{
|
||||
$j++;
|
||||
if ($pict[$i][$j]=='1')
|
||||
$longueur++;
|
||||
}
|
||||
return $longueur;
|
||||
|
||||
}
|
||||
|
||||
function tracer_c_d($pict,$i,$j,$height,$width)
|
||||
{
|
||||
while ($j<$width && $pict[$i][$j]!='0')
|
||||
{
|
||||
$pict[$i][$j] = 2;
|
||||
$j++;
|
||||
}
|
||||
return $pict;
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////
|
||||
|
||||
function distance_c_bg($pict,$i,$j,$height,$width)
|
||||
{
|
||||
$longueur = 0;
|
||||
while ($j>=0 && $i<$height && $pict[$i][$j]!='0')
|
||||
{
|
||||
$i++;
|
||||
$j--;
|
||||
$longueur++;
|
||||
}
|
||||
return $longueur-1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function distance_c_b($pict,$i,$j,$height,$width)
|
||||
{
|
||||
$longueur = 0;
|
||||
while ($i<$height && $pict[$i][$j]!='0')
|
||||
{
|
||||
$i++;
|
||||
$longueur++;
|
||||
}
|
||||
return $longueur-1;
|
||||
|
||||
}
|
||||
|
||||
function distance_c_bd($pict,$i,$j,$height,$width)
|
||||
{
|
||||
$longueur = 0;
|
||||
while ($i<$height && $j<$width && $pict[$i][$j]!='0' )
|
||||
{
|
||||
$j++;
|
||||
$i++;
|
||||
$longueur++;
|
||||
}
|
||||
return $longueur-1;
|
||||
|
||||
}
|
||||
|
||||
function distance_c_d($pict,$i,$j,$height,$width)
|
||||
{
|
||||
$longueur = 0;
|
||||
while ($j<$width && $pict[$i][$j]!='0')
|
||||
{
|
||||
$j++;
|
||||
$longueur++;
|
||||
}
|
||||
return $longueur-1;
|
||||
|
||||
}
|
||||
|
||||
function GegererImageFlinePlotLua($pict,$height,$width)
|
||||
{
|
||||
$string = "";
|
||||
|
||||
for ($i=0;$i<$height;$i++)
|
||||
{
|
||||
for ($j=0;$j<$width;$j++)
|
||||
{
|
||||
if ($pict[$i][$j] == '1') //on a un pixel que l'on peut encoder
|
||||
{
|
||||
$nbPixelInutilise_c_bg = nbPixelInutilise_c_bg($pict,$i,$j,$height,$width);
|
||||
$nbPixelInutilise_c_b = nbPixelInutilise_c_b($pict,$i,$j,$height,$width);
|
||||
$nbPixelInutilise_c_bd = nbPixelInutilise_c_bd($pict,$i,$j,$height,$width);
|
||||
$nbPixelInutilise_c_d = nbPixelInutilise_c_d($pict,$i,$j,$height,$width);
|
||||
|
||||
$distance_c_bg = distance_c_bg($pict,$i,$j,$height,$width);
|
||||
$distance_c_b = distance_c_b($pict,$i,$j,$height,$width);
|
||||
$distance_c_bd = distance_c_bd($pict,$i,$j,$height,$width);
|
||||
$distance_c_d = distance_c_d($pict,$i,$j,$height,$width);
|
||||
if (isset($_POST["variableLua"]) && $_POST["variableLua"]==="on")
|
||||
$variable = true;
|
||||
else
|
||||
$variable = false;
|
||||
|
||||
if ($nbPixelInutilise_c_bg==$nbPixelInutilise_c_b && $nbPixelInutilise_c_bd==$nbPixelInutilise_c_d && $nbPixelInutilise_c_bg==$nbPixelInutilise_c_bd && $nbPixelInutilise_c_bd==0)
|
||||
{
|
||||
$pict = tracer_c_bg($pict,$i,$j,$height,$width);
|
||||
if ($variable)
|
||||
$string = $string . "nbdraw.plot(a+". (string)($j) .",b+". (string)(64-$i) . ")";
|
||||
else
|
||||
$string = $string . "nbdraw.plot(". (string)($j) .",". (string)(64-$i) . ")";
|
||||
|
||||
}
|
||||
else if ($nbPixelInutilise_c_bg == maximum( maximum($nbPixelInutilise_c_bg,$nbPixelInutilise_c_b) , maximum($nbPixelInutilise_c_bd,$nbPixelInutilise_c_d) ))
|
||||
{
|
||||
$pict = tracer_c_bg($pict,$i,$j,$height,$width);
|
||||
if ($variable)
|
||||
$string = $string . "nbdraw.line(a+". (string)($j) .",b+". (string)(64-$i) .",a+". (string)($j-$distance_c_bg) .",b+". (string)(64-$i-$distance_c_bg) . ")" ;
|
||||
else
|
||||
$string = $string . "nbdraw.line(". (string)($j) .",". (string)(64-$i) .",". (string)($j-$distance_c_bg) .",". (string)(64-$i-$distance_c_bg) . ")";
|
||||
|
||||
}
|
||||
else if ($nbPixelInutilise_c_b == maximum( maximum($nbPixelInutilise_c_bg,$nbPixelInutilise_c_b) , maximum($nbPixelInutilise_c_bd,$nbPixelInutilise_c_d) ))
|
||||
{
|
||||
$pict = tracer_c_b($pict,$i,$j,$height,$width);
|
||||
if ($variable)
|
||||
$string = $string . "nbdraw.line(a+". (string)($j) .",b+". (string)(64-$i) .",a+". (string)($j) .",b+". (string)(64-$i-$distance_c_b) . ")" ;
|
||||
else
|
||||
$string = $string . "nbdraw.line(". (string)($j) .",". (string)(64-$i) .",". (string)($j) .",". (string)(64-$i-$distance_c_b) . ")";
|
||||
|
||||
}
|
||||
else if ($nbPixelInutilise_c_bd == maximum( maximum($nbPixelInutilise_c_bg,$nbPixelInutilise_c_b) , maximum($nbPixelInutilise_c_bd,$nbPixelInutilise_c_d) ))
|
||||
{
|
||||
$pict = tracer_c_bd($pict,$i,$j,$height,$width);
|
||||
if ($variable)
|
||||
$string = $string . "nbdraw.line(a+". (string)($j) .",b+". (string)(64-$i) .",a+". (string)($j+$distance_c_bd) .",b+". (string)(64-$i-$distance_c_bd) . ")";
|
||||
else
|
||||
$string = $string . "nbdraw.line(". (string)($j) .",". (string)(64-$i) .",". (string)($j+$distance_c_bd) .",". (string)(64-$i-$distance_c_bd) . ")";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$pict = tracer_c_d($pict,$i,$j,$height,$width);
|
||||
if ($variable)
|
||||
$string = $string . "nbdraw.line(a+". (string)($j) .",b+". (string)(64-$i) .",a+". (string)($j+$distance_c_d) .",b+". (string)(64-$i) . ")";
|
||||
else
|
||||
$string = $string . "nbdraw.line(". (string)($j) .",". (string)(64-$i) .",". (string)($j+$distance_c_d) .",". (string)(64-$i) . ")";
|
||||
|
||||
}
|
||||
$string = $string . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
function GegererImageFlinePlot($pict,$height,$width)
|
||||
{
|
||||
$string = "";
|
||||
|
||||
for ($i=0;$i<$height;$i++)
|
||||
{
|
||||
for ($j=0;$j<$width;$j++)
|
||||
{
|
||||
if ($pict[$i][$j] == '1') //on a un pixel que l'on peut encoder
|
||||
{
|
||||
$nbPixelInutilise_c_bg = nbPixelInutilise_c_bg($pict,$i,$j,$height,$width);
|
||||
$nbPixelInutilise_c_b = nbPixelInutilise_c_b($pict,$i,$j,$height,$width);
|
||||
$nbPixelInutilise_c_bd = nbPixelInutilise_c_bd($pict,$i,$j,$height,$width);
|
||||
$nbPixelInutilise_c_d = nbPixelInutilise_c_d($pict,$i,$j,$height,$width);
|
||||
|
||||
$distance_c_bg = distance_c_bg($pict,$i,$j,$height,$width);
|
||||
$distance_c_b = distance_c_b($pict,$i,$j,$height,$width);
|
||||
$distance_c_bd = distance_c_bd($pict,$i,$j,$height,$width);
|
||||
$distance_c_d = distance_c_d($pict,$i,$j,$height,$width);
|
||||
//echo "SketchThin ";
|
||||
if (isset($_POST["variable"]) && $_POST["variable"]==="on")
|
||||
$variable = true;
|
||||
else
|
||||
$variable = false;
|
||||
|
||||
if ($nbPixelInutilise_c_bg==$nbPixelInutilise_c_b && $nbPixelInutilise_c_bd==$nbPixelInutilise_c_d && $nbPixelInutilise_c_bg==$nbPixelInutilise_c_bd && $nbPixelInutilise_c_bd==0)
|
||||
{
|
||||
$pict = tracer_c_bg($pict,$i,$j,$height,$width);
|
||||
if ($variable)
|
||||
$string = $string . "PlotOn A+". (string)($j) .",B+". (string)(64-$i);
|
||||
else
|
||||
$string = $string . "PlotOn ". (string)($j) .",". (string)(64-$i);
|
||||
|
||||
}
|
||||
else if ($nbPixelInutilise_c_bg == maximum( maximum($nbPixelInutilise_c_bg,$nbPixelInutilise_c_b) , maximum($nbPixelInutilise_c_bd,$nbPixelInutilise_c_d) ))
|
||||
{
|
||||
$pict = tracer_c_bg($pict,$i,$j,$height,$width);
|
||||
if ($variable)
|
||||
$string = $string . "F-Line A+". (string)($j) .",B+". (string)(64-$i) .",A+". (string)($j-$distance_c_bg) .",B+". (string)(64-$i-$distance_c_bg) ;
|
||||
else
|
||||
$string = $string . "F-Line ". (string)($j) .",". (string)(64-$i) .",". (string)($j-$distance_c_bg) .",". (string)(64-$i-$distance_c_bg);
|
||||
|
||||
}
|
||||
else if ($nbPixelInutilise_c_b == maximum( maximum($nbPixelInutilise_c_bg,$nbPixelInutilise_c_b) , maximum($nbPixelInutilise_c_bd,$nbPixelInutilise_c_d) ))
|
||||
{
|
||||
$pict = tracer_c_b($pict,$i,$j,$height,$width);
|
||||
if ($variable)
|
||||
$string = $string . "F-Line A+". (string)($j) .",B+". (string)(64-$i) .",A+". (string)($j) .",B+". (string)(64-$i-$distance_c_b) ;
|
||||
else
|
||||
$string = $string . "F-Line ". (string)($j) .",". (string)(64-$i) .",". (string)($j) .",". (string)(64-$i-$distance_c_b);
|
||||
|
||||
}
|
||||
else if ($nbPixelInutilise_c_bd == maximum( maximum($nbPixelInutilise_c_bg,$nbPixelInutilise_c_b) , maximum($nbPixelInutilise_c_bd,$nbPixelInutilise_c_d) ))
|
||||
{
|
||||
$pict = tracer_c_bd($pict,$i,$j,$height,$width);
|
||||
if ($variable)
|
||||
$string = $string . "F-Line A+". (string)($j) .",B+". (string)(64-$i) .",A+". (string)($j+$distance_c_bd) .",B+". (string)(64-$i-$distance_c_bd);
|
||||
else
|
||||
$string = $string . "F-Line ". (string)($j) .",". (string)(64-$i) .",". (string)($j+$distance_c_bd) .",". (string)(64-$i-$distance_c_bd);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$pict = tracer_c_d($pict,$i,$j,$height,$width);
|
||||
if ($variable)
|
||||
$string = $string . "F-Line A+". (string)($j) .",B+". (string)(64-$i) .",A+". (string)($j+$distance_c_d) .",B+". (string)(64-$i);
|
||||
else
|
||||
$string = $string . "F-Line ". (string)($j) .",". (string)(64-$i) .",". (string)($j+$distance_c_d) .",". (string)(64-$i);
|
||||
|
||||
}
|
||||
$string = $string . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
function codeSpriteBasic($x, $y, $width, $height, $im, $maxwidth, $maxheight) //retourne sprite codé sous forme de string
|
||||
{
|
||||
$string = "";
|
||||
$string = $string . "Cls\n";
|
||||
$imagePixel = GenererImageEnBinaire ($x, $y, $width, $height, $im, 125, $maxwidth, $maxheight);
|
||||
$string = $string . GegererImageFlinePlot($imagePixel ,$height,$width);
|
||||
return $string;
|
||||
}
|
||||
|
||||
function codeSpriteLua($x, $y, $width, $height, $im, $name, $maxwidth, $maxheight) //retourne sprite codé sous forme de string
|
||||
{
|
||||
$string = "";
|
||||
$string = $string . "function ".$name."()\n";
|
||||
$imagePixel = GenererImageEnBinaire ($x, $y, $width, $height, $im, 125, $maxwidth, $maxheight);
|
||||
$string = $string . GegererImageFlinePlotLua($imagePixel ,$height,$width);
|
||||
$string = $string . "end\n";
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
nbdraw.line(x1,y1,x2,y2)
|
||||
nbdraw.line (...)
|
||||
..
|
||||
end*/
|
||||
|
||||
?>
|
Binary file not shown.
After Width: | Height: | Size: 260 B |
Binary file not shown.
After Width: | Height: | Size: 237 B |
|
@ -0,0 +1,325 @@
|
|||
<?php if (isset($_FILES['fichier'])) include("code.php"); ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Sprite Coder - codeur de sprite</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
|
||||
<script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function BitPrizmChange(value)
|
||||
{
|
||||
if (value === "Prizm/Cg-10/Cg-20")
|
||||
{
|
||||
document.getElementById("BitPrizm").style.maxHeight = "300px";
|
||||
document.getElementById("CouleurG75").style.maxHeight = "0px";
|
||||
}
|
||||
else if (value === "G75/G85/G95/G35")
|
||||
{
|
||||
document.getElementById("BitPrizm").style.maxHeight = "0px";
|
||||
document.getElementById("CouleurG75").style.maxHeight = "300px";
|
||||
}
|
||||
else
|
||||
{
|
||||
document.getElementById("BitPrizm").style.maxHeight = "0px";
|
||||
document.getElementById("CouleurG75").style.maxHeight = "0px";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function ApparaitreOutils(value)
|
||||
{
|
||||
if (value == 'Afficher les outils')
|
||||
{
|
||||
document.getElementById("outil").style.maxHeight = "900px";
|
||||
return 'Masquer les outils';
|
||||
}
|
||||
else
|
||||
{
|
||||
document.getElementById("outil").style.maxHeight = "0px";
|
||||
return 'Afficher les outils';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function AfficheTab(value)
|
||||
{
|
||||
if (value == 'oui')
|
||||
{
|
||||
document.getElementById('tabSpr').style.maxHeight="900px";
|
||||
}
|
||||
else
|
||||
{
|
||||
document.getElementById('tabSpr').style.maxHeight="0px";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function ChangeLangage()
|
||||
{
|
||||
var choix = document.getElementById("langage").options[document.getElementById("langage").selectedIndex].value;
|
||||
|
||||
if ( choix == "C/C++")
|
||||
{
|
||||
document.getElementById("PartieCPP").style.maxHeight = "900px";
|
||||
document.getElementById("PartieBAS").style.maxHeight = "0px";
|
||||
document.getElementById("PartieLUA").style.maxHeight = "0px";
|
||||
}
|
||||
else if (choix == "Basic")
|
||||
{
|
||||
document.getElementById("PartieCPP").style.maxHeight = "0px";
|
||||
document.getElementById("PartieBAS").style.maxHeight = "900px";
|
||||
document.getElementById("PartieLUA").style.maxHeight = "0px";
|
||||
}
|
||||
else if (choix == "Lua")
|
||||
{
|
||||
document.getElementById("PartieBAS").style.maxHeight = "0px";
|
||||
document.getElementById("PartieCPP").style.maxHeight = "0px";
|
||||
document.getElementById("PartieLUA").style.maxHeight = "900px";
|
||||
}
|
||||
else
|
||||
{
|
||||
document.getElementById("PartieBAS").style.maxHeight = "0px";
|
||||
document.getElementById("PartieCPP").style.maxHeight = "0px";
|
||||
document.getElementById("PartieBAS").style.maxHeight = "0px";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="toutSaufFooter">
|
||||
<div id="titre">
|
||||
<center> Sprite Coder V3 </center>
|
||||
</div>
|
||||
|
||||
<div id="cadre">
|
||||
<form method="post" name="post" action='index.php' enctype="multipart/form-data">
|
||||
<div id="contenu">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Langage de programmation :
|
||||
<select name="langage" id="langage" onChange="ChangeLangage()">
|
||||
<option value=" " selected></option>
|
||||
<option value="Basic">Basic</option>
|
||||
<option value="C/C++">C/C++</option>
|
||||
<option value="Lua">Lua</option>
|
||||
</select>
|
||||
|
||||
<fieldset>
|
||||
<legend>Choix des images</legend>
|
||||
<input type="file" name='fichier[]' accept="image/*" multiple/>
|
||||
</fieldset>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- C ou CPP -->
|
||||
<div id="PartieCPP">
|
||||
<fieldset>
|
||||
<legend>Calculatrice</legend>
|
||||
Choisissez le modèle de votre calculatrice :
|
||||
<select name="calculatriceC" id="calculatrice" onChange="BitPrizmChange(this.value)">
|
||||
<option value="Prizm/Cg-10/Cg-20">Prizm/Cg-10/Cg-20</option>
|
||||
<option value="G75/G85/G95/G35" >G75/G85/G95/G35</option>
|
||||
<option value=" " selected></option>
|
||||
</select>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Options</legend>
|
||||
<fieldset>
|
||||
<legend>Nom des sprites</legend>
|
||||
<input type="radio" name="nameC" value="default" checked/>Par défaut : Utiliser le nom de l'image<br/>
|
||||
<input type="radio" name="nameC" value="persona" />Personnalisé : <input type="text" name="namePersC"/>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Tableau de pointeur</legend>
|
||||
Voulez-vous générer un tableau de pointeur contenant tous les sprites?
|
||||
<input type="radio" name="tabpointeurC" value="non" onClick="AfficheTab(this.value)" checked/>Non
|
||||
<input type="radio" name="tabpointeurC" value="oui" onClick="AfficheTab(this.value)" />Oui
|
||||
<div id="tabSpr">
|
||||
Entrer le nom du tableau
|
||||
<input type="text" name="tabpointeur_name" id="tabpointeur_name"/>
|
||||
<br/>Retourner à la ligne entre chaque élément du tableau de pointeur?
|
||||
<input type="radio" name="retourLigne" id="retourLigne" value="non"/>Non
|
||||
<input type="radio" name="retourLigne" id="retourLigne" value="oui" checked/>Oui
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Retour à la ligne</legend>
|
||||
<input type="radio" name="retourLigneSpriteC" value="default" checked/>Par défaut : une ligne du tableau représente une ligne de l'image</br>
|
||||
<input type="radio" name="retourLigneSpriteC" value="uneLigne" />Chaque sprite tient sur une seule ligne</br>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Mot Clé</legend>
|
||||
<input type="radio" name="motcleC" value="null" checked />Ne pas rajouter de mot clé avant le nom des variables
|
||||
<br/>
|
||||
<input type="radio" name="motcleC" value="extern" />Rajouter le mot clé "extern" avant le nom des variables
|
||||
<br/>
|
||||
<input type="radio" name="motcleC" value="static" />Rajouter le mot clé "static" avant le nom des variables
|
||||
<br/>
|
||||
<div id="tabSpr">
|
||||
</div>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Outils</legend>
|
||||
<input type="button" value="Afficher les outils" onClick="this.value=ApparaitreOutils(this.value)"/>
|
||||
<div id="outil">
|
||||
<fieldset>
|
||||
<legend>Découpage des sprites</legend>
|
||||
Voulez-vous génerer plusieurs sprites d'une même image?
|
||||
<input type="radio" name="coupeSprC" value="non" checked/>Non
|
||||
<input type="radio" name="coupeSprC" value="oui"/>Oui<br/>
|
||||
Si oui définissez la taille de chaque sprite :
|
||||
<input type="text" name="outil_largSprC" size="2px" value="16"/>*<input type="text" name="outil_longSprC" size="2px" value="16"/>
|
||||
</fieldset>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div id="BitPrizm">
|
||||
<fieldset>
|
||||
<legend>Bits</legend>
|
||||
Voulez-vous coder les sprites en :<br/>
|
||||
<input type="radio" name="bitC" value="16bit">16-bits</input><br/>
|
||||
<input type="radio" name="bitC" value="8bit" checked/>8-bits</input>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div id="CouleurG75">
|
||||
<fieldset>
|
||||
<legend>Couleurs</legend>
|
||||
<input type="radio" name="couleur75" value="n" checked >Noir et blanc</input><br/>
|
||||
<input type="radio" name="couleur75" value="g" />Niveaux de gris (Noir, gris clair, gris foncé, blanc)</input>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- BASIC -->
|
||||
<div id = "PartieBAS">
|
||||
<fieldset>
|
||||
<legend>Calculatrice</legend>
|
||||
Choisissez le modèle de votre calculatrice :
|
||||
<select name="calculatriceB" id="calculatrice" onChange="bitPrizmChange(this.value)">
|
||||
<option value="Prizm/Cg-10/Cg-20"/>Prizm/Cg-10/Cg-20
|
||||
<option value="G75/G85/G95/G35" />G75/G85/G95/G35
|
||||
<option value=" " selected/>
|
||||
</select>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Option</legend>
|
||||
<fieldset>
|
||||
<legend>Couleur</legend>
|
||||
<input type="radio" name="basicCouleurB" value="default" checked/>Par défaut : Noir et blanc</br>
|
||||
<input type="radio" name="basicCouleurB" value="couleur" />En couleur ( fx-CG20 )</br>
|
||||
</fieldset>
|
||||
<input type="checkbox" name="variable"/>Utiliser des variables pour positionner l'image</br>
|
||||
</fieldset>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- LUA -->
|
||||
<div id = "PartieLUA">
|
||||
<fieldset>
|
||||
<legend>Option</legend>
|
||||
<input type="checkbox" name="variableLua"/>Utiliser des variables pour positionner l'image</br>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<input type="hidden" name="estCode">
|
||||
<center>
|
||||
<input type="submit"/><br/>
|
||||
</center>
|
||||
</form>
|
||||
</div>
|
||||
<div id="bas">
|
||||
<form method="post" name="post2" action='telecharger.php' enctype="multipart/form-data">
|
||||
<div id="lecode">
|
||||
<div id="messageErreur">
|
||||
|
||||
<?php
|
||||
if (isset($_FILES['fichier'])){
|
||||
$uploadedFile = uploadFile();
|
||||
$uploadedFile = deboguage($uploadedFile);
|
||||
displayError($uploadedFile);
|
||||
$AllPicture = convertToReadablePicture($uploadedFile);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<center>
|
||||
|
||||
|
||||
<textarea name="codeSource"><?php
|
||||
if (isset($_FILES['fichier'])){
|
||||
if (!estTropErreur($uploadedFile))
|
||||
echo codeSprite($AllPicture);
|
||||
else
|
||||
echo "Impossible de coder les sprites, car il y a trop d'erreurs.";
|
||||
}
|
||||
?></textarea><br/>
|
||||
<br/>
|
||||
<?php
|
||||
if (isset($_FILES['fichier'])){
|
||||
if (!estTropErreur($uploadedFile))
|
||||
{
|
||||
echo "Nom du programme (8 caractères au maximum) :<input type=\"text\" name=\"nomProgramme\" maxlength=\"8\"/>";
|
||||
if ($_POST["langage"] == "C/C++")
|
||||
{
|
||||
echo "<input type=\"submit\" value='Télécharger en .c'/>";
|
||||
echo "<input type=\"hidden\" name=\"ext\" value=\"3\"/>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<input type=\"submit\" value='Télécharger en .g1r'/>";
|
||||
echo "<input type=\"hidden\" name=\"ext\" value=\"";
|
||||
if ($_POST["calculatrice"] === "Prizm/Cg-10/Cg-20")
|
||||
echo "2";
|
||||
else
|
||||
echo "1";
|
||||
echo "\">";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</center>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<center>
|
||||
<br/>Sprite Coder, codeur de sprites et d'images pour les calculatrices CASIO, en C/C++ et Basic.<br/>
|
||||
Codé par Smashmaster pour le site <a href="http://www.planete-casio.fr">www.planete-casio.fr</a>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,140 @@
|
|||
#toutSaufFooter
|
||||
{
|
||||
margin : 20px auto 0 auto;
|
||||
box-shadow:0 0 10px 2px rgb(150,150,150);
|
||||
border-radius : 15px;
|
||||
border : 1px solid rgb(70,70,70);
|
||||
overflow : hidden;
|
||||
width : 1000px;
|
||||
}
|
||||
|
||||
#titre
|
||||
{
|
||||
color : white;
|
||||
font-size : 35px;
|
||||
background: #AA0000;
|
||||
padding-top: 20px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
#cadre
|
||||
{
|
||||
padding-bottom: 10px;
|
||||
border : 4px solid #AA0000;
|
||||
border-top : 0px;
|
||||
border-bottom : 0px;
|
||||
box-shadow: inset 0 0 5px 2px rgb(80,80,80);
|
||||
padding : 30px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#bas
|
||||
{
|
||||
background: #ff0000; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #AA0000 0%, #5a0000 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#AA0000), color-stop(100%,#5a0000)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #AA0000 0%,#5a0000 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #AA0000 0%,#5a0000 100%); /* Opera 11.10+ */
|
||||
background: -ms-linear-gradient(top, #AA0000 0%,#5a0000 100%); /* IE10+ */
|
||||
background: linear-gradient(to bottom, #AA0000 0%,#5a0000 100%); /* W3C */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff0000', endColorstr='#5a0000',GradientType=0 ); /* IE6-9 */
|
||||
padding-top : 15px;
|
||||
}
|
||||
|
||||
|
||||
#lecode
|
||||
{
|
||||
padding-left: auto;
|
||||
padding-right: auto;
|
||||
width : 100%;
|
||||
}
|
||||
|
||||
#messageErreur
|
||||
{
|
||||
width : 600px;
|
||||
height : 80px;
|
||||
background-color: white;
|
||||
border-radius: 5px;
|
||||
margin: 0 auto 10px auto;
|
||||
overflow : auto;
|
||||
}
|
||||
|
||||
.errorBox
|
||||
{
|
||||
margin : 5px 10px 5px 10px;
|
||||
}
|
||||
|
||||
textarea
|
||||
{
|
||||
border-radius : 10px;
|
||||
width : 600px;
|
||||
height : 200px;
|
||||
margin-bottom: 10px;
|
||||
box-shadow: inset 0 0 5px 2px rgb(100,50,50);
|
||||
border : 1px solid #660000;
|
||||
}
|
||||
|
||||
select
|
||||
{
|
||||
border-radius : 10px;
|
||||
border : 1px solid rgb(80,80,80);
|
||||
}
|
||||
|
||||
|
||||
fieldset
|
||||
{
|
||||
margin : 10px 20px;
|
||||
border-radius : 10px;
|
||||
border : 1px solid rgb(170,0,0);
|
||||
padding : 10px 20px 10px 20px;
|
||||
}
|
||||
|
||||
legend
|
||||
{
|
||||
color : white;
|
||||
background-color: #AA0000;
|
||||
padding : 0px 20px 0px 20px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
input[type=submit]
|
||||
{
|
||||
background-color: /*rgb(204 , 54 , 54)*/#AA0000;
|
||||
color:white;
|
||||
padding : 7px;
|
||||
margin : 3px;
|
||||
border: 1px solid rgb(204 , 25 , 25);
|
||||
box-shadow: inset 0px -10px 20px 0px rgb(141 , 14 , 14);
|
||||
border-radius : 6px;
|
||||
}
|
||||
|
||||
input[type=button]
|
||||
{
|
||||
background-color: /*rgb(204 , 54 , 54)*/#AA0000;
|
||||
border-radius : 6px;
|
||||
color:white;
|
||||
padding : 3px 10px;
|
||||
margin : 3px;
|
||||
border: 1px solid rgb(204 , 25 , 25);
|
||||
box-shadow: inset 0px -10px 20px 0px rgb(141 , 14 , 14);
|
||||
}
|
||||
|
||||
input[type=submit]:hover
|
||||
{
|
||||
box-shadow: inset 0px 0px 0px 0px rgb(141 , 14 , 14);
|
||||
}
|
||||
|
||||
input[type=button]:hover
|
||||
{
|
||||
box-shadow: inset 0px 0px 0px 0px rgb(141 , 14 , 14);
|
||||
}
|
||||
|
||||
#PartieCPP, #PartieBAS, #PartieLUA, #BitPrizm, #outil, #tabSpr, #CouleurG75
|
||||
{
|
||||
max-height : 0px;
|
||||
overflow : hidden;
|
||||
-webkit-transition: max-height 0.6s ease-in-out;
|
||||
-moz-transition: max-height 0.6s ease-in-out;
|
||||
transition: max-height 0.6s ease-in-out;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
if (isset($_POST["ext"]))
|
||||
{
|
||||
if (isset($_POST["nomProgramme"]) && $_POST["nomProgramme"]=== "")
|
||||
$_POST["nomProgramme"] = "tileset";
|
||||
if ($_POST["ext"] === "3")
|
||||
{
|
||||
$fileContent = $_POST["codeSource"];
|
||||
$title = $_POST["nomProgramme"];
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment;filename="'.$title.'.c"');
|
||||
header('Cache-Control: max-age=0');
|
||||
$fh = fopen('php://output', 'w');
|
||||
fwrite($fh, $fileContent);
|
||||
fclose($fh);
|
||||
}
|
||||
else
|
||||
{
|
||||
include('telechargerG1R.php');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
|
||||
function str_replace_char_to_2xChar($to,$str,$i)
|
||||
{
|
||||
return substr($str,0,$i).$to.substr($str,$i+1);
|
||||
}
|
||||
|
||||
$code = $_POST["codeSource"];
|
||||
|
||||
$function2hexArray = array(
|
||||
'BG-None' => 'f778',
|
||||
'LabelOff' => 'f7d4',
|
||||
'Plot/Line-Color ' => 'f999',
|
||||
'Black ' => 'f99b',
|
||||
'SketchThin ' => 'f9f3',
|
||||
'F-Line ' => 'f7a7',
|
||||
'PlotOn ' => 'f7a8',
|
||||
'(' => '28',
|
||||
')' => '29',
|
||||
'AxesOff' => 'f7d2',
|
||||
'<' => '3c',
|
||||
'>' => '3e',
|
||||
'Ù' => '0d',
|
||||
'ViewWindow ' => 'eb',
|
||||
',' => '2c',
|
||||
'ã' => '0e',
|
||||
'Do' => 'f70a',
|
||||
'Cls' => 'd1',
|
||||
'Text ' => 'f7a5',
|
||||
'"' => '22',
|
||||
'Getkey' => '7f8f',
|
||||
'-' => '99',
|
||||
'Á' => 'b9',
|
||||
'+' => '89',
|
||||
'Frac ' => 'b6',
|
||||
'=' => '3d',
|
||||
'×' => '13',
|
||||
'LpWhile ' => 'f70b',
|
||||
'È' => '11',
|
||||
' And ' => '7fb0',
|
||||
' Or ' => '7fb1',
|
||||
'Isz ' => 'e9',
|
||||
'If ' => 'f700',
|
||||
'Then ' => 'f701',
|
||||
'.' => '2e',
|
||||
'IfEnd' => 'f703',
|
||||
'AxesOn' => 'f7c2',
|
||||
'ClrGraph' => 'f719',
|
||||
' ' => '20',
|
||||
"\n" => '0d',
|
||||
"\r" => '0d');
|
||||
//Liste des fonctions
|
||||
$functionsArray = array_keys($function2hexArray);
|
||||
//Get the max length of all function
|
||||
$maxFuncLength = max(array_map('strlen',$functionsArray));
|
||||
//Transform each char in hex
|
||||
$output = '';
|
||||
$pos = 0;
|
||||
while(isset($code[$pos]))
|
||||
{
|
||||
$char = $code[$pos];
|
||||
//Take some "futur" chars
|
||||
$after = substr($code, $pos,$maxFuncLength);
|
||||
//Test if there is function in theses chars
|
||||
$functionPosArray = array_map('strpos', array_fill(0, count($functionsArray),$after),$functionsArray); //It return an array with a cell for each function if a cell value is 0 (position 0) then the function is here
|
||||
$key = array_search(0,$functionPosArray,true); //Find cell where value == 0
|
||||
if($key !== false) //If there is a function here
|
||||
{
|
||||
//put the hex value in the output
|
||||
$output .= $function2hexArray[$functionsArray[$key]];
|
||||
//jump after the function
|
||||
$pos += strlen($functionsArray[$key]);
|
||||
}
|
||||
else//just add the hex char
|
||||
{
|
||||
$output .= bin2hex($char);
|
||||
$pos++;
|
||||
}
|
||||
}
|
||||
//init
|
||||
$nbrPrgm = 0;
|
||||
$textSize = 0;
|
||||
$prgms = "";
|
||||
//Creation du bloc prgm (ce bloc peut être répété pour ajouter plusieurs programmes)
|
||||
//contenu
|
||||
$title = $_POST["nomProgramme"]; //Entre 1 et 8 caractères en caractères normaux
|
||||
$contenuPrgm = $output; //en hexadecimal
|
||||
//$contenuPrgm = "4142434445464748494a4b4c4d4e4f"; //en hexadecimal
|
||||
//gestion du titre
|
||||
$titleHex = bin2hex($title);
|
||||
$titleHex = str_pad($titleHex, 16, '0', STR_PAD_RIGHT);
|
||||
//prgm content
|
||||
$text ="00000000000000000000".$contenuPrgm;
|
||||
//calcul taille texte
|
||||
$tailleText = strlen($text)/2;
|
||||
$tailleText= $tailleText + (4-$tailleText%4);
|
||||
$textSize += $tailleText+44;
|
||||
$tailleTextHex = str_pad(dechex($tailleText), 8, '0', STR_PAD_LEFT);
|
||||
//arrondi la taille a 4
|
||||
$text = str_pad($text, $tailleText*2, '0', STR_PAD_RIGHT);
|
||||
//validation prgm
|
||||
$prgms .= "50524f4752414d0000000000000000000000000173797374656d0000".$titleHex."01".$tailleTextHex."000000".$text;
|
||||
$nbrPrgm++;
|
||||
|
||||
|
||||
//G1M generating
|
||||
//filesize calculation
|
||||
// $filesize = 32 + $textSize + 44*$nbrPrgm;
|
||||
$filesize = 32 + $textSize;
|
||||
if($filesize > 0xFFFFFFFF)
|
||||
{
|
||||
error("File too big.", "Fichier trop gros.");
|
||||
}
|
||||
//OFFSET 0xE : last filesize byte + 65(0x41) and NOT (inverted)
|
||||
$offset0xE = $filesize + 0x41;
|
||||
$offset0xE = 0xFFFFFFFF - $offset0xE;
|
||||
$offset0xE = dechex($offset0xE);
|
||||
$offset0xE = str_pad($offset0xE, 2, '0', STR_PAD_LEFT);
|
||||
$offset0xE = substr($offset0xE, -2); // take the last byte
|
||||
//OFFSET 0x10 : filesize NOT (inverted)
|
||||
$offset0x10 = 0xFFFFFFFF - $filesize;
|
||||
$offset0x10 = dechex($offset0x10);// to hex
|
||||
$offset0x10 = str_pad($offset0x10, 8, '0', STR_PAD_LEFT);
|
||||
//OFFSET 0x14 : last filesize byte + 184(0xB8) and NOT (inverted)
|
||||
$offset0x14 = $filesize + 0xB8;
|
||||
$offset0x14 = 0xFFFFFFFF - $offset0x14;
|
||||
$offset0x14 = dechex($offset0x14);
|
||||
$offset0x14 = str_pad($offset0x14, 2, '0', STR_PAD_LEFT);
|
||||
$offset0x14 = substr($offset0x14, -2);
|
||||
//OFFSET 0x14 : last filesize byte + 184(0xB8) and NOT (inverted)
|
||||
$offset0x1E = $nbrPrgm;
|
||||
$offset0x1E = 0xFFFF - $offset0x1E;
|
||||
$offset0x1E = dechex($offset0x1E);
|
||||
$offset0x1E = str_pad($offset0x1E, 4, '0', STR_PAD_LEFT);
|
||||
//making
|
||||
if ($_POST["ext"] == '1')
|
||||
{
|
||||
$fileContent = pack('H*',
|
||||
"aaacbdaf90889a8dceffefffefff".$offset0xE."fe".
|
||||
$offset0x10.$offset0x14."000000000000000000".$offset0x1E.
|
||||
$prgms);
|
||||
}
|
||||
else
|
||||
{
|
||||
$fileContent = pack('H*',
|
||||
"aaacbdaf90889a8d8affefffefff".$offset0xE."fe".
|
||||
$offset0x10.$offset0x14."000000000000000000".$offset0x1E.
|
||||
$prgms);
|
||||
}
|
||||
//sending
|
||||
header('Content-Type: application/octet-stream');
|
||||
if ($_POST["ext"] == '1')
|
||||
header('Content-Disposition: attachment;filename="'.$title.'.g1r"');
|
||||
else
|
||||
header('Content-Disposition: attachment;filename="'.$title.'.g3m"');
|
||||
header('Cache-Control: max-age=0');
|
||||
$fh = fopen('php://output', 'wb');
|
||||
fwrite($fh, $fileContent);
|
||||
fclose($fh);
|
||||
|
||||
?>
|
Loading…
Reference in New Issue