#### Archived

This topic is now archived and is closed to further replies.

# how to make a raw file

## Recommended Posts

jerry2    122
as we all know,we use raw to store the little-volume pic.but i don''t know the answer to a basic problem.i can find a tutorial about raw-loading easily ,but i still don''t how i can make a raw file.it is binary stream,but if i can get just change the filename to carry my point?or there is some way for us to make a bmp(or jpeg etc.)into raw? i know this question may be a bit stupid,but i really want to know the answer.thank u. jerry2 Programming,make a whole new world.

##### Share on other sites
David_Kay    122
To answer your questioon, yes it is possible. Find the format of a bitmap or jpeg, load it up and then extract the actual pixel data values.

##### Share on other sites
invective    118
Raw files are just a byte dump, so a 24bit rgb image is a list of width*hieght*3 bytes. To find any pixel in the file, it starts at x*width+y*width*3 and spans 3 bytes: 1 byte red, 1 byte green, 1 byte blue. Photoshop saves straight into raw. The easiest way to get raw data otherwise is from a 24 bit uncompressed bmp file -- just strip off the BITMAPFILEHEADER and BITMAPINFOHEADER and the rest of the data are the pixels.
Example, a 50x100 24 bit image is:
50x100x3 bytes in size.
pixel (1,1) is located at offset 1*3+1*50*3.

  char* buffer = new char [width * hieght *bytesPerPixel];std::ifstream file;file.open (filename, std::ios::binary );file.read ( (char *)buffer, width * hieght *bytesPerPixel);file.close();

convert bmp to raw:
  char* buffer = new char [width * hieght *bytesPerPixel];std::ifstream file;file.open (filename, std::ios::binary );//trash the headersfile.read ( (char *)buffer, sizeof(BITMAPFILEHEADER) );file.read ( (char *)buffer, sizeof(BITMAPINFOHEADER) );file.read ( (char *)buffer, width * hieght *bytesPerPixel);file.close();std::ostream output;output.open (filename, std::ios::binary );output.write ( (char *)buffer, width * hieght *bytesPerPixel);output.close ();

##### Share on other sites
Guest Anonymous Poster
www.wotsit.org

##### Share on other sites
jerry2    122
to David_Kay:

thanks,i have knowed the true concept of the raw.

to invective:

excuse me,u mean we can use photoshop to create raw directly?

to Anonymous Poster:

ok.thanks for yr url.

jerry2
Programming,make a whole new world.

##### Share on other sites
invective    118
yes. just choose file->save as, and change the type to raw -- i suggest you do image->mode->grayscale first, so you get only 1 byte per pixel or image->mode->RGB if you want 3 bytes per pixel. Photoshop will prompt you for a header when you want to save -- just ignore it and hit ok.

##### Share on other sites
GoofProg    127
Remember .RAW files can get very big in size, but then again.. most people have +4GB hard drives =).

##### Share on other sites
jerry2    122
to invective:

thanks for yr help,i have understood all these completely.

to GoofProg:

do u mean raw isn''t a good file format for game?but what kind of format is more suitable?

jerry2
Programming,make a whole new world.

##### Share on other sites
invective    118
If you are concerned about file size, consider PNG files (you can make these in photoshop too and they have good lossless compression). You can find code to support PNG here: http://libpng.sourceforge.net/

##### Share on other sites
jerry2    122
OK.thank u.

then i have aother question,which format is the most popular,or the perfect(combination of size,quality and feature) one nowadays?

jerry2
Programming,make a whole new world.

##### Share on other sites
Guest Anonymous Poster
Targa (tga), is quite good, check that out

##### Share on other sites
jerry2    122
i know it,maybe it''s the most wonderful?

jerry2
Programming,make a whole new world.

##### Share on other sites
invective    118
It depends what you are doing. JPG gives you the smallest files (usually), but it uses lossy compression and has no alpha support, and is complicated to encode/decode. PNG has lots of features including alpha support and lossless compression. BMP is usually the easiest to output for screen captures, since BITMAPINFOHEADER AND BITMAPFILEHEADER are defined for you as structs by windows, and the rest of the file is just a 24 bit byte dump.

It depends what is important to you: aplha channels, easy of reading/writing, file size, loading speed, etc.

In any case I vote for one of the above three formats, usually choosing PNG over TGA.

##### Share on other sites
jerry2    122
yep.i c.

thanks

jerry2
Programming,make a whole new world.