Farbtiefe eines TIFF Bildes ermitteln

  • Momentan komme ich nicht weiter, um die Farbtiefe eines TIFF Bildes zu bestimmen.

    Infos zum TIFF Bild: http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf

    Wenn ich mir die Stelle 0x0102, kann ich keine Infos zur Farbtiefe des TIFF Bildes sehen!

    Ich weiß, dass Lazycat ein Tool geschrieben hat: http://www.autoitscript.com/forum/topic/13…f-imagegetinfo/, aber ich blicke momentan da nicht richtig durch. 8|

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    3 Mal editiert, zuletzt von UEZ (3. Mai 2011 um 10:02)

  • Falls es euch interessiert:

    Spoiler anzeigen
    [autoit]


    #include-once
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Local $sFile = FileOpenDialog("Select an image", "", "(*.jpg;*.png;*.bmp;*.gif)")
    If @error Then Exit
    Local $aDimension = Get_Image_Info($sFile)
    If @error Then Exit MsgBox(16, "Error", "An error has occured!", 10)
    MsgBox(0, "Image Information", "Filename: " & $sFile & @LF & @LF & _
    "Width: " & @TAB & @TAB & $aDimension[0] & @LF & _
    "Height: " & @TAB & @TAB & $aDimension[1] & @LF & _
    "DPI: " & @TAB & @TAB & $aDimension[2] & "x" & $aDimension[3] & @LF & _
    "Color Depth: " & @TAB & $aDimension[4] & @LF & _
    "Image Type: " & @TAB & $aDimension[5], 30)
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# =====================================================================================
    ; Name.............: Get_Image_Info
    ; Description ...: Returns some information of an image from a file
    ; Syntax............: Get_Image_Info($sFile)
    ; Parameters ....: $sFile - filename of the image
    ; Return value ..: Zero based array ->
    ; $iDim[0] = width, $iDim[1] = height, $iDim[2] = DPIx, $iDim[3] = DPIy, $iDim[4] = color depth, $iDim[5] = image type
    ; Requirements .: GDIPlus.au3
    ; Author ...........: UEZ, Yashied (TIF bpp code)
    ; Version ..........: v0.80 build 2011-05-03 Beta
    ; ================================================================================================
    Func Get_Image_Info($sFile)
    If Not FileExists($sFile) Then Return SetError(1, 0, False)
    Local $declared = 1, $iDim[6]
    If Not $ghGDIPDll Then
    _GDIPlus_Startup()
    $declared = 0
    EndIf
    Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hImage)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipGetImageDimension", "handle", $hImage, "float*", 0, "float*", 0)
    If @error Then Return SetError(@error, @extended, False)
    $iDim[0] = $aResult[2]
    $iDim[1] = $aResult[3]
    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetDpiX", "handle", $hContext, "float*", 0)
    If @error Then Return SetError(@error, @extended, False)
    $iDim[2] = Round($aResult[2], 0)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetDpiY", "handle", $hContext, "float*", 0)
    If @error Then Return SetError(@error, @extended, False)
    $iDim[3] = Round($aResult[2], 0)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_ImageDispose($hImage)
    If Not $declared Then _GDIPlus_Shutdown()
    GetImageInfo($sFile, $iDim)
    Return $iDim
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;Internal Function
    Func GetImageInfo($sFile, ByRef $iDim)
    Local $tBuffer, $hFile, $nBytes, $bytes2read = 0x24, $sHeader
    $tBuffer = DllStructCreate("byte[" & $bytes2read & "]")
    $hFile = _WinAPI_CreateFile($sFile, 2, 2)
    _WinAPI_SetFilePointer($hFile, 0)
    _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $bytes2read, $nBytes)
    _WinAPI_CloseHandle($hFile)
    $sHeader = DllStructGetData($tBuffer, 1)
    If StringInStr($sHeader, "0x89504E47") Then ;http://www.w3.org/TR/PNG/#11IHDR
    $iDim[5] = "png"
    Switch DllStructGetData($tBuffer, 1, 0x1A)
    Case 0
    $iDim[4] = DllStructGetData($tBuffer, 1, 0x19) & " bit greyscale"
    Case 2
    $iDim[4] = 3 * DllStructGetData($tBuffer, 1, 0x19) & " bit truecolor"
    Case 3
    $iDim[4] = DllStructGetData($tBuffer, 1, 0x19) & " bit indexed-color"
    Case 4
    $iDim[4] = 3 * DllStructGetData($tBuffer, 1, 0x19) & " bit greyscale with alpha"
    Case 6
    $iDim[4] = 3 * DllStructGetData($tBuffer, 1, 0x19) & " bit truecolor with alpha"
    EndSwitch
    ElseIf Not StringRegExp($sHeader, "0x.+FFE0.+4A46[494600|585800]", 3) Then ;http://en.wikipedia.org/wiki/JPEG_File_Interchange_Format
    $iDim[5] = "jpg"
    $iDim[4] = "24 bit" ;that's is not really true ;)
    ElseIf StringInStr($sHeader, "0x424D") Then ;http://de.wikipedia.org/wiki/Windows_Bitmap
    $iDim[5] = "bmp"
    $iDim[4] = DllStructGetData($tBuffer, 1, 0x1D) & " bit"
    ElseIf Not StringRegExp($sHeader, "0x49492A|0x4D4D2A", 3) Then ;http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
    $iDim[5] = "tif"
    Local $Bytes, $i, $j, $Count, $Value, $tTag, $BPP
    Local $hFile = _WinAPI_CreateFile($sFile, 2, 2)

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    ; 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)

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    ; 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 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
    EndSwitch
    Next
    _WinAPI_CloseHandle($hFile)
    $iDim[4] = $BPP & " bit"
    ElseIf Not StringRegExp($sHeader, "0x474946383[7|9]61", 3) Then
    $iDim[5] = "gif"
    $iDim[4] = BitAND(DllStructGetData($tBuffer, 1, 0x0B), 7) + 1 & " bit"
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit]

    Dank an Yashied für seine Erläuterungen!

    Fehlt noch die Farbtiefe von JPG Bildern (ist nicht immer 24 bit!)

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (3. Mai 2011 um 10:09)