EXIF and I'm new to PureBasic

Just starting out? Need help? Post your questions and find answers here.
VinzZ
New User
New User
Posts: 9
Joined: Mon Aug 17, 2020 4:29 pm
Location: Belgium

EXIF and I'm new to PureBasic

Post by VinzZ »

Hey hey!
I had a small project that I want to program and I'm trying to find my way in PureBasic.

Project: Rename files to de EXIF date and time...

Ofcourse I started digging me in to PureBasic first.

And now I'm finally came to the point that I easily load a file list and can manipulate the filename...

But now, the bigger part, EXIF!! I found a lot here, and some code throws error (older PB version code?).

Is there someone how can point me out how to find EXIF data in a jpeg file?

Thanks a lot,
VinzZ
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: EXIF and I'm new to PureBasic

Post by infratec »

http://www.cipa.jp/std/documents/e/DC-X ... 2019-E.pdf

Chapter 4.5.4

And:

https://en.wikipedia.org/wiki/JPEG
Look at 'syntax and structure'

You have to 'walk' through the tags untill you reach APP1.
Then decode the EXIF data.
VinzZ
New User
New User
Posts: 9
Joined: Mon Aug 17, 2020 4:29 pm
Location: Belgium

Re: EXIF and I'm new to PureBasic

Post by VinzZ »

Thanks!!! I will look into this...

Regards,
VinzZ
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: EXIF and I'm new to PureBasic

Post by Saki »

VinzZ wrote:Thanks!!! I will look into this...

Regards,
VinzZ
Then you really have a lot to do !

--
Last edited by Saki on Tue Aug 25, 2020 8:12 am, edited 1 time in total.
地球上の平和
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: EXIF and I'm new to PureBasic

Post by infratec »

Code: Select all

#DHT = $C4FF
#DAC = $CCFF

#APP0 = $E0FF
#APP1 = $E1FF

#RST0 = $D0FF
#RST1 = $D1FF
#RST2 = $D2FF
#RST3 = $D3FF
#RST4 = $D4FF
#RST5 = $D5FF
#RST6 = $D6FF
#RST7 = $D7FF
#SOI = $D8FF
#EOI = $D9FF
#SOS = $DAFF
#DQT = $DBFF
#DRI = $DDFF

