how do i display a grayscale image ?

This is a discussion on how do i display a grayscale image ? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I have a grayscale image in the ".raw" file format. How do i display it under DOS using C? I ...

  1. #1
    Unregistered
    Guest

    Question how do i display a grayscale image ?

    I have a grayscale image in the ".raw" file format. How do i display it under DOS using C? I need a graphics mode where i have a 0-255 levels of pixel intensities.
    The image is to b displayed on a SVGA console.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    reply

    If 64 levels of gray is enough, mode 13 (VGA) is pretty easy to use. See the links section for tutorials.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    I need a graphics mode where i have a 0-255 levels of pixel intensities.
    No you don't. To convert from 24 bit to 8 bit color you would shift every value right by 3. Can be done for 16 bit RAW also.

    This way you could display the image in it's native 24-bit or in 16-bit, 256 color mode (13h).

    Since it's grayscale, you won't lose much image quality in the conversion. Also since grayscale is just equal r,g,b, mode 13h would provide every greyscale color possible since it has 256 palette entries and the max value for any one color in 24 bit is 255. Each palette entry would represent one of the r,g,b greyscales in 24-bit.

    You would have to parse the data and when the data is diff than any previously encountered, increment the palette index and shoot the RGB values shifted right by 3 to the ports to change the palette.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    reply

    Just a comment:

    You cannot use 255 levels of gray in mode 13, I have tried that . Only 64.
    If you set the palette to R=G=B=PaletteIndex, you will get Black->Gray->White in index 0-63, then it will start over in index 64-127, 128-191 and 192-255.
    Why? I don't know, maybe someone else do...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    Yes, I know. The bit depth for the colors in mode 13 is not 8, it is 6. You will get an approx. of those 255 colors when you convert them to the right format.

    You could also use linear interpolation on the colors to get an approx of the greyscale image

  6. #6
    kp
    Guest
    Thanks Magos and Bubba for your replies. I was the one who started this thread (though i was unregistered at that time).
    Unfortunately, i was off the problem for nearly a week.
    Now, i am back on it, but am right where i left.
    I am using the 13h mode of VGA. It offeres 256 colors, out of which i observed that only 16 are gray(16-31). So, that leaves with me a graylevel of 16.
    Going frm a 256 depth to 16 depth image is quite some degradation. Could you elaborate on how to get 64 (or preferably 256 ) gray levels.
    maybe i need only to change the palette in 13h mode ? but if so, how do i do that ?
    in 13h, i guess there r no RGB values - its just 1 byte of colorvalue for a pixel.

  7. #7
    kp
    Guest
    One more thing...if 256 gray levels are possible with SVGA programming...do tell me about that.

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    reply

    Originally posted by kp
    Going frm a 256 depth to 16 depth image is quite some degradation. Could you elaborate on how to get 64 (or preferably 256 ) gray levels.
    maybe i need only to change the palette in 13h mode ? but if so, how do i do that ?
    In the links section, there is a link to www.brackeen.com where you can find some really good mode 13 tutorials. One of them covers palette manipulation. Sorry, but I have no experience with SVGA however...
    Originally posted by kp
    In 13h, i guess there r no RGB values - its just 1 byte of colorvalue for a pixel.
    That's right, they use a palette to store the RGB data instead of storing the RGB value for each pixel. You get lesser colours, but it saves memory! That is one reason why this graphics mode is "easy" to use...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    kps
    kps is offline
    Registered User
    Join Date
    Jan 2002
    Posts
    3
    hey..thanks Magos. that was a great link. i adjusted the palette, and now...as u already told me of the limitation...i have a 64 gray level display. though this might do...but can i push my luck further ? any chance of getting a 256 level display ?
    Bubba, you said something about 'converting to the right format'..cud u plz elaborate on that ?
    one thing more ....while in the 13h VGA mode only...i want some formatted text display. like i want a string to be displayed at the bottom of the screen. how do i achieve that ?
    and thanks again for all ur effort. i won't have got the display working without ur help.

  10. #10
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    reply

    Originally posted by kps
    hey..thanks Magos. that was a great link. i adjusted the palette, and now...as u already told me of the limitation...i have a 64 gray level display. though this might do...but can i push my luck further ? any chance of getting a 256 level display ?
    Not in mode 13, I believe. You have to learn SVGA . Try a search on google, or search for SVGA on the forum.

    Bubba, you said something about 'converting to the right format'..cud u plz elaborate on that ?
    one thing more ....while in the 13h VGA mode only...i want some formatted text display. like i want a string to be displayed at the bottom of the screen. how do i achieve that ?
    There are no standard function that prints good-looking text in mode 13. You could use printf(), however the result is not so good . The best would be to build your own function that loads a bitmap (containing all the letters) and draw them to the screen.

    and thanks again for all ur effort. i won't have got the display working without ur help.
    Glad I could be of help.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  11. #11
    Unregistered
    Guest
    You can try 0x10F mode from the VESA standard - this is 320x200x32 mode and you will get all the 256 levels of gray.

    regards,
    Bojidar

  12. #12
    Unregistered
    Guest
    Most cards do not support 320x200 hi-color modes

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. display image name
    By shamee_banu in forum Windows Programming
    Replies: 1
    Last Post: 06-29-2007, 12:13 PM
  3. Hi, how to convert a grayscale image into 8 bit image?
    By Alexanderbinich in forum C++ Programming
    Replies: 3
    Last Post: 03-15-2005, 06:50 PM
  4. Linux framebuffer; display an image
    By bludstayne in forum Tech Board
    Replies: 1
    Last Post: 03-29-2004, 01:50 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21