Contains routines and types used when drawing graphics.

graphutil.pp contains routines and types used when drawing graphics. They focus primarily on converting colors and drawing gradients, scroll bars, and arrows.

It includes routines used to convert between both the HSL (hue, saturation, lightness) and HSV (hue, saturation, brightness value) alternative representations of the RGB color model.

HSV models the way different colors mix together, with the saturation dimension resembling various tints of brightly colored paint, and the value dimension resembling the mixture of those paints with varying amounts of black or white paint.

HSL places saturated colors around a circle with a lightness value of 0.5, where a lightness value of 0 or 1 is fully black or white (respectively).

GraphUtil is used in the Lazarus IDE, in LCL WidgetSet components, and optional Lazarus components like FPReport, SynEdit, and TAChart.

graphutil.pp is part of the Lazarus Component Library (LCL).

Converts a Lazarus TColor value to its grayscale equivalent. Byte contain the grayscale value for the specified color. TColor value converted in the method. Converts a TColor value to its Hue, Lightness, and Saturation values. TColor value converted in the method. Hue value for the specified color. Lightness value for the specified color. Saturation value for the specified color. Converts RGB color values to Hue, Lightness, and Saturation values. Converts Hue, Lightness, and Saturation values to a TColor value. Converts Hue, Lightness, and Saturation values to a RGB color values. Converts a TColor value to Hue, Saturation, and brightness Values. Converts Hue, Saturation, and brightness values to a TColor value. Converts RGB values to Hue, Saturation, and brightness values. Converts Hue, Saturation, and brightness values to RGB values. Converts Hue, Saturation, and brightness values to a TRGBTriple value . Converts Hue, Saturation, and brightness values to a TRGBQuad value . Gets the Hue value from the specified TColor value. Gets the Saturation value from the specified TColor value. Saturation value for the specified color. Color examined in the routine. Gets the brightness value from the specified TColor value. Brightness value for the specified color. Color examined in the routine. Draws a gradient from top to bottom with parabolic color variation. Canvas where the gradient is drawn. Rectangle that defines the drawing boundaries for the gradient. Color used at the top of the gradient. Color used at the end or bottom of the gradient. Draws a window with a Title using gradient coloring. Canvas where the gradient is drawn. Rectangle for the window drawn using a gradient . Height of the the title bar in the window. Base color for the window. Stretch-draws a bitmap using anti-aliased drawing. Bitmap drawn in the routine. Bitmap where the new image is drawn. Width for the resized image. Height for the resized image. Converts a bitmap to grayscale taking filtering parameters into account.

BitmapGrayscale is a procedure used to convert the specified bitmap image to a grayscale image. It calculates the weighted average of the RGB (Red, Green, Blue) color components of each pixel in the bitmap and assigns it to each color component. Weighting is done by multiplication of the RGB values with the corresponding filter factors in the RedFilter, GreenFilter and BlueFilter arguments. The end result is an image where the original colors are converted to various shades of gray.

ABitmap is the TCustomBitmap instance with the original image data.

RedFilter, GreenFilter and BlueFilter are multipliers (data type: single) for the red, green, blue color components of each pixel when the average value of the three color components is calculated. Usually these factors are between 0.0 and 1.0 and are selected to suppress or enhance the contribution of the corresponding color channel to the overall grayscale value. The combination 0.30, 0.59, 0.11 for the red, green and blue components, respectively, is often chosen because it matches the sensitivity of the human eye and thus results in a visual brightness impression like in the original color image.

Example Usage:

