Browse Source

changement de méthode pour l'écriture du gcode

Jackbot 4 years ago
parent
commit
16eb25e4c3
1 changed files with 21 additions and 63 deletions
  1. 21 63
      bmp2gcode.cc

+ 21 - 63
bmp2gcode.cc

@@ -12,58 +12,31 @@ class BMP2Gcode
 		void fichier_conf();
 
 	private:
-		unsigned int BMP_larg();
-		unsigned int BMP_haut();
-		unsigned int BMP_offset();
-		unsigned int BMP_profondeur();
-
 		int entete();
 		int donnees();
 		int sortie();
 
-		void BMP_larg(unsigned int nbr);
-		void BMP_haut(unsigned int nbr);
-		void BMP_offset(unsigned int nbr);
-		void BMP_profondeur(unsigned int nbr);
-
 		unsigned int conversion(unsigned int valeur, unsigned int min, unsigned int max);
 
-		unsigned int BMP_largeur, BMP_hauteur, BMP_off, BMP_prof, BMP_taille;
+		unsigned int BMP_largeur, BMP_hauteur, BMP_offset, BMP_profondeur, BMP_taille;
 		double conf_taille_laser, conf_puissance_min, conf_puissance_max, conf_vitesse, conf_taille_image;
 		std::vector<unsigned int> tab_donnees;
 		std::string nom_fichier_bmp;
 };
 
 BMP2Gcode::BMP2Gcode()
-:BMP_largeur(0), BMP_hauteur(0), BMP_off(0), BMP_prof(0), BMP_taille(0)
+:BMP_largeur(0), BMP_hauteur(0), BMP_offset(0), BMP_profondeur(0), BMP_taille(0)
 {}
 
 void BMP2Gcode::traitement(char* nom_fichier)
 {
 	nom_fichier_bmp = nom_fichier;
-	entete();
-	donnees();
-	sortie();
-}
-
-unsigned int BMP2Gcode::BMP_larg()
-{
-	return BMP_largeur;
-}
-
-unsigned int BMP2Gcode::BMP_haut()
-{
-	return BMP_hauteur;
-}
-
-unsigned int BMP2Gcode::BMP_offset()
-{
-	return BMP_off;
-}
-
-unsigned int BMP2Gcode::BMP_profondeur()
-{
-	return BMP_prof;
+	
+	if(entete() == 0)
+	{
+		if(donnees() == 0)
+		{sortie();}
+	}
 }
 
 int BMP2Gcode::entete()
@@ -117,14 +90,19 @@ int BMP2Gcode::entete()
 	de prendre sa valeur en faisant : *(int *)entete[indice]
 	*/
 
-	BMP_larg(*(int*)&entete[18]);
-	BMP_haut(*(int*)&entete[22]);
-	BMP_offset(*(int*)&entete[10]);
-	BMP_profondeur(*(short*)&entete[28]);
+	//pourquoi un indice de 9 ne correspond pas ????
+	BMP_offset = *(int*)&entete[10];
+
+	BMP_largeur = *(int*)&entete[18];
+	BMP_hauteur = *(int*)&entete[22];
+	BMP_profondeur = *(short*)&entete[28];
+	
+	std::cout << "compression : " << *(int*)&entete[30] << std::endl;
 
+	std::cout << "offset BMP : " << BMP_offset << std::endl;
 	std::cout << "largeur BMP : " << BMP_largeur << std::endl;
 	std::cout << "hauteur BMP : " << BMP_hauteur << std::endl;
-	std::cout << "profondeur BMP : " << BMP_prof << std::endl;
+	std::cout << "profondeur BMP : " << BMP_profondeur << std::endl;
 	
 	delete[] entete;
 	fichier.close();
@@ -144,15 +122,15 @@ int BMP2Gcode::donnees()
 		return 1;
 	}
 
-	if(BMP_off == 0)
+	if(BMP_offset == 0)
 	{entete();}
 
-	int limite = BMP_larg()*BMP_haut() * BMP_profondeur()/8 + BMP_offset();
+	int limite = BMP_largeur*BMP_hauteur * BMP_profondeur/8 + BMP_offset;
 
 	char *donnees = new char [ limite ];
 	fichier.read(donnees, limite);
 
-	for(int i = BMP_offset() ; i < limite ; i += BMP_prof/8)
+	for(int i = BMP_offset ; i < limite ; i += BMP_profondeur/8)
 	{
 		if(donnees[i] < 0)
 		{tab_donnees.push_back(256 + (int)donnees[i]);}
@@ -251,26 +229,6 @@ int BMP2Gcode::sortie()
 	return 0;
 }
 
-void BMP2Gcode::BMP_larg(unsigned int nbr)
-{
-	BMP_largeur = nbr;
-}
-
-void BMP2Gcode::BMP_haut(unsigned int nbr)
-{
-	BMP_hauteur = nbr;
-}
-
-void BMP2Gcode::BMP_offset(unsigned int nbr)
-{
-	BMP_off = nbr;
-}
-
-void BMP2Gcode::BMP_profondeur(unsigned int nbr)
-{
-	BMP_prof = nbr;
-}
-
 unsigned int BMP2Gcode::conversion(unsigned int valeur, unsigned int min, unsigned int max)
 {
 	/*pour une valeur de 0 la puissance du laser doit être égale à min