Results 1 to 5 of 5

Thread: Blur Image

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Thanks a lot User137! Your tips were very valuable! =)

    To achieve the best result I did use the 17 pixels around the current pixel.

    Here is the final code :

    Code:
      procedure BoxBlur(var Texture: zglPTexture);
      var
        X, Y: Integer;
        yLine, xLine, yLine2, yLine3: PByteArray;
        data: PByteArray;
        realWidth: Integer;
        realHeight: Integer;
      begin
        realWidth := Round(Texture.Width / Texture.U);
        realHeight := Round(Texture.Height / Texture.V);
        tex_GetData(Texture, data);
    
        for Y := 1 to realHeight - 2 do
        begin
          yLine := @data[realWidth * (Y) * 4]; // Current Line
          yLine2 := @data[realWidth * (Y - 1) * 4]; // Prior Line
          yLine3 := @data[realWidth * (Y + 1) * 4]; // Next Line
    
          xLine := @data[realWidth * Y * 4];
    
          for X := 1 to realWidth - 2 do
          begin
            xLine^[X * 4] := ((xLine^[X * 4] + xLine^[(X - 1) * 4] + xLine^[(X + 1) * 4] + yLine^[(X - 1) * 4] + yLine^[(X + 1) * 4] + yLine2^[(X - 1) * 4] + yLine2^[(X + 1) * 4] + yLine3^[(X - 1) * 4]
                  + yLine3^[(X + 1) * 4]) + (xLine^[(X - 2) * 4] + xLine^[(X + 2) * 4] + yLine^[(X - 2) * 4] + yLine^[(X + 2) * 4] + yLine2^[(X - 2) * 4] + yLine2^[(X + 2) * 4] + yLine3^[(X - 2) * 4]
                  + yLine3^[(X + 2) * 4])) div 17;
    
            xLine^[X * 4 + 1] := ((xLine^[X * 4 + 1] + xLine^[(X - 1) * 4 + 1] + xLine^[(X + 1) * 4 + 1] + yLine^[(X - 1) * 4 + 1] + yLine^[(X + 1) * 4 + 1] + yLine2^[(X + 1) * 4 + 1] + yLine2^[(X - 1)
                  * 4 + 1] + yLine3^[(X + 1) * 4 + 1] + yLine3^[(X - 1) * 4 + 1]) + (xLine^[(X - 2) * 4 + 1] + xLine^[(X + 2) * 4 + 1] + yLine^[(X - 2) * 4 + 1] + yLine^[(X + 2) * 4 + 1] + yLine2^[
                  (X + 2) * 4 + 1] + yLine2^[(X - 2) * 4 + 1] + yLine3^[(X + 2) * 4 + 1] + yLine3^[(X - 2) * 4 + 1])) div 17;
    
            xLine^[X * 4 + 2] := ((xLine^[X * 4 + 2] + xLine^[(X - 1) * 4 + 2] + xLine^[(X + 1) * 4 + 2] + yLine^[(X - 1) * 4 + 2] + yLine^[(X + 1) * 4 + 2] + yLine2^[(X + 1) * 4 + 2] + yLine2^[(X - 1)
                  * 4 + 2] + yLine3^[(X + 1) * 4 + 2] + yLine3^[(X - 1) * 4 + 2]) + (xLine^[(X - 2) * 4 + 2] + xLine^[(X + 2) * 4 + 2] + yLine^[(X - 2) * 4 + 2] + yLine^[(X + 2) * 4 + 2] + yLine2^[
                  (X + 2) * 4 + 2] + yLine2^[(X - 2) * 4 + 2] + yLine3^[(X + 2) * 4 + 2] + yLine3^[(X - 2) * 4 + 2])) div 17;
    
          end;
        end;
    
        tex_SetData(Texture, data, 0, 0, realWidth, Texture.Height);
        FreeMem(data);
      end;

  2. #2
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    ZenGL - the clue is in the name. Why don't you just use mip-map levels + filtering to do the blur in hardware? you can do it in a shader incredibly easily. You're already tied into GL with Zen so not doing it in hardware is folly
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Bookmarks

Posting Permissions

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