You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


Basic Dithering/Convert to BW
10-04-2016, 04:50 PM
Post: #1
 (Print Post)
Basic Dithering/Convert to BW
This is my simple method to convert an Image to B/W. Can someone help me doing Bayer Dithering?

_FULLSCREEN: _MOUSEHIDE: IF COMMAND$ = "" THEN Parameter$ = "earth.jpg" ELSE Parameter$ = COMMAND$
DIM SHARED VideoWidth: VideoWidth = 800
DIM SHARED VideoHeight: VideoHeight = 600
DIM SHARED PointReturn AS _UNSIGNED LONG
SCREEN _NEWIMAGE(VideoWidth, VideoHeight, 32)
Image = _LOADIMAGE(Parameter$, 32)
_PUTIMAGE (0, 0), Image: SLEEP: RenderDithering

SUB RenderDithering 'Actual Rendering!
DO
DO
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 x = VideoWidth THEN EXIT DO
LOOP
IF y = VideoHeight THEN EXIT DO
y = y + 1
x = 0
LOOP
END SUB
Find all posts by this user
Like Post
10-05-2016, 10:25 PM (This post was last modified: 10-30-2016 02:30 AM by Waltersmind.)
Post: #2
 (Print Post)
RE: Basic Dithering/Convert to BW
Aureal,

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:

Code Snippet: [Select]
_FULLSCREEN
_MOUSEHIDE

'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

REDIM MyCat(NumberOfPics)

MyImage$ = "MyCat.jpg"

SCREEN _NEWIMAGE(VideoWidth, VideoHeight, 32)
Image = _LOADIMAGE(MyImage$, 32)

_SOURCE Image

Threshold = MaxThreshold / NumberOfPics

' Create offscreen images
FOR i = 0 TO NumberOfPics - 1

   _DEST 0

   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

   _DEST MyCat(i)
   RenderDithering Red, Green, Blue, Alpha

   _DISPLAY


NEXT

_PRINTMODE _KEEPBACKGROUND

_DEST 0

_PUTIMAGE (0, 0), Image

LOCATE 15, 4: PRINT "PRESS ANY KEY TO ITERATE"
LOCATE 16, 4: PRINT "THROUGH"; NumberOfPics; "FRAMES"

_DISPLAY

SLEEP

pic = 0
picIterate = 1

_PRINTMODE _KEEPBACKGROUND


DO
   _LIMIT 10

   _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

   _DISPLAY

LOOP UNTIL _KEYHIT = 27

SYSTEM


SUB RenderDithering (Red AS _UNSIGNED _BYTE, Green AS _UNSIGNED _BYTE, Blue AS _UNSIGNED _BYTE, Alpha AS _UNSIGNED _BYTE) 'Actual Rendering!

DO
   DO
       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)
       ELSE
           PSET (x, y), _RGBA32(0, 255, 0, 128)
       END IF

       IF x = VideoWidth THEN EXIT DO
   LOOP
   IF y = VideoHeight THEN EXIT DO
   y = y + 1
   x = 0
LOOP
END SUB

Here is a screenshot of the DEMO:

   

As for the Bayer dithering... Well... That will be for another thread all together.


Walter Whitman
The Joyful Programmer


Attached File(s)
.zip  Aureal-Threshold-Demo-Modified.zip (Size: 94.35 KB / Downloads: 24)

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post
10-06-2016, 07:15 PM
Post: #3
 (Print Post)
RE: Basic Dithering/Convert to BW
Say Aureal, are you the same guy who made an interpreter for, what was it? O2 BASIC? RubenDev perhaps? Just checking.
Find all posts by this user
Like Post
05-01-2017, 02:56 PM
Post: #4
 (Print Post)
RE: Basic Dithering/Convert to BW
HI STATIC
NO i think is not ,My nick is Aurel
and i am aouthor of AurelBasic and Ruben Interpreter.
I also remember your attempt to interpreter.
Nice to find this topic and you

basicPro forum:
http://basicpro.mipropia.com/smf/index.php
EU Radioboard forum:
http://euradioboard.createmybb3.com/index.php
AurelSoft main site:
http://aurelsoft.ucoz.com
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Amazon
QB64 Member Project - Dakapo
QB64 Member Project - Overboard
QB64 Member Project - Exit
QB64 Member Project - Bowditch curve
QB64 Member Project - Point Blank
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Splatter
QB64 Member Project - Sabotage
QB64 Member Project - Spiro Roses
QB64 Member Project - Connect Four
QB64 Member Project - Color Rotating Text
QB64 Member Project - Line Thickness
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Algeria Weather
QB64 Member Project - Inside Moves
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Touche
QB64 Member Project - Color Triangles
QB64 Member Project - Pivet version one
QB64 Member Project - Swirl
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Rubix's Magic
QB64 Member Project - Input
QB64 Member Project - Qubic
QB64 Member Project - Isolation
QB64 Member Project - Martin Fractals version two
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Blokus
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Dreamy Clock
QB64 Member Project - Quarto
QB64 Member Project - Rotating Background
QB64 Member Project - Kings Court
QB64 Member Project - Score 4
QB64 Member Project - Foursight
QB64 Member Project - Domain
QB64 Member Project - Martin Fractals version four
QB64 Member Project - 9 Board
QB64 Member Project - ARB Checkers
QB64 Member Project - Kings Vallery version two
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Pivot version two
QB64 Member Project - Othello
QB64 Member Project - Basic Dithering
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Martin Fractals version one