Понадобилось перевести все фильтры в вычисление в single для большей точности и возможности выхода за диапазон[0-255]...
...Но как кэшировать вычисления с Floating Point(Single, Double)?
с Байтом все просто - таблица [0 - 255], а тут как?
Модератор: gaidar
' FILM CONTRAST
Public Sub flt_s_film (DT As Single PTR, ByVal LN As Long, ByVal V1 As Single, ByVal V2 As Single, ByVal Lg As Long, ByVal Pc As Long) EXPORT
If V1 = 0 Then
If v2 = 0 Then
If Lg = 0 Then
Exit Sub
End If
End If
End If
Dim X As Long, k As Long
Dim kk As Single, i As Long
Dim Y As Single, R As Single, G As Single, B As Single
Dim ln3 As Long = ln * 3
Dim C1 As Single
Dim C2 As Single
If V1 < - 40 Then V1 = - 40
If V1 > 40 Then V1 = 40
If V2 < - 50 Then V2 = - 50
If V2 > 100 Then V2 = 100
If V2 < 0 Then
kk = (100 + V2) / 100
Else
kk = 1 + V2 / 100
End If
C1 = V1 * kk
C2 = - 128 * kk + 128
' INIT FILTER TABLE
' For x = 0 To 255
' i = (x + Sin(x / 40.5845104) * V1 - 128) * kk + 128
' If Lg = 1 Then i = Sqr(i * 64) * 2
' If i < 0 Then i = 0
' If i > 255 Then i = 255
' filmc(x) = i
' Next
'i = (x + Sin(x / 40.5845104) * V1 - 128) * kk + 128
' x * kk + Sin(x / 40.5845104) * V1 * kk - 128 * kk + 128
' V1 * kk -128 * kk + 128
' x * kk + sin(x / 40.5845104) * C1 + C2
' C1 = V1 * kk C2 = -128 * kk + 128
'i = 16*sqr(((x + Sin(x / 40.5845104) * V1 - 128) * kk + 128))
' 16*sqr(x * kk + sin(x / 40.5845104) * C1 + C2 )
If Pc = 0 Then
If Lg = 0 Then
stt9: If k = ln3 Then Exit Sub
DT[k] = DT[k] * kk + Sin(DT[k] / 40.5845104) * C1 + C2
k = k + 1
Goto stt9:
Else
stt10: If k = ln3 Then Exit Sub
DT[k] = 16 * Sqr(DT[k] * kk + Sin(DT[k] / 40.5845104) * C1 + C2 )
k = k + 1
Goto stt10:
End If
Else
Dim kR As Long = 2
Dim kG As Long = 1
If Lg = 0 Then
sttp9: If k = ln3 Then Exit Sub
Y = (DT[k] + DT[kG] + DT[kR]) / 3
B = DT[k] - Y
G = DT[kG] - Y
R = DT[kR] - Y
Y = Y * kk + Sin(Y / 40.5845104) * C1 + C2
DT[k] = Y + B
DT[kG] = Y + G
DT[kR] = Y + R
k += 3
kG += 3
kR += 3
Goto sttp9:
Else
sttp10: If k = ln3 Then Exit Sub
Y = (DT[k] + DT[kG] + DT[kR]) / 3
B = DT[k] - Y
G = DT[kG] - Y
R = DT[kR] - Y
Y = 16 * Sqr(Y * kk + Sin(Y / 40.5845104) * C1 + C2 )
DT[k] = Y + B
DT[kG] = Y + G
DT[kR] = Y + R
k += 3
kG += 3
kR += 3
Goto sttp10:
End If
' Dim kR As Long = 2
' Dim kG As Long = 1
'
' stt10: If k > ln3 Then Exit Sub
' Y = filmGray(CLng(DT[k]) + DT[kG] + DT[kR])
' B = Y - DT[k]
' G = Y - DT[kG]
' R = Y - DT[kR]
' Y = filmc(Y)
' DT[k] = clim(Y - B)
' DT[kG] = clim(Y - G)
' DT[kR] = clim(Y - R)
' k += 3
' kG += 3
' kR += 3
' Goto stt10:
End If
End Sub
AWPStar писал(а):-32 битный Single обрабатывается быстрее 16-битного int(по тестам где-то на 17%)
Dim Ar() As Single, TabSz As Long
Sub FilmcInit(ByVal Lg As Long, ByVal Pc As Long)
Dim x As Long, i As Single
ReDim Ar(255)
For x = 0 To 255
i = (x + Sin(x / 40.5845104) * V1 - 128) * kk + 128
If Lg = 1 Then
i = Sqr(i * 64) * 2
End If
If Pc = 0 Then
If i < 0 Then i = 0
If i > 255 Then i = 255
End If
Ar(x) = i
Next i
End Sub
Function Filmc(ByVal s As Single) As Single
Dim i As Long
i = Int(s): s = s - i
Filmc = Ar(i) * (1 - s) + Ar(i + 1) * s
End Function
Ar(i) * (1 - s) + Ar(i + 1) * s
Вернуться в Раздел для Профессионалов
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 0