by じみっちぃ » 2007年3月19日(月) 04:42
いろいろトライして、プログラム自体は完成したのですが、
処理速度が遅く、また悩みの種が増えてしまいました(^^ゞ
自分なりにループを減らしてみたり、無駄な処理をしないようにして見たり・・・
色々と工夫して見ましたが、P4 2.8G Mem 1G WinXP sp2 でも 4分程度かかってしまって…(@o@)
みなさんは、画像処理とか重い処理する時、
どうやって処理時間を短縮していますか?
やはりマルチスレッド化ですか?
せっかくですので、ソースコードを乗せておきます。
ソースコード1:
[ここをクリックすると内容が表示されます] [ここをクリックすると非表示にします]コード: 全て選択
Sub Filter(hDC_Target As HDC, nWidth As Long, nHeight As Long) As Long
Dim nSize As Long
Dim hHeapEB As HANDLE
Dim hHeapEC As HANDLE
Dim dwSrcBits As DWordPtr
Dim dwDstBits As DWordPtr
Dim n As Char
Dim I As Char
Dim Size As Char
Dim Offset As Char
Dim WindowSize As Char
Dim X As Char
Dim SigmaB As Double
Dim k As Double
Dim Total As Double
Dim i As Char
Dim j As Char
Dim T(7) As Double
Dim tmpDouble As Double
Dim ND[16,7,7] As Double
Dim ix As Char
Dim iy As Char
Dim x As Long
Dim y As Long
Dim sumRa As Double
Dim sumGa As Double
Dim sumBa As Double
Dim sumRb As Double
Dim sumGb As Double
Dim sumBb As Double
Dim sumRc As Double
Dim sumGc As Double
Dim sumBc As Double
Dim aA As Double
Dim wA(15) As Double
Dim FRa As Double
Dim FGa As Double
Dim FBa As Double
'■画像の読み込み/書き込みバッファ作成 開始。
nSize = nWidth * nHeight
hHeapEB = HeapCreate( NULL, 0, 0 )
dwSrcBits = HeapAlloc( hHeapEB, HEAP_ZERO_MEMORY, nSize*4 ) 'RGB=24bit ≒ DWord = 4Byte = 32Bit
hHeapEC = HeapCreate( NULL, 0, 0 )
dwDstBits = HeapAlloc( hHeapEC, HEAP_ZERO_MEMORY, nSize*4 ) 'RGB=24bit ≒ DWord = 4Byte = 32Bit
'■画像の読み込み/書き込みバッファ作成 完了。
'▲画像を読み込み 開始。
For y = 0 To nHeight - 1
For x = 0 To nWidth - 1
dwSrcBits[y*nWidth + x] = GetPixel(hDC_Target, x, y)
Next x
Next y
'▲画像を読み込み 完了。
'□重みの計算 開始
I = 16
WindowSize = 7
Offset = (WindowSize-1) / 2 '(7-1)/2 = 3
Size = (Offset*2)+1 '(3*2)+1 = 7
aA = Sqr((2^11))
For n = 0 To I-1
SigmaB = Sqr((2^(n-3)))
k = 1.0 / (Sqr(6.2831853071795862) / SigmaB)
Total = 0
For i = 0 To Size-1
X = i - Offset
tmpDouble = ((X * X) / (2 * SigmaB * SigmaB))
T(i) = k / (2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274^tmpDouble)
Total = Total + T(i)
Next i
For i = 0 To Size-1
T(i) = T(i) / Total
Next i
For i = 0 To Size-1
For j = 0 To Size-1
ND[n,i,j] = T(i) * T(j)
Next j
Next i
If Not(n=0) Then
If (n-1)<=2 Then
wA(n) = 0
Else
wA(n) = aA / Sqr(2^((n)-3))
End If
End If
Next n
'□重みの計算 完了。
For y = 0 To nHeight-1
For x = 0 To nWidth-1
For n = 0 To I-1
sumRa = 0
sumGa = 0
sumBa = 0
If x-Offset<0 Or x+Offset>=nWidth Then GOTO *SkipA
If y-Offset<0 Or y+Offset>=nHeight Then GOTO *SkipA
'画面中央部
For ix = -Offset To Offset
For iy = -Offset To Offset
sumRa += GetRed(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)]
sumGa += GetGreen(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)]
sumBa += GetBlue(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)]
Next iy
Next ix
GOTO *SkipB
'画面の端部
*SkipA
Total=0
For ix = -Offset To Offset
If x+ix<0 OR x+ix>=nWidth Then GOTO *SkipIX
For iy = -Offset To Offset
If y+iy<0 OR y+iy>=nHeight Then GOTO *SkipIY
Total += ND[n,(ix+Offset),(iy+Offset)]
sumRa += (GetRed(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
sumGa += (GetGreen(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
sumBa += (GetBlue(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
*SkipIY
Next iy
*SkipIX
Next ix
sumRa /= Total
sumGa /= Total
sumBa /= Total
*SkipB
If Not(n=0) Then
FRa = FRa + ((sumRa - sumRb) * wA(n))
FGa = FGa + ((sumGa - sumGb) * wA(n))
FBa = FBa + ((sumBa - sumBb) * wA(n))
If n=14 Then
sumRc = sumRa
sumGc = sumGa
sumBc = sumBa
End If
End If
sumRb = sumRa
sumGb = sumGa
sumBb = sumBa
Next n
FRa = BInt((FRa+1+sumRc))
FGa = BInt((FGa+1+sumGc))
FBa = BInt((FBa+1+sumBc))
dwDstBits[y*nWidth + x] = RGB(FRa,FGa,FBa)
Next x
Next y
For y = 0 To nHeight - 1
For x = 0 To nWidth - 1
SetPixelV(hDC_Target, x, y, dwDstBits[y*nWidth + x])
Next x
Next y
End Sub
ソースコード2: (高速化しようとあがいた方… 多少早くなりましたが、無駄にソースが長くなってしまいました…)
[ここをクリックすると内容が表示されます] [ここをクリックすると非表示にします]コード: 全て選択
Sub Filter(hDC_Target As HDC, nWidth As Long, nHeight As Long) As Long
Dim nSize As Long
Dim hHeapEB As HANDLE
Dim hHeapEC As HANDLE
Dim dwSrcBits As DWordPtr
Dim dwDstBits As DWordPtr
Dim n As Char
Dim I As Char
Dim Size As Char
Dim Offset As Char
Dim WindowSize As Char
Dim X As Char
Dim SigmaB As Double
Dim k As Double
Dim Total As Double
Dim i As Char
Dim j As Char
Dim T(7) As Double
Dim tmpDouble As Double
Dim ND[16,7,7] As Double
Dim ix As Char
Dim iy As Char
Dim x As Long
Dim y As Long
Dim sumRa As Double
Dim sumGa As Double
Dim sumBa As Double
Dim sumRb As Double
Dim sumGb As Double
Dim sumBb As Double
Dim sumRc As Double
Dim sumGc As Double
Dim sumBc As Double
Dim aA As Double
Dim wA(15) As Double
Dim FRa As Double
Dim FGa As Double
Dim FBa As Double
Dim tmpWidthA As Long
Dim tmpWidthB As Long
Dim tmpWidthC As Long
Dim tmpWidthD As Long
Dim tmpWidthE As Long
Dim tmpWidthF As Long
Dim tmpWidthG As Long
Dim tmpHeightA As Long
Dim tmpHeightB As Long
Dim tmpHeightC As Long
Dim tmpHeightE As Long
Dim tmpHeightF As Long
Dim tmpHeightG As Long
'■画像の読み込み/書き込みバッファ作成 開始。
nSize = nWidth * nHeight
hHeapEB = HeapCreate( NULL, 0, 0 )
dwSrcBits = HeapAlloc( hHeapEB, HEAP_ZERO_MEMORY, nSize*4 ) 'RGB=24bit ≒ DWord = 4Byte = 32Bit
hHeapEC = HeapCreate( NULL, 0, 0 )
dwDstBits = HeapAlloc( hHeapEC, HEAP_ZERO_MEMORY, nSize*4 ) 'RGB=24bit ≒ DWord = 4Byte = 32Bit
'■画像の読み込み/書き込みバッファ作成 完了。
'▲画像を読み込み 開始。
For y = 0 To nHeight - 1
For x = 0 To nWidth - 1
dwSrcBits[y*nWidth + x] = GetPixel(hDC_Target, x, y)
Next x
Next y
'▲画像を読み込み 完了。
'□重みの計算 開始
aA = Sqr((2^11))
I = 16
WindowSize = 7
Offset = (WindowSize-1) / 2 '(7-1)/2 = 3
Size = (Offset*2)+1 '(3*2)+1 = 7
For n = 0 To I-1
SigmaB = Sqr((2^(n-3)))
k = 1.0 / (Sqr(6.2831853071795862) / SigmaB)
Total = 0
For x = 0 To Size-1
X = x - Offset
tmpDouble = ((X * X) / (2 * SigmaB * SigmaB))
T(x) = k / (2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274^tmpDouble)
Total = Total + T(x)
Next x
For x = 0 To Size-1
T(x) = T(x) / Total
Next x
For x = 0 To Size-1
For y = 0 To Size-1
ND[n,x,y] = T(x) * T(y)
Next y
Next x
If Not(n=0) Then
If (n-1)<=2 Then
wA(n) = 0
Else
wA(n) = aA / Sqr(2^((n)-3))
End If
End If
Next n
'□重みの計算 完了。
For y = 0 To nHeight-1
For x = 0 To nWidth-1
tmpWidthA = (y-3)*nWidth
tmpWidthB = (y-2)*nWidth
tmpWidthC = (y-1)*nWidth
tmpWidthD = y*nWidth
tmpWidthE = (y+1)*nWidth
tmpWidthF = (y+2)*nWidth
tmpWidthG = (y+3)*nWidth
tmpHeightA = x-3
tmpHeightB = x-2
tmpHeightC = x-1
tmpHeightE = x+1
tmpHeightF = x+2
tmpHeightG = x+3
For n = 0 To I-1
If x-Offset<0 Or x+Offset>=nWidth Then GOTO *SkipA
If y-Offset<0 Or y+Offset>=nHeight Then GOTO *SkipA
'画面中央部
sumRa = (GetRed(dwSrcBits[tmpWidthA + tmpHeightA]) * ND[n,0,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + tmpHeightB]) * ND[n,1,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + tmpHeightC]) * ND[n,2,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + x]) * ND[n,3,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + tmpHeightE]) * ND[n,4,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + tmpHeightF]) * ND[n,5,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + tmpHeightG]) * ND[n,6,0])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightA]) * ND[n,0,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightB]) * ND[n,1,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightC]) * ND[n,2,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + x]) * ND[n,3,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightE]) * ND[n,4,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightF]) * ND[n,5,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightG]) * ND[n,6,1])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightA]) * ND[n,0,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightB]) * ND[n,1,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightC]) * ND[n,2,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + x]) * ND[n,3,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightE]) * ND[n,4,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightF]) * ND[n,5,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightG]) * ND[n,6,2])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightA]) * ND[n,0,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightB]) * ND[n,1,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightC]) * ND[n,2,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + x]) * ND[n,3,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightE]) * ND[n,4,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightF]) * ND[n,5,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightG]) * ND[n,6,3])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightA]) * ND[n,0,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightB]) * ND[n,1,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightC]) * ND[n,2,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + x]) * ND[n,3,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightE]) * ND[n,4,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightF]) * ND[n,5,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightG]) * ND[n,6,4])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightA]) * ND[n,0,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightB]) * ND[n,1,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightC]) * ND[n,2,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + x]) * ND[n,3,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightE]) * ND[n,4,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightF]) * ND[n,5,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightG]) * ND[n,6,5])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightA]) * ND[n,0,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightB]) * ND[n,1,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightC]) * ND[n,2,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + x]) * ND[n,3,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightE]) * ND[n,4,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightF]) * ND[n,5,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightG]) * ND[n,6,6])
sumGa = (GetGreen(dwSrcBits[tmpWidthA + tmpHeightA]) * ND[n,0,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + tmpHeightB]) * ND[n,1,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + tmpHeightC]) * ND[n,2,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + x]) * ND[n,3,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + tmpHeightE]) * ND[n,4,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + tmpHeightF]) * ND[n,5,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + tmpHeightG]) * ND[n,6,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightA]) * ND[n,0,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightB]) * ND[n,1,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightC]) * ND[n,2,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + x]) * ND[n,3,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightE]) * ND[n,4,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightF]) * ND[n,5,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightG]) * ND[n,6,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightA]) * ND[n,0,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightB]) * ND[n,1,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightC]) * ND[n,2,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + x]) * ND[n,3,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightE]) * ND[n,4,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightF]) * ND[n,5,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightG]) * ND[n,6,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightA]) * ND[n,0,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightB]) * ND[n,1,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightC]) * ND[n,2,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + x]) * ND[n,3,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightE]) * ND[n,4,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightF]) * ND[n,5,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightG]) * ND[n,6,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightA]) * ND[n,0,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightB]) * ND[n,1,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightC]) * ND[n,2,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + x]) * ND[n,3,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightE]) * ND[n,4,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightF]) * ND[n,5,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightG]) * ND[n,6,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightA]) * ND[n,0,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightB]) * ND[n,1,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightC]) * ND[n,2,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + x]) * ND[n,3,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightE]) * ND[n,4,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightF]) * ND[n,5,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightG]) * ND[n,6,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightA]) * ND[n,0,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightB]) * ND[n,1,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightC]) * ND[n,2,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + x]) * ND[n,3,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightE]) * ND[n,4,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightF]) * ND[n,5,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightG]) * ND[n,6,6])
sumBa = (GetBlue(dwSrcBits[tmpWidthA + tmpHeightA]) * ND[n,0,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + tmpHeightB]) * ND[n,1,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + tmpHeightC]) * ND[n,2,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + x]) * ND[n,3,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + tmpHeightE]) * ND[n,4,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + tmpHeightF]) * ND[n,5,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + tmpHeightG]) * ND[n,6,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightA]) * ND[n,0,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightB]) * ND[n,1,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightC]) * ND[n,2,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + x]) * ND[n,3,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightE]) * ND[n,4,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightF]) * ND[n,5,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightG]) * ND[n,6,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightA]) * ND[n,0,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightB]) * ND[n,1,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightC]) * ND[n,2,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + x]) * ND[n,3,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightE]) * ND[n,4,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightF]) * ND[n,5,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightG]) * ND[n,6,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightA]) * ND[n,0,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightB]) * ND[n,1,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightC]) * ND[n,2,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + x]) * ND[n,3,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightE]) * ND[n,4,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightF]) * ND[n,5,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightG]) * ND[n,6,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightA]) * ND[n,0,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightB]) * ND[n,1,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightC]) * ND[n,2,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + x]) * ND[n,3,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightE]) * ND[n,4,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightF]) * ND[n,5,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightG]) * ND[n,6,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightA]) * ND[n,0,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightB]) * ND[n,1,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightC]) * ND[n,2,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + x]) * ND[n,3,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightE]) * ND[n,4,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightF]) * ND[n,5,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightG]) * ND[n,6,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightA]) * ND[n,0,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightB]) * ND[n,1,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightC]) * ND[n,2,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + x]) * ND[n,3,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightE]) * ND[n,4,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightF]) * ND[n,5,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightG]) * ND[n,6,6])
GOTO *SkipB
'画面の端部
*SkipA
Total = 0
sumRa = 0
sumGa = 0
sumBa = 0
For ix = -Offset To Offset
For iy = -Offset To Offset
If x+ix<0 OR x+ix>=nWidth Then GOTO *SkipC
If y+iy<0 OR y+iy>=nHeight Then GOTO *SkipC
Total += ND[n,(ix+Offset),(iy+Offset)]
sumRa += (GetRed(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
sumGa += (GetGreen(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
sumBa += (GetBlue(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
*SkipC
Next iy
Next ix
sumRa /= Total
sumGa /= Total
sumBa /= Total
*SkipB
If Not(n=0) Then
FRa = FRa + ((sumRa - sumRb) * wA(n))
FGa = FGa + ((sumGa - sumGb) * wA(n))
FBa = FBa + ((sumBa - sumBb) * wA(n))
If n=14 Then
sumRc = sumRa
sumGc = sumGa
sumBc = sumBa
End If
End If
sumRb = sumRa
sumGb = sumGa
sumBb = sumBa
Next n
FRa = BInt((FRa+1+sumRc))
FGa = BInt((FGa+1+sumGc))
FBa = BInt((FBa+1+sumBc))
dwDstBits[y*nWidth + x] = RGB(FRa,FGa,FBa)
Next x
Next y
For y = 0 To nHeight - 1
For x = 0 To nWidth - 1
SetPixelV(hDC_Target, x, y, dwDstBits[y*nWidth + x])
Next x
Next y
End Sub
いろいろトライして、プログラム自体は完成したのですが、
処理速度が遅く、また悩みの種が増えてしまいました(^^ゞ
自分なりにループを減らしてみたり、無駄な処理をしないようにして見たり・・・
色々と工夫して見ましたが、P4 2.8G Mem 1G WinXP sp2 でも 4分程度かかってしまって…(@o@)
みなさんは、画像処理とか重い処理する時、
どうやって処理時間を短縮していますか?
やはりマルチスレッド化ですか?
せっかくですので、ソースコードを乗せておきます。
ソースコード1:
[hide][code]
Sub Filter(hDC_Target As HDC, nWidth As Long, nHeight As Long) As Long
Dim nSize As Long
Dim hHeapEB As HANDLE
Dim hHeapEC As HANDLE
Dim dwSrcBits As DWordPtr
Dim dwDstBits As DWordPtr
Dim n As Char
Dim I As Char
Dim Size As Char
Dim Offset As Char
Dim WindowSize As Char
Dim X As Char
Dim SigmaB As Double
Dim k As Double
Dim Total As Double
Dim i As Char
Dim j As Char
Dim T(7) As Double
Dim tmpDouble As Double
Dim ND[16,7,7] As Double
Dim ix As Char
Dim iy As Char
Dim x As Long
Dim y As Long
Dim sumRa As Double
Dim sumGa As Double
Dim sumBa As Double
Dim sumRb As Double
Dim sumGb As Double
Dim sumBb As Double
Dim sumRc As Double
Dim sumGc As Double
Dim sumBc As Double
Dim aA As Double
Dim wA(15) As Double
Dim FRa As Double
Dim FGa As Double
Dim FBa As Double
'■画像の読み込み/書き込みバッファ作成 開始。
nSize = nWidth * nHeight
hHeapEB = HeapCreate( NULL, 0, 0 )
dwSrcBits = HeapAlloc( hHeapEB, HEAP_ZERO_MEMORY, nSize*4 ) 'RGB=24bit ≒ DWord = 4Byte = 32Bit
hHeapEC = HeapCreate( NULL, 0, 0 )
dwDstBits = HeapAlloc( hHeapEC, HEAP_ZERO_MEMORY, nSize*4 ) 'RGB=24bit ≒ DWord = 4Byte = 32Bit
'■画像の読み込み/書き込みバッファ作成 完了。
'▲画像を読み込み 開始。
For y = 0 To nHeight - 1
For x = 0 To nWidth - 1
dwSrcBits[y*nWidth + x] = GetPixel(hDC_Target, x, y)
Next x
Next y
'▲画像を読み込み 完了。
'□重みの計算 開始
I = 16
WindowSize = 7
Offset = (WindowSize-1) / 2 '(7-1)/2 = 3
Size = (Offset*2)+1 '(3*2)+1 = 7
aA = Sqr((2^11))
For n = 0 To I-1
SigmaB = Sqr((2^(n-3)))
k = 1.0 / (Sqr(6.2831853071795862) / SigmaB)
Total = 0
For i = 0 To Size-1
X = i - Offset
tmpDouble = ((X * X) / (2 * SigmaB * SigmaB))
T(i) = k / (2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274^tmpDouble)
Total = Total + T(i)
Next i
For i = 0 To Size-1
T(i) = T(i) / Total
Next i
For i = 0 To Size-1
For j = 0 To Size-1
ND[n,i,j] = T(i) * T(j)
Next j
Next i
If Not(n=0) Then
If (n-1)<=2 Then
wA(n) = 0
Else
wA(n) = aA / Sqr(2^((n)-3))
End If
End If
Next n
'□重みの計算 完了。
For y = 0 To nHeight-1
For x = 0 To nWidth-1
For n = 0 To I-1
sumRa = 0
sumGa = 0
sumBa = 0
If x-Offset<0 Or x+Offset>=nWidth Then GOTO *SkipA
If y-Offset<0 Or y+Offset>=nHeight Then GOTO *SkipA
'画面中央部
For ix = -Offset To Offset
For iy = -Offset To Offset
sumRa += GetRed(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)]
sumGa += GetGreen(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)]
sumBa += GetBlue(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)]
Next iy
Next ix
GOTO *SkipB
'画面の端部
*SkipA
Total=0
For ix = -Offset To Offset
If x+ix<0 OR x+ix>=nWidth Then GOTO *SkipIX
For iy = -Offset To Offset
If y+iy<0 OR y+iy>=nHeight Then GOTO *SkipIY
Total += ND[n,(ix+Offset),(iy+Offset)]
sumRa += (GetRed(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
sumGa += (GetGreen(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
sumBa += (GetBlue(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
*SkipIY
Next iy
*SkipIX
Next ix
sumRa /= Total
sumGa /= Total
sumBa /= Total
*SkipB
If Not(n=0) Then
FRa = FRa + ((sumRa - sumRb) * wA(n))
FGa = FGa + ((sumGa - sumGb) * wA(n))
FBa = FBa + ((sumBa - sumBb) * wA(n))
If n=14 Then
sumRc = sumRa
sumGc = sumGa
sumBc = sumBa
End If
End If
sumRb = sumRa
sumGb = sumGa
sumBb = sumBa
Next n
FRa = BInt((FRa+1+sumRc))
FGa = BInt((FGa+1+sumGc))
FBa = BInt((FBa+1+sumBc))
dwDstBits[y*nWidth + x] = RGB(FRa,FGa,FBa)
Next x
Next y
For y = 0 To nHeight - 1
For x = 0 To nWidth - 1
SetPixelV(hDC_Target, x, y, dwDstBits[y*nWidth + x])
Next x
Next y
End Sub
[/code][/hide]
ソースコード2: (高速化しようとあがいた方… 多少早くなりましたが、無駄にソースが長くなってしまいました…)
[hide][code]
Sub Filter(hDC_Target As HDC, nWidth As Long, nHeight As Long) As Long
Dim nSize As Long
Dim hHeapEB As HANDLE
Dim hHeapEC As HANDLE
Dim dwSrcBits As DWordPtr
Dim dwDstBits As DWordPtr
Dim n As Char
Dim I As Char
Dim Size As Char
Dim Offset As Char
Dim WindowSize As Char
Dim X As Char
Dim SigmaB As Double
Dim k As Double
Dim Total As Double
Dim i As Char
Dim j As Char
Dim T(7) As Double
Dim tmpDouble As Double
Dim ND[16,7,7] As Double
Dim ix As Char
Dim iy As Char
Dim x As Long
Dim y As Long
Dim sumRa As Double
Dim sumGa As Double
Dim sumBa As Double
Dim sumRb As Double
Dim sumGb As Double
Dim sumBb As Double
Dim sumRc As Double
Dim sumGc As Double
Dim sumBc As Double
Dim aA As Double
Dim wA(15) As Double
Dim FRa As Double
Dim FGa As Double
Dim FBa As Double
Dim tmpWidthA As Long
Dim tmpWidthB As Long
Dim tmpWidthC As Long
Dim tmpWidthD As Long
Dim tmpWidthE As Long
Dim tmpWidthF As Long
Dim tmpWidthG As Long
Dim tmpHeightA As Long
Dim tmpHeightB As Long
Dim tmpHeightC As Long
Dim tmpHeightE As Long
Dim tmpHeightF As Long
Dim tmpHeightG As Long
'■画像の読み込み/書き込みバッファ作成 開始。
nSize = nWidth * nHeight
hHeapEB = HeapCreate( NULL, 0, 0 )
dwSrcBits = HeapAlloc( hHeapEB, HEAP_ZERO_MEMORY, nSize*4 ) 'RGB=24bit ≒ DWord = 4Byte = 32Bit
hHeapEC = HeapCreate( NULL, 0, 0 )
dwDstBits = HeapAlloc( hHeapEC, HEAP_ZERO_MEMORY, nSize*4 ) 'RGB=24bit ≒ DWord = 4Byte = 32Bit
'■画像の読み込み/書き込みバッファ作成 完了。
'▲画像を読み込み 開始。
For y = 0 To nHeight - 1
For x = 0 To nWidth - 1
dwSrcBits[y*nWidth + x] = GetPixel(hDC_Target, x, y)
Next x
Next y
'▲画像を読み込み 完了。
'□重みの計算 開始
aA = Sqr((2^11))
I = 16
WindowSize = 7
Offset = (WindowSize-1) / 2 '(7-1)/2 = 3
Size = (Offset*2)+1 '(3*2)+1 = 7
For n = 0 To I-1
SigmaB = Sqr((2^(n-3)))
k = 1.0 / (Sqr(6.2831853071795862) / SigmaB)
Total = 0
For x = 0 To Size-1
X = x - Offset
tmpDouble = ((X * X) / (2 * SigmaB * SigmaB))
T(x) = k / (2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274^tmpDouble)
Total = Total + T(x)
Next x
For x = 0 To Size-1
T(x) = T(x) / Total
Next x
For x = 0 To Size-1
For y = 0 To Size-1
ND[n,x,y] = T(x) * T(y)
Next y
Next x
If Not(n=0) Then
If (n-1)<=2 Then
wA(n) = 0
Else
wA(n) = aA / Sqr(2^((n)-3))
End If
End If
Next n
'□重みの計算 完了。
For y = 0 To nHeight-1
For x = 0 To nWidth-1
tmpWidthA = (y-3)*nWidth
tmpWidthB = (y-2)*nWidth
tmpWidthC = (y-1)*nWidth
tmpWidthD = y*nWidth
tmpWidthE = (y+1)*nWidth
tmpWidthF = (y+2)*nWidth
tmpWidthG = (y+3)*nWidth
tmpHeightA = x-3
tmpHeightB = x-2
tmpHeightC = x-1
tmpHeightE = x+1
tmpHeightF = x+2
tmpHeightG = x+3
For n = 0 To I-1
If x-Offset<0 Or x+Offset>=nWidth Then GOTO *SkipA
If y-Offset<0 Or y+Offset>=nHeight Then GOTO *SkipA
'画面中央部
sumRa = (GetRed(dwSrcBits[tmpWidthA + tmpHeightA]) * ND[n,0,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + tmpHeightB]) * ND[n,1,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + tmpHeightC]) * ND[n,2,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + x]) * ND[n,3,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + tmpHeightE]) * ND[n,4,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + tmpHeightF]) * ND[n,5,0])
sumRa += (GetRed(dwSrcBits[tmpWidthA + tmpHeightG]) * ND[n,6,0])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightA]) * ND[n,0,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightB]) * ND[n,1,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightC]) * ND[n,2,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + x]) * ND[n,3,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightE]) * ND[n,4,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightF]) * ND[n,5,1])
sumRa += (GetRed(dwSrcBits[tmpWidthB + tmpHeightG]) * ND[n,6,1])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightA]) * ND[n,0,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightB]) * ND[n,1,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightC]) * ND[n,2,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + x]) * ND[n,3,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightE]) * ND[n,4,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightF]) * ND[n,5,2])
sumRa += (GetRed(dwSrcBits[tmpWidthC + tmpHeightG]) * ND[n,6,2])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightA]) * ND[n,0,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightB]) * ND[n,1,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightC]) * ND[n,2,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + x]) * ND[n,3,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightE]) * ND[n,4,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightF]) * ND[n,5,3])
sumRa += (GetRed(dwSrcBits[tmpWidthD + tmpHeightG]) * ND[n,6,3])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightA]) * ND[n,0,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightB]) * ND[n,1,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightC]) * ND[n,2,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + x]) * ND[n,3,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightE]) * ND[n,4,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightF]) * ND[n,5,4])
sumRa += (GetRed(dwSrcBits[tmpWidthE + tmpHeightG]) * ND[n,6,4])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightA]) * ND[n,0,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightB]) * ND[n,1,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightC]) * ND[n,2,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + x]) * ND[n,3,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightE]) * ND[n,4,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightF]) * ND[n,5,5])
sumRa += (GetRed(dwSrcBits[tmpWidthF + tmpHeightG]) * ND[n,6,5])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightA]) * ND[n,0,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightB]) * ND[n,1,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightC]) * ND[n,2,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + x]) * ND[n,3,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightE]) * ND[n,4,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightF]) * ND[n,5,6])
sumRa += (GetRed(dwSrcBits[tmpWidthG + tmpHeightG]) * ND[n,6,6])
sumGa = (GetGreen(dwSrcBits[tmpWidthA + tmpHeightA]) * ND[n,0,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + tmpHeightB]) * ND[n,1,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + tmpHeightC]) * ND[n,2,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + x]) * ND[n,3,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + tmpHeightE]) * ND[n,4,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + tmpHeightF]) * ND[n,5,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthA + tmpHeightG]) * ND[n,6,0])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightA]) * ND[n,0,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightB]) * ND[n,1,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightC]) * ND[n,2,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + x]) * ND[n,3,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightE]) * ND[n,4,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightF]) * ND[n,5,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthB + tmpHeightG]) * ND[n,6,1])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightA]) * ND[n,0,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightB]) * ND[n,1,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightC]) * ND[n,2,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + x]) * ND[n,3,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightE]) * ND[n,4,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightF]) * ND[n,5,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthC + tmpHeightG]) * ND[n,6,2])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightA]) * ND[n,0,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightB]) * ND[n,1,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightC]) * ND[n,2,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + x]) * ND[n,3,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightE]) * ND[n,4,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightF]) * ND[n,5,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthD + tmpHeightG]) * ND[n,6,3])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightA]) * ND[n,0,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightB]) * ND[n,1,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightC]) * ND[n,2,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + x]) * ND[n,3,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightE]) * ND[n,4,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightF]) * ND[n,5,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthE + tmpHeightG]) * ND[n,6,4])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightA]) * ND[n,0,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightB]) * ND[n,1,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightC]) * ND[n,2,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + x]) * ND[n,3,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightE]) * ND[n,4,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightF]) * ND[n,5,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthF + tmpHeightG]) * ND[n,6,5])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightA]) * ND[n,0,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightB]) * ND[n,1,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightC]) * ND[n,2,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + x]) * ND[n,3,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightE]) * ND[n,4,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightF]) * ND[n,5,6])
sumGa += (GetGreen(dwSrcBits[tmpWidthG + tmpHeightG]) * ND[n,6,6])
sumBa = (GetBlue(dwSrcBits[tmpWidthA + tmpHeightA]) * ND[n,0,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + tmpHeightB]) * ND[n,1,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + tmpHeightC]) * ND[n,2,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + x]) * ND[n,3,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + tmpHeightE]) * ND[n,4,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + tmpHeightF]) * ND[n,5,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthA + tmpHeightG]) * ND[n,6,0])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightA]) * ND[n,0,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightB]) * ND[n,1,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightC]) * ND[n,2,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + x]) * ND[n,3,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightE]) * ND[n,4,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightF]) * ND[n,5,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthB + tmpHeightG]) * ND[n,6,1])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightA]) * ND[n,0,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightB]) * ND[n,1,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightC]) * ND[n,2,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + x]) * ND[n,3,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightE]) * ND[n,4,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightF]) * ND[n,5,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthC + tmpHeightG]) * ND[n,6,2])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightA]) * ND[n,0,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightB]) * ND[n,1,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightC]) * ND[n,2,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + x]) * ND[n,3,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightE]) * ND[n,4,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightF]) * ND[n,5,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthD + tmpHeightG]) * ND[n,6,3])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightA]) * ND[n,0,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightB]) * ND[n,1,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightC]) * ND[n,2,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + x]) * ND[n,3,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightE]) * ND[n,4,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightF]) * ND[n,5,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthE + tmpHeightG]) * ND[n,6,4])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightA]) * ND[n,0,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightB]) * ND[n,1,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightC]) * ND[n,2,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + x]) * ND[n,3,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightE]) * ND[n,4,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightF]) * ND[n,5,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthF + tmpHeightG]) * ND[n,6,5])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightA]) * ND[n,0,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightB]) * ND[n,1,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightC]) * ND[n,2,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + x]) * ND[n,3,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightE]) * ND[n,4,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightF]) * ND[n,5,6])
sumBa += (GetBlue(dwSrcBits[tmpWidthG + tmpHeightG]) * ND[n,6,6])
GOTO *SkipB
'画面の端部
*SkipA
Total = 0
sumRa = 0
sumGa = 0
sumBa = 0
For ix = -Offset To Offset
For iy = -Offset To Offset
If x+ix<0 OR x+ix>=nWidth Then GOTO *SkipC
If y+iy<0 OR y+iy>=nHeight Then GOTO *SkipC
Total += ND[n,(ix+Offset),(iy+Offset)]
sumRa += (GetRed(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
sumGa += (GetGreen(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
sumBa += (GetBlue(dwSrcBits[(y+iy)*nWidth + (x+ix)]) * ND[n,(ix+Offset),(iy+Offset)])
*SkipC
Next iy
Next ix
sumRa /= Total
sumGa /= Total
sumBa /= Total
*SkipB
If Not(n=0) Then
FRa = FRa + ((sumRa - sumRb) * wA(n))
FGa = FGa + ((sumGa - sumGb) * wA(n))
FBa = FBa + ((sumBa - sumBb) * wA(n))
If n=14 Then
sumRc = sumRa
sumGc = sumGa
sumBc = sumBa
End If
End If
sumRb = sumRa
sumGb = sumGa
sumBb = sumBa
Next n
FRa = BInt((FRa+1+sumRc))
FGa = BInt((FGa+1+sumGc))
FBa = BInt((FBa+1+sumBc))
dwDstBits[y*nWidth + x] = RGB(FRa,FGa,FBa)
Next x
Next y
For y = 0 To nHeight - 1
For x = 0 To nWidth - 1
SetPixelV(hDC_Target, x, y, dwDstBits[y*nWidth + x])
Next x
Next y
End Sub
[/code][/hide]