How to Read JPG Height and Width from Binary/Hex data?

I'm trying to figure out a way to read the height and width data out of images programatically -- by opening the binary and finding the right bytes.

GIF is easy, there are four bytes, and they're always in the same place in the file, but I'm finding it very difficult to understand the JPG specification.

You can get the spec from Wotsit at this URL:

     http://www.wotsit.org/download.asp?f=jpeg

and all I really need is for someone to explain it to me -- is there a unique marker in hex that I can rely on to come before the height and width bytes, (or 3 bytes before or whatever) or is it more complicated than that? What's the formula for tracking down those four bytes?

TIA
LVL 2
johnny99Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hergeeknessCommented:
The header of a JPEG file consists of a series of blocks, called "markers". The image height and width are stored in a marker of type SOFn (Start Of Frame, type N).  To find the SOFn you must skip over the preceding markers; you don't have to know what's in the other types of markers, just use their length words to skip over them.  The minimum logic needed is perhaps a page of C code.  (Some people have recommended just searching for the byte pair representing SOFn, without paying attention to the marker block structure. This is unsafe because a prior marker might contain the SOFn pattern, either by chance or because it contains a JPEG-compressed thumbnail image.  If you don't follow the marker structure you will retrieve the thumbnail's size instead of the main image size.)  
A profusely commented example in C can be found in rdjpgcom.c in the IJG distribution (see  ftp.uu.net:/graphics/jpeg/jpegsrc.v6b.tar.gz.
If you are on a PC you may prefer ZIP archive format, which you can find at
ftp.simtel.net:/pub/simtelnet/msdos/graphics/jpegsr6b.zip or at any
Simtel mirror site).  Perl code can be found in wwwis, from http://www.tardis.ed.ac.uk/~ark/wwwis/.

how's that?

hg

johnny99Author Commented:
Thank you, I'll check it out -- I've got as far as finding that there are those Start of Frame markers, but, as you say, there may be more than one such marker.

If you can explain this, you can have the points:

 * I open a JPEG and get the Hex code.

 * The marker I need is FF C0, right?

 * there are more than one of those markers in the Hex, which both start like this, for the first five bytes "FF C0 00 11 08"

 * The first one is "FF C0 00 11 08 00" and does not appear to have the height and width in the right place

 * the second one is "FF C0 00 11 08 01" and the next four bytes contain the right Hex for the height and width.

Will that always be the case? Which bit of the first one do I use to skip ahead the right number of bytes? And why is the height and width in what appears to be the second frame, or frame 1, when the spec says it's in frame zero?
hergeeknessCommented:
Johnny,

sorry, can't answer your questions.

When I saw your original post I riffled through my faq archives and found the info in one of my Jpeg ones.  I thought it answered it perfectly! Sorry it apparently didn't.

Dammit, I'm a designer, Jim, not a programmer!

:-D

hg

PS the logic/comments in the C code (linked in my comment) didn't help answer those follow-up questions?
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

johnny99Author Commented:
Unfortunately I'm not a proper programmer either. I'm very grateful for your help. The only trouble is I'm trying to do this using very specific resources on Macintosh, and all I can do is read the Hex in and work on it as text. It's not as dumb as it sounds!

So you can see that the C code won't help me unless I can get a C programmer to interpret it as logic, like "find this pattern; find the second word of that pattern and skip ahead that many bytes, at which time you should find this pattern"...

I'll let you have the points if nobody can do that...
johnny99Author Commented:
Perhaps I should make that clearer.

The resources available to me can open binaries, and their contents can be read into variables like this, from an actual JPG on my computer:

FF D8 FF E0 00 10 4A 46 49 46 00 01 02 01 00 48 00 48 00 00 FF ED 05 2A 50 68 6F 74 6F 73 68 6F 70 20 33 2E 30 00 38 42 49 4D 03 E9 00 00 00 00 00 78 00 0B 00 00 00 48 00 48 00 00 00 00 03 0D 02 2F FF ED FF EE 03 37 02 41 1F 03 05 7B 03 E0 00 01 00 00 01 2C 01 2C 00 00 00 00 0C B6 09 1C 01 2C 00 2D 05 A0 5E EC 00 26 02 01 01 01 00 18 00 01 27 0F 00 01 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 04 02 04 05 00 02 00 00 38 42 49 4D 03 ED

and somewhere in there (not in that chunk) is the pattern that can be interpreted as "Here come four bytes that tell you the height and width" -- followed by those bytes the way that "4A 46 49 46" can be interpreted as "JFIF", the format.

I know I'm being difficult, but I'm happy to increase points -- somebody should be able to look at the C source nominated above by hergeekness, for reading JPGs, and dumb it down for me?
berberskiCommented:
I look at source and you:
1. Open the file.
2. Search for FF and after it C?(C0 .. CF).
3. After C? skip 3 bytes.
4. Read 2 bytes, they are height of image(don't swap them)
5. Read 2 bytes, they are width of image(don't swap them).
6. Close File.
Sample
.... FF C0 00 11 08 02 58 01 8e ....

skip 00 11 08
height = 0258
width = 018e
johnny99Author Commented:
I've increased the points to keep you all keen, but berberski, I don't understand your number 2 -- are you saying that the first time in the file I come across FF C0 that will be the chunk preceding the height and width? Because it isn't.

See my first comment to hergeekness above -- there are multiple markers like that in the file I'm looking at.

The first marker doesn't include the height and width in the place you tell me to look.

The trouble with JPEG is you can put all kinds of segments in with your own markers -- if you open up a photoshop file it's got "Photoshop" in there as a text string, and if you want, it can have "Picture of my dog" in there too.

And why have you put "C?" you mean *any* value following C? That doesn't make sense either.

I'm sure that if someone who's a professional programmer reads the file specification at http://www.wotsit.org/download.asp?f=jpeg 
or the c/perl source nominated by hergeekness above for doing it, they'll be able to figure it out easily -- but it isn't as easy as finding the first FF C0 marker.
berberskiCommented:
Hi, johnny99.
Try this:
1. Open file.
2. Find first FF byte.
3. if next byte is from C0 to CF, without C4 and CC, this is the length record.
4. else read next 2 bytes. This is the length of record + length field. Skip this number of bytes - 2.
5 . goto 2.

I think, I found the problem. If you are reading Photoshop files there are multiple application specific markers, that must be skiped. I found that there at least two copies of image. That's why there are multiple FF C? markers.
johnny99Author Commented:
Exactly!

I'll check that, but you're right, the spec seems to say that anyone can write up to 65kb of his own personal information into a JPEG before the picture even starts.

I'll come back and award points soon I promise.
johnny99Author Commented:
OK this is an example:

1) I dumped the hex from a JPEG into my editor, JPEG width 101, height 182

2) I searched for FF followed by a Cn, where "n" is not a 4 or a 'C'.

3) I found this string:

     FF C0 00 11 08

according to your pseudocode, this is the "length record" -- not entirely sure what you mean by this.

4) this is *not* the chunk of data containing the hex for the height and width

5) If I continue searching as above at point 2 I find this string:

     FF C2 00 11 08

which is immediately followed by this:

     00 B6 00 65

which is the height and width, i.e. 101 182

Another example, with a JPEG 473 x 481

1) I dump the hex

2) I search for the FF Cn string

3) I find this string FF C0 00 11 08

4) It is immediately followed by this string:

     01 E1 01 D9

which is 473 and 481

The first image was a Photoshop JPEG, (I can tell from the Hex dump). The second was an ImageReady JPEG.

Third example with a Photoshop JPEG 223 x 300, the first FF Cn string found is:

     FF C0 00 11 08 01 2C 00 DF

Which contains the height and width, 01 2C and 00 DF.


I'm still not able to spot the formula, maybe I'm being stupid? There should be something about those Application-Specific FF Cn strings which says "I'm not the string containing the height and width", shouldn't there? It's certainly not based on the n-value following the C...
berberskiCommented:
Hi johnny99.
I don't think, that you are stupid, may be the reason is in my bad english. I don't understand your problem. This is C structure of "length record"  form hergeekness comment:
struct LengthRecord
{
   BYTE ID; one byte C0 .. CF
   int length; //two bytes length of record with this field;
   BYTE data_precision; //bits per sample
   int image_height;
   int image_width;
   BYTE num_components; //color components
};
and your third example is all right. 12C is 300 and DF = 223. So image is 223x300.
berberskiCommented:
I forget for that:
if ID is from E0 to EC this is not part of your image, this is application specific coment. In this block C0 .. CF are only usable from program that was create the image
berberskiCommented:
I forget for that:
if ID is from E0 to EC this is not part of your image, this is application specific coment. In this block C0 .. CF are only usable from program that was create the image
johnny99Author Commented:
Thank you very much for your patience, berberski.

It's probably my stupidity after all, but how about if I put it this way,

In my example 1 above, I found TWO DIFFERENT strings which began with the FF Cn code.

The first one was FF C0 and didn't contain the height and width. The second was FF C1 and did contain the height and width.

In example 2 above, I found only one string, which began FF C0 and *did* contain the height and width info.

So in the first example, I'm searching for FF Cn, and the first thing I find isn't the one I'm looking for. What is my clue that I'm to skip it and move on to find the next one?

If all JPGs had a string that could be read "FF C0 something something something height width" then I wouldn't have a problem.

But one of the JPGs in question clearly has a string "FF C0 something something something not-height not-width", and a *second* string, further on, which is "FF C1 something something something height width",

In the first example, the bytes for height and width can be found by looking for FF C0. In the second it can be found by looking for FF C1, and a search for FF C0 will give the wrong information.

That's my problem! : )
hergeeknessCommented:
still looking, asking a few JPEG wizards, hang on....
hergeeknessCommented:
(btw does this help...)

JPEG files consist of segments, each of which starts with a two-byte marker that identifies the segment type. Some segments consist only of the marker, while others have data following the marker.  The two-byte marker always contains hexadecimal FF as the first byte. The second byte indicates the marker type.

JPEG files start out with a Start of Image, or SOI, segment. The SOI segment consists only of the marker, which is hex FF D8. That is how you can see if it is a JPEG image.

Following the two-byte marker of some segment types is a two-byte length of the segment. By reading this length, we can jump ahead to the next segment if the current one is of no interest to us. After the SOI segment comes the Application Type 0, or APP0, segment. This segment is used to store any application data. The second byte of the marker is hex E0. Since this segment doesn't contain anything of interest to us, we will just skip by it. After the APP0 segment, things start getting a little more unpredictable. Segments can now come in different orders, so what we will do is scan through them until we hit the one we are looking for -- a Start of Frame, which has markers of either hex C0 or hex C2.

I mentioned earlier that some segments consist only of the marker, while others have data after the marker. The ones that have no data are of types hex 01 and hex D1 through hex D9. All other segments have the two-byte length after the marker, so you should read that in and jump forward the correct number of bytes to get to the next segment.

If the current segment is an SOF0 segment, then you can read in the image dimensions.

In an SOF0 segment, the marker is followed by the segment length as usual. The next byte contains the sample precision (almost always 8). The height (number of rows of pixels) is given in the next two bytes. The two bytes following the height are the width (number of columns of pixels). These are, of course, what we want to find out about the image.

johnny99Author Commented:
"what we will do is scan through them until we hit the one we are looking for -- a Start of Frame, which has markers of either hex C0 or hex C2"

So I should be able to look for a string which is either FF C0 or FF C2?

But what about the chunk I found that *is* "FF C0 00 11 08", but which is *not* followed by the height and width?

If there are *two* chunks of data in the same file, one of them like this:

     FF C0 00 11 08 ?? ?? ?? ??

(where the ?? stands for "any byte") and the other like this:

     FF C2 00 11 08 ?? ?? ?? ??

which of these two strings contains the height and width?
berberskiCommented:
Give me sample JPG file, pls.
hergeeknessCommented:
Hmmm johnny99, well I wrote to Tom Lane, organizer of the Independent JPEG Group, and told him your problem. He said:

"If he doesn't skip over application-specific markers then he will get fooled by SOF markers belonging to thumbnail images.  Photoshop embeds such things in their app markers and so do some other people.  (There's also a real
possibility of seeing the byte-pair FF C0 inside whatever random data an application decides to stuff into an app-specific marker.)  You just plain cannot decode a JPEG's headers correctly if you don't have logic that understands about marker length words and skipping over
the data contents of the markers you don't care about.  Searching for byte pairs without paying attention to the marker-and-data structure of the file isn't going to cut it.

      SOI            2 bytes

      marker            2 bytes
        length word      2 bytes
          data      n bytes (value of length word is n+2)

      marker            2 bytes
        length word      2 bytes
          data      n bytes (value of length word is n+2)

      etc

Just because you find something that looks like a marker byte pair inside a data segment doesn't mean it is a marker.

johnny99Author Commented:
Thank you -- I really feel we're nearly there.

So as I understand it:

There will only be one FF Cn string, followed by the height and width OUTSIDE of an Application-Specific, to-be-ignored, marker.

There may be any number of such strings INSIDE those to-be-ignored markers.

So what is my clue that the erroneous FF Cn string I found is part of a to-be-ignored segment?
johnny99Author Commented:
Here's the hex from a 1x1 pixel JPEG I created in Photoshop just now:

FF D8 FF E0 00 10 4A 46 49 46 00 01 02 01 00 48
00 48 00 00 FF ED 04 4C 50 68 6F 74 6F 73 68 6F
70 20 33 2E 30 00 38 42 49 4D 03 E9 00 00 00 00
00 78 00 03 00 00 00 48 00 48 00 00 00 00 03 1D
02 30 FF E9 FF EF 03 33 02 42 03 42 05 7B 03 E0
00 02 00 00 00 48 00 48 00 00 00 00 02 D8 02 28
00 01 00 00 00 64 00 00 00 01 00 03 03 03 00 FF
00 01 27 0F 00 01 00 01 00 00 00 00 00 00 00 00
00 00 00 00 60 08 00 19 01 90 00 00 00 00 00 20
00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 38 42 49 4D 03 ED
00 00 00 00 00 10 00 48 00 00 00 01 00 02 00 48
00 00 00 01 00 02 38 42 49 4D 04 0D 00 00 00 00
00 04 00 00 00 78 38 42 49 4D 03 F3 00 00 00 00
00 08 00 00 00 00 00 00 00 00 38 42 49 4D 04 0A
00 00 00 00 00 01 00 00 38 42 49 4D 27 10 00 00

00 00 00 0A 00 01 00 00 00 00 00 00 00 02 38 42
49 4D 03 F5 00 00 00 00 00 48 00 2F 66 66 00 01
00 6C 66 66 00 06 00 00 00 00 00 01 00 2F 66 66
00 01 00 A1 99 9A 00 06 00 00 00 00 00 01 00 32
00 00 00 01 00 5A 00 00 00 06 00 00 00 00 00 01
00 35 00 00 00 01 00 2D 00 00 00 06 00 00 00 00
00 01 38 42 49 4D 03 F8 00 00 00 00 00 70 00 00
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF 03 E8 00 00 00 00 FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF 03 E8 00 00 00 00 FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF 03 E8
00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF 03 E8 00 00 38 42
49 4D 04 08 00 00 00 00 00 10 00 00 00 01 00 00
02 40 00 00 02 40 00 00 00 00 38 42 49 4D 04 14

00 00 00 00 00 04 00 00 00 01 38 42 49 4D 04 0C
00 00 00 00 02 37 00 00 00 01 00 00 00 01 00 00
00 01 00 00 00 04 00 00 00 04 00 00 02 1B 00 18
00 01 FF D8 FF E0 00 10 4A 46 49 46 00 01 02 01
00 48 00 48 00 00 FF EE 00 0E 41 64 6F 62 65 00
64 80 00 00 00 01 FF DB 00 84 00 0C 08 08 08 09
08 0C 09 09 0C 11 0B 0A 0B 11 15 0F 0C 0C 0F 15
18 13 13 15 13 13 18 11 0C 0C 0C 0C 0C 0C 11 0C
0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C
0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 01 0D 0B 0B 0D
0E 0D 10 0E 0E 10 14 0E 0E 0E 14 14 0E 0E 0E 0E
14 11 0C 0C 0C 0C 0C 11 11 0C 0C 0C 0C 0C 0C 11
0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C
0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C FF C0 00 11
08 00 01 00 01 03 01 22 00 02 11 01 03 11 01 FF
DD 00 04 00 01 FF C4 01 3F 00 00 01 05 01 01 01

01 01 01 00 00 00 00 00 00 00 03 00 01 02 04 05
06 07 08 09 0A 0B 01 00 01 05 01 01 01 01 01 01
00 00 00 00 00 00 00 01 00 02 03 04 05 06 07 08
09 0A 0B 10 00 01 04 01 03 02 04 02 05 07 06 08
05 03 0C 33 01 00 02 11 03 04 21 12 31 05 41 51
61 13 22 71 81 32 06 14 91 A1 B1 42 23 24 15 52
C1 62 33 34 72 82 D1 43 07 25 92 53 F0 E1 F1 63
73 35 16 A2 B2 83 26 44 93 54 64 45 C2 A3 74 36
17 D2 55 E2 65 F2 B3 84 C3 D3 75 E3 F3 46 27 94
A4 85 B4 95 C4 D4 E4 F4 A5 B5 C5 D5 E5 F5 56 66
76 86 96 A6 B6 C6 D6 E6 F6 37 47 57 67 77 87 97
A7 B7 C7 D7 E7 F7 11 00 02 02 01 02 04 04 03 04
05 06 07 07 06 05 35 01 00 02 11 03 21 31 12 04
41 51 61 71 22 13 05 32 81 91 14 A1 B1 42 23 C1
52 D1 F0 33 24 62 E1 72 82 92 43 53 15 63 73 34
F1 25 06 16 A2 B2 83 07 26 35 C2 D2 44 93 54 A3

17 64 45 55 36 74 65 E2 F2 B3 84 C3 D3 75 E3 F3
46 94 A4 85 B4 95 C4 D4 E4 F4 A5 B5 C5 D5 E5 F5
56 66 76 86 96 A6 B6 C6 D6 E6 F6 27 37 47 57 67
77 87 97 A7 B7 C7 FF DA 00 0C 03 01 00 02 11 03
11 00 3F 00 F5 54 97 CA A9 24 A7 FF D9 00 38 42
49 4D 04 06 00 00 00 00 00 07 FF FC 00 00 00 01
01 00 FF E2 0C 58 49 43 43 5F 50 52 4F 46 49 4C
45 00 01 01 00 00 0C 48 4C 69 6E 6F 02 10 00 00
6D 6E 74 72 52 47 42 20 58 59 5A 20 07 CE 00 02
00 09 00 06 00 31 00 00 61 63 73 70 4D 53 46 54
00 00 00 00 49 45 43 20 73 52 47 42 00 00 00 00
00 00 00 00 00 00 00 00 00 00 F6 D6 00 01 00 00
00 00 D3 2D 48 50 20 20 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 11 63 70 72 74 00 00 01 50

00 00 00 33 64 65 73 63 00 00 01 84 00 00 00 6C
77 74 70 74 00 00 01 F0 00 00 00 14 62 6B 70 74
00 00 02 04 00 00 00 14 72 58 59 5A 00 00 02 18
00 00 00 14 67 58 59 5A 00 00 02 2C 00 00 00 14
62 58 59 5A 00 00 02 40 00 00 00 14 64 6D 6E 64
00 00 02 54 00 00 00 70 64 6D 64 64 00 00 02 C4
00 00 00 88 76 75 65 64 00 00 03 4C 00 00 00 86
76 69 65 77 00 00 03 D4 00 00 00 24 6C 75 6D 69
00 00 03 F8 00 00 00 14 6D 65 61 73 00 00 04 0C
00 00 00 24 74 65 63 68 00 00 04 30 00 00 00 0C
72 54 52 43 00 00 04 3C 00 00 08 0C 67 54 52 43
00 00 04 3C 00 00 08 0C 62 54 52 43 00 00 04 3C
00 00 08 0C 74 65 78 74 00 00 00 00 43 6F 70 79
72 69 67 68 74 20 28 63 29 20 31 39 39 38 20 48
65 77 6C 65 74 74 2D 50 61 63 6B 61 72 64 20 43
6F 6D 70 61 6E 79 00 00 64 65 73 63 00 00 00 00

00 00 00 12 73 52 47 42 20 49 45 43 36 31 39 36
36 2D 32 2E 31 00 00 00 00 00 00 00 00 00 00 00
12 73 52 47 42 20 49 45 43 36 31 39 36 36 2D 32
2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 58 59 5A 20 00 00 00 00 00 00 F3 51
00 01 00 00 00 01 16 CC 58 59 5A 20 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 58 59 5A 20
00 00 00 00 00 00 6F A2 00 00 38 F5 00 00 03 90
58 59 5A 20 00 00 00 00 00 00 62 99 00 00 B7 85
00 00 18 DA 58 59 5A 20 00 00 00 00 00 00 24 A0
00 00 0F 84 00 00 B6 CF 64 65 73 63 00 00 00 00
00 00 00 16 49 45 43 20 68 74 74 70 3A 2F 2F 77
77 77 2E 69 65 63 2E 63 68 00 00 00 00 00 00 00
00 00 00 00 16 49 45 43 20 68 74 74 70 3A 2F 2F

77 77 77 2E 69 65 63 2E 63 68 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 64 65 73 63 00 00 00 00
00 00 00 2E 49 45 43 20 36 31 39 36 36 2D 32 2E
31 20 44 65 66 61 75 6C 74 20 52 47 42 20 63 6F
6C 6F 75 72 20 73 70 61 63 65 20 2D 20 73 52 47
42 00 00 00 00 00 00 00 00 00 00 00 2E 49 45 43
20 36 31 39 36 36 2D 32 2E 31 20 44 65 66 61 75
6C 74 20 52 47 42 20 63 6F 6C 6F 75 72 20 73 70
61 63 65 20 2D 20 73 52 47 42 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
64 65 73 63 00 00 00 00 00 00 00 2C 52 65 66 65
72 65 6E 63 65 20 56 69 65 77 69 6E 67 20 43 6F
6E 64 69 74 69 6F 6E 20 69 6E 20 49 45 43 36 31
39 36 36 2D 32 2E 31 00 00 00 00 00 00 00 00 00

00 00 2C 52 65 66 65 72 65 6E 63 65 20 56 69 65
77 69 6E 67 20 43 6F 6E 64 69 74 69 6F 6E 20 69
6E 20 49 45 43 36 31 39 36 36 2D 32 2E 31 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 76 69 65 77 00 00 00 00
00 13 A4 FE 00 14 5F 2E 00 10 CF 14 00 03 ED CC
00 04 13 0B 00 03 5C 9E 00 00 00 01 58 59 5A 20
00 00 00 00 00 4C 09 56 00 50 00 00 00 57 1F E7
6D 65 61 73 00 00 00 00 00 00 00 01 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 8F
00 00 00 02 73 69 67 20 00 00 00 00 43 52 54 20
63 75 72 76 00 00 00 00 00 00 04 00 00 00 00 05
00 0A 00 0F 00 14 00 19 00 1E 00 23 00 28 00 2D
00 32 00 37 00 3B 00 40 00 45 00 4A 00 4F 00 54
00 59 00 5E 00 63 00 68 00 6D 00 72 00 77 00 7C
00 81 00 86 00 8B 00 90 00 95 00 9A 00 9F 00 A4

00 A9 00 AE 00 B2 00 B7 00 BC 00 C1 00 C6 00 CB
00 D0 00 D5 00 DB 00 E0 00 E5 00 EB 00 F0 00 F6
00 FB 01 01 01 07 01 0D 01 13 01 19 01 1F 01 25
01 2B 01 32 01 38 01 3E 01 45 01 4C 01 52 01 59
01 60 01 67 01 6E 01 75 01 7C 01 83 01 8B 01 92
01 9A 01 A1 01 A9 01 B1 01 B9 01 C1 01 C9 01 D1
01 D9 01 E1 01 E9 01 F2 01 FA 02 03 02 0C 02 14
02 1D 02 26 02 2F 02 38 02 41 02 4B 02 54 02 5D
02 67 02 71 02 7A 02 84 02 8E 02 98 02 A2 02 AC
02 B6 02 C1 02 CB 02 D5 02 E0 02 EB 02 F5 03 00
03 0B 03 16 03 21 03 2D 03 38 03 43 03 4F 03 5A
03 66 03 72 03 7E 03 8A 03 96 03 A2 03 AE 03 BA
03 C7 03 D3 03 E0 03 EC 03 F9 04 06 04 13 04 20
04 2D 04 3B 04 48 04 55 04 63 04 71 04 7E 04 8C
04 9A 04 A8 04 B6 04 C4 04 D3 04 E1 04 F0 04 FE
05 0D 05 1C 05 2B 05 3A 05 49 05 58 05 67 05 77

05 86 05 96 05 A6 05 B5 05 C5 05 D5 05 E5 05 F6
06 06 06 16 06 27 06 37 06 48 06 59 06 6A 06 7B
06 8C 06 9D 06 AF 06 C0 06 D1 06 E3 06 F5 07 07
07 19 07 2B 07 3D 07 4F 07 61 07 74 07 86 07 99
07 AC 07 BF 07 D2 07 E5 07 F8 08 0B 08 1F 08 32
08 46 08 5A 08 6E 08 82 08 96 08 AA 08 BE 08 D2
08 E7 08 FB 09 10 09 25 09 3A 09 4F 09 64 09 79
09 8F 09 A4 09 BA 09 CF 09 E5 09 FB 0A 11 0A 27
0A 3D 0A 54 0A 6A 0A 81 0A 98 0A AE 0A C5 0A DC
0A F3 0B 0B 0B 22 0B 39 0B 51 0B 69 0B 80 0B 98
0B B0 0B C8 0B E1 0B F9 0C 12 0C 2A 0C 43 0C 5C
0C 75 0C 8E 0C A7 0C C0 0C D9 0C F3 0D 0D 0D 26
0D 40 0D 5A 0D 74 0D 8E 0D A9 0D C3 0D DE 0D F8
0E 13 0E 2E 0E 49 0E 64 0E 7F 0E 9B 0E B6 0E D2
0E EE 0F 09 0F 25 0F 41 0F 5E 0F 7A 0F 96 0F B3
0F CF 0F EC 10 09 10 26 10 43 10 61 10 7E 10 9B

10 B9 10 D7 10 F5 11 13 11 31 11 4F 11 6D 11 8C
11 AA 11 C9 11 E8 12 07 12 26 12 45 12 64 12 84
12 A3 12 C3 12 E3 13 03 13 23 13 43 13 63 13 83
13 A4 13 C5 13 E5 14 06 14 27 14 49 14 6A 14 8B
14 AD 14 CE 14 F0 15 12 15 34 15 56 15 78 15 9B
15 BD 15 E0 16 03 16 26 16 49 16 6C 16 8F 16 B2
16 D6 16 FA 17 1D 17 41 17 65 17 89 17 AE 17 D2
17 F7 18 1B 18 40 18 65 18 8A 18 AF 18 D5 18 FA
19 20 19 45 19 6B 19 91 19 B7 19 DD 1A 04 1A 2A
1A 51 1A 77 1A 9E 1A C5 1A EC 1B 14 1B 3B 1B 63
1B 8A 1B B2 1B DA 1C 02 1C 2A 1C 52 1C 7B 1C A3
1C CC 1C F5 1D 1E 1D 47 1D 70 1D 99 1D C3 1D EC
1E 16 1E 40 1E 6A 1E 94 1E BE 1E E9 1F 13 1F 3E
1F 69 1F 94 1F BF 1F EA 20 15 20 41 20 6C 20 98
20 C4 20 F0 21 1C 21 48 21 75 21 A1 21 CE 21 FB
22 27 22 55 22 82 22 AF 22 DD 23 0A 23 38 23 66

23 94 23 C2 23 F0 24 1F 24 4D 24 7C 24 AB 24 DA
25 09 25 38 25 68 25 97 25 C7 25 F7 26 27 26 57
26 87 26 B7 26 E8 27 18 27 49 27 7A 27 AB 27 DC
28 0D 28 3F 28 71 28 A2 28 D4 29 06 29 38 29 6B
29 9D 29 D0 2A 02 2A 35 2A 68 2A 9B 2A CF 2B 02
2B 36 2B 69 2B 9D 2B D1 2C 05 2C 39 2C 6E 2C A2
2C D7 2D 0C 2D 41 2D 76 2D AB 2D E1 2E 16 2E 4C
2E 82 2E B7 2E EE 2F 24 2F 5A 2F 91 2F C7 2F FE
30 35 30 6C 30 A4 30 DB 31 12 31 4A 31 82 31 BA
31 F2 32 2A 32 63 32 9B 32 D4 33 0D 33 46 33 7F
33 B8 33 F1 34 2B 34 65 34 9E 34 D8 35 13 35 4D
35 87 35 C2 35 FD 36 37 36 72 36 AE 36 E9 37 24
37 60 37 9C 37 D7 38 14 38 50 38 8C 38 C8 39 05
39 42 39 7F 39 BC 39 F9 3A 36 3A 74 3A B2 3A EF
3B 2D 3B 6B 3B AA 3B E8 3C 27 3C 65 3C A4 3C E3
3D 22 3D 61 3D A1 3D E0 3E 20 3E 60 3E A0 3E E0

3F 21 3F 61 3F A2 3F E2 40 23 40 64 40 A6 40 E7
41 29 41 6A 41 AC 41 EE 42 30 42 72 42 B5 42 F7
43 3A 43 7D 43 C0 44 03 44 47 44 8A 44 CE 45 12
45 55 45 9A 45 DE 46 22 46 67 46 AB 46 F0 47 35
47 7B 47 C0 48 05 48 4B 48 91 48 D7 49 1D 49 63
49 A9 49 F0 4A 37 4A 7D 4A C4 4B 0C 4B 53 4B 9A
4B E2 4C 2A 4C 72 4C BA 4D 02 4D 4A 4D 93 4D DC
4E 25 4E 6E 4E B7 4F 00 4F 49 4F 93 4F DD 50 27
50 71 50 BB 51 06 51 50 51 9B 51 E6 52 31 52 7C
52 C7 53 13 53 5F 53 AA 53 F6 54 42 54 8F 54 DB
55 28 55 75 55 C2 56 0F 56 5C 56 A9 56 F7 57 44
57 92 57 E0 58 2F 58 7D 58 CB 59 1A 59 69 59 B8
5A 07 5A 56 5A A6 5A F5 5B 45 5B 95 5B E5 5C 35
5C 86 5C D6 5D 27 5D 78 5D C9 5E 1A 5E 6C 5E BD
5F 0F 5F 61 5F B3 60 05 60 57 60 AA 60 FC 61 4F
61 A2 61 F5 62 49 62 9C 62 F0 63 43 63 97 63 EB

64 40 64 94 64 E9 65 3D 65 92 65 E7 66 3D 66 92
66 E8 67 3D 67 93 67 E9 68 3F 68 96 68 EC 69 43
69 9A 69 F1 6A 48 6A 9F 6A F7 6B 4F 6B A7 6B FF
6C 57 6C AF 6D 08 6D 60 6D B9 6E 12 6E 6B 6E C4
6F 1E 6F 78 6F D1 70 2B 70 86 70 E0 71 3A 71 95
71 F0 72 4B 72 A6 73 01 73 5D 73 B8 74 14 74 70
74 CC 75 28 75 85 75 E1 76 3E 76 9B 76 F8 77 56
77 B3 78 11 78 6E 78 CC 79 2A 79 89 79 E7 7A 46
7A A5 7B 04 7B 63 7B C2 7C 21 7C 81 7C E1 7D 41
7D A1 7E 01 7E 62 7E C2 7F 23 7F 84 7F E5 80 47
80 A8 81 0A 81 6B 81 CD 82 30 82 92 82 F4 83 57
83 BA 84 1D 84 80 84 E3 85 47 85 AB 86 0E 86 72
86 D7 87 3B 87 9F 88 04 88 69 88 CE 89 33 89 99
89 FE 8A 64 8A CA 8B 30 8B 96 8B FC 8C 63 8C CA
8D 31 8D 98 8D FF 8E 66 8E CE 8F 36 8F 9E 90 06
90 6E 90 D6 91 3F 91 A8 92 11 92 7A 92 E3 93 4D

93 B6 94 20 94 8A 94 F4 95 5F 95 C9 96 34 96 9F
97 0A 97 75 97 E0 98 4C 98 B8 99 24 99 90 99 FC
9A 68 9A D5 9B 42 9B AF 9C 1C 9C 89 9C F7 9D 64
9D D2 9E 40 9E AE 9F 1D 9F 8B 9F FA A0 69 A0 D8
A1 47 A1 B6 A2 26 A2 96 A3 06 A3 76 A3 E6 A4 56
A4 C7 A5 38 A5 A9 A6 1A A6 8B A6 FD A7 6E A7 E0
A8 52 A8 C4 A9 37 A9 A9 AA 1C AA 8F AB 02 AB 75
AB E9 AC 5C AC D0 AD 44 AD B8 AE 2D AE A1 AF 16
AF 8B B0 00 B0 75 B0 EA B1 60 B1 D6 B2 4B B2 C2
B3 38 B3 AE B4 25 B4 9C B5 13 B5 8A B6 01 B6 79
B6 F0 B7 68 B7 E0 B8 59 B8 D1 B9 4A B9 C2 BA 3B
BA B5 BB 2E BB A7 BC 21 BC 9B BD 15 BD 8F BE 0A
BE 84 BE FF BF 7A BF F5 C0 70 C0 EC C1 67 C1 E3
C2 5F C2 DB C3 58 C3 D4 C4 51 C4 CE C5 4B C5 C8
C6 46 C6 C3 C7 41 C7 BF C8 3D C8 BC C9 3A C9 B9
CA 38 CA B7 CB 36 CB B6 CC 35 CC B5 CD 35 CD B5

CE 36 CE B6 CF 37 CF B8 D0 39 D0 BA D1 3C D1 BE
D2 3F D2 C1 D3 44 D3 C6 D4 49 D4 CB D5 4E D5 D1
D6 55 D6 D8 D7 5C D7 E0 D8 64 D8 E8 D9 6C D9 F1
DA 76 DA FB DB 80 DC 05 DC 8A DD 10 DD 96 DE 1C
DE A2 DF 29 DF AF E0 36 E0 BD E1 44 E1 CC E2 53
E2 DB E3 63 E3 EB E4 73 E4 FC E5 84 E6 0D E6 96
E7 1F E7 A9 E8 32 E8 BC E9 46 E9 D0 EA 5B EA E5
EB 70 EB FB EC 86 ED 11 ED 9C EE 28 EE B4 EF 40
EF CC F0 58 F0 E5 F1 72 F1 FF F2 8C F3 19 F3 A7
F4 34 F4 C2 F5 50 F5 DE F6 6D F6 FB F7 8A F8 19
F8 A8 F9 38 F9 C7 FA 57 FA E7 FB 77 FC 07 FC 98
FD 29 FD BA FE 4B FE DC FF 6D FF FF FF EE 00 0E
41 64 6F 62 65 00 64 80 00 00 00 01 FF DB 00 84
00 20 21 21 33 24 33 51 30 30 51 42 2F 2F 2F 42
27 1C 1C 1C 1C 27 22 17 17 17 17 17 22 11 0C 0C
0C 0C 0C 0C 11 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C

0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C
0C 01 22 33 33 34 26 34 22 18 18 22 14 0E 0E 0E
14 14 0E 0E 0E 0E 14 11 0C 0C 0C 0C 0C 11 11 0C
0C 0C 0C 0C 0C 11 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C
0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C
0C 0C FF C0 00 11 08 00 01 00 01 03 01 22 00 02
11 01 03 11 01 FF DD 00 04 00 01 FF C4 01 1B 00
00 03 01 01 01 01 01 01 01 01 01 00 00 00 00 00
01 00 02 03 04 05 06 07 08 09 0A 0B 01 01 01 01
01 01 01 01 01 01 01 01 01 00 00 00 00 00 01 02
03 04 05 06 07 08 09 0A 0B 10 00 02 02 01 03 02
03 04 07 06 03 03 06 02 01 35 01 00 02 11 03 21
12 31 04 41 51 22 13 61 71 32 81 91 B1 42 A1 05
D1 C1 14 F0 52 23 72 33 62 E1 82 F1 43 34 92 A2
B2 15 D2 53 24 73 C2 63 06 83 93 E2 F2 A3 44 54
64 25 35 45 16 26 74 36 55 65 B3 84 C3 D3 75 E3

F3 46 94 A4 85 B4 95 C4 D4 E4 F4 A5 B5 C5 D5 E5
F5 56 66 76 86 96 A6 B6 C6 D6 E6 F6 11 00 02 02
00 05 01 06 06 01 03 01 03 05 03 06 2F 00 01 11
02 21 03 31 41 12 51 61 71 81 91 22 13 32 F0 A1
B1 04 C1 D1 E1 F1 42 52 23 62 72 14 92 33 82 43
24 A2 B2 34 53 44 63 73 C2 D2 83 93 A3 54 E2 F2
05 15 25 06 16 26 35 64 45 55 36 74 65 B3 84 C3
D3 75 E3 F3 46 94 A4 85 B4 95 C4 D4 E4 F4 A5 B5
C5 D5 E5 F5 56 66 76 86 FF DA 00 0C 03 01 00 02
11 03 11 00 3F 00 FA 05 7F 3F 54 0F FF D9      

berberskiCommented:
Hi johnny99
Now here how work algorithm that i was proposed to you in my comments:
read byte //FF
read byte //d8
read byte //ff
read byte//e0 Application Specific part  we must skip
read 2bytes // 0x10
skip 0x0e//16 -2
read byte // ff
read byte //ed we must skip
read 2bytes //0x44c
skip 0x044d //1103 -2
read byte //ff
read byte //e2 we must skip
read 2bytes // oxc58
skip 0xc56 //  3160 - 2
read byte //ff
read byte //ee we must skip
read 2bytes//0x0e
skip 0x0c //14 -2
read byte //ff
read byte //db - not interessed, skip
read 2bytes //0x84
skip 0x82 // 132 -2
read byte //ff
read byte //c0 - there is!!!!
read 2bytes//length
read byte
read 2bytes //height 0x01
read 2byte //width 0x01
No problem. After this in file is FF C4 but this is not "ength" byte.
hergeeknessCommented:
johnny, what is this for, anyway? I'm curious. I mean once you figure it out, what are you going to do with it?
johnny99Author Commented:
I'm doing this in order to automate the creation of web pages using a Mac application/development tool.

I can extend it by writing functions myself, so I'm just trying to write one like

    get dimensions(image)

anyway -- you guys have been great and I actually do understand it now.

I apologise again for my stupidity!

How about I give you guys 300 points each?
hergeeknessCommented:
fine with me...you'll have to reduce your points here and give it to one expert, then create a new question in this topic with "points for [name of other expert]" as the subject/title and assign that quest. the remaining points.

glad you figured it out!

hg
berberskiCommented:
ok
hergeeknessCommented:
johnny, if you've already given out berberski's and my points to this question via other "points for" questions, you should zero this one out (reduce points to 0) and accept a comment as an answer to close it up.

Or are you waiting for more input from other experts? If so, leave it open.

hg
johnny99Author Commented:
Hi, well I'd like to, but I can't!

It turns out you can't reduce the amount of points yourself. I'll have to ask someone at EE management to help me.
hergeeknessCommented:
Huh. <edmcmahon> I did not know that. </edmcmahon>

Just post a link to this question on the Community Support forum ... you probably already know that.

thx again for the points...don't forget to close out the "points for her geekness" one (accept my answer and grade it).

hg
linda101698Commented:
johnny99 has already awarded the points for this question so I am reducing the points to zero and moving it to the PAQ to save the information provided here.

Linda Gardner
Community Support @ Experts Exchange

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Graphics Software

From novice to tech pro — start learning today.