Page 1 of 2

EXIF and I'm new to PureBasic

Posted: Mon Aug 17, 2020 4:41 pm
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

Re: EXIF and I'm new to PureBasic

Posted: Mon Aug 17, 2020 5:50 pm
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.

Re: EXIF and I'm new to PureBasic

Posted: Mon Aug 17, 2020 6:11 pm
by VinzZ
Thanks!!! I will look into this...

Regards,
VinzZ

Re: EXIF and I'm new to PureBasic

Posted: Mon Aug 17, 2020 6:36 pm
by Saki
VinzZ wrote:Thanks!!! I will look into this...

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

--

Re: EXIF and I'm new to PureBasic

Posted: Mon Aug 17, 2020 9:19 pm
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

Re: EXIF and I'm new to PureBasic

Posted: Tue Aug 18, 2020 1:43 pm
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

Re: EXIF and I'm new to PureBasic

Posted: Tue Aug 18, 2020 4:03 pm
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).

Re: EXIF and I'm new to PureBasic

Posted: Tue Aug 18, 2020 4:13 pm
by Saki
Hi, for rotating the image you can look in the manual for "RotateCoordinates()", it's very simple.

Best Regards Saki

Re: EXIF and I'm new to PureBasic

Posted: Wed Aug 19, 2020 6:31 pm
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 ;)

Re: EXIF and I'm new to PureBasic

Posted: Thu Aug 20, 2020 9:23 am
by thyphoon
other solution, use Exiftools. A great tools
I made a module : viewtopic.php?f=12&t=72105

Re: EXIF and I'm new to PureBasic

Posted: Thu Aug 20, 2020 3:58 pm
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

Re: EXIF and I'm new to PureBasic

Posted: Thu Aug 20, 2020 4:45 pm
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

Re: EXIF and I'm new to PureBasic

Posted: Thu Aug 20, 2020 5:38 pm
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 )

Re: EXIF and I'm new to PureBasic

Posted: Wed Aug 26, 2020 2:35 pm
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 ;)

Re: EXIF and I'm new to PureBasic

Posted: Tue Sep 15, 2020 12:24 pm
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