# Object Pascal Demos

# Object Pascal Demos

These Object Pascal demos currently exist:
- Benchmark
- VCL Image Browser
- LCL Imager
- VampConvert
- OpenGL Demo
- Direct3D 9 Demo
- SDL Demo

If you have paths to compilers properly set you can build basic demos at once by calling build scripts named BuildDemos*.bat for Windows and DOS and BuildDemos*.sh for Linux. They are located in Scripts directory and compiled demos will be placed in Demos/Bin directory. Demos of Imaging extensions (like OpenGL support) which require 3rd party units (like OpenGL headers) can be compiled using BuildExtDemos*.bat and BuildExtDemos*.sh scripts. Remember that you must first set paths to required headers in these scripts for them to work.

Some demos from older Imaging releases were removed. DXTTool has been replaced by VampConvert. HighLevel was there to show how to use high level interface (class based) which is now used by nearly all demos so HighLevel is no longer necessary.

Benchmark
Simple program which measures time taken by the main Imaging functions (loading, manipulation, saving) in microsecond resolution. You can use it to compare the speeds of executables created by the supported compilers (you can find results for my machine in BenchmarkResults directory).

## Demo Information

Name | Benchmark
Language | Object Pascal
Source Path | (Imaging Root)\Demos\ObjectPascal\Benchmark
Exe Path | (Imaging Root)\Demos\Bin\Bench[.exe]
Platforms (tested) | Windows, Linux, FreeBSD
Compilers (tested) | Delphi 7/2007/2009/2010 W Free Pascal 2.2.4 WLBD
Demo shows usage of | low level

Benchmark first loads images (one for each supported and registered file format) and then calls various image manipulation functions on them. Finally, images are saved and log file (with time consumption of each action) is written. You can change behaviour of program by commenting/uncommenting two defines:
- LOG_TO_FILE If defined log is written to file (ResultsPas.log in the directory where executable is located), otherwise it is written to console.
- SAVE_IMAGES_TO_FILES If not defined, modified images are saved only to memory and taken time is measured. If defined, these images are saved to files after measurement.
Also note these things before running this demo:
- During the test large amounts of memory can be allocated by the program (e.g. conversion from 3000x3000x64 bit image to 128 bit requires over 200 MB of memory).
- Program's executable must be located in Demos, Demos\SomeDir or Demos\SomeDir1\SomeDir2 to be able to find used data files.
VCL Image Browser
This simple viewer application shows usage of high level class interface to Imaging library and also drawing images onto standard VCL TCanvas. TImagingCanvas class is also used here.

## Demo Information

Name | VCL Image Browser
Language | Object Pascal
Source Path | (Imaging Root)\Demos\ObjectPascal\VCLImageBrowser
Exe Path | (Imaging Root)\Demos\Bin\ImgBrowser.exe
Platforms (tested) | Win32
Compilers (tested) | Delphi 7/2007/2009/2010 W
Demo shows usage of | high level/component sets/canvas

In the left part of the window is shell tree view component. Here you can select files located in your computer. If the selected file is in one of the supported formats it is displayed in the viewer area and some information about the file is displayed in the info area. If image file contains subimages you can view them too. Select active subimage by clicking on buttons with arrows (Previous/Next or First/Last). There is also Save Image Copy button that allows you to save copy (that is used for display, in A8R8G8B8) of currently selected image to file.
When supported file is selected in shell tree view it is loaded to TMultiImage and converted to ifA8R8G8B8 data format. Active subimage is then drawn (with alpha blending if there is a alpha channel present - methods of TImagingCanvas are used) on background image (filled with back color). Final blended image is then drawn into TPainBox component's client area using DisplayImage procedure (direct bit copy, no need to convert Imaging's data to TGraphic). Image is rescaled to fit the whole display area and there is optional bicubic filtering (nearest neighbor is used when disabled).
LCL Imager
Simple image manipulator program which shows usage of Imaging LCL classes (TImagingGraphic and its descendants) to display images on the form. It also uses high level image classes and low level functions.

## Demo Information

Name | LCL Imager
Language | Object Pascal
Source Path | (Imaging Root)\Demos\ObjectPascal\LCLImager
Exe Path | (Imaging Root)\Demos\Bin\LCLImager.exe
Platforms (tested) | Windows, Linux, FreeBSD
Compilers (tested) | Lazarus 0.9.28 WLB interfaces: Win32/64, GTK/GTK2, Qt, Carbon
Demo shows usage of | high level/component sets/canvas

Demo uses TMultiImage class to store images (loaded from one file so its usually only one for most formats with exceptions like MNG and DDS) which can be modified by user. After each modification image is assigned to TImagingBitmap class which provides visualization on the app form (using standard TImage component). Demo also uses new TImagingCanvas class to do some effects.
In File menu you can open new image and save the current one. Items in View menu provide information about the current image and controls how it is displayed. You can also select next and previous subimage if loaded file contains more than one image. Format menu allows you to convert image to different image data formats supported by Imaging. Manipulate menu allows you to enlarge/shrink/flip/mirror/swap channels/reduce colors of the current image. Linear Filters menu allows you to apply various linear filters to the image like bluring, sharpening, or edge detection. Nonlinear Filters menu allows you to apply nonlinear filters like median or maximum. Using operations in Point Transforms menu you can adjust image contrast, brightness, or gamma. Filters and point transforms are provided by TImagingCanvas. Binary Morphology menu provides image segmentation functions using basic morphology operators (unit ImagingBinary). Colors menu allows user to set the value of specific color/alpha channel of all image pixels. There is also option to show histogram of current image (R, G, B, and Gray values displayed).
VampConvert
Image Converter is command line tool for converting images between file and data formats. It also provides some basic manipulation functions like resizing, rotating, or color reduction.

## Demo Information

Name | VampConvert
Language | Object Pascal
Source Path | (Imaging Root)\Demos\ObjectPascal\VampConvert
Exe Path | (Imaging Root)\Demos\Bin\VampConvert[.exe]
Platforms (tested) | Windows, Linux, FreeBSD
Compilers (tested) | Delphi 7/2007/2009/2010 W, Free Pascal 2.2.4 WLBD
Demo shows usage of | low level

Here is usage information with possible command switches and parameters (as printed by demo if invalid input is given):
Vampyre Image Converter (library version 0.26.0) by Marek Mauder

Error: Input file not specified

Usage: VampConvert [-op=arg] [..] -infile=file.ext [..] [-outfile=file.ext] [-op=arg] Options: -infile | -i: specify input image file path -outfile | -o: specify output image file path argument: file path or "*.ext" where input file name will be used but with "ext" extension Operations: Note: they are processed in the same order as they appear on command line -format: changes data format of input images argument: name of data format supported by Imaging like A8R8G8B8 -resize: changes size of input images argument: string in format AxBxC (%dx%dx%s) where A is desired width, B is desired height, and C is resampling filter used. If A or B is 0 then original dimension will be preserved. C is optional and can have one of following values: nearest(default), bilinear, bicubic. -flip: flips input images upside down -mirror: mirrors input images left to right -colorcount: reduces number of colors in image argument: number of desired colors (2-4096) -genmipmaps: generates mipmaps for main image argument: number of desired mip levels. 0 or no arg means create all possible levels -rotate: rotates input images counterclockwise argument: angle in degrees, multiple of 90

Supported file formats (INPUT): bmp jpg png mng jng gif dds tga pbm pgm ppm pam pfm jp2 psd pcx xpm bsi cif img dagtexture Supported file formats (OUTPUT): bmp jpg png mng jng gif dds tga pgm ppm pam pfm jp2 psd cif img Supported data formats: Index8 Gray8 A8Gray8 Gray16 Gray32 Gray64 A16Gray16 X5 R1G1B1 R3G3B2 R5G6B5 A1R5G5B5 A4R4G4B4 X1R5G5B5 X4R4G4B4 R8G8B8 A8R8G8B8 X8R8G8B 8 R16G16B16 A16R16G16B16 B16G16R16 A16B16G16R16 R32F A32R32G32B32F A32B32G32R32F R16F A16R16G16B16F A16B16G16R16F DXT1 DXT3 DXT5 BTC ATI1N ATI2N

Operations (change format, resize, rotate) are processed in the same order as they appear on the command line.

OpenGL Demo
Demo that shows how to create OpenGL textures from files and Imaging's images and vice versa.

This demo requires OpenGL drivers and SDL installed to run and requires Object Pascal headers to compile.

## Demo Information

Name | OpenGL Demo
Language | Object Pascal
Source Path | (Imaging Root)\Demos\ObjectPascal\OpenGLDemo
Exe Path | (Imaging Root)\Demos\Bin\OpenGLDemo[.exe]
Platforms (tested) | Win32, Linux
Compilers (tested) | Delphi 7/2007/2009/2010 WFPC 2.2.4 WL
Demo shows usage of | low level/OpenGL extension

This sample uses SDL to create window and process messages. Background and sprite textures are loaded from files and rendered. Sprite is mapped on the spinning cube in the center of the window. You can change sprite's texture format by pressing SPACE key (it cycles trough all TImageFormat values). Screehshot can be saved to file by pressing S key and sprite texture can be saved by pressing D key.
Direct3D 9 Demo
Demo that shows how to create Direct3D 9 textures from files and Imaging's images and vice versa.

This demo requires Direct3D 9.0 and SDL installed to run and requires Object Pascal headers to compile.

## Demo Information

Name | D3D Demo
Language | Object Pascal
Source Path | (Imaging Root)\Demos\ObjectPascal\D3DDemo
Exe Path | (Imaging Root)\Demos\Bin\D3DDemo.exe
Platforms (tested) | Win32
Compilers (tested) | Delphi 7/2007/2009/2010 W, FPC 2.0.4 W
Demo shows usage of | low level/D3D9 extension

This sample uses SDL to create window and process messages. Background and sprite textures are loaded from files and rendered. Sprite is rendered in each corner of the window using various texture stage and blending settings. You can change sprite's texture format by pressing SPACE key (it cycles trough all TImageFormat values). Screehshot can be saved to file by pressing S key and sprite texture can be saved by pressing D key.
SDL Demo
Demo that shows how to create SDL surfaces from Imaging's images and vice versa.

This demo requires SDL installed to run and requires Object Pascal headers to compile.

## Demo Information

Name | SDL Demo
Language | Object Pascal
Source Path | (Imaging Root)\Demos\ObjectPascal\SDLDemo
Exe Path | (Imaging Root)\Demos\Bin\SDLDemo[.exe]
Platforms (tested) | Win32, Linux
Compilers (tested) | Delphi 7/2007/2009/2010 W, FPC 2.2.4 WL
Demo shows usage of | low level/SDL extension

SDL
window is opened and background and sprite surfaces are loaded and blitted to window. You can change sprite's data format by pressing SPACE key (it cycles trough all TImageFormat values) and toggle alpha blending (working only when sprite's current format has alpha channel) and color keying. Sprite can be moved across the screen using arrow keys. Screenshots can also be taken. Status of the sprite and list of active keys are shown in the console window (but SDL window must have focus for the key input to be recognized).