Displaying image (in raw format)
hey..
i am using C++ (wxWindows for GUI)--I have an image file in RAW format ...i have read the file into a 2-D array,
how that data is to be used to display the image on a control?
thanks
[211 byte] By [
ali_5680] at [2007-11-20 11:45:17]

# 1 Re: Displaying image (in raw format)
The first question that comes to my mind is, do you understand the format of each pixel in that raw image data?
Raw images aren't formally standardized, though most are along the lines of 24 bit pixels (8 bits per channel), but they can be 16 bits per channel or even floating point. They could even by non RGB.
The basic plan would be to create a wxImage object, initialize to an appropriate size, use the GetData member function of wxImage to get a pointer to the pixel data and copy the pixels into position with whatever color conversion is required.
If, for example, your source image is RGB 8 bits per channel, you have very little work to do other than ensuring the order of the color channels matches (some, occasionally, could be BGR, and there could be an alpha channel).
In other words, this isn't the most complicated thing to do, but you'll need to research a little on the colorspace conversion (if any), and experiment with wxImage. After that, widgets is fairly good about converting the wxImage to a wxBitmap which can be displayed as a DIB using blits.
JVene at 2007-11-9 13:32:55 >

# 2 Re: Displaying image (in raw format)
you will have to make a bitmap and then load that into a DC.
wxBitmap::Create
virtual bool Create(void* data, int type, int width, int height, int depth = -1)
"Creates a bitmap from the given data, which can be of arbitrary type."
wxDC::DrawBitmap
void DrawBitmap(const wxBitmap& bitmap, wxCoord x, wxCoord y, bool transparent)
"Draw a bitmap on the device context at the specified point. If transparent is true and the bitmap has a transparency mask, the bitmap will be drawn transparently."
look here:
http://www.wxwidgets.org/manuals/2.6/wx_wxbitmap.html#wxbitmapcreate
edit: you might have to pad out your image array rows to multiples of 4 bytes in order to display the bitmap correctly?
# 3 Re: Displaying image (in raw format)
Thanks for your replies
@Loki
My application is ok with bmp, jpg images but stuck with .raw
I am reading the data into a 2d array of unsigned char
then I am trying to use to create image
wxImage(int width, int height, unsigned char* data, bool static_data = false)
i am declaring array as:
unsigned char *pixevalues[rows][cols]
user slelcts the file through the GUI --the data is read through a fstream object opened for input
fstream rawimage;
rawimage(filename, ios::in) ///filename got through the File open dialog box
then with a nested for loop the data is read into the array
rawimage>>pixelvalues[rows][cols]
it compiles ok but the problem is that whenever the pogram is run it throws an exception--maybe because the data is not being read into the array...i am confused because apparently above code worked well when i tried it in a separate program with just cout statements. kindly check the code is there something wrong with declaration etc. any help will be appreciated
thanks
# 4 Re: Displaying image (in raw format)
You'll need to post code for us to check into :)
JVene at 2007-11-9 13:35:56 >

# 5 Re: Displaying image (in raw format)
@Loki
My application is ok with bmp, jpg images but stuck with .raw
i realised that - what i mean is that you will have to create your own image handler to read the pixel information from the RAW format and create a bitmap to display.
windows can only display bitmaps, it is just that your jpg handler is already written for you :)
# 6 Re: Displaying image (in raw format)
hey,
this is the code for file open and for the images it is one-byte unsigned integer per pixel,
void MyFrame::OnOpenFile(wxCommandEvent & event){
unsigned char *pixelval[row][col]; //2D array to read data
wxFileDialog *openFileDialog = new wxFileDialog ( this, _T("Open file"), _T(""), _T(""), FILETYPES, wxOPEN, wxDefaultPosition);
if(openFileDialog->ShowModal() == wxID_OK){
wxString filename = openFileDialog->GetFilename();
wxString path = openFileDialog->GetDirectory() + wxString(_T("/"));
if(filename==_T("test.raw");
{
fstream rawimage;
rawimage(filename, ios::in);
//then with a nested for loop the data is read into the array
for(row=0; row<256;row++)
{
for(col=0; col<256;col++)
{
rawimage>>pixelvalue[row][col];
}
}
rawimage.close();
}
//create image
loadedImage = wxImage(int width, int height, pixval[row][col], bool static_data = false);
if(loadedImage->Ok()){
//Refresh();
}
else {
loadedImage->Destroy();
loadedImage = 0;
}
Refresh();
}
}
# 7 Re: Displaying image (in raw format)
should it not be:
//width and height must first be obtained from somewhere
//unless they are 256 as your loop suggests?
int width, height;
width = height = 256;
unsigned char pixelval[width][height];
...
for(row=0; row<width;row++)
{
for(col=0; col<height;col++)
{
rawimage>>pixelvalue[row][col];
}
}
rawimage.close();
}
# 8 Re: Displaying image (in raw format)
i would give up if i were you..
according to wiki:
"There is still no widely accepted standard raw format. Adobe's Digital Negative (DNG) format has been put forward as a standard, but has not been adopted by major camera companies. Numerous different raw formats are currently in use and new raw formats keep being developed while others are orphaned.
Because of the lack of a standard raw format, more specialized software may be required to open raw files than for standardized formats like JPEG or TIFF. Software vendors are also having to frequently update their products to support the raw formats of the latest cameras."
one is described here:
http://download.oracle.com/docs/html/B14297_01/ap_imgraw.htm
# 9 Re: Displaying image (in raw format)
size of the image is known
thanks for the link but but last question:) what could be the reason for data not being read into the array?
include "fstream"
ifstream rawimage;
rawimage(filename, ios::in);
.....
rawimage>>pixelvalues[row][col]
thanks
# 10 Re: Displaying image (in raw format)
size of the image is known
thanks for the link but but last question:) what could be the reason for data not being read into the array?
include "fstream"
ifstream rawimage;
rawimage(filename, ios::in);
.....
rawimage>>pixelvalues[row][col]
thanks
see above, you have originally delared the array as an array of pointers:
unsigned char *pixelval[row][col]; //2D array to read data
# 11 Re: Displaying image (in raw format)
I have tried that but still there is problem
thanks
# 12 Re: Displaying image (in raw format)
I have tried that but still there is problem
thanks
can you be more specific?
do you know what data you are expecting? as far as i know, none of the *.RAW formats will have pixel data in their data part.
have you had a look at the file in a binary data viewer?
# 13 Re: Displaying image (in raw format)
thanks
this problem :)is solved