Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 GreyScale Converter
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DIIST




PostPosted: Sun Dec 18, 2005 5:24 pm   Post subject: GreyScale Converter

This program converts colour images to black and white! Something i did over the weekend! Cool
code:
/*****
 Name:    Thuvarrakan Ruban
 Date:    December 18 2005
 Purpose: To convert colour images to black and white!
 *****/

proc convert (fname, save : string)
    var temp : int := Pic.FileNew (fname)
    var res : string := "graphics:" + intstr (Pic.Width (temp)) + ";" + intstr (Pic.Height (temp))

    View.Set (res)

    Pic.Draw (temp, 0, 0, picCopy)

    for x : 0 .. maxcolor /*Sets all the standard colors to shades of black for the purpose of the conversion!*/
        RGB.SetColor (x, x / maxcolor, x / maxcolor, x / maxcolor)
    end for

    for x : 0 .. maxx
        for y : 0 .. maxy
            drawdot (x, y, whatdotcolor (x, y))
        end for
    end for

    Pic.ScreenSave (0, 0, maxx - 1, maxy - 1, save)

    Pic.Free (temp)

end convert



/******************Main Program!!!*******************/
var op : int := Window.Open ("graphics:640;480,nobuttonbar,title:Black and White Conversions") /*Opens Window!*/

var fname, filesavename : string

put "Enter the name of picture file(eg,sample.jpg)"
get fname

put "Enter the name you wish to save it as (eg,thuvs.bmp)"
get filesavename


convert (fname, filesavename) /*Function Call*/


Window.Close (op)
/**************End of Main Program!!!****************/
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun Dec 18, 2005 7:49 pm   Post subject: (No subject)

I see you've modified the colour pallete. Good work! Smile

Just a note:
code:

    var pix : int:=0
    for x : 0 .. maxx
        for y : 0 .. maxy
            pix := whatdotcolor (x, y)
            drawdot (x, y, pix)
        end for
    end for

could be changed to:
code:

    for x : 0 .. maxx
        for y : 0 .. maxy
            drawdot (x, y, whatdotcolor (x, y))
        end for
    end for
DIIST




PostPosted: Sun Dec 18, 2005 9:26 pm   Post subject: (No subject)

Very Happy Thanks, i updated the file!
Shyfire




PostPosted: Sun Dec 18, 2005 11:02 pm   Post subject: (No subject)

thats awsome thanks man it will come in handy
ecliptical




PostPosted: Mon Dec 19, 2005 2:29 pm   Post subject: (No subject)

Ya good work... I would also probably remove the get statements so that you just input the files directly
code:

convert ("sample.jpg", "bwd.bmp")
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: