|
Going to roll your own loader? Cool project.
Lots of useful info can be obtained and/or linked to from here: JPEG Homepage[^]
You'll probably need to understand the JFIF file format and the compression itself.
Enjoy!
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
|
Hi,
thanks a lot for the links. but, cant i directly load like any other file using fopen command in C or similar commands? does it require a library separately for definite??
thanks a lot,
-cedance
|
|
|
|
|
You can easily open the file and read the data, the problem comes if you want to display the picture on the screen / printer etc. Here you need a bitmap.
Assume that the picture that the jpg represents was taken with 24 bit colour - this means that each pixel was represented by 24 bits. Saving all this information to a file results in LARGE files. The jpg format is a lossy compression format that allows you to store the picture at around 2 bits/pixel or less (1.5 - 2 bits per pixel usually results in a picture indistinguishable from the original). What is stored is a whole bunch of fourier coefficients and some tables of quantization levels. Basically you have to invert a lot of fourier cosine transforms to recover the original bitmap. If you know what I'm talking about then you should be able to do the decoding from the spec, if not, read up on it before you decide to start.
Sorry - I just re-read your original post - seems like you do understand about FFTs , so if you understand C you can do exactly the same in C++ as this is generally a superset of C. You can use fopen and read the file into a buffer. There are a bunch of C++ things you could do depending on your application, but as far as getting the contents of the file into a buffer, they are not significantly better.
|
|
|
|
|
hi cp9876
thanks a lot for ur quick reply. i guess you misunderstood my question, reg. your explanation in the second paragraph. i already have written the code for fft both decimation in time and frequency in matlab. i was told by my professor to create a stand alone application using VC++ which i am not familiar to that extent. i have done a bunch of usual programs with C++ thats it! and i have loaded the jpeg files in C++ for these stuffs before but dont remember how i did it, nor do i have the source code of those now with me! i can write the program from matlab to C, not a big issue i guess, i know the algorithm... all i need to do is create an application that loads an image and calculates the fft and ifft.
i needed the syntax for that fopen to read jpg files into the buffer exactly... can you tel me where i can find them or can u post it here??
thanks a lot,
-cedance
|
|
|
|
|
I guess your problem is not with the syntax for using fopen or CFile (if it is you can easily find this in MSDN), but once you have the handle to the file how you unpack the information - the detailed file format to put into your arrays and tables. Can't help you here, however a quick google on "reading jpeg files" threw up links to standards and some open source software that does what you want (even a C++ one) - should be a good place to start.
|
|
|
|
|
JPEG is a compression scheme, not a file format. JPEG File Interchange Format (JFIF) is a file format commonly used for storing and transferring images that have been compressed according to the JPEG scheme.
For displaying the image you need to first decompress the image.
|
|
|
|
|
Hi,
I am not sure if I explained it right... sorry for the confusion. Like that of *.bmp images, there are *.jpg images right? My question is, how will one load this *.bmp or *.jpg picture file into an array for further processing in C/C++?? I need to say, construct a Gaussian filter or median filter or whatever, for further processing like blurring, etc... contrast, or take the FFT of the image, in this case... And then, I have to store the values obtained in a file. If it could be stored as a picture back itself, then fine, otherwise, please specify how to do it.
Its like, after calculating the fft, i run the filters from the fft obtained results, like bessel or gaussian filters and then restore the modified (blurred, in this case) image. This is what i hav to do. In case I made some mistakes in explaining here too, please specify.
thanks,
-cedance
|
|
|
|
|
So you want to load and decompress the image, and THEN do some processing on the pixels?
The CImage class can help
#include <atlimage.h>
...
CImage image;
image.Load("C:\\TEST.JPG");
Then you can use
image.GetWidth()/image.GetWidth() to get the image dimensions in pixels
image.GetBPP() to get the bits-per-pixel
image.GetPitch() to get the bytes-per-row in the pixel data
image.GetBits() to get a pointer to the RGB pixel data
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Hi Mark,
thanks a lot. Will try this one...
regards,
-cedance
|
|
|
|
|
Hi,
My understanding of your query is as follows::
You need to do some processing on the image (raw bits that means pixel values). Now you have the .jpeg image file, a compressed file. so first you need to extract the pixel values from jpeg file. As jpeg file is compressed file first you need to decompress using decompression logic.
Please refer http://www.faqs.org/faqs/jpeg-faq/part2/section-15.html[^]
Regards,
Paresh.
|
|
|
|
|
Hi paresh,
I understood finally what you mean. And thanks a lot for your link. If i have to get the pixel values from the jpeg file, then i will have to go thro the set of operations instructed by the jpeg manual to get them from the compressed jpeg file format... hope i got u right this time. Will try to do it this way too. Thanks a lot again!! this forum rocks!!
regards,
-cedance
|
|
|
|
|
You are most Welcome .
Regards,
Paresh.
|
|
|
|
|
I think I answered your query.
Regards,
Paresh.
|
|
|
|
|
Hello all,
This morning I've found something interesting: a boolean that works perfect in all the application but it fails in just one function. Just before going deeper, I know that this is impossible, so I think that I'm missing something or I'm completely stucked on that code and I cannot see why do this is happening.
Let me explain that a little bit more:
1. I have 6 instances of one class that inherits from a MSChart.
2. That class has a private boolean member "m_bGraficaTempsReal"
3. That class has a public member function that returns the value of that private boolean member.
4. That class also has a public member function that modifies the value of that private boolean member.
I've been using AfxTrace in order to know the value of that boolean along the program code (spreading it along the code itself).
Each time I click a MSChart the event that is generated is handled by the respective OnClick message handler. Then is when I call the public function that set the value of that boolean variable, in fact I'm doing this: m_bGraficaTempsReal = !m_bGraficaTempsReal; and after that I've placed one AfxTrace call in order to see if everything has gone right. Of course the value is changed only each time that I click on that graph and each time I click on it only one ONCLICK message is generated so only one time the boolean variable gets modified.
In other parts of the application I'm using the function that returns the value of that boolean variable successfully. I mean that I know the value of that variable and everything is reacting in the way it should. So in other parts of the application I know the right value of the boolean variable.
Well, I also have one OnTimer that is called each 500 milliseconds.
Inside that Ontimer I call SetValor, that is a function that modifies the value of a bar of the graph. I'm passing some parameters to that function: the number of the bar that I'm modifying, the value that I want to place there and if I want to write the little label that is in the bottom of the graph again.
Inside the SetValor function, I'm using this code:
CString buf = "";<br />
if (m_bGraficaTempsReal)<br />
{<br />
buf.Format("U%i-%.0f", iBar+1, m_vfData[iBar]);<br />
}<br />
else<br />
{<br />
buf.Format("C%i-%.0f", iBar+1, m_vfData[iBar]);<br />
}<br />
AfxTrace("\n\nBOOL VALUE: %i",m_bGraficaTempsReal);<br />
As you can see I've placed another AfxTrace in order to see which is the value of that variable at that moment.
Well this is my surprise, I'm modifying only the value of that variable in the OnClick event, and I'm clicking it only one time, and I see how the variable changes it's value.
The OnTimer is also dependant and that variable, so SetValor is not being called unless the boolean variable has the right value (false), so if the function is getting called I must understand that the value is false, but I cannot understand why do the CString buf starts always with "U".
What could you recommend me in order to find out what is happening here?
Thank you in advance, an please excuse me for this large post.
|
|
|
|
|
m_bGraficaTempsReal is initialized? To what?
If it starts as false, and you only click once, won't it be true from then on?
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Of course you are right, that variable is initialized to "true".
But then, in all the application I'm using the value of that variable to fill up the MSChart values, and depending on that value the data come from different sources.
Again, each time I click on the MSChart object I can see how the data changes (the values that fill the MSChart change as they came from different places). That data is filled from an external OnTimer event that checks the value of the boolean variable m_bGraficaTempsReal. Then, if the data insertion changes correctly, and it depends on that boolean value, I do not understand how do the string is not changing.
So the bool variable is initialized, but then the user can click several times to the MSChart object in order to change the values it represent. I'd love to be able to change the labels on each bar of the graph in order to show a change.
Thank you for your feedback.
|
|
|
|
|
hmm...going back to your original post...
Joan Murt wrote: The OnTimer is also dependant and that variable, so SetValor is not being called unless the boolean variable has the right value (false), so if the function is getting called I must understand that the value is false, but I cannot understand why do the CString buf starts always with "U".
Something strange there - If you put a breakpoint at the decision code and a breakpoint in
SetValor then the value should be the same. Is it?
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Yes, this is the strangest thing I've ever seen programming, it should be the same value, but mysteriously it isn't.
I must be making something extremely incorrect, but I cannot find it.
I cannot understand how, if inside the OnTimer event I call SetValor and the code is this:
if (boolvar)<br />
{<br />
SetValor(...<br />
}
Then when I'm inside the function I see the code entering in the first code:
if (!boolvar)<br />
{<br />
FIRST CODE<br />
}<br />
else<br />
{<br />
SECOND CODE<br />
}
This is incredible and I have no clue on how to change that.
Moreover, as I was explaining in the first post, that value is not being changed anywhere else, it only changes after one click in the MSChart object.
[Mod]
Sorry, I've missed to say Thank you!
[/Mod]
|
|
|
|
|
I'm losing sleep over this...
Sorry in advance about the long question
I've got an unformatted binary(.mid) file I want to display as text. When I use fscanf, like this:
*****************************
#include <stdio.h>
int main ()
{
void *list;
int i;
FILE * pFile;
pFile = fopen ("C:/Moondance.mid", "rb");
for(i=1; i<5; i++) //read 4 chars
{
fread(&list, 1, 1, pFile);
printf("%c ", list);
}
list=0;
for(i=1; i<5; i++) // read 4 bytes of decimals
{
fread(&list, 1, 1, pFile);
printf("%x ", list);
}
fclose (pFile);
return 0;
}
************************
it shows a byte at a time like this:
M T h d 0 0 0 6
(file header) (next chunk size)
where 0 0 0 6 is really 00 00 00 06, a 4-byte number
But when I try to replace the "for" number reader code with this:
******
fread(&list, 4, 1, pFile);
printf("%x ", list);
******
I get:
M T h d 6000000
It seems to have switched endedness or read each byte in the wrong order into the pointer.
I want it to print out as just decimal "6"
help?
regzim
|
|
|
|
|
regzim wrote: When I use fscanf, like this...
Are you hiding its usage someplace?
Why do you have list defined as a void* rather than a char ? fread() needs a spot to store the information it reads.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
fread doesn't care at all about 'endianness'.
the 'endianness' here is in the act of treating those four bytes like an integer value.
#include < stdio.h>
int main(int argc, char* argv[])
{
unsigned char b[4] = {1,2,3,4};
unsigned int p = *(unsigned int *)&b[0];
printf("%x", p);
return 0;
}
prints "4030201"
|
|
|
|
|
Aw, crumbs. I meant to write in the fscanf version, but it really doesn't matter. My intended point was that every function (except fread) I have been able to find to read a file either reads it one byte at a time, or needs a delimiter, like a null or so. Sorry about that, David.
Chris- I still don't get it... does that mean anytime I try to put four bytes together into an int to print, it stores it backwards? Was your example intended as the way not to do it, or as the only way to do it? The four-byte 00 00 00 06 is translated as an integer, "6". I could just "is.ignore" the extra zeros, but what if those spaces are filled with hex code for a larger integer?
Thanks for your replies,
regzim
|
|
|
|
|
If you do a binary write of an int to a file, then there are two ways to order the bytes, either msb first or lsb first. As long as you read / write on the same hardware you are OK and you don't need to worry about the endian nature. If you are reading byte by byte, and then want to reconstruct your int you need to know which order they were written. If you transfer binary files between machines with different hardware you can also run into difficulties.
See http://www.cs.umass.edu/~verts/cs32/endian.html[^]
|
|
|
|
|
regzim wrote: Was your example intended as the way not to do it, or as the only way to do it?
it's an example of the way it is: the byte order of an integer in memory is not the same as what you'd write on a piece of paper.
regzim wrote: The four-byte 00 00 00 06 is translated as an integer, "6".
it's translated as an integer, 6000000
regzim wrote: I could just "is.ignore" the extra zeros, but what if those spaces are filled with hex code for a larger integer?
why would an integer value ever have 'extra' data in it? if you only want that one byte, then just read that one byte. if you need all four bytes, you have to correct for byte order and accept all four bytes. right?
|
|
|
|
|