Sub image_draw( img As image, sx As Int, sy As Int, sw As Int, sh As Int, x As Int, y As Int, col1 As Int, col2 As Int )
Dim iox, ioy, ix, iy As Int
Dim iw, ih, icw, ich As Int
Dim sstride As Int
Dim Var1, Var2, Var3, Var4, Var5 As Int
Dim des() As Int
Dim src() As Int
'Log (" IMG: " & img.c_w )
sstride = img.c_w
iox = sx
ioy = sy
iw = sw
ih = sh
'Log("image_draw: c_w = " & c_w & " c_h = " & c_h & " - x = " & x & " y = " & y)
If (x >= c_w) OR (y >= c_h) Then
Log("image_draw: Return #1!")
Return
End If
If (x + iw <= 0) OR (y + ih <= 0) Then
Log("image_draw: Return #2!")
Return
End If
If ( x + iw > c_w ) Then
icw = c_w - x
Else
icw = iw
End If
If ( y + ih > c_h ) Then
ich = c_h - y
Else
ich = ih
End If
If ( x < 0 ) Then
iox = iox - x
icw = icw + x
x = 0
End If
If ( y < 0 ) Then
ioy = ioy - y
ich = ich + y
y = 0
End If
' Hier...
'Log (" Debug1: " & img.c_pixels_8.Length)
des = c_pixels
src = img.c_pixels
Dim d_i, d_ii As Int
Dim s_i, s_ii As Int
s_i = ioy * sstride
d_i = y * c_w
If ( img.c_depth = 8 ) Then
'Log("image_draw: depth = 8")
' ---------------------
Dim src8() As Byte
src8 = img.c_pixels_8
'Log("img8: " & img.c_pixels_8.Length)
' ---------------------
If ( col1 <> 0 ) Then
If ( col2 <> 0 ) Then
Dim r1, g1, b1 As Int
Dim r2, g2, b2 As Int
Dim dr, dg, db As Int
Dim ooh As Int
ooh = 65536 / sh
r1 = Bit.ShiftRight(Bit.And(col1,0x00ff0000), 16)
g1 = Bit.ShiftRight(Bit.And(col1,0x0000ff00), 8)
b1 = Bit.ShiftRight(Bit.And(col1,0x000000ff), 0)
r2 = Bit.ShiftRight(Bit.And(col2,0x00ff0000), 16)
g2 = Bit.ShiftRight(Bit.And(col2,0x0000ff00), 8)
b2 = Bit.ShiftRight(Bit.And(col2,0x000000ff), 0)
dr = (r2 - r1) * ooh
dg = (g2 - g1) * ooh
db = (b2 - b1) * ooh
r1 = Bit.ShiftLeft(r1,16)
g1 = Bit.ShiftLeft(g1,16)
b1 = Bit.ShiftLeft(b1,16)
For iy = ich To 0 Step -1
Dim row_col As Int
s_ii = s_i + iox
d_ii = d_i + x
s_i = s_i + sstride
d_i = d_i + c_w
Var1 = Bit.And( r1, 0x00ff0000 )
Var2 = Bit.And( Bit.ShiftRight( g1, 8 ), 0x0000ff00 )
Var3 = Bit.And( Bit.ShiftRight( b1, 16 ), 0x000000ff )
Var4 = Bit.Or(Var1,Var2)
row_col = Bit.Or(Var4,Var3)
For ix = icw To 0 Step -1
If src8(s_ii) <> 0 Then
des(d_ii) = row_col
'Log("RowCol " & row_col)
End If
s_ii = s_ii + 1
d_ii = d_ii + 1
Next
r1 = r1 + dr
g1 = g1 + dg
b1 = b1 + db
Next
Else
For iy = ich To 0 Step -1
s_ii = s_i + iox
d_ii = d_i + x
s_i = s_i + sstride
d_i = d_i + c_w
For ix = icw To 0 Step -1
Dim c As Int
'Log ("Debug : " & src8(1))
c = Bit.And(src8(s_ii),0x000000ff)
s_ii = s_ii + 1
If ( c <> 0 ) Then
des(d_ii) = col1
End If
d_ii = d_ii + 1
Next
Next
End If ' col2 <> 0
Else
Log("image_draw:24bit: ich=" & ich & " icw=" &icw)
For iy = ich To 0 Step - 1
s_ii = s_i + iox
d_ii = d_i + x
s_i = s_i + sstride
d_i = d_i + c_w
For ix = icw To 0 Step -1
Dim c As Int
c = Bit.And(src8(s_ii),0x000000ff) : s_ii = s_ii + 1
If ( c <> 0 ) Then
' des[d_ii] = c | (c << 8) | (c << 16)
Log(" TODO!!!!!!!!!!! ")
des(d_ii) = 0
End If
d_ii = d_ii + 1
Next
Next
End If ' col1 <> 0
Else
Log("image_draw: depth = 24")
For iy = ich To 0 Step -1
s_ii = s_i + iox
d_ii = d_i + x
s_i = s_i + sstride
d_i = d_i + c_w
For ix = icw To 0 Step -1
Dim c As Int
c = src(s_ii) : s_ii = s_ii + 1
Log("C=" & c)
If Bit.And(c, 0xff000000) = 0xff000000 Then
des(d_ii) = c
Log("SetBit")
End If
d_ii = d_ii + 1
Next
Next
End If
c_pixels = des
'Log("kasldfjkejw " & des.Length)
'Dim x1 As Int
'For x1 = 0 To des.Length-1
' If des(x1) <> 0 Then
' Log(" Pixel: " & des(x1))
' End If
'Next
End Sub