TFastImageEx is the main class of package, the image. Its internal structure is quite simple; it’s not much more than a list of channels. It is this structural simplicity that makes it easy to manipulate the image. Well, that and the dozens of methods implemented and planned for the class, though that does not appear in the public part of the class, are there to support three types of channels mixed in the same image.
Constructors
TFastImageEx can be instantiated in several ways: 9 constructors so far. At the moment, there is no way to load or write image on disk, but is provided full support to TBitmap. It is possible to construct an image from and transfer the result to a TBitmap.
TBitmap can be read in 1, 8, 24 or 32 bits pixel formats and can be written in 8, 24 or 32 bits pixel formats. Furthermore it is possible to select a rectangle within the TBitmap and/or read the bitmap directly into gray levels.
List of constructors
constructor Create(fSize: TfiSize; Depth, nChannels: integer);
Empty image constructor. TfiSize is a record with size of image (width and height). All channels are allocated in memory and created using the depth informed. You can add more channels of different types after construction. Is possible create images with 0 channels. It’s useful to create an image whose channels will be added later.
constructor Create(fi: TFastImageEx);
Copy constructor, make a copy of fi.
constructor Create(fi: TFastImageEx; Rt: TRect);
Copy the portion indicated by Rt. All channels of fi are copied with same depth of fi channels. No range check is performed.
constructor CreateGray(fi: TFastImageEx);
Construct gray image from color image. Gray image constructors always result in a single channel image. fi must have 8-bit depth in the channels that will be used to calculate the gray levels. If fi have 1 or 2 channels, the first channel is copied to make the new image. If have 3 or more, the first 3 are considered RGB channels (in this order) and used to calculate the gray levels.
constructor Create(ch: TfiChannel);
Single channel copy constructor. Create a image with 1 channel.
Bellow the TBitmap constructors. All bitmap constructors create only images with 8 bits depth channels. bmp can have 1, 8, 24 or 32 depth pixel format.
constructor Create(bmp: TBitmap);
constructor Create(bmp: TBitmap; Rt: TRect);
constructor CreateGray(bmp: TBitmap);
constructor CreateGray(bmp: TBitmap; Rt: TRect);
Example:
var
fi, fj: TFastImageEx;
bmp: TBitmap;
begin
bmp:= TBitmap.Create;
bmp.LoadFromFile(‘image.bmp’);
fi:= TFastImageEx.CreateGray(bmp);
fj:= TFastImageEx.Create(fi, Rect(100,100,200,200));
bmp.Free;
[…]
end;
Channel’s list
TFastImgEx have a channel list (based on TList Delphi class) to store the channels of image. All channels references are made throw theirs indexes on list. There is a list of constants with the common values to channel’s index:
const
// Channels/Source channels
fi_BIN = 0;
fi_GRAY = 0;
fi_RED = 0;
fi_BLUE = 1;
fi_GREEN= 2;
fi_ALPHA= 3;
fi_ALL_CHANNELS= -1;
Gray and binary images usually have a single channel, so the processes that expect or generate gray or binary images manipulate the first channel (index=0). Color images can have 3 or 4 channels; in this case the first 3 are considered RGB channels (in this order). However, the processes must indicate the source channel using their index.
You can get a reference to specific channel by Channels property.
Adding new channels
Regardless of the number of channels in the image, you can add new channels. The added channels not required to be the same type as the existing channels, but must have the same dimensions. There is two methods to directly add new channels listed below, but is also possible add channels with processes results.
function MakeNewChannel(Depth: integer): integer;
Create and add a new channel with depth informed. Return the new channel index on list.
function AddChannel(Channel: TfiChannel): integer;
Add an existing channel at the end of list and return their index. There is no check of channel dimensions, but you will have problems ahead if you try use any process mixing channels with different dimensions.
Processing the image
Ok, at the moment there are only few methods to process the images, but the general structure of parameters list of process methods it’s defined, so excuse me for using the term "all" to refer to process methods. And maybe with your help, the list of process methods will grow soon.
"All" process methods use the following structure:
function NameProcess(ChnSrc, Dst, OperationType: integer;
Param1, ..., ParamN: single;
Binary: boolean): pointer;
ChnScr: Is the source channel to process. Can be the index of a specific channel on image, or the const fi_ALL_CHANNELS to indicate all channels on image.
Dst: Destination of process result. Must be one of constants bellow:
fi_NEW_IMAGE: A new image will be created to store the process result. The process method returns a reference to new image. With this constant the new image will be created with same depth of source image. To select other depth, you can use one of constants below to select a specific depth:
fi_NEW_IMAGE_8B: Create a new image with 8 bits
fi_NEW_IMAGE_16B: Create a new image with 16 bits
fi_NEW_IMAGE_32B: Create a new image with 32 bits
fi_NEW_CHANNEL: A new channel will be created to store the result of process. You can subtract the depth const to specify the depth of new channel (e.g. fi_NEW_CHANNEL-fi_32F). If no depth is specify, the source depth is used. The process method returns a reference to new channel. You also can use one of follow three constants defined to specified new channels. In this case, no subtraction is needed:
fi_NEW_CHN_8B: Destination is a new channel with 8-bit depth.
fi_NEW_CHN_16B: Destination is a new channel with 16-bit depth.
fi_NEW_CHN_32B: Destination is a new channel with 32-bit depth.
fi_INPLACE_CHN: Use an existing channel on image to store the process results. In this case you can sum the index of channel to fi_INPLACE_CHN constant (e.g. fi_INPLACE_CHN + fi_BLUE). Look the table below for details.
Destination Source is 1 channel Source is all channels
fi_NEW_CHANNEL
fi_NEW_CHN_8B
fi_NEW_CHN_16B
fi_NEW_CHN_32B A new channel is created to store the results. Method returns a reference to new channel. If the depth is not informed (fi_NEW_CHANNEL) new channel use the source depth, or you can specify the depth with the other constants. The new channel is not added on the source image. Not allowed
fi_NEW_IMAGE
fi_NEW_IMAGE_8B
fi_NEW_IMAGE_16B
fi_NEW_IMAGE_32B A new image with single channel is created to store the result. Method returns a reference to new image. fi_NEW_IMAGE means use the same depth of source, others constants inform the depth of new image. A new image with same number of channels in source image is created to store the results. All channels are processed and method returns a reference to new image. fi_NEW_IMAGE means use the same depth of source, others constants inform the depth of new image’s channels.
fi_INPLACE_CHN An existing channel is used to store the method results, not necessarily the source channel. Sum the index of destination channel to in place constant to indicate were the results will be stored. Method returns a reference to destination channel. Each channel on image is processed and used to store the method results. The method returns a reference to source image (self).
Important: Depending of process method some combinations may not be allowed. The process can also add other restrictions, particularly related to the depth of the channels to be processed.
OperationType: most of process methods have variations or different modes to operate. This parameter indicates how the process must work. Eventually, can be omitted if the process has only one operation mode.
Param1,…,ParamN: List of parameters needed for the process. This list may vary in amount and type of parameters depending of process.
Binary: Some processes can operate on binary or gray mode, whit different results. This parameter informs how the process must operate.