BBC BASIC for Windows
Programming >> Database and Files >> Reading dates from JPG files
http://bb4w.conforums.com/index.cgi?board=database&action=display&num=1394016348

Reading dates from JPG files
Post by simong42 on Jan 15th, 2014, 08:17am

Is there anyone out there who's learned how to read date information from JPEG files, using BBC BASIC?
Re: Reading dates from JPG files
Post by admin on Jan 15th, 2014, 09:12am

on Jan 15th, 2014, 08:17am, simong42 wrote:
Is there anyone out there who's learned how to read date information from JPEG files, using BBC BASIC?

I personally haven't, but I don't think the EXIF data is particularly difficult to parse. BBC BASIC's PTR# pseudo-variable makes following the links straightforward.

There's a description of the EXIF file format here:

http://www.media.mit.edu/pia/Research/deepview/exif.html

Richard.
Re: Reading dates from JPG files
Post by JGHarston on Jan 19th, 2014, 3:40pm

Here's an initial framework to scan through the Exif header:

REM > ReadExif
:
in%=OPENIN("")
PROCexif_list(in%)
END
:
DEFPROCexif_list(in%)
LOCAL marker%,endian%,size%,tag%,format%,offset%,exif%,lp%,ptr%
:
REPEAT
marker%=FNrd16(in%,1)
IF marker%<>&FFD8 THEN size%=FNrd16(in%,1) ELSE size%=2
IF marker%<>&FFE1 THEN PTR#in%=PTR#in%-2+size%
UNTIL EOF#in% OR marker%=&FFE1
IF EOF#in% THEN ENDPROC :REM No TIFF marker found
IF FNrd32(in%,0)<>&66697845 THEN ENDPROC :REM No 'Exif' marker
IF FNrd16(in%,0)<>0 THEN ENDPROC :REM No zero word
exif%=PTR#in%-1 :REM Base of exif area
endian%=FNrd16(in%,0) :REM Get endian flag
IF endian%=&4949 THEN endian%=0 ELSE IF endian%=&4D4D THEN endian%=1 ELSE ENDPROC
:
size%=FNrd32(in%,endian%) :REM Size of exif catalogue
num%=FNrd16(in%,endian%) :REM Skip two bytes
num%=FNrd16(in%,endian%) :REM Number of exif entries
:
item%=0
REPEAT
tag% =FNrd16(in%,endian%)
format%=FNrd16(in%,endian%)
size% =FNrd32(in%,endian%)
offset%=FNrd32(in%,endian%)
ptr%=PTR#in%
IF size%<4 THEN PTR#in%=PTR#in%-4 ELSE PTR#in%=exif%+offset%
:
CASE tag% OF
WHEN &0132:
PRINT "Date: ";:FOR lp%=1 TO size%:VDU BGET#in%:NEXT lp%: PRINT
WHEN &010F:
PRINT "Make: ";:FOR lp%=1 TO size%:VDU BGET#in%:NEXT lp%: PRINT
ENDCASE
:
PTR#in%=ptr%:item%=item%+1
UNTIL EOF#in% OR item%=num%
ENDPROC
:
DEFFNrd16(i%,e%)
IF e%=0:=BGET#i%+256*BGET#i% ELSE =256*BGET#i%+BGET#i%
:
DEFFNrd32(i%,e%)
LOCAL m%: DIM m% LOCAL 3
IF e%=0 :m%?0=BGET#i%:m%?1=BGET#i%:m%?2=BGET#i%:m%?3=BGET#i%
IF e%<>0:m%?3=BGET#i%:m%?2=BGET#i%:m%?1=BGET#i%:m%?0=BGET#i%
=!m%

Re: Reading dates from JPG files
Post by simong42 on Feb 11th, 2014, 11:49am

Excellent : thanks very much indeed!