Is this a bug?

Blitz3D Forums/Blitz3D Beginners Area/Is this a bug?

Josaih6/10(Posted 2010) [#1]
;It looks like GetColor() is alway looking at black!!!



Graphics 1000,700
Global avgRed
Global avgGreen
Global avgBlue

Const maxVary = 20

Type block
Field x,y
Field size
Field r,g,b
End Type

Global image = LoadImage("X:\100_3060.jpg")
Global iw = ImageWidth(image)
SetBuffer(ImageBuffer(image))








MakeBlocks()
Draw()
End










Function MakeBlocks()

For x = 0 To ImageWidth(image)
Cls
Locate 0,0
Print x+"/"+iw
For y = 0 To ImageHeight(image)
s = 0
GetColor(x,y)
r = ColorRed()
g = ColorGreen()
b = ColorBlue()
Repeat
s = s + 1
GetAvgs(x,y,s)
Color 255,255,255
Print GetColorDif(avgRed,avgGreen,avgBlue,r,g,b)+" at "+s +"|orig rgb: "+r+","+g+","+b+"|"+s+":"+avgRed+","+avgGreen+","+avgBlue+"| x,y:"+x+","+y
If s = 10 Then Stop
If GetColorDif(avgRed,avgGreen,avgBlue,r,g,b) >= maxVary Or CheckOverlap(x,y,s) Then Exit
Forever
l.block = New block
l\x = x
l\y = y
l\r = avgRed
l\g = avgGreen
l\b = avgBlue
l\size = s - 1
If y = 10 Then Stop
Next
Next

End Function






Function GetAvgs(x1,y1,s)

For x = x1 To x1 + s
For y = y1 To y1 + s
GetColor(x,y)
r = r + ColorRed()
g = g + ColorGreen()
b = b + ColorBlue()
Next
Next
avgRed = r/(s^2)
avgGreen = g/(s^2)
avgBlue = b/(s^2)


End Function







Function GetColorDif(r1,g1,b1,r2,g2,b2)

r = Abs(r1-r2)
g = Abs(g1-g2)
b = Abs(b1-b2)
Return r+g+b

End Function








Function CheckOverlap(x,y,s)

For b.block = Each block
If RectsOverlap(x,y,s,s,b\x,b\y,b\size,b\size) Then Return True
Next
Return False

End Function







Function Draw()

bImage = CreateBlockImage()
DrawImage image,0,0
WaitKey()
DrawImage bImage,0,0
WaitKey()

End Function






Function CreateBlockImage()

blockImage = CreateImage(ImageWidth(image),ImageHeight(image))
SetBuffer(ImageBuffer(blockImage))
For b.block = Each block
Color b\r,b\g,b\b
Rect(b\x,b\y,b\size,b\size)
Next
Return blockImage

End Function


Matty(Posted 2010) [#2]
Considering you never draw to the backbuffer, and never flip the backbuffer into view, it's not surprising you don't see anything.

I had a brief look over your code, but couldn't quite work out what you were trying to do?


Charrua(Posted 2010) [#3]
hi

you do a "CLS" inside the MakeBlocks that result in ImageBuffer cleared!

Juan


Josaih6/10(Posted 2010) [#4]
Thanks Charrua. I thought Cls would clear the screen, not the current buffer.

Sorry Matty, I should have said what I was doing. In short, I'm trying too make an image compressor. I saw pretty early that it wasn't going to save much (if any) space but wanted to finish it just for the fun of it. Before I made my own format however, I wanted to make sure it looked alright.