I've converted this processing example to PB, but for the life of me cant figure out why it wont work as expected.
Code: Select all
UseJPEGImageDecoder()
ExamineDesktops():InitSprite():InitKeyboard()
OpenWindow(0,DesktopWidth(0)/2-400,DesktopHeight(0)/2-300,800,600,"Demo")
OpenWindowedScreen(WindowID(0),0,0,800,600)
Global image = LoadImage(#PB_Any,"kitten.jpg")
Global copimg = CopyImage(image,#PB_Any)
Global Dim image.i(ImageWidth(image),ImageHeight(image))
Procedure ImageToArray()
fact.i = 1
; fill array
StartDrawing(ImageOutput(image))
For y = 0 To ImageHeight(image)-2
For x = 1 To ImageWidth(image)-2
image(x,y) = Point(x,y)
Next
Next
StopDrawing()
StartDrawing(ImageOutput(copimg))
For y = 0 To ImageHeight(copimg)-2
For x = 1 To ImageWidth(copimg)-2
col.i = image(x,y)
oldr.f = Red (col)
oldg.f = Green (col)
oldb.f = Blue (col)
newr.i = Round(fact * oldr / 255,#PB_Round_Nearest )*(255/fact)
newg.i = Round(fact * oldg / 255,#PB_Round_Nearest )*(255/fact)
newb.i = Round(fact * oldb / 255,#PB_Round_Nearest )*(255/fact)
image(x,y)=RGB(newr,newg,newb)
errr.f = oldr - newr
errg.f = oldg - newg
errb.f = oldb - newb
c.i = image(x+1, y )
r.f = Red(c)
g.f = Green(c)
b.f = Blue(c)
r = r + errr * 7/ 16.0
g = g + errg * 7/ 16.0
b = b + errb * 7/ 16.0
image(x+1,y) = RGB(r,g,b)
c = image(x-1,y+1)
r = Red(c)
g = Green(c)
b = Blue(c)
r = r + errr * 3/ 16.0
g = g + errg * 3/ 16.0
b = b + errb * 3/ 16.0
image(x-1,y+1) = RGB(r,g,b)
c = image(x,y+1)
r = Red(c)
g = Green(c)
b = Blue(c)
r = r + errr * 5/ 16.0
g = g + errg * 5/ 16.0
b = b + errb * 5/ 16.0
image(x,y+1) = RGB(r,g,b)
c = image(x+1, y+1 )
r = Red(c)
g = Green(c)
b = Blue(c)
r = r + errr * 1/ 16.0
g = g + errg * 1/ 16.0
b = b + errb * 1/ 16.0
image(x+1,y+1) = RGB(r,g,b)
Next
Next
StopDrawing()
EndProcedure
Procedure UpdateImage()
StartDrawing(ImageOutput(copimg))
For y = 0 To ImageHeight(copimg)-1
For x=0 To ImageWidth(copimg)-1
Plot(x,y,image(x,y))
Next
Next
StopDrawing()
EndProcedure
Procedure UpdateScreen()
ClearScreen(0)
; draws the copy image
StartDrawing(ScreenOutput())
DrawImage(ImageID(copimg),0,0)
StopDrawing()
FlipBuffers()
Delay(1)
EndProcedure
ImageToArray()
UpdateImage()
Repeat
event=WaitWindowEvent()
ExamineKeyboard()
UpdateScreen()
Until KeyboardPushed(#PB_Key_Escape)
The output should be dithered like so (ignore the greyscale) :
Here is what I get
Link for the kitten image https://github.com/CodingTrain/website/ ... kitten.jpg
Cheers!