home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2003 November
/
PCWK1103B.iso
/
PCWK-txt
/
Warsztat_Cpp_Builder
/
Unit1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2003-10-02
|
8KB
|
296 lines
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "fotoretusz.h"
#include "UnitJasnosc.h"
#include "UnitKontrast.h"
#include "UnitNasycenie.h"
#include "UnitBalans.h"
#include "UnitEdytorFiltrow.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cdiroutl"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Otwrz1Click(TObject *Sender)
{
if( op->Execute() )
{
img->Picture->LoadFromFile( op->FileName );
if( !img->Picture->Bitmap->Empty )
{
img->Picture->Bitmap->PixelFormat = pf32bit;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Poprawianiekolorw1Click(TObject *Sender)
{
//przygotuj i za│aduj miniaturΩ rysunku
PrzygotujMiniature(img->Picture->Bitmap,FormJasnosc->rys1->Picture->Bitmap,240,180);
//pokaz okno ustawiania jasnosci
int wynik = FormJasnosc->ShowModal();
if( IsPositiveResult( wynik) )
{
// przekszta│c orygina│
DostosujJasnosc( img->Picture->Bitmap,FormJasnosc->tbJasnosc->Position*2.55 );
img->Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Kontrast1Click(TObject *Sender)
{
//przygotuj i za│aduj miniaturΩ rysunku
PrzygotujMiniature(img->Picture->Bitmap,FormKontrast->rys1->Picture->Bitmap,240,180);
//pokaz okno ustawiania jasnosci
int wynik = FormKontrast->ShowModal();
if( IsPositiveResult( wynik) )
{
// przekszta│c orygina│
DostosujKontrast( img->Picture->Bitmap,FormKontrast->tbKontrast->Position );
img->Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Nasyceniekolorw1Click(TObject *Sender)
{
//przygotuj i za│aduj miniaturΩ rysunku
PrzygotujMiniature(img->Picture->Bitmap,FormNasycenie->rys1->Picture->Bitmap,240,180);
//pokaz okno ustawiania jasnosci
int wynik = FormNasycenie->ShowModal();
if( IsPositiveResult( wynik) )
{
// przekszta│c orygina│
DostosujNasycenie( img->Picture->Bitmap,FormNasycenie->tbNasycenie->Position );
img->Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Balanskolor1Click(TObject *Sender)
{
//przygotuj i za│aduj miniaturΩ rysunku
PrzygotujMiniature(img->Picture->Bitmap,FormBalans->rys1->Picture->Bitmap,240,180);
//pokaz okno ustawiania jasnosci
int wynik = FormBalans->ShowModal();
if( IsPositiveResult( wynik) )
{
// przekszta│c orygina│
DostosujBalans( img->Picture->Bitmap,FormBalans->tbR->Position*2.55,FormBalans->tbG->Position*2.55,FormBalans->tbB->Position*2.55 );
img->Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Zapisz1Click(TObject *Sender)
{
sd->FileName = op->FileName;
if( sd->Execute() )
img->Picture->Bitmap->SaveToFile( sd->FileName );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Zapiszjako1Click(TObject *Sender)
{
sd->FileName = "";
if( sd->Execute() )
img->Picture->Bitmap->SaveToFile( sd->FileName );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edytorfiltrw1Click(TObject *Sender)
{
//przygotuj i za│aduj miniaturΩ rysunku
PrzygotujMiniature(img->Picture->Bitmap,FormEdytor->rys1->Picture->Bitmap,240,180);
//pokaz okno ustawiania jasnosci
int wynik = FormEdytor->ShowModal();
if( IsPositiveResult( wynik) )
{
//przekszta│c orygina│
double f[3][3];
for( int i=0;i<3;i++)
for( int j=0; j<3; j++)
{
if( !TryStrToFloat( Trim(FormEdytor->sgFiltr->Cells[i][j]), f[i][j]) )
f[i][j] = 0.0;
}
TMemoryStream *pms = new TMemoryStream;
pms->Position = 0;
img->Picture->Bitmap->SaveToStream( pms );
pms->Position = 0;
simg->Picture->Bitmap->LoadFromStream( pms );
delete pms;
Filtr3x3( simg->Picture->Bitmap,img->Picture->Bitmap, f );
img->Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Negatyw1Click(TObject *Sender)
{
// przekszta│c orygina│
Negatyw( img->Picture->Bitmap );
img->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Odcienieszaro1Click(TObject *Sender)
{
// przekszta│c orygina│
OdcienieSzarosci( img->Picture->Bitmap );
img->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Rozmyciewyostrzenie1Click(TObject *Sender)
{
//przekszta│c orygina│
double f[3][3];
//ustaw tablicΩ filtru - rozmycia
// 1 1 1
// 1 1 1
// 1 1 1
for(int i=0;i<3;i++)
for( int j=0;j<3;j++)
f[i][j] = 1;
// przygotuj rysunek ƒr≤d│owy
TMemoryStream *pms = new TMemoryStream;
pms->Position = 0;
img->Picture->Bitmap->SaveToStream( pms );
pms->Position = 0;
simg->Width = img->Width;
simg->Height = img->Height;
simg->Picture->Bitmap->LoadFromStream( pms );
delete pms;
//uruchom przeksztalcenie
Filtr3x3( simg->Picture->Bitmap,img->Picture->Bitmap, f );
img->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Wyostrzenie1Click(TObject *Sender)
{
//przekszta│c orygina│
double f[3][3];
//ustaw tablicΩ filtru - wyostrzenia
// 0 -0.2 0
// -0.2 1.8 -0.2
// 0 -0.2 0
for(int i=0;i<3;i++)
for( int j=0;j<3;j++)
f[i][j] = 0;
f[0][1] = f[1][0] = f[2][1] = f[1][2] = -0.2;
f[1][1] = 1.8;
// przygotuj rysunek ƒr≤d│owy
TMemoryStream *pms = new TMemoryStream;
pms->Position = 0;
img->Picture->Bitmap->SaveToStream( pms );
pms->Position = 0;
simg->Width = img->Width;
simg->Height = img->Height;
simg->Picture->Bitmap->LoadFromStream( pms );
delete pms;
//uruchom przeksztalcenie
Filtr3x3( simg->Picture->Bitmap,img->Picture->Bitmap, f );
img->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Wykryciekrawdzi1Click(TObject *Sender)
{
//przekszta│c orygina│
double f[3][3];
//ustaw tablicΩ filtru - wykrycie krawedzi
// -1 0 -1
// 0 4 0
// -1 0 -1
for(int i=0;i<3;i++)
for( int j=0;j<3;j++)
f[i][j] = 0;
f[0][0] = f[2][0] = f[0][2] = f[2][2] = -1;
f[1][1] = 4;
// przygotuj rysunek ƒr≤d│owy
TMemoryStream *pms = new TMemoryStream;
pms->Position = 0;
img->Picture->Bitmap->SaveToStream( pms );
pms->Position = 0;
simg->Width = img->Width;
simg->Height = img->Height;
simg->Picture->Bitmap->LoadFromStream( pms );
delete pms;
//uruchom przeksztalcenie
Filtr3x3( simg->Picture->Bitmap,img->Picture->Bitmap, f );
img->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Relief1Click(TObject *Sender)
{
//przekszta│c orygina│
double f[3][3];
//ustaw tablicΩ filtru - relief
// 1 1 0
// 1 1 -1
// 0 -1 -1
f[0][2] = f[2][0] = 0;
f[0][0] = f[0][1] = f[1][0] = 1;
f[2][1] = f[2][2] = f[1][2] = -1;
f[1][1] = 1;
// przygotuj rysunek ƒr≤d│owy
TMemoryStream *pms = new TMemoryStream;
pms->Position = 0;
img->Picture->Bitmap->SaveToStream( pms );
pms->Position = 0;
simg->Width = img->Width;
simg->Height = img->Height;
simg->Picture->Bitmap->LoadFromStream( pms );
delete pms;
//uruchom przeksztalcenie
Filtr3x3( simg->Picture->Bitmap,img->Picture->Bitmap, f );
img->Invalidate();
}
//---------------------------------------------------------------------------