BitmapGrayscale(Image1.Picture.Bitmap, 0.30, 0.59, 0.11); // Neutral filter BitmapGrayscale(Image1.Picture.Bitmap, 1.00, 0.00, 0.00); // Red filter BitmapGrayscale(Image1.Picture.Bitmap, 0.00, 1.00, 0.00); // Green filter BitmapGrayscale(Image1.Picture.Bitmap, 0.00, 0.00, 1.00); // Blue filter BitmapGrayscale(Image1.Picture.Bitmap, 0.00, 0.50, 0.50); // Cyan filter BitmapGrayscale(Image1.Picture.Bitmap, 0.50, 0.00, 0.50); // Magenta filter BitmapGrayscale(Image1.Picture.Bitmap, 0.50, 0.50, 0.00); // Yellow filter
TCustomBitmap
Bitmap with the image data converted to grayscale in the routine. Weighting factor for the contribution of the Red color component to the final grayscale image. It multiplies to the value of the Red component of each pixel and thus controls the contribution of the Red color channel to the resulting image. Having RedFilter = 0, for example, results in grayscale shades in which all parts with Red color components are rendered darker. Weighting factor for the contribution of the Green color component to the final grayscale image. It multiplies to the value of the Green component of each pixel and thus controls the contribution of the Green color channel to the resulting image. Having GreenFilter = 0, for example, results in grayscale shades in which all parts with Green color components are rendered darker. Weighting factor for the contribution of the Blue color component to the final grayscale image. It multiplies to the value of the Blue component of each pixel and thus controls the contribution of the Blue color channel to the resulting image. Having BlueFilter = 0, for example, results in grayscale shades in which all parts with Blue color components are rendered darker. Enumerated type that indicates the direction for scrollbar arrows. Indicates the drawing style for an arrow. Arrow is drawn using a solid, filled color. Arrow is drawn using chevrons. 45*pi/180 Draws a line with an arrow at the specified location on a canvas.

DrawArrow is an overloaded procedure used to draw a line between the specified points with an arrow at the ending point.

Overloaded variants of the routine allow the arguments to be specified using various types. The variant with Direction, Location, Size, and ArrowType arguments can draw a line with an arrow head in horizontal or vertical directions only. The variant with the ArrowAngleRad argument allows the slope for sides on the arrow head to be specified as a number of radians.

Direction is a TScrollDirection enumeration value, and indicates the direction for the line and the arrow head. Allowed values include: sdLeft, sdRight, sdUp, or sdDown.

Location is a TPoint instance which contains the coordinates for the line starting point. This is the same as the p1 argument in an overloaded variant. p2 is the ending point for the line and the position where the tip of the arrow head is drawn.

Size contains the length of the line in pixels. It is used to calculate both the ending point for the line starting at Location, and the position where the tip of the arrow head is drawn.

ArrowType is a TArrowType enumeration value, and indicates the drawing style used for the arrow head. atSolid causes the arrow head to be drawn as a filled triangular polygon. atArrows causes two inclined lines to be draw at the tip of the arrow head using the slope angle specified in ArrowAngleRad.

ArrowAngleRad is a floating point value with the number of radians for the slope on the sides of the arrow head. The default value for the argument is defined in the NiceArrowAngle constant, and causes a 45 degree angle to be used to draw the inclined sides on arrow head. Use <angle>*pi/180 to convert an angle in degrees to radians.

Canvas where the line and arrow are drawn. Direction for arrow head. Left, Right, Up, or Down. TPoint instance with the canvas coordinates for the line starting point. Length of the line in pixels. Determines the ending point for the line and the position where the tip of the arrow head is drawn. Drawing style for the arrow. TPoint instance with the starting point for the line drawn in the routine. TPoint instance with the ending point for the line drawn in the routine. It is also the position where the tip of the arrow head is drawn. Length in pixels for the arrow head. It is used as an offset from the ending point in the opposite direction used for the line. Angle specified in radians used to draw the sloped sides on the arrow head. A simple first-in-first-out circular buffer (queue) for flood-filling contiguous voxels.

FloodFill is a procedure which implements a simple first-in-first-out circular buffer (queue) for flood-filling contiguous voxels. This algorithm avoids stack problems associated simple recursive algorithms described in the discussion at . Please note that the routine is slow because of its use of Canvas.Pixels.

Original author: Chris Rorden

Scales the specified image to the required dimensions.

ScaleImg is a procedure used to scale the image in AImage to the dimensions in AWidth and AWidth.

ScaleImg calls the CreateIntfImage method in AImage to get a TLazIntfImage instance with the original content. A temporary TLazCanvas instance is created for the source image, and its StretchDraw method is called to resize and draw the interface image on the Canvas. AImage is updated with the resized content, and its Height and Width properties are set to the parameter values.

Bitmap image resize in the routine. New Width requested for the image. New height requested for the image. Converts an RGB color value to Hue, Lightness, and Saturation values . Ensures that coordinates in the rectangle are in the correct order. Rectangle with the corrected values for its coordinates. Rectangle examined in the routine. Draws a horizontal or vertical wave at the specified position to the given device context. Device context that is the target for the drawing operation. Horizontal position where the wave is drawn. Vertical position where the wave is drawn. Amplitude for changes in horizontal or vertical positions in the wave.