Emboss Filter i Firemonkey

Jeg har visst fremdeles et par filterfunksjoner i Firemonkey som jeg ikke har vist, Emboss filter er et av dem.

Design i RAD Studio er igjen ganske enkel, to TImage og to Tbuttons. Denne gang skal det også være med to TTrackBars, mengde og bredde:

Emboss Filter i Firemonkey
Emboss Filter i Firemonkey

Deklarasjonen av Emboss klassen er som følger:

//---------------------------------------------------------------------------

#ifndef EmbossH
#define EmbossH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
#include <FMX.Effects.hpp>
#include <FMX.Filter.Effects.hpp>
#include <FMX.Objects.hpp>
//---------------------------------------------------------------------------
class TForm11 : public TForm
{
__published:	// IDE-managed Components
	TImage *Image1;
	TImage *Image2;
	TTrackBar *TrackBar1;
	TTrackBar *TrackBar2;
	TButton *Cancel;
	TButton *OK;
	TLabel *Label2;
	TLabel *Label1;
	void __fastcall OnCreate(TObject *Sender);
	void __fastcall CancelClick(TObject *Sender);
	void __fastcall OKClick(TObject *Sender);
	void __fastcall TrackBar1Change(TObject *Sender);
	void __fastcall TrackBar2Change(TObject *Sender);
private:	// User declarations
public:		// User declarations
	int iretState;
	//TFilterSharpen * MySharpenFilter;
	//TFilterGaussianBlur *myGaussianBlur;
	//TFilterBoxBlur *myBoxBlur;
	//TFilterRadialBlur *myRadialBlur;
	//TFilterDirectionalBlur *myDirectionalBlur;
	TFilterEmboss *myEmboss;


