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 Graphics -- Simple Bar Chart Lab Report
    could also be used for printing The HeightPercent and WidthPercent functions create device independent drawings by determining the number of pixels a certain certain percentage of canvas height or width something is The first CLX VCL difference is in the uses statement SimpleBarChart pas Project File uses Statement CLX uses SysUtils Types Classes Variants QGraphics QControls QForms QDialogs QStdCtrls QExtCtrls VCL uses SysUtils WinProcs Messages Classes Graphics Controls Forms Dialogs StdCtrls Buttons ExtCtrls Besides the difference in the name of form files with CLX xfm and with VCL dfm an RGB function must be provided for the CLX environment SimpleBarChart pas Project File Implementation Difference CLX R xfm Delphi Windows unit function missing in Kylix FUNCTION RGB CONST r g b BYTE TColor BEGIN RESULT r OR g SHL 8 OR b SHL 16 END RGB VCL R dfm I normally design forms to be a fixed size such that there is no need to resize the form at run time This can be easily implemented in Delphi VCL by setting the form s BorderStyle to bsSingle A different approach is needed with CLX The following code in a form s create method prevents any resizing SimpleBarChart pas Project File FormCreate Difference CLX procedure TFormBarChart FormCreate Sender TObject begin Need this in CLX to prevent resizing form WITH FormBarChart Constraints DO BEGIN MaxHeight Height MaxWidth Width MinHeight Height MinWidth Width END VCL Set form s BorderStyle to bsSingle in IDE A minor CLX VCL difference was needed in SimpleBarChart pas Project File TBitmap PixelFormat CLX Bitmap PixelFormat pf32bit No pf24bit PixelFormat in Kylix VCL Bitmap PixelFormat pf24bit avoid working with palettes I try to always use pf24bit bitmaps in Windows since they re smaller than pf32bit bitmaps Unfortunately CLX only supports pf32bit TBitmaps Certain graphics operations needed to be tweaked to get the same results in Delphi and Kylix During the first conversion attempt Delphi showed a white background and Kylix showed a black background The FillRect code shown below was added to both versions to always establish the background color The DrawBarChart procedure shown above was called to draw the graphics on any canvas in a device independent way Here the complete VCL source code for this procedure the CLX version is quite similar SimpleBarChart pas Project File FormCreate Difference VCL PROCEDURE DrawBarChart Canvas TCanvas Width Height INTEGER CONST BarWidth 5 bar width is 5 Reserved 5 reserve 5 margin TextHeight 8 text height is 8 VAR iBase INTEGER iWidth INTEGER jBase INTEGER jHeight INTEGER j INTEGER FUNCTION WidthPercent CONST percent INTEGER INTEGER BEGIN RESULT iBase MulDiv iWidth percent 100 END FUNCTION HeightPercent CONST percent INTEGER INTEGER BEGIN sign here to flip Y since Y goes from top to bottom RESULT jBase MulDiv jHeight percent 100 END PROCEDURE DrawBar CONST BarColor OutlineColor TColor CONST X height INTEGER BEGIN Canvas Brush Color BarColor Canvas Pen Color OutlineColor Use 100 height since Y values are top to bottom Canvas Rectangle WidthPercent X HeightPercent height WidthPercent X BarWidth HeightPercent 0 END BEGIN

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


  • efg's Graphics -- Simple Graph Lab Report
    to create an 800 by 600 pixel SimpleGraph BMP file If desired press the Print button to print a full page graph in landscape orientation Discussion The DrawLineGraphs procedure draws lines on the Image Canvas the Printer Canvas or a Bitmap Canvas The DrawState parameter to DrawLineGraphs is a bit of a kludge When this parameter has the value ptShowGraph and the Dynamic checkbox is checked the Image is updated

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

  • efg's Graphics -- BMPJPG Lab Report
    with 100 JPEG Quality some of the information in an image is lost when stored in JPEG format A BMP image of two parrots see below contains 294 966 bytes With 100 JPEG Quality the JPG version of this image contains 75 437 bytes a significant reduction in the size of the file But by about 80 JPEG Quality the file sizes drops to about 16 000 bytes A lower JPEG Quality yields a smaller file size as shown in the following graph But how good are the images with lower JPEG Quality Here are three visual examples JPEG Quality Factor 1 52 100 From a DOS command line window run the Experiment BAT file Experiment filename to repeat this experiment with any other 24 bit BMP file Three output files are created JPEGList DAT contains a list of the files and their sizes Statistics DAT contains a list of relative and absolute error differences between the original image and the various lossy images Data are also summarized by R G B color plane Correlation DAT computes a correlation coefficient of each lossy image against the original image At the end of the experiment run the Cleanup BAT to erase unneeded files The following graph summarizes the correlation of the JPEG images with the original image by color plane The JPEG compression algorithm tries to exploit limitations of our own eyes Since the eye is less sensitive to blue and most sensitive to green the JPEG compression algorithm maintains better fidelity with the green component of an image and less with the blue component of an image Based on the above two graphs for some images such as the Parrots a JPEG Quality Factor of roughly 20 80 gives good reduction in files size without affecting the image fidelity significantly NOTE The correlation facgtor would be 1 00 if an all white image were compared with an all black image The correlation factor measures how well one image predicts the other image and does not measure error directly The palettes are usually OK in 256 color mode after loading a JPG image This is rarely the case after loading a 24 bit color BMP image JPG image compression is very effective for real world images as opposed to line drawings or text where it is not so good Note the graphs on this web page are stored in GIF format instead of JPG format efg s UseNet Post and Bob Villiers Summary Response about JPEGs and PixelFormat Postscript The code in this Lab Report needs to be reviewed and updated The user interface is misleading about how 8 bit 24 bit PixelFormat is used Bob Villiers verified that after some experiment PixelFormat has no influence on the jpg colour depth but GrayScale True produces an 8 bit B W image Command Line Programs Enter BMPtoJPG or JPGtoBMP in a DOS window without parameters for the syntax of these commands or just look at the source code or the VaryQuality BAT

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

  • efg's Graphics -- Line Stretch Lab Report
    normally prefer a line to be a specific color During the OnMouseDown the event handler determines whether the down point X Y is in one of the handles or near the line Determining whether a point is within a rectangle is straightforward Determining whether a point is near a line takes a little more work A formula exists that tells how far a point is from a line but this is at best awkward and may be slow to use since the computation involves a square root For lines with a slope 1 the slope intercept line equation is useful y mx b where m is the slope computed as m y 2 y 1 x 2 x 1 For a given point X Y the value Y mX b can be quickly computed If Y Y is fairly small perhaps just a few pixels then the line can be considered selected See the NearLine routine For slopes 1 the X and Y values are reversed The line equation becomes X mY b and if X X is sufficiently small the line is selected This approach avoids vertical lines with infinite slopes The ClipCursor Windows API call is used to restrict cursor motion The RestrictCursorToDrawingArea limits drawing within an area defined by a TImage This restriction is imposed as part of the MouseDow n method PROCEDURE RestrictCursorToDrawingArea CONST Image TImage VAR CursorClipArea TRect BEGIN CursorClipArea Bounds Image ClientOrigin X Image ClientOrigin Y Image Width Image Height Windows ClipCursor CursorClipArea END RestrictCursorToDrawingArea The restriction is removed via the RemoveCursorRestrictions procedure as part of the MouseUp method PROCEDURE RemoveCursorRestrictions BEGIN Windows ClipCursor NIL END RemoveCursorRestrictions The LineLibrary PAS unit contains the low level routines CalcLineParameters NearLine and other routines so this functionality can be used with other programs CalcLineParameters Procedure Determine whether a line is ltHorizonal or ltVertical along with the appropriate slope and intercept FOR point slope line equations These parameters are used to determine if a line is selected PROCEDURE CalcLineParameters CONST PointA PointB TPoint VAR Slope Intercept DOUBLE VAR LineOrientation TLineOrientation VAR Delta TPoint BEGIN Delta SubtractPoints PointB PointA IF Delta X 0 AND Delta Y 0 THEN BEGIN This special CASE should never happen if iMinPixels 0 LineOrientation loPoint Slope 0 0 Intercept 0 0 END ELSE BEGIN IF ABS Delta X ABS Delta Y THEN BEGIN The line is more horizontal than vertical Determine values FOR equation Y slope X intercept LineOrientation loHorizontal TRY Slope Delta Y Delta X conventional slope in geometry EXCEPT Slope 0 0 END Intercept PointA Y PointA X Slope END ELSE BEGIN The line is more vertical than horizontal Determine values for equation X slope Y intercept LineOrientation loVertical TRY Slope Delta X Delta Y reciprocal of conventional slope EXCEPT Slope 0 0 END Intercept PointA X PointA Y Slope END END END CalcLineParameters NearLine Function Determine if Target1 is near line segment between Point1 and Point2 FUNCTION NearLine CONST Target Point1 Point2 TPoint BOOLEAN CONST LineSelectFuzz 4 Pixel fuzz used in

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

  • efg's Graphics -- Sphere in Cube Lab Report
    the various views of the sphere in a cube in landscape orientation Discussion The DrawNineViews routine uses various viewports to draw a 3 by 3 matrix of views The top row shows orthographic views X Y X Z and Y Z while the middle and bottom rows show various perspective views When the Draw button is pressed DrawNineViews is called twice to fill the two TImages ImageBig and ImageSmall FillRect

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

  • efg's Graphics -- Sphere In Cube Movie Lab Report
    a ViewTransformMatrix which automatically transforms each point plotted by DrawCube and DrawSphere as part of the default transformation of the TPantograph Use FrameIndex in parametric equation to define location of camera for each frame a ViewTransformMatrix Use spherical coordinates instead of cartesian coordSpherical azimuth cycle around object every 300 Frames ToRadians 1 2 degrees FrameIndex elevation cycle up and down 90 degrees every 90 Frames ToRadians 90 degrees SIN ToRadians 4 0 FrameIndex distance from camera to object cycle every 400 Frames 10 6 SIN ToRadians 0 9 FrameIndex screen parameters 10x10 from 30 away 10 10 30 pantograph SetTransform a DrawCube PantoGraph clRed DrawSphere PantoGraph LatitudeColor clBlue LongitudeColor clLime LatitudeCircles 9 LongitudeSemicircles 25 PointsInCircle 40 A TList of Bitmaps BitmapList is used to store the sequence of bitmaps An EOutOfMemory or an EOutOfResource error should be trapped if sufficient resources are not present The Show button steps through TList and sets the ScrollBar Position The side effect of setting the ScrollBar Position is to display the appropriate frame in the animation sequence procedure TFormSphereMovie ScrollBarChange Sender TObject begin WITH ImageMovieFrame Picture Bitmap DO BEGIN Copy in memory frame back to screen Canvas CopyRect Rect 0 0 Width Height TNode BitMapList Items ScrollBar Position BitMap Canvas Rect 0 0 Width Height END end The animated stack can be saved to a GIF file using code courtesy of Finn Tolderlund in the GIFAnimate PAS unit Also required is Anders Melander s GIFImage component The GIFImage unit can be downloaded from Finn Tolderlund s websites http finn mobilixnet dk delphi http home20 inet tele dk tolderlund delphi If you do not have TGIFImage installed change the conditional compilation variable form GIF to NOGIF Project Options Directories Conditionals Conditioanl Defines NOGIF Thanks to Finn Tolderlund for adding this animated GIF improvement This change

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

  • efg's Graphics Page
    then use ScanLine to create Red and Green planes with 2D sinusoidal patterns Print a 2000 by 1500 pixel image at a specified location with a specified size Write a 1024 by 768 pixel BMP file to disk Moiré pattern Golden Ratio TCanvas Ellipse TBitmap ScanLine GetDeviceCaps Delphi 3 Delphi 1 Version of Football SphereInCube Surface3D 338 KB Delphi 1 2D 3D vector graphics Football Football shows three perspective views and an orthographic view of a football field American Display these four views on the screen print them out or save them to a BMP file The GraphicsMathLibrary and GraphicsPrimitivesLibrary units define a non visual TPantograph object for mapping real coordinates to pixel coordinates mostly for scientific and engineering calculations These libraries do not require OpenGL or DirectX I DO need to create more documentation for these libraries to make them more useful to others Erratum The constants in the FromCartesian function in the GraphicsMathLibrary unit should be PI 2 instead of PI 4 This affects some boundary values This will eventually be fixed 25 Sept 2000 Thanks to Christoph Christmann for bringing this to my attention 2D 3D vector graphics translation rotation scaling view transform homogeneous coordinates clipping projections vectors matrices TPantograph Delphi 3 LineStretch Demonstrate an alternative to using XOR to stretch lines Show how to restrict cursor movement to a specified rectangular area Show how to detect whether a cursor is near a line OnMouseDown OnMouseMove OnMouseUp Bounds ClipCursor PtInRect Rectangle Screen Cursor crHandPoint crDrag crDefault AddPoints SubtractPoints NearLine Canvas MoveTo Canvas LineTo Palettes and Colors Separate page summarizing Lab Reports about Palettes and Colors Display Color Chart Cycle colors using Scanline Experiment with the Palette Lab Show 16 8 million RGB Colors Optimized Palette Demos One Image Versus Many Images Palettes ScanLine TOctreeNode TColorQuantizer CreateHalftone Palette Optimized Palette Idle Action TRGBTriple dither and non dithered display colors FractInt color maps Macbeth Color Checker Delphi 3 Simple Bar Chart Create a simple bar chart and print two ways draw directly on the printer canvas or create bar chart as bitmap and then draw the bitmap on the printer canvas In Delphi 3 you might want to consider the TChart component instead Canvas Brush Color Pen Color Rectangle FillRect Delphi 3 Simple Graph Create a simple graph y a sin b x Display graph on screen dynamically or print or write to a BMP file In Delphi 3 you might want to consider using the TChart component instead TPantograph Vector2D MoveTo LineTo Repaint PointAt TextOut Delphi 3 SnappyLine Demonstration of line drawing snapping and rubber banding SnappyLine demonstrates the creation of a LogFont for drawing the text dimensions at any angle C ontributed by Gordon Whittam AlignAngleText procedure LogFont API call Line rubber banding Canvas MoveTo Canvas LineTo Canvas FillRect Cansvas Pen Mode user defined cursor RES file Screen Cursors OnMouseDown OnMouseMove OnMouseUp PtInRect MessageBeep TStatusBar Sphere In Cube Sphere in Cube shows six perspective views and three orthographic views of a sphere inside a cube You can

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

  • efg's Tech Note: Exploring Numbers, Not-a-Number, and Infinity
    hexadecimal representation of these values can be converted to decimal for a normal Double The Figure shows that 100 0 can be represented in exponential notation as 1 00E 2 which is shorthand for 1 x 10² or in hexadecimal as 4059000000000000 This hexadecimal string needs to be parsed into three fields the sign bit s the exponent e and the fraction f normal double 0 e 2047 v 1 s x 2 e 1023 x 1 f denormal e 0 and f 0 v 1 s x 2 1022 x 0 f Zero e 0 and f 0 v 1 s x 2 1022 x 0 f Infinity INF e 2047 and f 0 v 1 s x INF Not a Number NaN e 2047 and f 0 NaN The IEEE Double precision value can be found using the three factors in the normal double equation see above When the high order bit is 0 such as with 4 0100 binary the number is positive When the high order bit is 1 such as with the 0 or Infinity values see Table 1 the value is negative The first factor for 100 0 in the above equation is 1 The exponent is the first three hex digits which is 405 1029 This exponent is biased by 1023 so this value must be reduced by 1023 The second factor for 100 0 in the previous equation becomes 2 1029 1023 2 6 64 The fraction has an implied 1 so the signficand is 1 9 In decimal this value becomes 1 9 16 which is the third factor Putting these three decimal factors together 1 x 64 x 1 9 16 100 0 Binary floating point values aren t that complicated or mysterious The code is simple to create a double constant with the value of 100 0 CONST x Double 100 0 How can this value be defined using its hexadecimal form In Delphi 4 5 with the Int64 type the task is fairly simple J CONST HundredBits Int64 4059000000000000 VAR Hundred Double ABSOLUTE HundredBits The ABSOLUTE directive tells the compiler that the variable Hundred is at the same location in memory as the HundredBit s constant Since both are 64 bit values they should have the same memory alignment Use the J compiler directive to make sure a constant cannot be changed at runtime Interestingly since the HundredBits constant cannot be changed neither can the Hundred variable Without the J directive Delphi has allowed a variable constant but with it we now we have a constant variable In Delphi 2 or 3 with only 32 bit LongInts defining a Double value 100 0 using hex was a bit more involved and complicated by the Little Endian storage format J CONST HundredBits ARRAY 1 2 OF LongInt 00000000 40590000 VAR Hundred Double ABSOLUTE HundredBits Defining most Double constants in hex would be a real pain but it s the only way to deal with many of the special values shown in Figure 1 The ButtonConstantsClick procedure for the Constants button in the IEEEDemo program uses conditional compilation to implement these techniques IFDEF VER130 Delphi 5 code ELSE IFDEF VER120 Delphi 4 code ELSE Delphi 2 3 code ENDIF ENDIF Download the complete source code file for details A NaN function and PositiveInfinity and NegativeInfinity functions are in the IEEE754 unit using constants defined as described previously These functions can be used to obtain these special values whenever they are needed anywhere in code The decimal values in Figure 1 were formatted with the following statement Format 24 17e x In Delphi 4 for some unexplained reason Delphi formats both INF and INF as simple INF this was fixed in Delphi 5 The hex strings in Figure 1 were formatted using a DoubleToHex function which is defined in a separate IEEE754 unit FUNCTION DoubleToHex CONST d DOUBLE STRING VAR Overlay ARRAY 1 2 OF LongInt ABSOLUTE d BEGIN Look at element 2 before element 1 because of Little Endian order RESULT IntToHex Overlay 2 8 IntToHex Overlay 1 8 END DoubleToHex Seemingly this routine could have been simplified in Delphi 4 to the following but IntToHex works slightly differently with Int64 values In D4 but not D5 IntToHex suppresses leading 0s in the hex string so the above Delphi 3 code still works best Delphi 4 code suppresses leading 0s in hex strings below Why Fixed in Delphi 5 FUNCTION DoubleToHex CONST d DOUBLE STRING VAR Overlay Int64 ABSOLUTE d BEGIN RESULT IntToHex Overlay 16 END DoubleToHex The inverse function HexToDouble is also defined in the IEEE754 unit TYPE EIEEEMath CLASS Exception FUNCTION HexToDouble CONST hex STRING DOUBLE VAR d DOUBLE Overlay ARRAY 1 2 OF LongInt ABSOLUTE d BEGIN IF LENGTH hex 16 THEN RAISE EIEEEMath Create Invalid hex string for HexToDouble Overlay 1 StrToInt COPY hex 9 8 Overlay 2 StrToInt Copy hex 1 8 RESULT d END HexToDouble DoubleToHex provides a way to save all the binary precision of a floating point value in an ASCII form and also a way to save the NaN and INF values Converting from a binary double to an ASCII decimal string and back to the binary double is not always a reversible process especially if many decimal digits are not saved and restored DoubleToHex and HexToDouble provide an alternative that saves and restores all bits exactly Note The Borland StrToFloat routine coughs if you pass it a string NAN The ButtonConstantsClick procedure for the Constants button in the IEEEDem o program uses both the DoubleToHex and HexToDouble functions to show these functions are inverses for each of the special IEEE values However testing equality with NaN and INF values isn t completely straightforward Given the Double array named constant the following shows the conversion of value constant i to a hex string and back to a Double d VAR i INTEGER d Double hex STRING Constant ARRAY 1 12 OF DOUBLE hex DoubleToHex Constant i d HextoDouble hex Inside a

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



  •