archive-com.com » COM » E » EFG2.COM

Total: 878

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • efg's Computer Lab and Reference Library
    The Delphi section is divided into a number of subsections and contains a large number of Delphi programming examples and code fragments The Delphi Reference Library is mostly about technical topics other than databases except for the ADO subsection The Algorithms Graphics Printing and Math pages are the most popular The Technical section contains a large number of links to technical information The Algorithms Color and Image Processing Reference Library

    Original URL path: http://www.efg2.com/ (2016-02-14)
    Open archived version from archive


  • efg's Lab & Library Search
    Search WWW Search efg2 com Home Page http www efg2 com Lab Borland Mirror http homepages borland com efg2lab Updated 18 Feb 2002 since 8 Nov 1998

    Original URL path: http://www.efg2.com/Lab/search.htm (2016-02-14)
    Open archived version from archive

  • efg's Computer Lab
    Processing Projects Color Color Mask View selected bits in 24 bit color image CIE Chromaticity Diagrams 1931 1960 or 1976 diagram using either 2 or 10 degree standard observer Maxwell Triangle Color Mix Additive Subtractive Colors Show RGB HSV HLS CMYK Coordinates Planes Histograms Count Colors Combine pf4Bit Bitmaps with Different Palettes Color Charts Color Range Segmentation of an Image RGBColors Hue Saturation Value YUV YV 12 YVU 9 UYVY Y8 411 Palette Lab Complete List of Color Projects Graphics Smoothing Algorithm Using Bézier curves by Jean Yves Quéinec Brush Bitmaps Cursor Overlay Very Large Bitmap Experiment Polygon Area and Centroid z f x y 3D Lab Football Field Basketball Court Simple Graph and Simple Bar Chart Kylix version JPG to BMP and BMP to JPG Line Stretch SphereInCube and Movie Complete List of Graphics Projects Mathematics NaN Tech Note Exploring Numbers Not a Number and Infinity Maze Maker Gauss Legendre Quadrature Estimate value of pi using Buffon s needles f z Complex Numbers and Functions CRC 16 CRC 32 Calculator Kylix version CRC 32 FileCheck Complete List of Mathematics Projects Fractals Chaos Fractals Show 2 von Koch Snowflake Lyapunov Exponents Sierpinski Triangle Gasket Complete List of Fractals Chaos Projects

    Original URL path: http://www.efg2.com/Lab/index.html (2016-02-14)
    Open archived version from archive

  • efg's Reference Library
    subsections Math Functions 7 subsections Math Info Resources Miscellany Printing Info Links Strings Technical Algorithms Color 3 subsections Graphics Image Processing 5 subsections Mathematics Physical Sciences Engineering Simulation Modeling In the Reference Library since few books are online a link

    Original URL path: http://www.efg2.com/Lab/Library/index.html (2016-02-14)
    Open archived version from archive

  • Copyright and Conditions of Use
    of the total lines of code in the application Software that is more my code than yours must not be sold as a commercial product The copyright notice above must be included with my original code External or public attribution is not required but is appreciated Software and articles may be used for educational purposes including commercial training to supplement existing course materials There is no warranty or other guarantee

    Original URL path: http://www.efg2.com/Lab/Copyright.htm (2016-02-14)
    Open archived version from archive

  • efg's Tech Note: Manipulating Pixels With Delphi's ScanLine Property
    palettes It is not intended for pixel access You ll notice that in the evolution from D1 to D4 I ve eliminated a lot of temporary memory allocations in the bitmap routines One of the big timesavers was not allocating heap memory for temporary color palettes Instead I just use a local variable on the stack of the maximum possible size I ll need 256 RGBTriples That burns between 700 and 1k bytes of stack space but stack is cheap in Win32 and it will be recycled in a few nanoseconds That wouldn t work with a TRGBTripleArray type with a WORD range Even if it didn t blow the stack it d still be prohibitively expensive The use of Borland s TRGBTripleArray type will cause problems even for normal sized bitmaps since a Byte value must range from 0 to 255 The definition I use above does not have this limitation The Borland definition in the Windows unit for a TRGBTriple follows pRGBTriple TRGBTriple TRGBTriple PACKED RECORD rgbtBlue BYTE rgbtGreen BYTE rgbtRed BYTE END Listing 8 shows how to create a pf24Bit array filled with yellow pixels Note that pixels with red 255 green 255and blue 0 are yellow Listing 8A Creating a Yellow pf24bit Bitmap VAR i INTEGER j INTEGER Row pRGBTripleArray Bitmap TBitmap Create TRY Bitmap PixelFormat pf24bit Bitmap Width ImageRGB Width Bitmap Height ImageRGB Height FOR j 0 TO Bitmap Height 1 DO BEGIN Row Bitmap Scanline j FOR i 0 TO Bitmap Width 1 DO BEGIN WITH Row i DO BEGIN rgbtRed 255 yellow pixels rgbtGreen 255 rgbtBlue 0 END END END Display on screen ImageRGB Picture Graphic Bitmap FINALLY Bitmap Free END In Delphi 4 02 or later this somewhat simpler approach will work using a CONST TRGBTriple Listing 8B Using a CONST TRGBTriple CONST Yellow TRGBTriple rgbtBlue 0 rgbtGreen 255 rgbtRed 255 VAR i INTEGER j INTEGER Row pRGBTripleArray Bitmap TBitmap Create TRY Bitmap PixelFormat pf24bit Bitmap Width ImageRGB Width Bitmap Height ImageRGB Height FOR j 0 TO Bitmap Height 1 DO BEGIN Row Bitmap Scanline j FOR i 0 TO Bitmap Width 1 DO BEGIN Row i Yellow END END Display on screen ImageRGB Picture Graphic Bitmap FINALLY Bitmap Free END How can a TColor be converted to a TRGBTriple FUNCTION ColorToRGBTriple CONST Color TColor TRGBTriple BEGIN WITH RESULT DO BEGIN rgbtRed GetRValue Color rgbtGreen GetGValue Color rgbtBlue GetBValue Color END END ColorToRGBTriple Be aware that a TColor can have several internal formats and the above assumes a format of 00bbggrr which can be created using the RGB function How can a pf24bit bitmap be converted to a pf15bit bitmap Let s consider the hard way using Scanline and the easy way using PixelFormat See Listing 9 Listing 9 Conversion of pf24bit bitmap to pf15bit VAR Bitmap15 TBitmap Bitmap TBitmap i INTEGER j INTEGER Row15 pWordArray Row24 pRGBTripleArray Bitmap TBitmap Create TRY Bitmap LoadFromFile N Images Flowers Tulip3 BMP Convert pf24bit bitmap to pf15bit bitmap the hard way Bitmap15 TBitmap Create TRY Bitmap15 Width Bitmap Width Bitmap15 Height Bitmap Height Bitmap15 PixelFormat pf15bit FOR j 0 TO Bitmap Height 1 DO BEGIN Row15 Bitmap15 Scanline j Row24 Bitmap Scanline j FOR i 0 TO Bitmap Width 1 DO BEGIN WITH Row24 i DO Row15 i rgbtRed SHR 3 SHL 10 OR rgbtGreen SHR 3 SHL 5 OR rgbtBlue SHR 3 END END Bitmap15 SaveToFile Tulip3 15A BMP FINALLY Bitmap15 Free END Convert pf24bit bitmap to pf15bit bitmap the easy way ASSERT Bitmap PixelFormat pf24bit verify pf24bit Bitmap PixelFormat pf15bit Assignment results in conversion Bitmap SaveToFile Tulip3 15B BMP FINALLY Bitmap Free END Tulip3 15A BMP and Tulip3 15B BMP should be identical bitmaps In the example above the two bitmaps are identical on a pixel by pixel basis but they have different CRC 32 values so the files are not completely identical Perhaps some header value is slightly different in the two files A better approach in reducing 24 bit pixels to 15 16 bit pixels is given in Phil McRevis UseNet Post where he suggests using Floyd Steinberg dithering Other examples How to create a Bitmap from numeric data D5 efg s UseNet Post about how to flip a TBitmap by writing Scanlines to a MemoryStream and loading the Scanlines of a second TBitmap in the flipped order pf32bit Bitmaps Analogous to the TRGBTriple define a TRGBQuadArray to work with pf32bit bitmaps See Listing 10 Listing 10 TRGBQuadArray Definition CONST PixelCountMax 32768 TYPE pRGBQuadArray TRGBQuadArray TRGBQuadArray ARRAY 0 PixelCountMax 1 OF TRGBQuad A simpler definition that eliminates the need for PixelCountMax would be TYPE TRGBQuadArray ARRAY WORD OF TRGBQuad The Borland definition in the Windows unit for a TRGBQuad follows pRGBQuad TRGBQuad TRGBQuad PACKED RECORD rgbBlue BYTE rgbGreen BYTE rgbRed BYTE rgbReserved BYTE END As far as color information is concerned note that the TRGBQuad is equivalent to the TRGBTriple both records provide for 24 bits of color information with 8 bits for Red 8 bits for Green and 8 bits for Blue The TRGBQuad had an extra rgbReserved field for what is sometimes called the alpha channel especially in the Mac world The alpha channel is used by some applications to pass grayscale mask information but there is no consistent definition of what the alpha channel may contain NOTE the contents of the alpha channel are in general unpredictable See this UseNet post by Stan that you NEVER know the state of the alpha channel byte Danny Thorpe s Borland R D comments NT supports nearly arbitrary arrangements of RGB bits The only limitation is the bits of each color element must be contiguous It would be trivial to load a big endian RGB file like Sun s RAW or whatnot by simply creating the DIBSection with BGR masks Just for grins I once created a 32bpp DIBSection with 24 bits of color info then created another DIBSection using the same pixel memory buffer but defining the pixels in the alpha channel reserved byte of the 32bpp data One novel use of a pf32bit Scanline would be to use a TBitma p as a dynamic array of Single values from numerical calculations Such large arrays could be saved to disk with the Bitmap SaveToFile method or loaded from disk with the LoadFromFile method This numeric array can even be displayed in a TImage where each pixel is the floating point fraction the rgbReserved part of the Single is the exponent of the floating point number and this would not normally affect the image Images created this way from scientific engineering calculations can show some very interesting patterns See an example of using a pf32bit bitmap to hold and display a matrix of IEEE single floating point values in the Lyapunov Exponents Lab Report The Fractals Show 2 Lab Report shows how to use a pf32bit bitmap as a matrix of 4 byte integers In limited tests the use of pf32bit Scanlines was about 5 faster than pf24bi t Scanlines in performing an identical task This is probably due to alignment of pf32bit values on 32 bit word boundaries So using the 3 bytes pixel pf24bit Scanlines does involve some extra overhead but usually not enough given the space savings of pf24bit over pf32bit Scanlines Ken Florentino s example of using pf32bit bitmaps with assembly language efg s UseNet Post about pf32bit enigma alpha byte indeterminate in new bitmap efg s UseNet Post about typecasting a shifted TColor to a TRGBQuad VAR Color TColor yellow TRGBQuad Color clYellow yellow TRGBQuad Color SHL 8 So starting with a TColor with an internal format of 00bbggrr if you shift this 8 bits left you get bbggrr00 which matches the internal format of a TRGBQuad A typecast then allows conversion of the shifted TColor to a TRGBQuad Kylix Note efg s UseNet Post with Kylix pf32bit example PixelFormat Conversion Assign a new PixelFormat to convert from one PixelFormat to another This works well if converting from a lower bits pixel to a higher bits pixel or when converting between PixelFormat s that do not have any palette implications e g pf15bit to from pf24bit But assigning a new PixelFormat does nothing to ensure you have the correct palette if you need one A pf24bit bitmap can have thousands of colors For example the Mandrill monkey bitmap is an array of 512 by 512 262 144 pixels but has 230 427 unique RGB colors The Show Image utility gives the number of unique colors in an image look in the lower left corner of the display In 256 color pf8bit display mode Windows normally reserves 20 of the colors for display of buttons panels icons etc leaving only 236 colors to an application To display the Mandrill monkey image an algorithm is needed to pick the best 236 colors of the 230 427 colors in the image See the Show Demo One Lab Report for an algorithm that creates a palette to display a 24 bits pixel image in 256 color mode What this example does not do is to take each TRGBTriple in the pf24bit Scanline and lookup the nearest color in the palette it does not convert a pf24bit bitmap to a pf8bit bitmap You re extremely lucky if all your pf24bi t images display correctly in 256 color mode Other Scanline Notes Question Paul Nicholls s UseNet Post If I wanted to store the pointers to some ScanLines from a bitmap into some variables when would I have to update these variables to have the pointers be valid again Answer Steve Schafer s UseNet Post I don t think it s ever really safe to keep a copy of a ScanLine pointer Even if it were safe to do so under some circumstances in one version of Delphi it might not be safe under those same circumstances in the next Obtain a ScanLine pointer use it immediately and then throw it away Peter Haas UseNet Post about using Bitmap Dormant after setting PixelFormat to fix a problem in D1 D4 with the TBitmapInfoHeader Finn Tolderlund s UseNet Post about Scanline and FreeImage Matthijs Laan s UseNet Post with MMX example to XOR bitmaps Andrew Rybenkov s UseNet Post about using GetDIBits SetDIBits as an alternative to Scanline Danny Thorpe s UseNet Post about Bilinear Interpolation and Scanline Additional Examples of Using Scanline The Daisy Program The DAISY program uses the same technique as shown in Listing 8 to create a pf24bit image The details in the DrawDaisy method show how this image is created Briefly the red and green planes of this image contain all the variations of these colors The blue plane contains the daisy with only the brightest values of blue You will need an 800 by 600 screen and 15 bit or higher color for this application Displaying a 24 bit true color image is easy in 15 bit or higher color video modes since Windows only has palettes with 256 color or lower video modes If you try to display a 24 bit bitmap with only 256 colors you are at the mercy of the current palette in Windows See the Show Demo One Lab Report for an alternative The Split Program The SPLIT program is a simple image processing program for studying the color planes of an image The SPLIT program reads the DAISY BMP file created by the DAISY program or any other 24 bit color BMP file Pressing the speed buttons along the left side results in the display of the corresponding red green and blue color planes The SPLIT programs stores the original image in a BitmapRGB bitmap and keeps it available as the base image for creating the other bitmaps When the Monochrome Checkbox next to the RGB Composite button is checked each red green and blue component of the pixel is assigned the same intensity where Intensity is defined as R G B 3 The resulting bitmap BitmapGray is assigned back to Image Picture Graphic for display See Listing 11 Listing 11 MakeShadesofGrayImage from RGB Composite Image PROCEDURE TFormSplit MakeShadesOfGrayImage VAR Gray INTEGER i INTEGER j INTEGER rowRGB pRGBTripleArray rowGray pRGBTripleArray BEGIN Screen Cursor crHourGlass TRY FOR j BitmapRGB Height 1 DOWNTO 0 DO BEGIN rowRGB BitmapRGB Scanline j rowGray BitmapGray Scanline j FOR i BitmapRGB Width 1 DOWNTO 0 DO BEGIN Intensity R G B DIV 3 WITH rowRGB i DO Gray rgbtRed rgbtGreen rgbtBlue DIV 3 WITH rowGray i DO BEGIN rgbtRed Gray rgbtGreen Gray rgbtBlue Gray END END END FINALLY Screen Cursor crDefault END END Other better methods of creating a gray scale can be used See the Spectra Lab Report for two alternatives involve Y the gray scale used to convert color information YUV YIQ for display on black and white TV sets To display the Red plane the red pixel values that is the rgbtRed values are assigned to another bitmap namely BitmapR but the pixel values for the blue and green components are assigned a 0 value When the Monochrome Checkbox is checked the red pixel values are assign to rgbtRed rgbtBlue and rgbtGreen resulting in a shades of gray intensity map The explanation of the conversion of RGB Red Green Blue to HSV Hue Saturation Value is in the HSV Lab Report An excellent book about color conversions and anything about Computer Graphics is Computer Graphics Principles and Practice by Foley et al Addison Wesley 1996 Or take a look at the general Color Information in efg s Reference Library For Delphi color information look at Section B Color of the Delphi Graphics Algorithms page Rotation of an Image As discussed earlier rotation of a bitmap is too slow with the canvas Pixels property But the use of the ScanLine property makes rotation of a bitmap any angle fairly fast The Rotate Scanline Lab Report shows that the rotation of the 640 by 480 pf24bit bitmap degrees clockwise takes slightly more than a second on a 166 MHz Pentium Each pixel is not rotated to a new position in a forward direction You start with the rotated image and consider where each pixel was in the original image You rotate back and take the closest pixel from the original image Because of the integer math in the rotation certain artifacts can be introduced with a rotation Usually anti aliasing isn t necessary when rotating 24 bit images of most objects Anti aliasing may be necessary if rotating thin lines or text however Also see the Flip Reverse Rotate Lab Report Color Cycling in a pf24bit Bitmap The old VGA palette tricks won t work with 24 bit color images Remember Windows only uses palettes with 256 color display modes or lower Palettes are not used with high color 15 or 16 bit color or true color 24 bit color video modes When Windows uses palettes you only have 236 colors available for your application since usually the bottom 10 and top 10 colors of the palette are fixed by Windows Even though this technique of color cycling with a pf24bit bitmap is a little slow without using assistance from the hardware the Color Cycle Lab Report uses a lookup table of 1280 colors 5 256 which is a far greater number than in a normal Windows palette The FormCreate method defines the entries in the ColorCycle ARRAY OF TRGBTriples The first 256 colors are shades of red followed by 256 shades of green and 256 shades of blue The fourth set of 256 is somewhat similar to a Fire Storm palette used by the FractInt fractal program The fifth set defines shades of gray After starting the CycleColors program the fractal image takes about 90 seconds to create on a 166 MHz Pentium The math behind this image is outside the scope of this article When the image has completed the Cycle Colors Checkbox is enabled This fractal image is a pf8bit bitmap created much like the method in Listing 4 With the Cycle Color checkbox checked the application s OnIdle hander takes the pf8bit bitmap BitmapBase and defines all the RGB pixels in BitmapRGB using the ColorCycle array See Listing 12 below Uncheck the Cycle Colors Checkbox to stop the change of colors While somewhat slow this color cycling which is done completely in software is fairly impressive Listing 12 Using IdleAction to Cycle Colors PROCEDURE TFormColorCycle IdleAction Sender TObject VAR Done BOOLEAN VAR i INTEGER index INTEGER j INTEGER RowIn pByteArray RowRGB pRGBTripleArray BEGIN IF NOT CheckBoxCycle Checked THEN Done TRUE ELSE BEGIN INC CycleStart IF CycleStart ColorList Count THEN CycleStart 0 LabelCycle Caption IntToStr CycleStart FOR j 0 TO BitmapBase Height 1 DO BEGIN RowIn BitmapBase ScanLine j RowRGB BitmapRGB ScanLine j FOR i 0 TO BitmapBase Width 1 DO BEGIN index CycleStart RowIn i IF index ColorList Count THEN index index ColorList Count RowRGB i pRGBTriple ColorList Items index END END ImageShow Picture Graphic BitmapRGB Done FALSE END END IdleAction Example of image resampling using Scanline D3 D5 Shrink Flip Reverse image example D3 Example of comparing two TBitmaps D3 D5 Misuse of Scanline by Danny Thorpe Borland R D Many people are too quick to use Scanlines to perform operations that are better handled by GDI and raster ops Scanlines s main advantage is that it gives you direct access to the pixels with a minimum of overhead That doesn t mean that Scanlines is the fastest way to manipulate the bitmap contents Most video cards today contain very sophisticated purpose built blit engines that can do raster ops on bitmap data usually much faster than the main CPU I ve seen a video card ROP an entire bitmap faster than the main CPU can finish even one scanline The CPU can only do one pixel at a time and each access is a memory reference that could stall the CPU pipeline because of a cache miss If the DIBSection lives in video memory the CPU has to cross the PCI or AGP bus to get to it The video

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/Scanline.htm (2016-02-14)
    Open archived version from archive

  • efg's Tech Note: USAF 1951 and Microcopy Resolution Test Charts
    caption indicates lines are 2 5 x mm long So for the 2 group we have Or x 2 2 0 25 which means there are 0 25 lines resolved per mm Table 3 summarizes the test target group 2 to 5 Group Line Length of First Element of Group mm Lines Resolved Per Millimeter x 2 Group 2 10 000 0 25 1 5 0000 0 50 0 2 5000 1 1 1 2500 2 2 0 62500 4 3 0 31250 8 4 0 15625 16 5 0 078125 32 Table 3 USAF 1951 Test Target Group Summary A general formula for the length or width of any target element line can be expressed as the following Line Length mm Since Line Width mm Line Length mm 5 the following expression holds Line Width mm Table 4 shows the length in millimeters of target element lines for the various groups Element Group 1 2 3 4 5 6 2 10 00000 8 90899 7 93701 7 07107 6 29961 5 61231 1 5 00000 4 45449 3 96850 3 53553 3 14980 2 80616 0 2 50000 2 22725 1 98425 1 76777 1 57490 1 40308 1 1 25000 1 11362 0 99213 0 88388 0 78745 0 70154 2 0 62500 0 55681 0 49606 0 44194 0 39373 0 35077 3 0 31250 0 27841 0 24803 0 22097 0 19686 0 17538 4 0 15625 0 13920 0 12402 0 11049 0 09843 0 08769 Table 4 Line Length mm as Function of Group Index and Element Index Let s reconsider Selwyn s rule of thumb that says the numerical value of the magnification should approximately equal the number of lines resolved per millimeter From above the lines resolved per millimeter is x which can be expressed and Magnification x From this information we can construct Table 5 that shows the approximate magnification needed to resolve a particular test target group element Element Group 1 2 3 4 5 6 2 0 3 0 3 0 3 0 4 0 4 0 4 1 0 5 0 6 0 6 0 7 0 8 0 9 0 1 0 1 1 1 3 1 4 1 6 1 8 1 2 0 2 2 2 5 2 8 3 2 3 6 2 4 0 4 5 5 0 5 7 6 3 7 1 3 8 0 9 0 10 1 11 3 12 7 14 3 4 16 0 18 0 20 2 22 6 25 4 28 5 Table 5 Approximate Magnification Needed to Resolve USAF Test Target Elements Based on Selwyn s Rule of Thumb Values in the above table that are less than 1 0 indicate a macroscopic view i e no magnification is needed to resolve the target elements Microcopy Resolution Test Chart NBS 1010A This resolution chart is a five bar chart that conforms to ANSI ISO and NBS standards Each of the five bars in a

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/TestTargets/index.html (2016-02-14)
    Open archived version from archive

  • efg's Image Processing -- Feathering
    the round rectangle on top of the ImageForeground TImage The last two statements setting the update flags are necessary when the tabsheets are not selected in order from left to right A problem was identified by John Clark that he could not select figures that had been drawn from right to left instead of from left to right To fix this problem the StandardizeOrder method was added to the TVectorGraphicsNode class Whenever a new node is created or modified the StandardizeOrder makes sure that point A is always the upper left point and that point B is always the lower right point efg 25 Feb 2001 Simple Drawing Tool The VectorGraphicsNodeLibrary defines the various kinds of drawing tools shown along the top of the foreground image The base class for each of these drawing nodes is the TVectorGraphicsNode class shown in Listing 3 Listing 3 TVectorGraphicsNode base class Each node in TVectorGraphicsList has a base class of TVectorGraphicsNode TYPE TVectorGraphicsNode CLASS TObject PROTECTED FHandleRadius INTEGER FPenColor TColor FPenStyle TPenStyle FPenWidth INTEGER FPointA TPoint FPointB TPoint Normally the selected item is flagged TRUE When multiple selections are allowed more than one node can be flagged as selected however FSelected BOOLEAN PUBLIC PROCEDURE DrawFigure CONST Canvas TCanvas CONST Factor INTEGER 0 VIRTUAL ABSTRACT PROCEDURE Translate CONST TranslateVector TPoint VIRTUAL ABSTRACT PROCEDURE DrawHandles CONST Canvas TCanvas CONST PenColor TColor CONST BrushColor TColor CONST Radius INTEGER VIRTUAL ABSTRACT FUNCTION GetHandleAtPoint CONST x y INTEGER CONST Radius INTEGER TDrawingHandle VIRTUAL ABSTRACT PROPERTY PenColor TColor READ FPenColor WRITE FPenColor PROPERTY PenStyle TPenStyle READ FPenStyle WRITE FPenStyle PROPERTY PenWidth INTEGER READ FPenWidth WRITE FPenWidth PROPERTY PointA TPoint READ FPointA WRITE FPointA PROPERTY PointB TPoint READ FPointB WRITE FPointB PROPERTY Selected BOOLEAN READ FSelected WRITE FSelected END When saving data to a database or a file there is little advantage to using an object hierarchy to define the various drawing objects Often it s useful to just have a data field that defines the type of the object in the class definition as shown above instead of deriving a new object for each drawing object A problem with the object oriented methodology is that only the data from an object is stored in a file or a database The data and the methods are stored in two separate places I used a TBoundingRectangle class derived from the TVectorGraphicsNode above and then derived separate tool classes for each of the drawing objects TRectangleNode TRoundRectangleNode and TEllipseNode Find all the details of this in the VectorGraphicsNodeLibrary unit Again if I were saving the data to a file or a database it is likely just as easy to derive all objects from the base class directly instead of introducing a three level hierarchy The TVectorGraphicsNodes are stored in a TVectorGraphicsList which is derived from a TList and defined in the VectorGraphicsListLibrary unit shown in List 4 Listing 4 TVectorGraphicsList class TYPE Use TList of TVectorGraphicsNodes to store list of graphical objects TVectorGraphicsList CLASS TList PROTECTED FIndexOfSelected INTEGER index of node in TList when only single figure is selected PUBLIC CONSTRUCTOR Create DESTRUCTOR Destroy OVERRIDE Group of routines that manages selected flags for the figures PROCEDURE SelectedFigureIncrementIndex CONST increment INTEGER FUNCTION SelectedFigureCount INTEGER FUNCTION SelectedContainsPoint CONST TargetPoint TPoint BOOLEAN PROCEDURE DeleteSelectedFigures PROCEDURE DrawAllFigures CONST Canvas TCanvas PROCEDURE DrawSelectedFigures CONST Canvas TCanvas PROCEDURE DrawBandAround CONST Canvas TCanvas CONST Factor INTEGER FUNCTION GetSelectedNode TVectorGraphicsNode PROCEDURE TranslateSelectedFigures CONST TranslateVector TPoint PROCEDURE SelectFigures CONST Shift TShiftState CONST X Y Integer FUNCTION GetSelectedHandleAtPoint CONST X Y INTEGER TDrawingHandle PROCEDURE SetSelectedFlags CONST state BOOLEAN PROCEDURE SetSelectedIndex CONST index INTEGER PROPERTY SelectedIndex INTEGER READ FIndexOfSelected WRITE SetSelectedIndex END As shown in Listing 2 a new GraphicsList with a single node is created whenever a new foreground image is defined A node is added to the GraphicsList on the MouseUp event after drawing an object The order of the nodes in the GraphicsList defines the z order for selecting or drawing the objects Selecting a drawing tool creates a new drawing node of the appropriate type which is shown in part of the SpeedButtonToolClick method in Listing 5 The MouseDown MouseMove and MoveUp methods for ImageForeground also use the DrawingNode created in Listing 5 Listing 5 ToolClick method for Drawing SpeedButtons procedure TFormFeathering SpeedButtonToolClick Sender TObject begin IF Assigned DrawingNode THEN DrawingNode Free CASE Sender AS TSpeedButton Tag OF ORD dtSelectTool BEGIN DrawingTool dtSelectTool DrawingNode NIL END ORD dtRectangleTool BEGIN DrawingTool dtRectangleTool DrawingNode TRectangleNode Create ShapeLineColor Brush Color TPenStyle ComboBoxLineStyle ItemIndex ComboBoxLineWidth ItemIndex 1 PenWidth Point 1 1 Point 1 1 END end Find all the details of the Mouse events such as TFormFeathering ImageForegroundMouseDown in the ScreenFeathering unit The MouseDown method defines a DrawingState variable which is used by MouseMove and MouseUp to determine whether a new figure is being drawn or whether a figure is being moved translated to a new location In addition to using the mouse to manipulate the vector objects keystrokes can also be used Listing 6 shows some of the details of processing the keystrokes to move the selected figure s Listing 6 Part of keystroke processing to manipulate vector objects The form s KeyPreview must be set to TRUE for this to work procedure TFormFeathering FormKeyDown Sender TObject var Key Word Shift TShiftState VAR TranslateVector TPoint translate vector to move selected objects begin IF PageControl ActivePage TabSheetForeground THEN BEGIN We only care about keystrokes when figure s are selected IF GraphicsList SelectedFigureCount 0 THEN BEGIN Simulte clicking erase button when delete key is pressed IF key VK DELETE THEN SpeedButtonEraseClick Sender ELSE BEGIN Use Ctrl shift keys to translate objects just like Delphi s IDE IF ssCtrl IN Shift AND key IN VK LEFT VK RIGHT VK UP VK DOWN THEN BEGIN CASE key OF VK LEFT TranslateVector Point 1 0 VK RIGHT TranslateVector Point 1 0 VK UP TranslateVector Point 0 1 VK DOWN TranslateVector Point 0 1 END GraphicsList TranslateSelectedFigures TranslateVector DrawAllFigures sfHighlightSelectedFigure Make sure other controls don t see this key key 0 END END END Using the OnDrawItem for

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/Feathering.htm (2016-02-14)
    Open archived version from archive



  •