Recent

Author Topic: [solved] Can't us GetDataLineStart and Move why ?  (Read 2812 times)

bubulemaster

  • New Member
  • *
  • Posts: 47
[solved] Can't us GetDataLineStart and Move why ?
« on: November 26, 2011, 02:03:04 pm »
Hi,

I look about GetDataLineStart() and I would like use Move to copy fast a picture to another picture.

All picture is TBitmap 24 bits per pixel color.

When I use a code like below :
Code: [Select]
type
  TRGBArray = array[word] of TRGBTriple ;
  pRGBArray = ^TRGBArray ;

procedure ....
var
    // Source image
    lSrc : TLazIntfImage ;
    // Destination image
    lDst : TLazIntfImage ;
    // Source line
    lSrcLine : pRGBArray ;
    // Destination line
    lDstLine : pRGBArray ;
begin
       // PixelFormat := pf24bit

        // For each line of source
        for lLineIndex := 0 to lSrc.Height - 1 do
        begin
            lSrcLine := lSrc.GetDataLineStart(lLineIndex) ;
            lDstLine := lDst.GetDataLineStart(lLineIndex) ;

            Move(lSrcLine, lDstLine, lSrc.Width * 3) ; // * 3 -> for 24 bits
        end ;
end ;

First time (lLineIndex  = 0) is ok, but the second time (lLineIndex = 1), I receive a SIGSEGV on first GetDataLineStart().

Ok, it doesn't work. But I just want understand why.
It's two pointer on differents memories.

Someone can explain me ?

Thanks you.
« Last Edit: November 27, 2011, 08:01:45 am by bubulemaster »

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Can't us GetDataLineStart and Move why ?
« Reply #1 on: November 26, 2011, 02:52:29 pm »
Quote
Move(lSrcLine, lDstLine, lSrc.Width * 3)
This copies the contents of lSrcLine to lDstLine for lSrc.Width * 3 bytes. So you copy lSrcLine to lDstLine and overwrite a big chunk of the stack in doing so. What you want to do is to copy the memory pointed to by lSrcLine to the memory pointed to by lDstLine:
Code: [Select]
Move(lSrcLine^, lDstLine^, lSrc.Width * 3)

bubulemaster

  • New Member
  • *
  • Posts: 47
Re: Can't us GetDataLineStart and Move why ?
« Reply #2 on: November 27, 2011, 08:01:27 am »
Ok, thank.

I don't know where I saw the methode Move(pointer,pointer, integer).

I read the source code of freepascal and I see
Code: [Select]
Procedure Move(const source;var dest;count:SizeInt);
I'm so stupid sorry !

 

TinyPortal © 2005-2018