Results 1 to 5 of 5

Thread: Handling bitmaps in a plugin?

  1. #1
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default Handling bitmaps in a plugin?

    How do I use GetPixel with Lazarus? I want to have this function in a plugin:
    Simba Code:
    function G_MakeColorBoxEx(bmp, x1, y1: integer): Array of Integer;  //[0]=Red [1]=Green [2]=Blue
    var
      x, y: integer;
      R, G, B: integer;
    begin
      SetLength(Result, 3);

      for x := x1 to (x1 + 4) do
        for y := y1 to (y1 + 4) do
        begin
          try
            ColorToRGB(FastGetPixel(bmp, x, y), R, G, B); // <--- How is this done in a plugin?
            Result[0] := Result[0] + R;
            Result[1] := Result[1] + G;
            Result[2] := Result[2] + B;
          except
            //writeln('ColorToRGB exception: '+inttostr(x)+', '+inttostr(y));
          end;
        end;
    end;

    And I really want the bmp parameter to be an integer, so I can first call
    CopyClientCanvas()
    in Simba and input that bitmap into the function above.
    Last edited by marpis; 01-09-2011 at 07:05 PM.

  2. #2
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Pass the TMufasaBitmap. Then use FastGetPixel.

    GetMufasaBitmap(bmp) returns the TMufasaBitmap.

    E:
    Simba Code:
    program new;

    function G_MakeColorBoxEx(bmp: TMufasaBitmap; x1, y1: integer): Array of Integer;  //[0]=Red [1]=Green [2]=Blue
    var
      x, y: integer;
      R, G, B: integer;
    begin
      SetLength(Result, 3);

      for x := x1 to (x1 + 4) do
        for y := y1 to (y1 + 5) do
        begin
          try
            ColorToRGB(bmp.FastGetPixel(x, y), R, G, B);
            Result[0] := Result[0] + R;
            Result[1] := Result[1] + G;
            Result[2] := Result[2] + B;
          except
            //writeln('ColorToRGB exception: '+inttostr(x)+', '+inttostr(y));
          end;
        end;
    end;

    var
       bmp, w, h: Integer;
       mbmp: TMufasaBitmap;

    begin
      bmp := CreateBitmap(10, 10);
      mbmp := GetMufasaBitmap(bmp);

      GetClientDimensions(w,h);

      mbmp.CopyClientToBitmap(GetTClient.IOManager, True, 0, 0, 0, 0, w-1, h-1);

      G_MakeColorBoxEx(mbmp, 42, 42);
    end.

    You'll need to include parts of the MML in your plugin. (You should anyway)
    Last edited by Wizzup?; 01-09-2011 at 07:09 PM.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  3. #3
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    I dont understand.
    I want the G_MakeColorBox to be in my plugin, how can I use type TMufasaBitmap and function FastGetPixel inside the plugin?

    Also, what's the x parameter in ReadFileString?

  4. #4
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    I dont understand.
    I want the G_MakeColorBox to be in my plugin, how can I use type TMufasaBitmap and function FastGetPixel inside the plugin?
    Where is your plugin source? I'll add it.
    Anyway, passing a pointer of the TMufasaBitmap is perfectly valid and there's no reason you can't call FastGetPixel on it.

    Also, what's the x parameter in ReadFileString?
    http://docs.villavu.com/simba/script...readfilestring



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  5. #5
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    Also, what's the x parameter in ReadFileString?
    How much of the file to read. IE FileSize() would read everything inside the specific file, while 2 would read the first 2 bytes(?).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •