Re: opening jpeg file in c++



mohi wrote:
hello everyone ,

i am trying to read a jpeg image through c++ but is unable to do so ,
presently i tried it with code in c as i use something like ;

FILE * fp=fopen("./x.jpg","rb");
int c;
do{
fread(fp,&c,sizeof(c));

You don't have enough arguments here, and they're in the wrong order.
I think that should be

if(fread(&c, sizeof(c), 1, fp) != 1)
{
// Error handling.
}

You're assuming here that the value you're looking for is stored in
sizeof(int) bytes. That's not a portable assumption - are you sure
it's correct?

if( c==(int) 0xFF23){

If INT_MAX < 0xFF23, that conversion has undefined behavior.

do.....
do....

}

printf("%x",c);

}

while(c!=EOF);



but the problem is the if condition never evalutes to true as i know
that according to the jpeg standard there should be market with value
0xFFD8 and others also .....and also the printf() of integer 'c' as

Well, your code tests against 0xFF23, not 0xFFD8. Could that be the
problem?
Also, are you sure that the endianess of the data in the file that
you're reading is the same as the endianess of 'int' on the compiler
you're using?

hex is never displayed it just displays a blank ..

what could be wrong ??

or what is the best way to read a binary file such as an image ??

Assuming CHAR_BIT==8 and that the jpeg tag is stored in 16 bits, in
big-endian order, the best way to handle this is:

#include <limits.h>
#if CHAR_BIT != 8
#error This code assumes CHAR_BIT == 8
#endif
unsigned char buffer[2];
if(fread(buffer, 2, 1, fp)!=1)
{
// Error handling
}
else
{
if(buffer[0] == 0xFF && buffer[1] == 0x23 /* ? 0xD8 ? */)
// handle as jpeg file
}
else
{
// handle as non-jpeg file.
}
}
.



Relevant Pages

  • Re: Anyone install Nikon Capture NX yet?
    ... What advantage would there be to saving a jpeg image as RAW? ... The ONLY thing I might need CS2 for is the clone tool and if I ...
    (rec.photo.digital)
  • www.CeBeans.com - new program listings - Nov 30 2009
    ... This program allows you to select a JPEG image and converts to a monochrome ... The JPEG libraries are from Independent JPEG Group. ... The new bitmap file is written to the storage folder. ...
    (microsoft.public.pocketpc)
  • www.CeBeans.com - new program listings - Nov 23 2009
    ... This program allows you to take customized JPEG screen shots of your ... The JPEG libraries are from Independent JPEG Group. ... file to convert it to a JPEG image and send as an email attachment. ...
    (microsoft.public.pocketpc)
  • Re: Telepathology and DICOM
    ... Microscope with digital camera for telepathology application. ... camera will give JPEG output. ... You can use the JPEG encoder to wrap the DICOM layer around the JPEG image and then use the other tools to send them to a specific IP address ... The only reason for using DICOM is to store patient and other information in the same file as the JPEG, if you do not care about patient informatin or information related to the subject etc etc then just send the JPEG image and use the EXIF additional tag information to ...
    (comp.protocols.dicom)
  • RAW Dateiformat (war: Karls Ringblitz)
    ... >> RAW and JPEG simultaneous recording in separate files ... >> While the EOS Kiss Digital stores a JPEG image within ... >> the RAW image file and requires dedicated software to extract the JPEG ... >> recorded without the JPEG image if desired. ...
    (de.rec.fotografie)