Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to display a greyscale raw image (*.raw) in vc++?

Posted on 2003-02-22
4
Medium Priority
?
551 Views
Last Modified: 2011-09-20
I am doing a project that needs to display image of raw format (*.raw) in VC++. It seems it is necessary for creating image header for display in Bitmap format.

I am just a student and the problem has not yet been solved for a long time. Could anyone help me to solve it? Thanks.
0
Comment
Question by:wesker
3 Comments
 
LVL 12

Accepted Solution

by:
Salte earned 150 total points
ID: 7998342
greyscale isn't that difficult.

I assume it is (at most) 8 bit per pixel and thus maximum 256 different greyscale tones.

If so you can easily make a bitmap file.

Open a file as binary file:

write the bitmap file header and the bitmap header (both of them). specify 8 bit per pixel and specify as many colors as you have greyscale tones.

write a palette.

THe lowest index (index 0) of the palette should be the color RGB = (0,0,0);

The highest index of the palette should correspond to white color: RGP (255,255,255);

Then do something like this:

if you use 64 grey scale tones then you have values in the range 0-63 with 0 meaning black and 63 meaning white.
Index 0 and 63 has already been placed, insert all the greyscale tones in between, RGB = (x,x,x) where each x is a one byte value that is computed based on your n-bit value (n <= 8). This is probably best done by extended the missing bits if any with all zeroes. Note that the white color will have all bit set instead and so the distance between 62 and 63 is larger than between 48 and 49 in the tones. That shouldn't be noticable though.

Just make sure that the highest greyscale tone is 255,255,255.

Grey scale values are all values with RGB = (x,x,x);

Once you have made the palette you can build the image in such a way that it will fit in a bit map.

Just copy pixel by pixel. Use one byte per pixel in the bitmap. Not sure how many bits per pixel in the .raw file and not sure about the format there but you probably know that.

.bmp files have their image stored as an array of lines. There are H lines where H is the height of the image.

Each line have room for W pixels where W is the width. However, a line is always a multiple of 4 so if the width is not a multiple of 4 there are some extra bytes at the end of the line which is ignored as far as displaying the image but they are used to align the next line on a 4 byte boundary. For example if width is 41 you get 3 bytes extra so the line length is 44 bytes.

line_length = (width + 3) & ~3;

can be used to compute the length of a line given the width. This assumes 8 bits per pixel. If you use 3 bytes per pixel it would be (width * 3 + 3) & ~3; instead.

All the pixels are stored left to right in a line. Byte by byte. Place the palette indices for that color. The way the palette was made, the palette index is the same as the greyscale tone and so that pixel value should be easy.

Then save the palette and image after the headers and the file is complete.

Alf
0
 

Author Comment

by:wesker
ID: 7998935
Hi Alf,

Thank you very much for your detailed explanation!
I can get some idea how to do now. But, could you mind explaining more on how to code the data from *.raw format to RGB(x,x,x) and the palette? I am a VC++ beginner and don't know how to build such program from zero. Thanks.

Cheers,
Wesker.
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9784164
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered: Points to Salte

Please leave any comments here within the next seven days. Experts: Silence
means you don't care.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question