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 -- Brush Bitmaps
    TBitmap VAR i INTEGER j INTEGER Row pByteArray BEGIN RESULT TBitmap Create RESULT Width PatternColumns RESULT Height PatternRows RESULT PixelFormat pf4bit 4 bits pixel Fill the bitmap from the constant array Each byte of scanline contains two pixels Each nibble of byte is a pixel FOR j 0 TO PatternRows 1 DO BEGIN Row RESULT Scanline j FOR i 0 TO PatternColumns DIV 2 1 DO Row i BrushPattern j i END END DefineBrushPattern The BitmapBackground is created and displayed in the ImageBackground BitmapBackground TBitmap Create BitmapBackground Width ImageOriginal Width BitmapBackground Height ImageOriginal Height This can be done in Windows 2000 but in other versions the BitmapBackground needs to be pfDevice the default so that FillRect works correctly below BitmapBackground PixelFormat pf24bit BitmapBackground Canvas Brush Bitmap DefineBrushPattern BrushPattern BitmapBackground Canvas FillRect BitmapBackground Canvas ClipRect ImageBackground Picture Graphic BitmapBackground The default BitmapBackground appears like this on the screen Changing the SpinEditBoxes will change the colors in the above image Alternately if you are running Windows 98 or Windows 2000 you can press the Win 98 2000 button you ll get a strange image in Windows 95 This background bitmap is formed from a 32 by 32 pixel true color bitmap in the TFormBitmapBrushes ButtonWin982000Click method This code TYPE TRGBTripleArray ARRAY WORD OF TRGBTriple pRGBTripleArray TRGBTripleArray VAR BitmapBrush TBitmap i INTEGER j INTEGER row pRGBTripleArray begin BitmapBackground TBitmap Create BitmapBackground Width ImageOriginal Width BitmapBackground Height ImageOriginal Height BitmapBackground PixelFormat pf24bit BitmapBrush TBitmap Create BitmapBrush Width 32 BitmapBrush Height 32 BitmapBrush PixelFormat pf24bit FOR j 0 TO BitmapBrush Height 1 DO BEGIN row BitmapBrush Scanline j FOR i 0 TO BitmapBrush Width 1 DO BEGIN WITH row i DO BEGIN rgbtRed MulDiv 255 i BitmapBrush Width 1 rgbtGreen MulDiv 255 j BitmapBrush Height 1 rgbtBlue 0 END END END BitmapBackground Canvas Brush Bitmap BitmapBrush BitmapBackground Canvas FillRect BitmapBackground Canvas Clip Rect ImageBackground Picture Graphic BitmapBackground creates the following background image Since this bitmap has a height and width of 96 pixels the 32 by 32 brush bitmap is painted in a 3 by 3 matrix as shown above Masks Pressing the Masks button calls TFormBitmapBrushes ButtonMasksClick method This method consists of separate calls to a CreateAndShowMask procedure for each of the colored areas This is not a very general routine since it assumes three colored blobs of particular colors are present in the original bitmap There are two or more possible implementation options One option would be to find the blob and fill it in place with the desired bitmap brush I chose a second way that involves a separate mask for each of the blobs This second approach allowed showing how to use transparency to form a composite image of a base bitmap and several mask bitmaps The following code defines the BluePattern which is the brush bitmap for the blue area RGB 0 0 128 in the original bitmap CONST BluePattern TBrushPattern C blue F white FF FF FF FF FF CC CC FF FC FF FF CF FC FC CF

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


  • efg's Computer Lab -- Cursor Overlay
    call PROCEDURE TFormCursorOverlay AssignSpeedButton CONST index INTEGER CONST SpeedButton TSpeedButton VAR Bitmap TBitmap hCursor THandle BEGIN Bitmap TBitmap Create TRY Bitmap Width 32 Bitmap Height 32 Bitmap PixelFormat pf24bit avoid working with palettes hCursor Screen Cursors index DrawIconEx Bitmap Canvas Handle 0 0 hCursor 32 32 0 0 DI NORMAL Flood fill cursor from the outside so a white cursor will appear white Assume right top position will work for floodfilling the whole area Assume RGB 250 250 250 will work as transparency color Bitmap Canvas Brush Color RGB 250 250 250 Bitmap Canvas FloodFill 31 0 clWhite fsSurface Kludge fix for 3DMove cursor since upper left corner is blocked during flood fill Bitmap Canvas FloodFill 0 0 clWhite fsSurface SpeedButton Glyph Bitmap SpeedButton Tag index could be set in design mode FINALLY Bitmap Free END END AssignSpeedButton Some of the details used in AssignSpeedButton above are explained below since some of the same operations are used in UpdateCursor which is explained next The FormCreate and the SpeedButtonCursorClick methods both result in a call to UpdateCursor This procedure creates a new CursorBitmap which is later used to draw the cursor transparently onto the bitmap The CursorBitmap is created using the DrawIconEx API call The GetIconInfo API call is used to get the position of the cursor s hot spot which is an adjustment that is needed before overlaying the cursor s bitmap on the desired bitmap PROCEDURE TFormCursorOverlay UpdateCursor CONST index INTEGER VAR Bitmap TBitmap hCursor THandle IconInfo TIconInfo BEGIN CursorBitmap Free Convert existing cursor to bitmap and display CursorBitmap TBitmap Create CursorBitmap Width 32 CursorBitmap Height 32 CursorBitmap PixelFormat pf24bit avoid working with palettes hCursor Screen Cursors index GetIconInfo hCursor IconInfo TRY DrawIconEx CursorBitmap Canvas Handle 0 0 hCursor 32 32 0 0 DI NORMAL ImageCursor Picture Graphic CursorBitmap Flood fill cursor from the outside so a white cursor will appear white Assume right top position will work for floodfilling the whole area Assume RGB 250 250 250 will work as transparency color CursorBitmap Canvas Brush Color RGB 250 250 250 CursorBitmap Canvas FloodFill 31 0 clWhite fsSurface Kludge fix for 3DMove cursor since upper left corner is blocked during flood fill CursorBitmap Canvas FloodFill 0 0 clWhite fsSurface CursorBitmap TransparentMode tmFixed CursorBitmap TransparentColor RGB 250 250 250 CursorBitmap Transparent TRUE xOffset IconInfo xHotSpot yOffset IconInfo yHotSpot LabelHotSpot Caption Hot Spot IntToStr xOffset IntToStr xOffset FINALLY DeleteObject IconInfo hbmMask DeleteObject IconInfo hbmColor END END UpdateCursor After the CursorBitmap is drawn with DrawIconEx FloodFill is used to fill the outside of the cursor with a color that is not likely to be in the bitmap This unlikely color RGB 250 250 250 in this case is set as the transparency color by assignments to TransparentColor and TransparentMode Transparency only works with a bitmap after the Transparent property is set True and the bitmap is drawn onto a canvas The omission above after the first TRY statement is shown next The GetIconInfo call returns the IconInfo in a record Two of

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

  • efg's Graphics -- Very Large Bitmap Experiment
    bitmap is created by assigning the Bitmap Width and Bitmap Height first followed by the Bitmap PixelFormat significant additional resources are required than if the PixelFormat is specified first as suggested above by Alexandre Once the large pf24bit bitmap has been created each pixel is assigned a unique color assuming the bitmap has 16 777 216 using Scanline CONST MaxPixelCount 65536 TYPE For pf24bit Scanlines pRGBTripleArray TRGBTripleArray TRGBTripleArray ARRAY 0 MaxPixelCount 1 OF TRGBTriple VAR index INTEGER i j INTEGER row pRGBTripleArray Assign unique color to first 16 777 216 pixels index 0 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 index AND 000000FF rgbtGreen index AND 0000FF00 SHR 8 rgbtBlue index AND 00FF0000 SHR 16 END INC index END END Once the large bitmap is created and filled with unique colors the number of unique colors is counted when requested using a 2D array of TBits Count number of unique R G B triples in a pf24bit Bitmap Use 2D array of TBits objects when R G combination occurs for the first time create 256 bit array of bits in blue dimension So overall this is a fairly sparse matrix for most pictures Tested with pictures created with a known number of colors including a specially constructed image with 1024 1024 1 048 576 colors efg October 1998 FUNCTION CountColors CONST Bitmap TBitmap INTEGER VAR Flags ARRAY BYTE BYTE OF TBits i INTEGER j INTEGER k INTEGER rowIn pRGBTripleArray BEGIN Be sure bitmap is 24 bits pixel ASSERT Bitmap PixelFormat pf24Bit Clear 2D array of TBits objects FOR j 0 TO 255 DO FOR i 0 TO 255 DO Flags i j NIL Step through each scanline of image setting bits FOR j 0 TO Bitmap Height 1 DO BEGIN rowIn Bitmap Scanline j FOR i 0 TO Bitmap Width 1 DO BEGIN WITH rowIn i DO BEGIN IF NOT Assigned Flags rgbtRed rgbtGreen THEN BEGIN Create 3D column when needed Flags rgbtRed rgbtGreen TBits Create Flags rgbtRed rgbtGreen Size 256 END Mark this R G B triple Flags rgbtRed rgbtGreen Bits rgbtBlue TRUE END END END RESULT 0 Count and Free TBits objects FOR j 0 TO 255 DO BEGIN FOR i 0 TO 255 DO BEGIN IF Assigned Flags i j THEN BEGIN FOR k 0 TO 255 DO IF Flags i j Bits k THEN INC RESULT Flags i j Free END END END END CountColors This 2D array of TBits is usually a sparse array for a real world picture but the performance is still satisfactory when the array is not sparse at all The warning DO NOT BE SURPRISED IF YOUR SYSTEM CRASHES USE CAUTIOUSLY is for those that can t read smaller print In past experiments I mentioned I was stressing system resources and then I received E mail from some that were surprised with the program crashed Windows This experiment was performed

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

  • efg's Graphics -- Polygon Area and Centroid
    special case of this formula is for the triangle with the vertices a b c d e f which can be written in compact form using the following matrix determinant The centroid and area can be computed at the same time The coordinates for the centroid of a closed planar region R are where Look at the PolygonArea or PolygonCentroid functions in the PolygonLibrary PAS unit for the implementation of these formulas Find this method explained in Centroid of a Polygon in Graphics Gems IV or in Chapter 8 Image Measurements in The Image Processing Handbook See Frank van het Veld s comments about numerical difficulties that can be encountered using this method and Manuel Martin s comments about using relative coordinates to minimize loss of accuracy Method 2 in calculating a polygon s area is based on counting pixels First an in memory bitmap is filled with a solid color The polygon is plotted with a specified border color Finally the outside is floodfilled with a background color The area is computed from the ratio of the solid color to the total number of pixels times the area in real coordinates An option is present inside the program to include all some or none of the area of the border line Normally half of this area should be included A 1024 by 1024 pf8bit in memory bitmap was used in this program for Method 2 The CalculateEnclosedArea function in the ScreenAreaAndCentroid PAS unit has parameters to allow other sizes of in memory bitmaps The PaletteIndex function was used to define colors in the pf8bit bitmap to avoid palette problems with 256 color displays A third method which only applies to a triangle the Scalene triangle option in this program uses Heron s formula to compute the area A of

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

  • efg's Graphics -- Surface3D Lab Report
    Write BMP button to create a 1024 by 1024 pixel bitmap Surface BMP Select the Print button to print the surface views in a landscape orientation Discussion The DrawSurface procedure draws the surface views on the Image Canvas the Printer Canvas or a Bitmap Canvas using four different viewports The RepaintNeeded parameter to DrawSurface is a bit of a kludge When this parameter has the value TRUE the Image is

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

  • efg's Graphics -- 3D Lab Report
    Requirements VGA Display Procedure Double click on the ThreeDLab EXE icon to start the program Select one of the figures to display from the Combobox Cube Sphere Sphere In Cube Surface Football Field Use the spinboxes to change the eye position or the screen parameters Discussion The DrawFigures PAS unit defines the various objects in 3D space using world coordinates The default viewing azimuth elevation and distance is set when an object is selected See the absolute trick used in the GraphicsMathLibrary PAS unit in defining parameters to ViewTransformMatrix to be either x y z or azimuth elevation distance A large ScreenToCameraDistance ScreenHeight ratio specifies a narrow aperture a telephoto view Conversely a small ratio specifies a large aperture which is a wide angle view Hold down on the spinboxes assuming you have enough spare cycles it works fine on a 166 MHz Pentium with 32 MB memory to see the figure rotate left or right or up or down or change the viewing distance Changing these values directly changes the ViewTransformMatrix used to display the object Conclusions This program is a convenient way to interactively view one of the selected objects Keywords 2D 3D vector graphics translation rotation scaling

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

  • efg's Graphics -- Football Lab Report
    400 by 400 pixel image If desired select the Clear button and repeat Step 2 Select the Print button to print the same image as shown above on a full sheet of paper in portrait orientation using the Printer Canvas Select the Write BMP button to create a 600 by 600 pixel bitmap containing the images shown above The filename is KSUField BMP Discussion The DrawFields procedure is used to draw on any canvas namely the Image Canvas Printer Canvas or the Bitmap Canvas This shows how to write a single routine for various types of display either on the screen printed output or even a file DrawFields defines its own viewports for writing on specific areas of a canvas with the help of a TPantograph object The pOrthoXY projection in DrawFields gives an orthographic view of the field i e an X Y view of the X Y Z field The WorldCoordinatesRange for this 2D orthographic view are defined in feet which is how the coordinates of the field are defined in DrawFootbalField in the DrawFigures unit The pPerspective projections in DrawFields show three perspective views The ViewTransformMatrix routine creates the transformation from object space to camera point of

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

  • efg's Computer Lab -- Basketball Court
    x TReal y TReal END TRealRect RECORD CASE Integer OF 0 Left Top Right Bottom TReal 1 TopLeft BottomRight TRealPoint END TSimplePantograph CLASS TObject PRIVATE FCanvas TCanvas FPixelRect TRect FRealRect TRealRect FxDelta TReal FyDelta TReal FiDelta INTEGER FjDelta INTEGER FiDeltaOverxDelta TReal FjDeltaOveryDelta TReal FxDeltaOveriDelta TReal FyDeltaOverjDelta TReal PUBLIC CONSTRUCTOR Create Canvas TCanvas PixelRect TRect RealRect TRealRect Could make these functions but don t always want to use x and y to access fields PROCEDURE MapRealToPixel CONST x y TReal VAR i j INTEGER PROCEDURE MapPixelToReal CONST i j INTEGER VAR x y TReal PROCEDURE MoveTo CONST x y TReal PROCEDURE LineTo CONST x y TReal PROCEDURE Ellipse CONST x1 y1 x2 y2 TReal PROCEDURE Arc CONST x1 y1 x2 y2 x3 y3 x4 y4 TReal PROPERTY Canvas TCanvas READ FCanvas END FUNCTION RealPoint CONST aX aY DOUBLE TRealPoint FUNCTION RealRect CONST aLeft aTop aRight aBottom DOUBLE TRealRect The SimplePantograph constructor connects a specified canvas with the two rectangular areas the array of pixels and the world coordinates that define the basketball court ScreenBasketball PAS Bitmap Width ImageCourt Width Bitmap Height ImageCourt Height Bitmap PixelFormat pf24bit Origin of area is the center of the basketball court Normal math quadrants are used y dimension is flipped Pantograph TSimplePantograph Create Bitmap Canvas Rect 0 0 Bitmap Width Bitmap Height RealRect 50 30 50 30 ft Drawing the basketball court was broken into several local routines in the DrawCourt method in the ScreenBasketball unit DrawOutline DrawCenterCourt DrawHashLines DrawFoulLanes DrawThreePointLines Instead of using the MoveTo LineTo Canvas methods that operate with pixel coordinates similar methods of the TSimplePantograph can be used to draw directly in world coordinates For example DrawOutline shows the outline of the basketball court PROCEDURE DrawOutline BEGIN Outline of court Pantograph MoveTo HalfLength HalfWidth Pantograph LineTo HalfLength HalfWidth Pantograph LineTo HalfLength HalfWidth Pantograph LineTo HalfLength HalfWidth Pantograph LineTo HalfLength HalfWidth Save this rect to determine if shot is in bounds RectCourt RealRect HalfLength HalfWidth HalfLength HalfWidth END DrawOutline The most difficult part of the court to draw is the 3 point line especially in a way that can be used to draw both the college court and the NBA court In both cases the 3 point line is an arc of a circle with a specified radius This arc intersects two lines that are parallel to the sides of the court These lines parallel to the sides of the court are also at a specified location and length The following shows how draw the 3 point line around the right goal in the diagram Similar code is used to draw the line for the left goal PROCEDURE DrawThreePointLines VAR xCenter Double yCenter Double BEGIN Three Point Line Right side xCenter BaselineRight BackboardToBaseLine GoalCentertoBackBoard yCenter 0 0 GoalRight RealPoint xCenter yCenter Pantograph Arc xCenter ThreePointRadius yCenter ThreePointRadius xCenter ThreePointRadius yCenter ThreePointRadius BaselineRight ThreePointStraight ThreePointSide BaselineRight ThreePointStraight ThreePointSide Pantograph MoveTo BaselineRight ThreePointSide Pantograph LineTo BaselineRight ThreePointStraight ThreePointSide Pantograph MoveTo BaselineRight ThreePointSide Pantograph LineTo BaselineRight ThreePointStraight ThreePointSide Save RectRight for 2 3 point determination RectRight

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



  •