	__fastcall TForm11(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm11 *Form11;
//---------------------------------------------------------------------------
#endif

Implementering av den samme klassen er som følger:

//---------------------------------------------------------------------------

#include <fmx.h>
#pragma hdrstop

#include "Emboss.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm11 *Form11;
//---------------------------------------------------------------------------
__fastcall TForm11::TForm11(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm11::OnCreate(TObject *Sender)
{
  	//myGaussianBlur = new TFilterGaussianBlur(this);
	//myBoxBlur = new TFilterBoxBlur(this);
	//myRadialBlur = new TFilterRadialBlur(this);
	//myDirectionalBlur = new TFilterDirectionalBlur(this);
	myEmboss = new TFilterEmboss(this);

	 myEmboss->Input = Image1->Bitmap;
	 myEmboss->Amount = TrackBar1->Value / 100;
	 Image2->Bitmap = myEmboss->Output;
	 TrackBar2->Value = 30;
	 myEmboss->Width = TrackBar2->Value / 10;
	 //myEmboss->Width = 3;

}
//---------------------------------------------------------------------------
void __fastcall TForm11::CancelClick(TObject *Sender)
{
	iretState = 0;
	Close();

}
//---------------------------------------------------------------------------
void __fastcall TForm11::OKClick(TObject *Sender)
{
	iretState = 1;
	Close();

}
//---------------------------------------------------------------------------
void __fastcall TForm11::TrackBar1Change(TObject *Sender)
{
	myEmboss->Amount = TrackBar1->Value / 100;
	Image2->Bitmap = myEmboss->Output;

}
//---------------------------------------------------------------------------
void __fastcall TForm11::TrackBar2Change(TObject *Sender)
{
	myEmboss->Width = TrackBar1->Value / 10;
	Image2->Bitmap = myEmboss->Output;

}
//---------------------------------------------------------------------------

Jeg har vel til det kjedsommeligste sagt at DocPage deklarasjonen min inneholder litt av hvert (som fremdeles er under testing), du får plukke ut det som er av interesse:

// --------------------------------------------------------------------------
//                  class DocPage
// --------------------------------------------------------------------------
class DocPage : public TTabItem
{
private:



public:

	// ----------------------------------------------
	// Page and screen sizes
	enum ePageSizeTypes {
		ePixels,
		eInches,
		eMilliMetres
	};

	ePageSizeTypes 	eSizeType;   		// pixels, inches, etc...

	float		fPageWidth;         	// Page Width
	float		fPageHeight;       		// Page Height
	int  		iPageWidthInPixels; 	// Page Width in Pixels
	int  		iPageHeightInPixels;	// Page Height in Pixels

	int  		iDisplayCount; 			// Display count
	int         iScreenWidthInPixels;   // Screen Width in pixels
	int         iScreenHeightInPixels;  // Screen Height in pixels
	int         iScreenSizeInPixels;    // Screen Size in pixels
	float       fScreenSizeInInches;    // Screen Size In Inches
	float       fScreenSizeInMM;        // Screen Size In MM
	int         iScreenPPI;             // Screen ppi
	int         iDesktopWidthInPixels;  // Desktop Width (Dualscreen?)
	int         iDesktopHeightInPixels; // Desktop Height
	int 		iWorkAreaWidthInPixels; // Work Area in Pixels
	int         iWorkAreaHeightInPixels;//

	// -----------------------------------------------
	// Zip class
	//
	TZipFile   * myZipFile;

	// -----------------------------------------------
	// Testing Frame  (Layer list, etc...)
	//
	TFrame2 *myFrame;

	// -----------------------------------------------
	// Pathnames Win 10:
    //
	// ProgHomeDir 		- c:\Users\svein\AppData\Roaming\Gamlisen\
	// ProjectFileComp  - c:\Users\svein\AppData\Roaming\Gamlisen\anyname.zip
	// ProjectFile      - c:\Users\svein\AppData\Roaming\Gamlisen\anyname.gam
	// ProjectIndexCount- c:\Users\svein\AppData\Roaming\Gamlisen\nnnn
	// ProjectIniFile   - c:\Users\svein\AppData\Roaming\Gamlisen\Gamlis.ini
	// ProjectTempComp  - c:\Users\svein\AppData\Roaming\Gamlisen\Comp2020\
	// ProjectWorkDir   - c:\Users\svein\AppData\Roaming\Gamlisen\G20200501nnnn\
	// ProjectItems     - c:\Users\svein\AppData\Roaming\Gamlisen\G20200501nnnn\Gamlis.ini
	// ProjectItems     - c:\Users\svein\AppData\Roaming\Gamlisen\G20200501nnnn\Image1.png
	// ProjectItems     - c:\Users\svein\AppData\Roaming\Gamlisen\G20200501nnnn\etc...anyfile
	// ProjectBackup    - c:\Users\svein\AppData\Roaming\Gamlisen\Backup\
	//
	System::UnicodeString *ProgHomeDir;
	System::UnicodeString *ProjectFileComp;
	System::UnicodeString *ProjectFile;
	int                    ProjectIndexCount;
	System::UnicodeString *ProjectIniFile;
	System::UnicodeString *ProjectTempComp;
	System::UnicodeString *ProjectWorkDir;
	System::UnicodeString *ProjectBackup;

	// -----------------------------------------------
	// Page Images and Bitmaps

	TFramedScrollBox *FramedScrollBox1; // TFramed ScrollBox
	TLayout 		* Layout1;          // TLayout
	TTabControl     * myTabControl;     // TabControl

	TImage 			* Image1;	        // TImage
	TBitmap			* myBitmap; 	    // TBitmap

	TImage  		* PasteImage;       // Temp Images
	TImage  		* WorkImage;        //

	TSelection 		* mySelection;
	float   	 	zoomFactor;

	// ----------------------------------------------
	// Layers
	TLayerItem *LayerItem;

	boost::ptr_list<TLayerItem> LayerList;
	boost::ptr_list<TLayerItem>::iterator iterLayers;

	TListBox *myLayerListBox;

	// ---------------------------------------------
	// Undo Stack
	TUndoItem  *UndoItem;

	std::stack<TUndoItem *> mystack;

	// ---------------------------------------------

	DocPage(TTabControl *Parent);   // Constructor
	~DocPage();                     // Destructor

void __fastcall ImageProperties();  // Display  image properties

void __fastcall Copy();         // Edit Copy
void __fastcall Paste();        // Edit Paste
void __fastcall UnDo();         // Edit undo
void __fastcall SepiaFilter();  // Sepia Filter
void __fastcall SharpenFilter();// Sharpening Filter
void __fastcall CropFilter(TSelection *localSelection);   // Crop
void __fastcall Rotate();       // Rotate image
void __fastcall Rotate180Click(TObject *Sender); 		// Rotate 180
void __fastcall Rotate90CWClick(TObject* Sender);       // Rotate 90 CW
void __fastcall Rotate90CCWClick(TObject *Sender);      // Rotate 90 CCW
void __fastcall FlipHorizontallyClick(TObject *Sender); // Flip Horizontally
void __fastcall FlipVerticallyClick(TObject *Sender);   // Flip Vertically
void __fastcall GaussianBlur();         // Gaussian Blur
void __fastcall BoxBlur();              // Box Blur
void __fastcall RadialBlur();           // Radial Blur
void __fastcall DirectionalBlur();      // Directional Blur
void __fastcall Emboss();               // Emboss
void __fastcall Pixelate();             // Pixelate
void __fastcall BrightnessContrast();   // Brightness / Contrast
void __fastcall Monochrome();           // MonoChrome
void __fastcall Wave();                 // Wave

void __fastcall ScaleUp();              // Scale Up
void __fastcall ScaleDown();            // Scale Down
void __fastcall Zoom(float Val);        // Zoom

void __fastcall PencilStroke();         // Pencil Stroke
void __fastcall PaperSketch();          // Paper Sketch

void __fastcall FileSaveAs();

//void __fastcall OnMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, bool &Handled);

	void __fastcall LayerButtonShowClick();
	void __fastcall LayerButtonHideClick();
	void __fastcall LayerButtonDownClick();
	void __fastcall LayerButtonUpClick();
	void __fastcall LayerButtonUnlockClick();
	void __fastcall LayerButtonLockClick();
	void __fastcall LayerButtonRemoveClick();
	void __fastcall LayerButtonAddClick();

};

Implementeringen av Emboss er også ganske enkel og nokså lik andre filtre:

// --------------------------------------------------------------------------
//  				Emboss
// --------------------------------------------------------------------------

void __fastcall DocPage::Emboss()
{
	try
	{
		TForm11 *dlgEmboss =  new TForm11(Application);

		dlgEmboss->Image1->Bitmap = Image1->Bitmap;
		dlgEmboss->Caption = _T("Emboss");

		dlgEmboss->myEmboss->Input = dlgEmboss->Image1->Bitmap;
		dlgEmboss->myEmboss->Amount = dlgEmboss->TrackBar1->Value / 100;
		dlgEmboss->Image2->Bitmap = dlgEmboss->myEmboss->Output;


		dlgEmboss->ShowModal();
		if( dlgEmboss -> iretState == 1 ) {

			// Don't forget the undo-stack

			UndoItem = new TUndoItem();
			UndoItem->UndoName = new String("Emboss");
			UndoItem->UndoBitmap = new TBitmap();

			// Have to use "Assign()" because everything are pointers!!!

			UndoItem->UndoBitmap->Assign(Image1->Bitmap);
			mystack.push(UndoItem);

			Image1->Bitmap->Assign(dlgEmboss->Image2->Bitmap);

		}

		dlgEmboss->DisposeOf();
	}
	catch(...)
	{
		ShowMessage("Emboss did not succeed");
	}

}

Da gjenstår det vel bare å vise et par bilder fra runtime:

Firemonkey Emboss Filter runtime 1
Firemonkey Emboss Filter runtime 1
Firemonkey Emboss Filter ved runtime 2
Firemonkey Emboss Filter ved runtime 2

Legg igjen en kommentar

Din e-postadresse vil ikke bli publisert. Obligatoriske felt er merket med *

Dette nettstedet bruker Akismet for å redusere spam. Lær om hvordan dine kommentar-data prosesseres.