//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Piles.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Edit1->Text=X; Edit2->Text=Y; Edit3->Text=GetRValue(Image1->Canvas->Pixels[X][Y]); Edit4->Text=GetGValue(Image1->Canvas->Pixels[X][Y]); Edit5->Text=GetBValue(Image1->Canvas->Pixels[X][Y]); Shape1->Brush->Color= Image1->Canvas->Pixels[X][Y]; } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn2Click(TObject *Sender) { Shape1->Brush->Color=RGB(Edit3->Text.ToInt(),Edit4->Text.ToInt(),Edit5->Text.ToInt()); } //---------------------------------------------------------------------------struct TMaillon struct TMaillon { int x,y; struct TMaillon *Suivant; }; int PileVide(struct TMaillon *Sommet) { if(Sommet==NULL) {return 1;} else {return 0;}; } void InitPile(struct TMaillon **Sommet) { struct TMaillon *P; while(*Sommet!=NULL) { P=*Sommet; *Sommet=(*Sommet)->Suivant; free(P); } } void Empiler(struct TMaillon **Sommet,int x,int y) { struct TMaillon *P; P=(struct TMaillon *)malloc(sizeof(TMaillon)); P->x=x; P->y=y; P->Suivant=*Sommet; *Sommet=P; } void Depiler(struct TMaillon **Sommet,int *x,int *y) { struct TMaillon *P; if(!PileVide(*Sommet)) { P=*Sommet; *x=P->x; *y=P->y; *Sommet=P->Suivant; free(P); } } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn1Click(TObject *Sender) { struct TMaillon *Pile=NULL; TColor C1=Image1->Canvas->Pixels[Edit1->Text.ToInt()][Edit2->Text.ToInt()]; TColor C=Shape1->Brush->Color; int i=0; int x=Edit1->Text.ToInt(), y=Edit2->Text.ToInt(), M=Image1->Picture->Width, N=Image1->Picture->Height; InitPile(&Pile); Empiler(&Pile,x,y); while((PileVide(Pile)==0)&& (i<60000)) { Depiler(&Pile,&x,&y); if(Image1->Canvas->Pixels[x][y]==C1) { Image1->Canvas->Pixels[x][y]=C; if(x>0) {Empiler(&Pile,x-1,y);}; if(x0) {Empiler(&Pile,x,y-1);}; if(y