Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-08

Scanline on certain size images seems to be failing : Access Violation...

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

I have the following 2 functions to determine the transparency colour of a bitmap...

// Returns the transparent color for the bitmap
function Bitmap24_TransparentColor(bitmap:TBitmap):TColor;
var
  row : PRGBArray;
  {$IFDEF FPC}
  ScanLineImage : TLazIntfImage;
  {$ENDIF}
begin
  Result := clBlack;
  if not IsValidBitmap( bitmap, 'Bitmap24_TransparentColor' ) then
  begin
    Exit;
  end;
  {$IFDEF FPC}
  ScanLineImage := bitmap.CreateIntfImage;
  {$ENDIF}
  {$IFDEF FPC}
  row := ScanLineImage.GetDataLineStart( bitmap.Height - 1 );
  {$ELSE}
  row := bitmap.ScanLine[ bitmap.Height - 1 ];
  {$ENDIF}
  {$IFDEF FPC}
  ScanLineImage.Free;
  {$ENDIF}
  Result := Color_RGBtoColor(row[0]);
end;
// Transforms a RGB color into a standard color
function Color_RGBToColor(col : TRGB) : TColor;
begin
  Result := $10000 *  col.b + $100 * col.g + col.r; // ACCESS VIOLATION
HERE if Image greater than 640x480
end;

I'm getting an Access violation when passing the row[0] to the RGBtoColor. Can anyone see what I might be doing wrong?
The only thing I noticed is that it seems to fail when I use images greater than 640x480, but I'm willing to concede it may be a bit depth issue. Smaller image sizes seem to work fine.

Would I be right in thinking that row[0] is the bottom right corner of the image?

Thanks,

Dominique.

Reply by email

Unknown author
to Unknown author

Please ignore,
I just realised that ScanLineImage.Free was being called before the Color_RGBtoColor funcation. Which caused the AV.
Hence why the code works under Delphi, but was AVing with FreePascal.

Dominique.

I have the following 2 functions to determine the transparency colour of

a

Show quoted text 42 lines
bitmap... // Returns the transparent color for the bitmap function Bitmap24_TransparentColor(bitmap:TBitmap):TColor; var row : PRGBArray; {$IFDEF FPC} ScanLineImage : TLazIntfImage; {$ENDIF} begin Result := clBlack; if not IsValidBitmap( bitmap, 'Bitmap24_TransparentColor' ) then begin Exit; end; {$IFDEF FPC} ScanLineImage := bitmap.CreateIntfImage; {$ENDIF} {$IFDEF FPC} row := ScanLineImage.GetDataLineStart( bitmap.Height - 1 ); {$ELSE} row := bitmap.ScanLine[ bitmap.Height - 1 ]; {$ENDIF} {$IFDEF FPC} ScanLineImage.Free; {$ENDIF} Result := Color_RGBtoColor(row[0]); end; // Transforms a RGB color into a standard color function Color_RGBToColor(col : TRGB) : TColor; begin Result := $10000 * col.b + $100 * col.g + col.r; // ACCESS VIOLATION HERE if Image greater than 640x480 end; I'm getting an Access violation when passing the row[0] to the

RGBtoColor.

Can anyone see what I might be doing wrong? The only thing I noticed is that it seems to fail when I use images

greater

than 640x480, but I'm willing to concede it may be a bit depth issue. Smaller image sizes seem to work fine. Would I be right in thinking that row[0] is the bottom right corner of

the

Show quoted text 11 lines
image? Thanks, Dominique. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mattias Gaertner
to Unknown author
Please ignore, I just realised that ScanLineImage.Free was being called before the Color_RGBtoColor funcation. Which caused the AV. Hence why the code works under Delphi, but was AVing with FreePascal.

Note:
The ScanLine differences have nothing to do with FPC, but with the LCL. You can use:

{$IFDEF LCL}

Mattias

