Basic Dithering/Convert to BW - Waltersmind - 10-05-2016 10:25 PM
That is a really cool threshold demo. Thank you for sharing.
There is a code box feature you can use to place any source code in. This helps in not only viewing the code better since it uses a source code font, but it allows quick and easy selecting of all the code. You can see this feature below.
Since you did not share any images to use with the source code, I had to use my own, which is fine, but many people will not take the time or effort to try out a demo, which is sad, but I have seen it.
I found the perfect image to us in your demo that contains lighting from light to dark. It is an photo of a cat I had a few years back until she passed away. This was one of the best pictures I had taken of her. Her name was Halo.
I decided to share my picture so it could be used in your demo, and since I did, I went a step further. I modified your demo a slight bit to show how rotating through some threshold values would look animated.
You can download the source code and photo below in the *.ZIP file, but here is the modified code so you can quickly see it with downloading it first:
'IF COMMAND$ = "" THEN Parameter$ = "earth.jpg" ELSE Parameter$ = COMMAND$
DIM SHARED VideoWidth
DIM SHARED VideoHeight
DIM SHARED PointReturn AS _UNSIGNED LONG
REDIM MyCat(-1) AS _UNSIGNED LONG
DIM Threshold AS _FLOAT
DIM NumberOfPics AS _UNSIGNED INTEGER
DIM MaxThreshold AS _UNSIGNED INTEGER
DIM Red AS _UNSIGNED _BYTE
DIM Green AS _UNSIGNED _BYTE
DIM Blue AS _UNSIGNED _BYTE
DIM Alpha AS _UNSIGNED _BYTE
VideoWidth = 800
VideoHeight = 600
NumberOfPics = 60 '32
MaxThreshold = 256
MyImage$ = "MyCat.jpg"
SCREEN _NEWIMAGE(VideoWidth, VideoHeight, 32)
Image = _LOADIMAGE(MyImage$, 32)
Threshold = MaxThreshold / NumberOfPics
' Create offscreen images
FOR i = 0 TO NumberOfPics - 1
LOCATE 18, 35
PRINT "Rendering MyCat Image:"; i; " / "; NumberOfPics
MyCat(i) = _NEWIMAGE(800, 600, 32)
Red = (NumberOfPics - 1 - i + 1) * Threshold - 1
Green = (NumberOfPics - 1 - i + 1) * Threshold - 1
Blue = (NumberOfPics - 1 - i + 1) * Threshold - 1
Alpha = 255
RenderDithering Red, Green, Blue, Alpha
_PUTIMAGE (0, 0), Image
LOCATE 15, 4: PRINT "PRESS ANY KEY TO ITERATE"
LOCATE 16, 4: PRINT "THROUGH"; NumberOfPics; "FRAMES"
pic = 0
picIterate = 1
_PUTIMAGE (0, 0), Image
_PUTIMAGE (0, 0), MyCat(pic)
LOCATE 15, 4: PRINT "PRESS <ESC> TO EXIT";
LOCATE 16, 4: PRINT "Pic #:"; pic; "/"; (NumberOfPics - 1);
pic = pic + picIterate
IF pic < 1 OR pic > NumberOfPics - 2 THEN picIterate = -picIterate
LOOP UNTIL _KEYHIT = 27
SUB RenderDithering (Red AS _UNSIGNED _BYTE, Green AS _UNSIGNED _BYTE, Blue AS _UNSIGNED _BYTE, Alpha AS _UNSIGNED _BYTE) 'Actual Rendering!
x = x + 1
PointReturn = POINT(x, y)
'IF PointReturn < 4289243304 THEN PSET (x, y), _RGB32(0, 0, 0) ELSE PSET (x, y), _RGB32(255, 255, 255)
IF PointReturn < _RGBA32(Red, Green, Blue, Alpha) THEN
PSET (x, y), _RGBA32(0, 0, 0, 0)
PSET (x, y), _RGBA32(0, 255, 0, 128)
IF x = VideoWidth THEN EXIT DO
IF y = VideoHeight THEN EXIT DO
y = y + 1
x = 0
Here is a screenshot of the DEMO:
As for the Bayer dithering... Well... That will be for another thread all together.
The Joyful Programmer