Jump to content

UDF: ImageGetInfo


Lazycat
 Share

Recommended Posts

KaFu

I found a time to look into code. It was fully incorrect handling of tEXt section, looks like in my test set was no single file with this block. Also modified code to support for sections that may appear after IDAT section.

Now fixed and reuploaded.

Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

  • 3 weeks later...

Uploaded the third incarntion of UDF, that have many parts changed to newest features supported by Autoit (for example, binary strings). Therefore it will not work on earlier versions. This slightly increased speed for complex parsers. Output format remain the same.

TIFF/Exif parsers was merged and almost fully rewritten, since their implementation was not fully correct. Added most remain TIFF and Exif tags (all that can have an interest for "end user") and GPS tags as well. Some TIFF advanced features still not supported, but can be in future.

Also added second example (GUI) of using UDF.

Here surely can be bugs, so try carefully before updating.

Link to comment
Share on other sites

  • 5 months later...

Can you describe me shortly how to get the color depth of a TIF image? I cannot follow your code... :unsure:

According to the TIF documentation the information should be at offset 0x102 in a TIF file but I cannot see it. :>

What about the color depth of a JPG?

Thanks,

UEZ

PS: great bunch of code!

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Can you describe me shortly how to get the color depth of a TIF image?

In most cases, so

; http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf

#Include <WinAPI.au3>

Global $Bytes

$hFile = _WinAPI_CreateFile(@ScriptDir & '\Test.tif', 2, 2)

; Read TIFF file header (8 bytes)
$tData = DllStructCreate('ushort Order;ushort Type;dword Offset')
_WinAPI_ReadFile($hFile, DllStructGetPtr($tData), 8, $Bytes)

; Read number of tags (NumDirEntries) from the first IDF pointed to by "Offset" member (2 bytes)
_WinAPI_SetFilePointer($hFile, DllStructGetData($tData, 'Offset'))
$tData = DllStructCreate('ushort')
_WinAPI_ReadFile($hFile, DllStructGetPtr($tData), 2, $Bytes)

; Read all tags from the first IDF (12 * NumDirEntries bytes, the size of each tag = 12 bytes)
$Entries = DllStructGetData($tData, 1)
$tIFD = DllStructCreate('byte[' & (12 * $Entries) & ']')
$pIFD = DllStructGetPtr($tIFD)
_WinAPI_ReadFile($hFile, $pIFD, 12 * $Entries, $Bytes)

; Search the necessary tags and read the relevant data (if data size > 4 bytes, the "Value" member contains the offset to this data)
For $i = 1 To $Entries
    $tTag = DllStructCreate('ushort ID;ushort Type;dword Count;dword Value', $pIFD + 12 * ($i - 1))
    Switch DllStructGetData($tTag, 'ID')
        Case 0x0100 ; ImageWidth
            $W = DllStructGetData($tTag, 'Value')
        Case 0x0101 ; ImageLength
            $H = DllStructGetData($tTag, 'Value')
        Case 0x0102 ; BitsPerSample
            $Count = DllStructGetData($tTag, 'Count')
            $Value = DllStructGetData($tTag, 'Value')
            If $Count > 2 Then
                _WinAPI_SetFilePointer($hFile, $Value)
                $tData = DllStructCreate('ushort[' & $Count & ']')
                _WinAPI_ReadFile($hFile, DllStructGetPtr($tData), 2 * $Count, $Bytes)
                $BPP = DllStructGetData($tData, 1, 1)
            Else
                $BPP = BitAND($Value, 0xFF)
            EndIf
        Case 0x0103 ; Compression
            Switch DllStructGetData($tTag, 'Value')
                Case 1
                    $Compression = 'Uncompressed'
                Case 2
                    $Compression = 'CCITT Group 3'
                Case 5
                    $Compression = 'LZW'
                Case 7
                    $Compression = 'JPEG'
                Case 8
                    $Compression = 'ZIP'
                Case 32773
                    $Compression = 'PackBits'
                Case Else
                    $Compression = 'Unknown'
            EndSwitch
        Case 0x011A ; XResolution
            _WinAPI_SetFilePointer($hFile, DllStructGetData($tTag, 'Value'))
            $tData = DllStructCreate('dword[2]')
            _WinAPI_ReadFile($hFile, DllStructGetPtr($tData), 8, $Bytes)
            $XRes = Round(DllStructGetData($tData, 1, 1) / DllStructGetData($tData, 1, 2), 2)
        Case 0x011B ; YResolution
            _WinAPI_SetFilePointer($hFile, DllStructGetData($tTag, 'Value'))
            $tData = DllStructCreate('dword[2]')
            _WinAPI_ReadFile($hFile, DllStructGetPtr($tData), 8, $Bytes)
            $YRes = Round(DllStructGetData($tData, 1, 1) / DllStructGetData($tData, 1, 2), 2)
        Case 0x0128 ; ResolutionUnit
            Switch DllStructGetData($tTag, 'Value')
                Case 2
                    $Unit = 'dpi'
                Case 3
                    $Unit = 'dpcm'
                Case Else
                    $Unit = '?'
            EndSwitch
    EndSwitch
Next

_WinAPI_CloseHandle($hFile)

ConsoleWrite('Dimensions:  ' & $W & ' x ' & $H & ' pixels' & @CR)
ConsoleWrite('Resulution:  ' & $XRes & ' x ' & $YRes & ' ' & $Unit & @CR)
ConsoleWrite('Bit depth:   ' & $BPP & ' bpp' & @CR)
ConsoleWrite('Compression: ' & $Compression & @CR)

TIFF Specification (Revision 6.0)

According to the TIF documentation the information should be at offset 0x102 in a TIF file but I cannot see it.

0x102 is not offset, is an ID of the "BitsPerSample" tag. Edited by Yashied
Link to comment
Share on other sites

@Yashied: thank you very much for your explanation! I got it know!

But you made a mistake at the calculation of the BPP:

it should something like this:

...
        Case 0x0102 ; BitsPerSample
            $Count = DllStructGetData($tTag, 'Count')
            $Value = DllStructGetData($tTag, 'Value')
            If $Count > 2 Then
                _WinAPI_SetFilePointer($hFile, $Value)
                $tData = DllStructCreate('ushort[' & $Count & ']')
                _WinAPI_ReadFile($hFile, DllStructGetPtr($tData), 2 * $Count, $Bytes)
                For $j = 1 To $Count
                    $BPP += DllStructGetData($tData, 1, $j)
                Next
            Else
                $BPP = BitAND($Value, 0xFF)
            EndIf
...

You forgot to add the values in the struct if bpp is > 8.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 9 months later...

I've read about no plans for a "write" function because "there is no reason to write anything".

Well, here is a reason: I do have lots of images taken and I haven't added any copyright info (too lazy to set up the camera to do it but now I learned my lesson). I would like to add the copyright info to these images.

AFAIK, it can be done from Photoshop but that doesn't do it in bulk (not sure about the Organiser, have to do a bit of research).

So, if you have some spare time would you consider adding write support? Thanks.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

  • 2 years later...

Hello, This UDF is great :thumbsup:

I have been using version 3.0 of this script without any problem, but there some images (like one I have attached) that makes the script gives an error;

#include <image_get_info.au3>
Local $aInfo = _ImageGetInfo("test.jpg")
MsgBox(64, "test", $aInfo)

If im using SciTE, the script finish giving this error but the msgbox is not displayed;

image_get_info.au3" (355) : ==> Array maximum size exceeded.:

When I compile it, gives the same error "Error: Array maximum size exceeded"

The version 2.8 of the UDF work without problem.

I have to check various images in the script, how i can solve or bypass this error?

Thanks :bye:

post-62371-0-93180600-1422123585.jpg

Edited by ElEsteban
Link to comment
Share on other sites

  • 2 years later...
  • 1 year later...

What an old thread! But since Lazycat now hasn't logged into this forum since 2015, it may be that cat has just had his 10th life! In fact, lots of threads have not seen action in a decade or more and there aren't a lot of recent activity. Sign of the times? Is AutoIt gone along with the time of the desktop PC?

Anyway, is anyone doing anything with this code? I've tried it since I'd like to be able to get exif GPS location from my images, then send that to Google and get verbage about where the pic was taken. Hopefully incorporating that into my slide shows somehow.

I"ve tried the v3.0 udf on my pics and just get garbage back for GPS latitude and longitude. Anyone able to help with this problem?

Link to comment
Share on other sites

On 9/14/2019 at 2:29 AM, wysocki said:

Anyway, is anyone doing anything with this code? I've tried it since I'd like to be able to get exif GPS location from my images, then send that to Google and get verbage about where the pic was taken. Hopefully incorporating that into my slide shows somehow.

Take a look at the cGDIPlus_ImageGetAllPropertyItems() function here, it extracts GPS for my IPhone photos just fine:

 

Edited by KaFu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...