Filename$ = OpenFileRequester("Choose a jpg file", "", "JPG|*.jpg", 0)
If Filename$
  File = ReadFile(#PB_Any, Filename$)
  If File
    *Buffer = AllocateMemory(Lof(File), #PB_Memory_NoClear)
    If *Buffer
      If ReadData(File, *Buffer, MemorySize(*Buffer)) = MemorySize(*Buffer)
        If PeekU(*Buffer + Ptr) = #SOI
          Debug "Ok"
          Ptr + 2
          Repeat 
            Marker = PeekU(*Buffer + Ptr)
            Debug Hex(Marker)
            Ptr + 2
            Select Marker
              Case #APP1
                Break
              Case #DRI
                Ptr + 4
              Case #RST0, #RST1, #RST2, #RST3, #RST4, #RST5, #RST6, #RST7
              Default
                Debug Hex(PeekA(*Buffer + Ptr) << 8 | PeekA(*Buffer + Ptr + 1))
                Ptr + (PeekA(*Buffer + Ptr) << 8 | PeekA(*Buffer + Ptr + 1))
            EndSelect
            
          Until Ptr >= MemorySize(*Buffer) Or Marker = #SOS
          
          If Marker = #APP1
            Debug PeekS(*Buffer + Ptr + 2, 4, #PB_Ascii)
            If PeekS(*Buffer + Ptr + 2, 4, #PB_Ascii) = "Exif"
              Debug "Exif found"
            EndIf
          Else
            Debug "No Exif found"
          EndIf
          
        EndIf
      EndIf
      FreeMemory(*Buffer)
    EndIf
    CloseFile(File)
  EndIf
EndIf
VinzZ
New User
New User
Posts: 9
Joined: Mon Aug 17, 2020 4:29 pm
Location: Belgium

Re: EXIF and I'm new to PureBasic

Post by VinzZ »

Holy!!! Saki and Infratec... Thank you so much.
As I said, new to purebasic and some examples that I found were for the older versions!

I know EXIF to start with isn't that easy, but I need a project for my own that I can use to dig me in to PureBasic.

It's quite a long time a go that I really was into programming. A lifetime ago I was programming in assembly for the Commodore64. And I was starting to miss programming a bit.

Don't know if PureBasic is the best option to start some programming again. But I saw some very neat free utilities (forgot the author) that were written in Pure Basic.

But already bought the license :)

Kind regards,
And again: thank you for the help!

VinzZ
Bitblazer
Enthusiast
Enthusiast
Posts: 761
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: EXIF and I'm new to PureBasic

Post by Bitblazer »

Welcome to the purebasic forum.

You might like the fact that you can use inline assembler in purebasic. But it is a bit different to 65xx assembler, especially since many switch to 64-Bit lately ;)
Check the Inline x86 assembly instructions. Purebasic allows you to create a comented assembly listing of a purebasic program (see the command line compiler switch /commented, but i think that option is not available from inside the IDE).
Last edited by Bitblazer on Tue Aug 18, 2020 4:37 pm, edited 3 times in total.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: EXIF and I'm new to PureBasic

Post by Saki »

Hi, for rotating the image you can look in the manual for "RotateCoordinates()", it's very simple.

Best Regards Saki
地球上の平和
VinzZ
New User
New User
Posts: 9
Joined: Mon Aug 17, 2020 4:29 pm
Location: Belgium

Re: EXIF and I'm new to PureBasic

Post by VinzZ »

Yeah, I saw that there was en ASM option. Made my choice for PureBasic easier, however I'm not sure if I will use it :)

Well, I started something with that EXIF / TIFF tag... Just want to get out the date the picture was taken, but I'm digging deeper and deeper in all kind of markers and Intel/Motorola, Hex editor... Kind of fun.
I'm so out of programming that I didn't know what the little endian was. Was confusing at first why the bytes were inversed.

Well well, my feet back on the ground. Looks all new again :) But interesting!

Thanks a lot! I'm enjoying the exploration ;)
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 345
Joined: Sat Dec 25, 2004 2:37 pm

Re: EXIF and I'm new to PureBasic

Post by thyphoon »

other solution, use Exiftools. A great tools
I made a module : viewtopic.php?f=12&t=72105
VinzZ
New User
New User
Posts: 9
Joined: Mon Aug 17, 2020 4:29 pm
Location: Belgium

Re: EXIF and I'm new to PureBasic

Post by VinzZ »

Thanks Thyphoon!
Will see where I get without third-party tools. Even if it is just for learning the PureBasic code and syntax

Building a picasa alternative looks like a big project!

Kind regards,
VinzZ
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: EXIF and I'm new to PureBasic

Post by Saki »

Hi,
this is in itself a far too deep project to get started.
The problem is that with increasing PB knowledge you will in fact always start from scratch.
I would recommend first creating a window that can be resized.
Then add an image viewer, which always adjusts the image proportionally on demand.
A few gadgets below.

Remember to make it DPI aware if it is for Windows,
this is often extremely difficult to achieve afterwards.

Then you can think about how you want to edit or optimize it.

Best Regards Saki
地球上の平和
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 283
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: EXIF and I'm new to PureBasic

Post by oreopa »

VinzZ wrote:A lifetime ago I was programming in assembly for the Commodore64.
Come back then - there are a lot of easy cross development options these days :) (Yes the C64 scene still exists! :D )
Proud supporter of PB! * Musician * C64/6502 Freak
VinzZ
New User
New User
Posts: 9
Joined: Mon Aug 17, 2020 4:29 pm
Location: Belgium

Re: EXIF and I'm new to PureBasic

Post by VinzZ »

oreopa wrote:Come back then - there are a lot of easy cross development options these days :) (Yes the C64 scene still exists! :D )
Haha, nice to meet you! Super!! I know it isn't dead yet... But I don't have that much sparetime left, but it was a good time then, way back when I was 16 and over, now I am 47 ;)
VinzZ
New User
New User
Posts: 9
Joined: Mon Aug 17, 2020 4:29 pm
Location: Belgium

Re: EXIF and I'm new to PureBasic

Post by VinzZ »

Thanks for all your input!
I finally have working code to find the "date/time captured" of a jpg file and rename the file as I wish. Pure code, just took a deep dive into EXIF, IFD, SubIFDs and it was quite fun :)
This was the best info about EXIF I could find: https://www.media.mit.edu/pia/Research/ ... /exif.html

I have written a little procedure to change the output of some peek values form big endian to little endian.

I wonder if purebasic has something build in? Didn't find something though.

Kind regards,
Vincent
Post Reply