import java.io.File; import javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; public class PreEcriture { private int cetteTaille; private String path; private int octetRemaining; private boolean[][] cetteGrille; private Cellules[][] grilleCellules; private int[] resultat; private String[] tabTemp; private byte[] resultatByte; public PreEcriture(boolean[][] uneGrille, Cellules[][] uneGrilleCell , int uneTaille){ this.cetteTaille = uneTaille; this.cetteGrille = uneGrille; this.grilleCellules = uneGrilleCell; /* ======================================== Confection du header ============================================== */ this.resultat = new int[5]; this.resultatByte = new byte[5]; int[] tabEntrortie = new int[4]; tabEntrortie=outils.ParcoursCell(this.grilleCellules, this.cetteTaille); this.resultat[0]=this.cetteTaille; this.resultat[1]=tabEntrortie[0]; this.resultat[2]=tabEntrortie[1]; this.resultat[3]=tabEntrortie[2]; this.resultat[4]=tabEntrortie[3]; this.resultatByte = outils.ConvertToByte(this.resultat); /* ====================================== Confection de l'Offset ============================================ */ if((this.cetteTaille*this.cetteTaille)%8 == 0){ //définit les tailles s'il y a besoin d'un octet en plus ou pas this.tabTemp = new String[(this.cetteTaille*this.cetteTaille)/8]; this.octetRemaining = this.cetteTaille*this.cetteTaille; } else if((this.cetteTaille*this.cetteTaille)%8 > 0){ this.tabTemp = new String[(this.cetteTaille*this.cetteTaille)/8+1]; this.octetRemaining = (this.cetteTaille*this.cetteTaille)+(this.cetteTaille*this.cetteTaille)%8; } String tempString = ""; boolean[] tabHorizontal = new boolean[this.cetteTaille*this.cetteTaille]; tabHorizontal = outils.PutToVertical(this.cetteGrille, this.cetteTaille); // Transformation du tableau de boolean en un tableau de chaine de String qui stock des nombre sous formes de byte int compteur1=0; int decompte=0; for(boolean cetteIteration : tabHorizontal){ if(this.octetRemaining<8){ break; } if(cetteIteration==true){ tempString = tempString + "0"; } else if(cetteIteration==false){ tempString = tempString + "1"; } if(tempString.length()==8){ tabTemp[compteur1] = tempString; tempString=""; compteur1++; this.octetRemaining = this.octetRemaining - 8; } decompte++; } if(decompte != tabHorizontal.length){ while(decompte != tabHorizontal.length){ if(tabHorizontal[decompte]==true){ tempString=tempString+"0"; }else if(tabHorizontal[decompte]==false){ tempString=tempString+"1"; } decompte++; } while(tempString.length() < 8){ tempString=tempString+"0"; } this.tabTemp[compteur1] = tempString; } for(int i=0; i