2026-01-02 20:52:44 +01:00
|
|
|
package fr.iutfbleau.sae.mpif;
|
2026-01-04 18:05:46 +01:00
|
|
|
import fr.iutfbleau.sae.mimage.RGBImage;
|
2026-01-02 20:52:44 +01:00
|
|
|
import fr.iutfbleau.sae.util.BitInputStream;
|
|
|
|
|
|
2026-01-04 18:05:46 +01:00
|
|
|
import java.io.BufferedInputStream;
|
2026-01-02 20:52:44 +01:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PIFReader {
|
|
|
|
|
|
|
|
|
|
private int width;
|
|
|
|
|
private int height;
|
|
|
|
|
private int[] lenR;
|
|
|
|
|
private int[] lenG;
|
|
|
|
|
private int[] lenB;
|
|
|
|
|
|
|
|
|
|
public RGBImage read(String filepath)
|
|
|
|
|
throws Exception {
|
2026-01-04 18:05:46 +01:00
|
|
|
|
|
|
|
|
// j'Utilise d'un BufferedInputStream pour une meilleure performance
|
2026-01-02 20:52:44 +01:00
|
|
|
FileInputStream fis = new FileInputStream(filepath);
|
2026-01-04 18:05:46 +01:00
|
|
|
BufferedInputStream bis = new BufferedInputStream(fis);
|
|
|
|
|
BitInputStream lecteur = new BitInputStream(bis);
|
2026-01-02 20:52:44 +01:00
|
|
|
|
|
|
|
|
// je lis l'entête et les tables canoniques
|
|
|
|
|
this.readHeader(lecteur);
|
|
|
|
|
this.readCanonicalTables(lecteur);
|
|
|
|
|
|
|
|
|
|
// je reconstructe les tables canoniques car dans le fichier on a juste les longueurs en bits
|
|
|
|
|
Map<String, Integer> canonR = rebuildCanonical(lenR);
|
|
|
|
|
Map<String, Integer> canonG = rebuildCanonical(lenG);
|
|
|
|
|
Map<String, Integer> canonB = rebuildCanonical(lenB);
|
|
|
|
|
|
|
|
|
|
DecodeNode trieR = buildDecodageTree(canonR);
|
|
|
|
|
DecodeNode trieG = buildDecodageTree(canonG);
|
|
|
|
|
DecodeNode trieB = buildDecodageTree(canonB);
|
|
|
|
|
|
|
|
|
|
RGBImage img = decodePixels(lecteur, trieR, trieG, trieB);
|
|
|
|
|
|
|
|
|
|
lecteur.closeFlux();
|
|
|
|
|
return img;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readHeader(BitInputStream in) {
|
2026-01-04 18:05:46 +01:00
|
|
|
|
2026-01-02 20:52:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readCanonicalTables(BitInputStream in) {
|
|
|
|
|
// TODO: Implement canonical table reading
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<String,Integer> rebuildCanonical(int[] lengths) {
|
|
|
|
|
// TODO: Implement canonical table reconstruction
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RGBImage decodePixels(BitInputStream in, DecodeNode red, DecodeNode green, DecodeNode blue) {
|
|
|
|
|
// TODO: Implement pixel decoding
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DecodeNode buildDecodageTree(Map<String,Integer> codes) {
|
|
|
|
|
// TODO: Implement trie building
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|