Board index » delphi » AV in Graphics Routine
Jim
![]() Delphi Developer |
AV in Graphics Routine2007-04-26 09:14:37 PM delphi240 Can someone who is more versed in graphics then I look at this and tell me where I went wrong? I have been getting a large number of reports on the last line shown LongColor := PDWORD( PMask)^; I am clearly not accounting for something in this routine. Thanks, Jim exception class : EAccessViolation exception message : Access violation at address 004F67CC in module 'UltraExplorer.exe'. Read of address 055E8E80. ********************************************** procedure ConvertBitmapEx(Image32: TBitmap; var OutImage: TBitmap; const BackGndColor: TColor); var I, N: Integer; PImage, PTarget, PMask: PByte; LongColor: DWORD; SourceRed, SourceGreen, SourceBlue, BkGndRed, BkGndGreen, BkGndBlue, RedTarget, GreenTarget, BlueTarget, Alpha: Byte; Target, Mask: TBitmap; PImageDelta, PBitmapDelta, PMaskDelta: Integer; begin // Algorithm only works for bitmaps with a height>1 pixel, should not be a limitation // as it would then be a line! if (Image32.PixelFormat = pf32Bit) and (Image32.Height>1) then begin Target := TBitmap.Create; Mask := TBitmap.Create; try Target.Width := Image32.Width; Target.Height := Image32.Height; Target.Assign(Image32); Mask.Width := Image32.Width; Mask.Height := Image32.Height; Mask.Canvas.Brush.Color := BackGndColor; Mask.Canvas.FillRect(Mask.Canvas.ClipRect); // initialize the bitmaps PImage := Image32.ScanLine[0]; PTarget := Target.ScanLine[0]; PMask := Mask.ScanLine[0]; // Calculate the number of bytes in a row to do the direct calculation // of the pixel index address, note for a "bottom up" storage this will // these will be negative numbers PImageDelta := Integer( Image32.ScanLine[1]) - Integer(PImage); PBitmapDelta := Integer( Target.ScanLine[1]) - Integer( PTarget); PMaskDelta := Integer( Mask.ScanLine[1]) - Integer( PMask); // If the Deltas are postive then it is a "top down" bitmap and easier // to calculate then next rows address, just add one if PImageDelta>0 then PImageDelta := 1; if PBitmapDelta>0 then PBitmapDelta := 1; if PMaskDelta>0 then PMaskDelta := 1; for I := 0 to Image32.Height - 1 do begin for N := 0 to Image32.Width -1 do begin // Pixel encoded: // Source GetColorValues ; Profiled = ~24-30% of time LongColor := PDWORD( PImage)^; SourceBlue := LongColor and $000000FF; SourceGreen := (LongColor and $0000FF00) shr 8; SourceRed := (LongColor and $00FF0000) shr 16; Alpha := (LongColor and $FF000000) shr 24; Inc(PImage, 4); // Mask GetColorValues ; Profiled = ~24-30% of time LongColor := PDWORD( PMask)^; <<<<<<< AV Right Here. ...... -- www.mustangpeak.net |