Show quoted text 77 lines
Dominique. On Sat, 15 Aug 2009 08:28:53 -0400, wrote: > I have the following 2 functions to determine the transparency > colour of a > bitmap... > > // Returns the transparent color for the bitmap > function Bitmap24_TransparentColor(bitmap:TBitmap):TColor; > var > row : PRGBArray; > {$IFDEF FPC} > ScanLineImage : TLazIntfImage; > {$ENDIF} > begin > Result := clBlack; > > if not IsValidBitmap( bitmap, 'Bitmap24_TransparentColor' ) then > begin > Exit; > end; > > {$IFDEF FPC} > ScanLineImage := bitmap.CreateIntfImage; > {$ENDIF} > > {$IFDEF FPC} > row := ScanLineImage.GetDataLineStart( bitmap.Height - 1 ); > {$ELSE} > row := bitmap.ScanLine[ bitmap.Height - 1 ]; > {$ENDIF} > > {$IFDEF FPC} > ScanLineImage.Free; > {$ENDIF} > > Result := Color_RGBtoColor(row[0]); > end; > > // Transforms a RGB color into a standard color > function Color_RGBToColor(col : TRGB) : TColor; > begin > Result := $10000 * col.b + $100 * col.g + col.r; // ACCESS > VIOLATION HERE if Image greater than 640x480 > end; > > I'm getting an Access violation when passing the row[0] to the RGBtoColor. > Can anyone see what I might be doing wrong? > The only thing I noticed is that it seems to fail when I use images greater > than 640x480, but I'm willing to concede it may be a bit depth > issue. Smaller image sizes seem to work fine. > > Would I be right in thinking that row[0] is the bottom right corner > of the > image? > > Thanks, > > Dominique. > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Unknown author
to Mattias Gaertner: On Sat, 15 Aug 2009 09:26:59 -0400 Note: The ScanLine differences have nothing to do with…

I didn't know there was an LCL define hence why I used FPC. I'll use that from now on.

Thanks for the heads up.

Dominique.

Mattias Gaertner wrote 100 lines
On Sat, 15 Aug 2009 09:26:59 -0400 wrote: > Please ignore, > I just realised that ScanLineImage.Free was being called before the > Color_RGBtoColor funcation. Which caused the AV. > Hence why the code works under Delphi, but was AVing with FreePascal. Note: The ScanLine differences have nothing to do with FPC, but with the LCL. You can use: {$IFDEF LCL} Mattias > > Dominique. > > On Sat, 15 Aug 2009 08:28:53 -0400, > wrote: > > I have the following 2 functions to determine the transparency > > colour of > a > > bitmap... > > > > // Returns the transparent color for the bitmap > > function Bitmap24_TransparentColor(bitmap:TBitmap):TColor; > > var > > row : PRGBArray; > > {$IFDEF FPC} > > ScanLineImage : TLazIntfImage; > > {$ENDIF} > > begin > > Result := clBlack; > > > > if not IsValidBitmap( bitmap, 'Bitmap24_TransparentColor' ) then > > begin > > Exit; > > end; > > > > {$IFDEF FPC} > > ScanLineImage := bitmap.CreateIntfImage; > > {$ENDIF} > > > > {$IFDEF FPC} > > row := ScanLineImage.GetDataLineStart( bitmap.Height - 1 ); > > {$ELSE} > > row := bitmap.ScanLine[ bitmap.Height - 1 ]; > > {$ENDIF} > > > > {$IFDEF FPC} > > ScanLineImage.Free; > > {$ENDIF} > > > > Result := Color_RGBtoColor(row[0]); > > end; > > > > // Transforms a RGB color into a standard color > > function Color_RGBToColor(col : TRGB) : TColor; > > begin > > Result := $10000 * col.b + $100 * col.g + col.r; // ACCESS > > VIOLATION HERE if Image greater than 640x480 > > end; > > > > I'm getting an Access violation when passing the row[0] to the > RGBtoColor. > > Can anyone see what I might be doing wrong? > > The only thing I noticed is that it seems to fail when I use images > greater > > than 640x480, but I'm willing to concede it may be a bit depth > > issue. Smaller image sizes seem to work fine. > > > > Would I be right in thinking that row[0] is the bottom right corner > > of > the > > image? > > > > Thanks, > > > > Dominique. > > > > -- > > _______________________________________________ > > Lazarus mailing list > > > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Unknown author
to theo: When trying to convert Bitmap manipulation stuff using Scanline from Delphi to Freepascal…

Thanks for the link Theo. The stuff I have works on Win32 with Delphi, its just getting it all working with FPC and LCL on Mac OS X that I'm trying to do.

Dominique

theo wrote 10 lines
When trying to convert Bitmap manipulation stuff using Scanline from Delphi to Freepascal / Lazarus Opbitmap might help you. http://www.theo.ch/lazarus/opbitmap64.zip If you are not on 32 bit intel install the opbitmapforlazcompat.lpk package. The demos should get you going. I don't know if this is what you need.

Reply by email