Page d'accueil Description du projet
/*****************************************
 *
 *  Cedric Pradalier    2001
 *  mail : http://cedric.pradalier.free.fr/mail.html
 *
 * ***************************************/
#ifndef PIXMAP_IO_H
#define PIXMAP_IO_H
#include <stdlib.h>


// Classe definissant des pixmaps, en niveaux de gris.
// --> Représentation en mémoire d'images.
// --> Fonction de manipulation de base (ligne,point,remplissage)
// --> Lecture/Sauvegarde au format ppm

class Pixmap
{
    private :
        unsigned char * datas;
        int width;
        int height;

    public :
        enum {BLACK=0,WHITE=255} BnW;
        // Constructeur par defaut
        Pixmap() {datas=NULL;width=0;height=0;}
        // Constructeur : initialisation en blanc
        Pixmap(int w,int h, unsigned char init = WHITE);
        // Constructeur : initialisation par lecture de filename
        Pixmap(char * filename);
        
        ~Pixmap();
        
        // Libération des ressources et réinitialisation a 0 x 0 
        void Free();
        
        // Chargement d'une image. Les données précédentes sont libérées
        void Load(char *filename);

        // Sauvegarde des données courantes
        void Store(char *filename);

        // Dessine une ligne dans le pixmap. Utilise PutPixel
        void DrawLine(int x1,int x2,int y1,int y2, unsigned char color = BLACK);

        // Remplissage de la zone autour de (x,y), de la couleur de (x,y).
        // Utilise PutPixel
        void FloodFill(int x, int y, unsigned char color = BLACK);

        // Définit la couleur d'un pixel. Pas d'erreur si le pixel n'est pas
        // dans l'image.
        void PutPixel(int x,int y,int c) 
        {
            if ((x>=0) && (x<width) && (y>=0) && (y<height))
                datas[y*width+x] = c;
        } 

        // Lit la couleur d'un pixel. Pas d'erreur si le pixel n'est pas
        // dans l'image.
        unsigned char GetPixel(int x,int y) 
        {
            if ((x>=0) && (x<width) && (y>=0) && (y<height))
                return datas[y*width+x];
            else return 0;
        } 

        // Fonction de test de la classe.
        static void TestPixmap();
    private :
        void drawline ( int x1, int y1, int x2, int y2, int pred, int incdec ,
                int dx, int dy, int e, int e_inc, int e_noinc , 
                unsigned char color = BLACK) ;

        static int match_key(int fd, char *key);

        static void skip_comment(int fd, char code, char *c);

        static void read_header_line(int fd, char *buf);

        int get_pgm_header(int fd, char *magic);

        static int open_read(char *filename);

        int open_read_pixmap(char *filename, char *magic);

        void alloc_pixmap(long size);

        void load_data(int fd,long size);

        void load_pixmap(char *filename);

        static void put_header_line(int fd, char *buf);

        static void put_header_info(int fd, char *mark, char *filename);

        void put_pgm_header(int fd, char *magic, char *filename);

        static int open_write(char *filename);

        void store_data(int fd, long size);

        void store_pixmap(char *filename);



};

#ifdef RGB_PIXMAPS
// not needed here
void store_RGB_pixmap(char *filename,
    unsigned char *R_data, unsigned char *G_data, unsigned char *B_data,
    int width, int height);
int load_RGB_pixmap(char *filename, int *width, int *height,
    unsigned char**R_data, unsigned char**G_data, unsigned char**B_data);
#endif

#endif // PIXMAP_IO_H