how get the JPG image size?
from these page: https://www.fileformat.info/format/jpeg/egff.htm
i get the JPG file format:
Code:
typedef struct _JFIFHeader{
BYTE SOI[2]; /* 00h Start of Image Marker */
BYTE APP0[2]; /* 02h Application Use Marker */
BYTE Length[2]; /* 04h Length of APP0 Field */
BYTE Identifier[5]; /* 06h "JFIF" (zero terminated) Id String */
BYTE Version[2]; /* 07h JFIF Format Revision */
BYTE Units; /* 09h Units used for Resolution */
BYTE Xdensity[2]; /* 0Ah Horizontal Resolution */
BYTE Ydensity[2]; /* 0Ch Vertical Resolution */
BYTE XThumbnail; /* 0Eh Horizontal Pixel Count */
BYTE YThumbnail; /* 0Fh Vertical Pixel Count */ } JFIFHEAD;
but i need a correction: the Xdensity isn't the horizontal size?
Re: how get the JPG image size?
From the documentation
Quote:
Units, Xdensity, and Ydensity identify the unit of measurement used to describe the image resolution. Units may be 01h for dots per inch, 02h for dots per centimeter, or 00h for none (use measurement as pixel aspect ratio). Xdensity and Ydensity are the horizontal and vertical resolution of the image data, respectively. If the Units field value is 00h, the Xdensity and Ydensity fields will contain the pixel aspect ratio (Xdensity : Ydensity) rather than the image resolution. Because non-square pixels are discouraged for portability reasons, the Xdensity and Ydensity values normally equal 1 when the Units value is 0.
Re: how get the JPG image size?
1 st i must found the the SOF marker that contains the image dimensions.
Code:
while (FileImage) {
// seek for next marker
int b;
while (FileImage and ( FileImage.get() != 0xFF)) /* no body */ ;
while (FileImage and ((b = FileImage.get()) == 0xFF)) /* no body */ ;
// the SOF marker contains the image dimensions
if ((0xC0 <= b) and (b <= 0xCF) and (b != 0xC4) and (b != 0xC8) and (b != 0xCC))
{
FileImage.seekg( 3, std::ios::cur );
height = big_endian::read_word( FileImage );
width = big_endian::read_word( FileImage );
}
// Otherwise we must skip stuff (like thumbnails...)
else
{
FileImage.seekg( big_endian::read_word( FileImage ) - 2, std::ios::cur );
}
}
the big_endian() and little_endian():
Code:
namespace little_endian
{
unsigned read_word( std::istream& ins )
{
unsigned a = ins.get();
unsigned b = ins.get();
return b << 8 | a;
}
}
namespace big_endian
{
unsigned read_word( std::istream& ins )
{
unsigned a = ins.get();
unsigned b = ins.get();
return a << 8 | b;
}
}
can explain to me these 2 functions?
Re: how get the JPG image size?
Do you understand the terms bigendian and littleendian? if not, do an internet search.
Re: how get the JPG image size?
from what i read, have to with data order
Re: how get the JPG image size?
big endian is from 0 to 10 and little endian is from 10 to 0
Re: how get the JPG image size?
i get these, but why i must use for read data on image files?
Re: how get the JPG image size?
When dealing with binary files that store numbers (integers), you have to know the byte ordering of both the binary data and the CPU used in order to correctly read and obtain numbers.
Re: how get the JPG image size?
and the file information tells us what is used.
i tried do the same for ICO but don't works :(
https://en.wikipedia.org/wiki/ICO_(file_format)
from that i the byte 6 give me the width and the 7 height... so i did these code:
Code:
else if(strFormat== "ICO"|| strFormat=="ico") {
FileImage.seekg(2);
if(little_endian::read_word( FileImage )==1) //testing if is realy an ICO
{
FileImage.seekg( 6 );
height = little_endian::read_word( FileImage );
FileImage.seekg( 7);
width = little_endian::read_word( FileImage );
cout <<"File format ICO:\n" << "Width: " << width << "\nHeight: " << height;
}
}
and yes it uses the little endian
Re: how get the JPG image size?
the output is both zero and i don't know why
Re: how get the JPG image size?