|  |  | 
|  | 
|  | 
|  Sven
 Bader
 | | Hier habe ich einen Code für einen Weichzeichen-Filter, aus Performance-Gründen eher für kleine Grafiken geeignet. 
 
  
 Über den dritten Parameter der Blur-Funktion lässt sich steuern, wie oft der Filter angewendet wird.
 
 
Proc Blur
    Parameters width&, height&, passes&
    Declare avg_red&, avg_green&, avg_blue&, new_image&[width&-1, height&-1, 2]
    Declare count&, box&, x&, y&, i&, j&
    whileLoop passes&
        box& = 1
        WhileLoop 0, width& - 1
            i& = &loop
            WhileLoop 0, height& - 1
                j& = &loop
                clear avg_red&, avg_blue&, avg_green&, count&
                WhileLoop (i& - box&), (i& + box&)
                    x& = &loop
                    Case (x& = width&)  : Break
                    Case (x& < 0) : Continue
                    WhileLoop (j& - box&), (j& + box&)
                        y& = &loop
                        case (y& = height&) : Break
                        case (y& < 0) : Continue
                        inc count&
                        avg_red&   = avg_red&   + image&[x&, y&, 0]
                        avg_green& = avg_green& + image&[x&, y&, 1]
                        avg_blue&  = avg_blue&  + image&[x&, y&, 2]
                    EndWhile
                EndWhile
                new_image&[i&, j&, 0] = avg_red&   / count&
                new_image&[i&, j&, 1] = avg_green& / count&
                new_image&[i&, j&, 2] = avg_blue&  / count&
            EndWhile
        EndWhile
        MAT image&[] = new_image&[]
    EndWhile
EndProc
Cls
Declare x&, y&, px&, width&, height&
'===================== Bild in Array einlesen
DrawIcon "EIS", 50, 50
width& = 32
height& = 32
Declare image&[width&-1, height&-1, 2]
WhileLoop 0, height& - 1
    y& = &loop
    WhileLoop 0, width& - 1
        x& = &loop
        px& = GetPixel(50 + x&, 50 + y&)
        image&[x&, y&, 0] = GetRValue(px&)
        image&[x&, y&, 1] = GetGValue(px&)
        image&[x&, y&, 2] = GetBValue(px&)
    EndWhile
EndWhile
'===================== Filter anwenden
Blur(width&, height&, 5)
'===================== geglättetes Bild anzeigen
WhileLoop 0, height& - 1
    y& = &loop
    WhileLoop 0, width& - 1
        x& = &loop
        SetPixel 100 + x&, y& + 50, RGB(image&[x&, y&, 0], image&[x&, y&, 1], image&[x&, y&, 2])
    EndWhile
EndWhile
WaitKey
End
Der Flaschenhals ist hier nicht einmal der Filter selbst (wobei der auch) sondern das GetPixel und SetPixel. Umgehen könnte man das zum Beispiel über eine 24-Bit-Bitmap-Datei, die man als Block einliest.
 
 Ein qualitativer Tweak wäre, die Funktion nur einen Teilbereich glätten zu lassen, die Ränder aber trotzdem im Array vorzuhalten. Dann würden die Randbereiche nicht so abgehackt aussehen. Hierzu müsste man dann die 4 Case-Abfragen entfernen und den x/y-Offset als Parameter mitgeben.
 
 Viel Spaß beim Glätten
  | 
 
  | 
|  | 
|  |  | 
|  | 
| 
 
 
 |