ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 example to loop through a TIEMask with scanline
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

nwscomps

185 Posts

Posted - May 03 2016 :  09:33:22  Show Profile  Reply
IS there any example to loop using scanline through a selection (TIEMask), instead of using getpixel? What I have tried did not work so far. It seems as the scanline property in a TIEMask acts differently than the scanline of a TIEBitmap.
Thanks.

I am looking to convert the following sample code to scanline:

procedure TestMaskScanline1;
var
k, x,y, x1,x2,y1,y2, pc: integer;
polysel:ppointarray;
mask:Tiemask;
p: pbyte;
bpp: integer;
begin
  case ImageEnView1.IEBitmap.PixelFormat of
    ie8g: bpp := 1;
    ie24RGB: bpp := 3;
    else
    exit;
  end;

  imageenview1.proc.GetReSel(x1,y1,x2,y2,polysel, pc, mask);
  for y := y1 to y2 do
  begin
    p := imageenview1.ieBitmap.scanline[y];
    inc(p, x1 * bpp);
    for x:= x1 to x2 do
    begin
      if mask.GetPixel(x, y)>0 then
         p^ := 255;
      for k := 1 to bpp do
        inc(p);
    end;
  end;

end;

Francesco Savastano
Nwscomps.com
Add-ons for the ImageEn Library

rmklever

Norway
52 Posts

Posted - May 03 2016 :  15:31:11  Show Profile  Reply
Hi Francesco,

A selection mask can only be 1 bit or 8 bit deep. See the:

TImageEnView.SelectionMaskDepth
http://www.imageen.com/help/TIEMask.html


Hope this helps

Roy M Klever
Klever on Delphi - www.rmklever.com
Go to Top of Page

xequte

39056 Posts

Posted - May 03 2016 :  21:28:54  Show Profile  Reply
Hi Francesco

// Set all selected pixels red
var
  x, y: Integer;
  pSel: pbyte;
  pPix: PRGB;
begin
  if ImageEnView1.SelectionMask.IsEmpty then
    raise Exception.create( 'Nothing selected' );

  if ImageEnView1.IEBitmap.PixelFormat <> ie24RGB then
    raise Exception.create( 'Not 24bit' );

  // Process selected area
  for y := 0 to ImageEnView1.SelectionMask.Height - 1 do
  begin
    pSel := ImageEnView1.SelectionMask.ScanLine[ y ];
    pPix := ImageEnView1.IEBitmap.ScanLine[ y ];

    case ImageEnView1.SelectionMask.BitsPerPixel of
      1:
        for x := 0 to ImageEnView1.SelectionMask.Width - 1 do
        begin
          // 1 Bit mask (values are 0 or 1)
          if (pbytearray(pSel)^[x shr 3] and iebitmask1[x and $7]) <> 0 then
          begin
            pPix^.R := 255;
            pPix^.G := 0;
            pPix^.B := 0;
          end;
          inc( pPix );
        end;
      8:
        for x := 0 to ImageEnView1.SelectionMask.Width - 1 do
        begin
          // 8 Bit mask (values are 0 to 255)
          if pSel^ <> 0 then
          begin
            pPix^.R := 255;
            pPix^.G := 0;
            pPix^.B := 0;
          end;
          inc( pSel );
          inc( pPix );
        end;
    end;
  end;
  ImageEnView1.Update();
end;


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

xequte

39056 Posts

Posted - May 03 2016 :  21:34:05  Show Profile  Reply
Which is the same as:

var
  x, y, x1, x2, y1, y2, pc: integer;
  polysel:ppointarray;
  SelMask:Tiemask;
  pSel: pbyte;
  pPix: PRGB;
begin
  with (ActiveMDIChild as TMDIChild) do
 begin
  if ImageEnView1.IEBitmap.PixelFormat <> ie24RGB then
    raise Exception.create( 'Not 24bit' );

  ImageEnView1.proc.GetReSel( x1, y1, x2, y2, polysel, pc, SelMask );

  if SelMask.IsEmpty then
    raise Exception.create( 'Nothing selected' );

  // Process selected area
  for y := 0 to SelMask.Height - 1 do
  begin
    pSel := SelMask.ScanLine[ y ];
    pPix := ImageEnView1.IEBitmap.ScanLine[ y ];

    case SelMask.BitsPerPixel of
      1:
        for x := 0 to SelMask.Width - 1 do
        begin
          // 1 Bit mask (values are 0 or 1)
          if (pbytearray(pSel)^[x shr 3] and iebitmask1[x and $7]) <> 0 then
          begin
            pPix^.R := 255;
            pPix^.G := 0;
            pPix^.B := 0;
          end;
          inc( pPix );
        end;
      8:
        for x := 0 to SelMask.Width - 1 do
        begin
          // 8 Bit mask (values are 0 to 255)
          if pSel^ <> 0 then
          begin
            pPix^.R := 255;
            pPix^.G := 0;
            pPix^.B := 0;
          end;
          inc( pSel );
          inc( pPix );
        end;
    end;
  end;
  ImageEnView1.Update();
end;


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

nwscomps

185 Posts

Posted - May 04 2016 :  04:42:59  Show Profile  Reply
Thank you, Nigel

Francesco Savastano
Nwscomps.com
Add-ons for the ImageEn Library
Go to Top of Page

nwscomps

185 Posts

Posted - May 04 2016 :  04:45:11  Show Profile  Reply
Hi Roy, thanks, I knew that, but I was looking for a faster way to loop through the mask other than using getpixel method which was quite slow. Nigel has provided a solution. As you can see from the example he posted, using the scanline access in a TIEMask is not as in a normal TIEBitmap.

Francesco Savastano
Nwscomps.com
Add-ons for the ImageEn Library
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: