Topic: Determining bounding box of JPG files (1 of 9), Read 50 times
Conf: Other (Not related to VEDIT)
From: Fritz Heberlein
Date: Saturday, November 01, 2003 11:23 AM

I have often to convert JPG files to EPS. Until now, I use an external program (GraphicsMagick) to determine the bounding box. However, i would prefer an Vedit-internal solution.

I have tried a suggestion found on Scott Lambert's Vedit web page
(http://carver.pinc.com/~slambert/codectr.htm), but
to no avail:

>>

// get the height and width of a .jpg file
// works with garden variety standard or progressive jpegs
// might not work with exotic subtypes
// #20 = the height in pixels
// #21 = the width in pixels

goto_pos(163)
#20=cur_char*256 // multiple the height high byte by 256
goto_pos(164)
#20=#20+cur_char // add the low byte
goto_pos(165)
#21=cur_char*256 // multiple the width high byte by 256
goto_pos(166)
#21=#21+cur_char // add the low byte

<<

Unfortunately, Scott doesn't seem to participate on Webboard discussions any more, and also his email address seems to be invalid.

So i wonder if anybody could tell me what's wrong / outdated with this code.

Thanks,

Fritz

 


Topic: Determining bounding box of JPG files (2 of 9), Read 47 times
Conf: Other (Not related to VEDIT)
From: Ian Binnie
Date: Sunday, November 02, 2003 01:13 AM

On 11/1/2003 11:23:05 AM, Fritz Heberlein wrote:
>I have often to convert JPG
>files to EPS. Until now, I use
>an external program
>(GraphicsMagick) to determine
>the bounding box. However, i
>would prefer an Vedit-internal
>solution.
>
I have written a macro to unpack Exif files, which are jpeg from a digital camera.

What I have done would not get the values you want, but it would not be too hard.

You need to follow the structure of the file, as there is considerable variation.

The following are some notes I wrote, the latter reference may help you.

"Most current digital camera store images using Exif compressed files.
The image data can be read by any application supporting "JPEG".
Exif/JPEG stores metadata at the beginning of the file. This includes aperture, shutter speed, flash, focal length etc.

The Exif (Exchangeable Image File) format is a JEIDA standard that is referenced as a preferred image format for digital cameras in ISO 12234-1.
Exif version 2.1 can be downloaded from http://www.pima.net/standards/it10/PIMA15740/exif.htm
(There is a later vesion Exif 2.2)

A more user friendly description of Exif file format can be found at:-
http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html"

I could email you the macro if you like, and will have a go at picking uout the info if I have time.

 


Topic: Determining bounding box of JPG files (3 of 9), Read 45 times
Conf: Other (Not related to VEDIT)
From: Ian Binnie
Date: Sunday, November 02, 2003 04:37 PM

On 11/1/2003 11:23:05 AM, Fritz Heberlein wrote:
>I have often to convert JPG
>files to EPS. Until now, I use
>an external program
>(GraphicsMagick) to determine
>the bounding box. However, i
>would prefer an Vedit-internal
>solution.
>
The following code should work with any JPEG.

It checks for the JPEG header, then skips any blocks (including embedded thumbnails) until it finds the Start of Frame of first image.


// Macro to extract JPEG information
// Ian Binnie 2/11/2003

Begin_Of_File()
if(Match("ff d8",HEX|ADVANCE)) { return } // JPEG not found
// locate Start of Frame of main image
while(Match("ff C0",HEX)) // find SOF
{
#5 = cur_char(2) * 256 + cur_char(3) // length of field
char(#5+2) // skip field
}
#6 = cur_char(5) * 256 + cur_char(6) // width
#7 = cur_char(7) * 256 + cur_char(8) // height
return

 


Topic: Determining bounding box of JPG files (4 of 9), Read 48 times
Conf: Other (Not related to VEDIT)
From: Pauli Lindgren
Date: Monday, November 03, 2003 01:34 PM

On 11/2/2003 4:37:57 PM, Ian Binnie wrote:
>
>It checks for the JPEG header, then skips any blocks (including embedded
>thumbnails) until it finds the Start of Frame of first image.
...
>while(Match("ff C0",HEX)) // find SOF
...

I don't think it is necessary to skip over blocks. JPG format does not contain bytes ff c0 anywhere except as start of frame tag. Therefore, you can simply use search.

However, some JPG files may use frame 1 or frame 2 instead of frame 0. My HTML_img.vdm uses the following:

Search("|Hff|{|Hc0,|Hc1,|Hc2}",NOERR+BEGIN)

I have not yet found a JPG file that would not work with that.

--
Pauli

 


Topic: Determining bounding box of JPG files (5 of 9), Read 47 times
Conf: Other (Not related to VEDIT)
From: Fritz Heberlein
Date: Monday, November 03, 2003 04:18 PM

Ian and Pauli:

Thank you very much for your kind help!

It's not only me who has to thank you but also our secretary, who is always struggling with missing bounding boxes (BTW, she admires Vedit because "everything" can be done by it, and she hates it because it "is
so complicated" ....)

Thanks again to both of you.

Fritz

 


Topic: Determining bounding box of JPG files (6 of 9), Read 41 times
Conf: Other (Not related to VEDIT)
From: Ian Binnie
Date: Tuesday, November 04, 2003 01:07 AM

On 11/3/2003 1:34:00 PM, Pauli Lindgren wrote:
>On 11/2/2003 4:37:57 PM, Ian Binnie
>wrote:
>>
>I don't think it is necessary to skip
>over blocks. JPG format does not contain
>bytes ff c0 anywhere except as start of
>frame tag. Therefore, you can simply use
>search.
>
I just checked one of the jpeg files from my digital camera.

It contains ff c0 3 times.

2 of these are before the main image, found by the macro.

I suspect the first is the thumbnail included by Exif format.

 


Topic: Determining bounding box of JPG files (7 of 9), Read 39 times
Conf: Other (Not related to VEDIT)
From: Ian Binnie
Date: Tuesday, November 04, 2003 09:58 PM

On 11/3/2003 1:34:00 PM, Pauli Lindgren wrote:
>On 11/2/2003 4:37:57 PM, Ian Binnie
>wrote:
>>
>I don't think it is necessary to skip
>over blocks.

Exif encoded images contain an APP1 block which contains digicam information.
This block is encoded in TIFF format.
While the Exif specification states that thumbnails are optional, most cameras insert a thumbnail.
This is a complete jpeg ff d8 ... ff d9. These can be extracted easily by Vedit and saved as a jpeg.

If you search for ff c0 you will normally find this thumbnail.

Until now I had always assumed that the thumbnails were the recommended 160*120.
This is what is displayed by viewers that show the thumbnail.

Today I discovered that my camera inserts 320*240 thumbnails in addition to the 160*120.
These are encoded in the "Makernote" a non standardised area of the file.
This physically occurs before the Exif thumbnail.

There are thus 2 complete jpeg embedded in the .JPG file.

Searching for ff c0 will find one of these.

 


Topic: Determining bounding box of JPG files (8 of 9), Read 41 times
Conf: Other (Not related to VEDIT)
From: Pauli Lindgren
Date: Thursday, November 06, 2003 10:25 AM

On 11/4/2003 9:58:07 PM, Ian Binnie wrote:
>
>Exif encoded images contain an APP1 block which contains digicam information.
>This block is encoded in TIFF format.
>While the Exif specification states that thumbnails are optional, most cameras insert a thumbnail.
>This is a complete jpeg ff d8 ... ff d9.
>These can be extracted easily by Vedit and saved as a jpeg.
>
>If you search for ff c0 you will normally find this thumbnail.

I checked some digital camera pictures, and, indeed, they may contain multiple SOF markers.

In JFIF files, the thumbnails are usually not stored in JPEG format, but the new JFIF v1.02 spec does allow this option, too.

By the way, do you have a web page from where your EXIF extracting macro can be downloaded? Is it possible to edit and write the EXIF data, too?

--
Pauli

 


Topic: Determining bounding box of JPG files (9 of 9), Read 45 times
Conf: Other (Not related to VEDIT)
From: Ian Binnie
Date: Thursday, November 06, 2003 08:49 PM

On 11/6/2003 10:25:30 AM, Pauli Lindgren wrote:

>By the way, do you have a web page from
>where your EXIF extracting macro can be
>downloaded? Is it possible to edit and
>write the EXIF data, too?

I do have a web page, but it doesn't have much on it (the macro is not currently there):-
http://members.optusnet.com.au/~ibinnie/

I have emailed you the macro.
This was never intended to be a finished product, but does find most of the tags.

I had intended to extract info to a database of images, but this was really part of a project to include Exif support in a viewer program PGV, see:-
http://www.users.bigpond.com/pdeleeuw/

There are a number of Exif resources at:-
http://www.exif.org