#include "bmp.h" #include using namespace std; ////////////////////////////////////////////////////////////////////////////////////////////////// //Bmp(w,h, color): constructeur affectant la mémoire pour une image w*h de couleur de fond color// ////////////////////////////////////////////////////////////////////////////////////////////////// Bmp::Bmp(SHORT w,SHORT h, ULONG couleur_fond){ width=w; height=h; length=3*width*height; couleur=couleur_fond; pixel=new BYTE[length]; for (LONG i=0; i>8); //V pixel[i+2] = 255&(couleur>>16); //R } } //////////////////////////////////////////////////////////////// //destructeur de Bmp: libère la memoire occupée par les pixels// //////////////////////////////////////////////////////////////// Bmp::~Bmp(void){ if(pixel) delete [] pixel; } //////////////////////////////////////////////////////////////// //affecte la couleur 'color' au pixel de coordonnees (X,Y) // //////////////////////////////////////////////////////////////// void Bmp:: setpixel(SHORT X,SHORT Y,ULONG color) { assert((X>16)); G = (BYTE)(255&(color>>8)); B = (BYTE)(255&color); pixel[ind] = B; //B pixel[ind+1]= G; //G pixel[ind+2]= R; //R return; } ////////////////////////////////////////////////////////////// //retourne la couleur du pixel de coordonnees (X,Y) // ////////////////////////////////////////////////////////////// ULONG Bmp::getpixel(SHORT X,SHORT Y){ ULONG couleur; BYTE R,G,B; assert((Yb?a-b:b-a; } void Bmp::line(SHORT I1,SHORT J1,SHORT I2,SHORT J2,ULONG color){ SHORT dI,dJ,incrI,incrJ,currentI,currentJ,dPi,dPj,dPij,P; //Algorithme de Bresenham (1962) dI=diff(I1,I2); dJ=diff(J1,J2); currentI=I1; currentJ=J1; incrI=(I2>I1?1:-1); incrJ=(J2>J1?1:-1); if (dJ>=dI) //|tan(theta)|<=1 { dPj=dI<<1; dPij=dPj-(dJ<<1); P=dPj-dJ; for(;dJ>=0;dJ--){ setpixel(currentI,currentJ,color); if(P>0){ currentI+=incrI; currentJ+=incrJ; P+=dPij; } else{ currentJ+=incrJ; P+=dPj; } } } else{ //|tan(theta)|>1 dPi=dJ<<1; dPij=dPi-(dI<<1); P=dPi-dI; for(;dI>=0;dI--){ setpixel(currentI,currentJ,color); if(P>0) { currentJ+=incrJ; currentI+=incrI; P+=dPij; } else { currentI+=incrI; P+=dPi; } } } return; } ////////////////////////////////////////////////////////// // Les fonctions privées // ////////////////////////////////////////////////////////// void Bmp:: convert(BYTE *temp, ULONG Champ) { BYTE *ptr; ULONG *ptr_u; ptr_u=&Champ; ptr = (BYTE*)ptr_u; temp[0]= *ptr; temp[1]= *(ptr+1); temp[2]= *(ptr+2); temp[3]= *(ptr+3); } void Bmp:: convert(BYTE *temp, USHORT Champ) { BYTE *ptr; USHORT *ptr_u; ptr_u=&Champ; ptr = (BYTE*)ptr_u; temp[0]= *ptr; temp[1]= *(ptr+1); }