ExifTool Forum

ExifTool => Developers => Topic started by: Curtis on November 01, 2013, 05:10:26 PM

Title: How to get the count of values for a tag when using the -X -n options?
Post by: Curtis on November 01, 2013, 05:10:26 PM
Hi Phil,

As you have seen from my previous posts, I'm using the -listx option to get all my information about tags (see samples at end).  Some tags (like ExifIFD:ComponentsConfiguration and EXifIFD:ColorSpace) have a given set of valid values (key/val list), most just have one value like ColorSpace does but some have more.  The EXIF spec says ExifIFD:ComponentsConfiguration will have 4 (count = 4 in the IFD structure for this tag).  Is there a way I can get this count from ExifTool?  It does not show up in the -listx output for these tags (and likely others).  (some tags do have a count attribute, but it does not seem to be the 'count' I am looking for, or is it... and the count attribute is just missing on some of the tags from the -listx output?)

As an example in my -X -n output I have:
<ExifIFD:ComponentsConfiguration et:id='37121' et:table='Exif::Main'>1 2 3 0</ExifIFD:ComponentsConfiguration>

since from my -listx output I know ExifIFD:ComponentsConfiguration has a key/val list, is it safe to assume that the returned tag value string is the set of values, space delimited? (ie would be  1, 2, 3 and 0)  Will the values always be space delimited?

Bottom line: how can I determine the number of values and the individual values I should have for a tag that has a key/val list?

Thanks!
Curtis

PS:  See edit at very end....

<tag id="37121" name="ComponentsConfiguration" type="undef" writable="true" flags="Mandatory,Unsafe" g1="ExifIFD">
  <desc lang="en">Components Configuration</desc>
  <desc lang="cs">Určení složek</desc>
  <desc lang="de">Bedeutung jeder Komponente</desc>
  <desc lang="es">Configuración de Componentes</desc>
  <desc lang="fi">Kunkin komponentin tarkoitus</desc>
  <desc lang="fr">Signification de chaque composante</desc>
  <desc lang="it">Configurazione componenti</desc>
  <desc lang="ja">å,,æ§‹æˆè¦ç´ ã®æ,,å'³</desc>
  <desc lang="ko">각 구ì,,± ìš"소의 의미</desc>
  <desc lang="nl">Betekenis van elke component</desc>
  <desc lang="pl">Znaczenie każdego komponentu</desc>
  <desc lang="ru">Значение каждого компоненÑ,а</desc>
  <desc lang="sv">Enskilda komponenters betydelse</desc>
  <desc lang="tr">Her komponentin anlamı</desc>
  <desc lang="zh_cn">å,,分ç»,,çš,,含义</desc>
  <desc lang="zh_tw">每個çµ,,成部分çš,,æ,,ç¾©</desc>
  <values>
    <key id="0">
      <val lang="en">-</val>
    </key>
    <key id="1">
      <val lang="en">Y</val>
    </key>
    <key id="2">
      <val lang="en">Cb</val>
    </key>
    <key id="3">
      <val lang="en">Cr</val>
    </key>
    <key id="4">
      <val lang="en">R</val>
    </key>
    <key id="5">
      <val lang="en">G</val>
    </key>
    <key id="6">
      <val lang="en">B</val>
    </key>
  </values>
</tag>

and ....

<tag id="40961" name="ColorSpace" type="int16u" writable="true" flags="Mandatory" g1="ExifIFD">
  <desc lang="en">Color Space</desc>
  <desc lang="cs">Barevný prostor</desc>
  <desc lang="de">Farbraum</desc>
  <desc lang="en_ca">Colour Space</desc>
  <desc lang="en_gb">Colour Space</desc>
  <desc lang="es">Espacio Color</desc>
  <desc lang="fi">Väriavaruus</desc>
  <desc lang="fr">Espace colorimétrique</desc>
  <desc lang="it">Spazio colore</desc>
  <desc lang="ja">色空é–"</desc>
  <desc lang="ko">색공ê°,,</desc>
  <desc lang="nl">Kleur ruimte</desc>
  <desc lang="pl">Informacja o przestrzeni barwowej</desc>
  <desc lang="ru">Ð"анные о цвеÑ,овой среде</desc>
  <desc lang="sv">FärgomrÃ¥desinformation</desc>
  <desc lang="tr">Renk alanı bilgisi</desc>
  <desc lang="zh_cn">色彩空间信息</desc>
  <desc lang="zh_tw">色彩空é–"</desc>
  <values>
    <key id="1">
      <val lang="en">sRGB</val>
      <val lang="fr">sRVB</val>
    </key>
    <key id="2">
      <val lang="en">Adobe RGB</val>
    </key>
    <key id="65533">
      <val lang="en">Wide Gamut RGB</val>
      <val lang="es">Gamut RVB Grande</val>
      <val lang="fi">Laaja Gamut RVB</val>
      <val lang="fr">Wide Gamut RVB</val>
    </key>
    <key id="65534">
      <val lang="en">ICC Profile</val>
      <val lang="cs">ICC Profil</val>
      <val lang="de">ICC-Profil</val>
      <val lang="es">Perfil ICC</val>
      <val lang="fi">ICC-profiili</val>
      <val lang="fr">Profil ICC</val>
      <val lang="it">Profilo ICC</val>
      <val lang="ja">ICCプロフã,£ãƒ¼ãƒ«</val>
      <val lang="ko">ICC í",,로í•,,</val>
      <val lang="nl">ICC-profiel</val>
      <val lang="ru">ПроÑ,,иль ICC</val>
      <val lang="sv">ICC-profil</val>
      <val lang="zh_cn">色彩特性文件</val>
      <val lang="zh_tw">色彩描述æª"</val>
    </key>
    <key id="65535">
      <val lang="en">Uncalibrated</val>
      <val lang="cs">Nekalibrován</val>
      <val lang="de">Nicht festgelegt</val>
      <val lang="es">Sin calibrar</val>
      <val lang="fi">Kalibroimaton</val>
      <val lang="fr">Non calibré</val>
      <val lang="it">Non calibrato</val>
      <val lang="ja">未調整</val>
      <val lang="ko">ì¡°ì •ë˜ì§€ 않음</val>
      <val lang="nl">Niet vastgelegd</val>
      <val lang="pl">Nie skalibrowany</val>
      <val lang="ru">Не калиброванный</val>
      <val lang="sv">Ej kalibrerat</val>
      <val lang="tr">Kalibre edilmemiÅŸ</val>
      <val lang="zh_cn">自å'</val>
      <val lang="zh_tw">æœªæ ¡æº–</val>
    </key>
  </values>
</tag>




Edit: Just realized that tags without key/val lists may also have multiple values, such as: (will have 2 values for width & height)

<table name="Casio::Type2" g0="MakerNotes" g1="Casio" g2="Camera">
    <desc lang="en">Casio Type2</desc>
    <tag id="2" name="PreviewImageSize" type="int16u" writable="true" flags="Permanent" g2="Image">
      <desc lang="en">Preview Image Size</desc>
      <desc lang="de">Vorschaubild-Größe</desc>
      <desc lang="es">Tamaño Imagen Previa</desc>
      <desc lang="fi">Kuvakoon esikatselu</desc>
      <desc lang="fr">Taille d'image miniature</desc>
      <desc lang="it">Dimensioni immagine anteprima</desc>
      <desc lang="ja">プレãƒ"ューã,¤ãƒ¡ãƒ¼ã,¸ã,µã,¤ã,º</desc>
      <desc lang="pl">Rozmiar podglÄ...du</desc>
    </tag>


As an example in my -X -n output I have:

<Casio:PreviewImageSize et:id='2' et:table='Casio::Type2'>640 480</Casio:PreviewImageSize>

showing 2 values 640 and 480 (without -n option, output is "640x480")

So... final bottom line question:
When using -X -n how can I determine how many values are contained in the returned value string from Exiftool? (for tags that have a fixed number of values like this, (not for arrays with a List/Seq/Bag/Alt flag))

Thanks again for any ideas!
Title: Re: How to get the count of values for a tag when using the -X -n options?
Post by: Phil Harvey on November 01, 2013, 08:20:36 PM
Hi Curtis,

Good catch.  ExifTool was was not reporting the count for EXIF-type tags in the XML output.  I'll fix this in the next release.

- Phil
Title: Re: How to get the count of values for a tag when using the -X -n options?
Post by: Curtis on November 01, 2013, 09:01:52 PM
Thanks Phil!   :) 

Is it safe to assume that when the count is greater than 1 that the individual key values given in the tag value from ExifTool will always be space delimited?   This would assume there are no valid individual key values that could have a space in them.

Thanks again for a great tool!

Curtis
Title: Re: How to get the count of values for a tag when using the -X -n options?
Post by: Phil Harvey on November 01, 2013, 09:06:45 PM
Hi Curtis,

What type of value?  There could very well be spaces in the print-converted values, but likely not in the numerical values.  Also, if type is 'string' or 'undef', the count will represent the number of character/bytes, with no spaces between them.  There may be other exceptions, but I can't think of any right now.

- Phil
Title: Re: How to get the count of values for a tag when using the -X -n options?
Post by: Curtis on November 01, 2013, 09:36:29 PM
Hi Phil,

I guess the only for sure ones would be where there is a key/val list,  like for ExifIFD:ComponentsConfiguration  type="undef".  For this I'd expect the count to be 4.  And the output string I'm getting from ExifTool now is, as given in my first post, "1 2 3 0" which is 4 values separated by 3 spaces = 7 character/bytes.  Some tags with key/val lists (ie MXP-mwg-rs:RegionType have strings for the keys, hopefully the keys would always have no spaces in them OR the count is 1 (like MXP-mwg-rs:RegionType is) so no parsing is needed.

I do always use the -n option so I don't get print-converted values, so that should not be a problem.

Curtis
Title: Re: How to get the count of values for a tag when using the -X -n options?
Post by: Phil Harvey on November 02, 2013, 05:48:02 AM
Hi Curtis,

Looking at ComponentsConfiguration in Exif.pm, I see that it is a special case.  It is stored as undef, but ExifTool reads it as int8u (because that's what it really should have been -- the EXIF people weren't very smart).  So this is one rare case where the count for an undef format indicates a number of space-delimited values.

- Phil
Title: Re: How to get the count of values for a tag when using the -X -n options?
Post by: Curtis on November 02, 2013, 08:53:09 PM
Hi Phil,

After looking into this some more I have found several examples where I'm going to run into problems with determining what 'choices' to offer the user for inputting different tag values. 

My goal is to use all of the info that ExifTool has for doing its Print Conversion (and other info?) for the tag values to help determine how to get input from the user for tag values.  Previously in my code I had assumed (incorrectly) that if there was a key/val list, that ExifTool would return one of the keys from that list for tag values, and I could then allow the user to input one key from the list, I now know I can't make this assumption and there are a variety of ways to combine either a fixed or variable number of key values together.

So as in the example of ExifIFD:ComponentsConfiguration, having the count (4) with the –listx XML info I would then know that I need 4 values (not just one) and the valid values are given in the key/val list. Also, possibly I could assume that each key could only be used once in the set of 4, but I doubt this is generally true.

There are some other situations that ExifTool knows how to handle, but it seems like the info needed to handle these situations is not given in the –listx XML.  Below are examples of types of tags I found where I think I need a little more info included in the –listx output or some other info from ExifTool.

All below are extractions from the –listx output (<desc lang... lines deleted for brevity)  All but the XMP LensInfo examples have key/val lists.

Thanks for any advice!
Curtis

<table name="Canon::CameraInfoUnknown32" g0="MakerNotes" g1="Canon" g2="Camera">

---lines deleted---

<tag id="29" name="FlashBits" type="int16s" writable="true" flags="Permanent">
      <values>
        <key id="1">
          <val lang="en">Manual</val>
        </key>
        <key id="2">
          <val lang="en">TTL</val>
        </key>
        <key id="4">
          <val lang="en">A-TTL</val>
        </key>
        <key id="8">
          <val lang="en">E-TTL</val>
        </key>
        <key id="16">
          <val lang="en">FP sync enabled</val>
        </key>
        <key id="128">
          <val lang="en">2nd-curtain sync used</val>
        </key>
        <key id="2048">
          <val lang="en">FP sync used</val>
        </key>
        <key id="8192">
          <val lang="en">Built-in</val>
        </key>
        <key id="16384">
          <val lang="en">External</val>
        </key>
      </values>
    </tag>

From the above, for a tag value of 8200 (= 8 + 8192), Print Converted value = "E-TTL, Built-in". How can I determine I should use the key id attribute values as bits instead of numbers and know that can have multiple (ie variable number of) values?  Here 2 values are used, but I assume it could be 0 to 9 values used.

<table name="Canon::CameraSettings" g0="MakerNotes" g1="Canon" g2="Camera">

---lines deleted---

<tag id="22" name="LensType" type="int16s" writable="true" flags="Permanent">
      <values>
        <key id="1">
          <val lang="en">Canon EF 50mm f/1.8</val>
        </key>
        <key id="2">
          <val lang="en">Canon EF 28mm f/2.8</val>
        </key>
        <key id="3">
          <val lang="en">Canon EF 135mm f/2.8 Soft</val>
        </key>
--and more lens values......---

Here for a particular jpeg file I get back a value of "-1", for this the Print Converted value is "Unknown (-1)".  Can I assume that if I get a value back of "-1" that that is a valid value and its value is "unknown", versus I get say "-2" and that is simply an invalid value?

<table name="Canon::Main" g0="MakerNotes" g1="Canon" g2="Camera">

---lines deleted---

<tag id="35" name="Categories" type="int32u" writable="true" flags="Permanent">
      <values>
        <key id="1">
          <val lang="en">People</val>
        </key>
        <key id="2">
          <val lang="en">Scenery</val>
        </key>
        <key id="4">
          <val lang="en">Events</val>
        </key>
        <key id="8">
          <val lang="en">User 1</val>
        </key>
        <key id="16">
          <val lang="en">User 2</val>
        </key>
        <key id="32">
          <val lang="en">User 3</val>
        </key>
        <key id="64">
          <val lang="en">To Do</val>
        </key>
      </values>
    </tag>

This also looks like a type where the bits can be added to have multiple values given.  In my sample jpg file I have a value of 0 and the Print Converted value is "(none)"

<table name="ICC_Profile::Measurement" g0="ICC_Profile" g1="ICC-meas" g2="Image">

---lines deleted---

<tag id="24" name="MeasurementGeometry" type="int32u" writable="false">
      <values>
        <key id="1">
          <val lang="en">0/45 or 45/0</val>
        </key>
        <key id="2">
          <val lang="en">0/d or d/0</val>
        </key>
      </values>
    </tag>

In my sample jpg file I get a value of "0" and the Print Converted value is "Unknown (0)"   Whereas before a value of "0" for Categories came back as "(none)", how can I distinguish the correct meaning of a value of "0"?

<table name="XMP::aux" g0="XMP" g1="XMP-aux" g2="Camera">

---lines deleted---

<tag id="LensInfo" name="LensInfo" type="string" writable="true">
    </tag>

This is a tough one, there is not key/val list, but Print Convert knows how to convert this from a value of "100 100 undef undef" a Print Converted value comes back as "100mm f/?"  Where can I get the data/info to be able to know (that it appears) 4 values can be put in?

<table name="Canon::CameraSettings" g0="MakerNotes" g1="Canon" g2="Camera">
---lines deleted---

<tag id="13" name="Contrast" type="int16s" writable="true" flags="Permanent">
      <values>
        <key id="0">
          <val lang="en">Normal</val>
        </key>
      </values>
    </tag>

From my sample jpg I get a value of "1" and even though it is not in the key/val list, the Print Converted value is "+1".  How do I know 1 is a valid value when it is not in the list?
Title: Re: How to get the count of values for a tag when using the -X -n options?
Post by: Phil Harvey on November 02, 2013, 09:58:07 PM
Hi Curtist,

Let me start off by saying that applying formatting templates to the input values is not something that ExifTool does, and as such, the -listx output will never be able to provide all of the details that you want to know.  If you really want to go down this path in a strict way, then you will have to build your own database of templates for each tag.

Quote from: Curtis on November 02, 2013, 08:53:09 PM
So as in the example of ExifIFD:ComponentsConfiguration, having the count (4) with the –listx XML info I would then know that I need 4 values (not just one) and the valid values are given in the key/val list.

Not generally true.  As I mentioned, the count for 'undef' values is usually the length of a (possibly binary) string.  ComponentsConfiguration is an exception.

QuoteThere are some other situations that ExifTool knows how to handle, but it seems like the info needed to handle these situations is not given in the –listx XML.

True.  In general, ExifTool doesn't do much high-level validation of the input data, and will often even let you write illegal values, but I find this preferable to restricting possibly valid but unanticipated uses for some tag.

QuoteFrom the above, for a tag value of 8200 (= 8 + 8192), Print Converted value = "E-TTL, Built-in". How can I determine I should use the key id attribute values as bits instead of numbers and know that can have multiple (ie variable number of) values?  Here 2 values are used, but I assume it could be 0 to 9 values used.

Good question.  I have provided no way for you to tell if the keys are bit masks or values.  I'll have to think about this.

QuoteHere for a particular jpeg file I get back a value of "-1", for this the Print Converted value is "Unknown (-1)".  Can I assume that if I get a value back of "-1" that that is a valid value and its value is "unknown", versus I get say "-2" and that is simply an invalid value?

If Canon ever writes a value of -2, who are we to call it invalid?  But I get your point.  "Unknown (-1)" indicates an unknown lens (either a built-in PowerShot lens or an unchipped lens on an EOS model), and "Unknown (-2)" indicates a value unknown to ExifTool.  There may be other cases like this.

QuoteThis also looks like a type where the bits can be added to have multiple values given.  In my sample jpg file I have a value of 0 and the Print Converted value is "(none)"

Yes, another bitmask.

QuoteIn my sample jpg file I get a value of "0" and the Print Converted value is "Unknown (0)"   Whereas before a value of "0" for Categories came back as "(none)", how can I distinguish the correct meaning of a value of "0"?

This is the same question again.  One is a bitmask.  I have to think about this.

QuoteThis is a tough one, there is not key/val list, but Print Convert knows how to convert this from a value of "100 100 undef undef" a Print Converted value comes back as "100mm f/?"  Where can I get the data/info to be able to know (that it appears) 4 values can be put in?

I would think that this scenario would be very common.  Many tags are converted into more readable values like this.  Exposing the details of all ExifTool print conversions for use in other software would be prohibitively difficult, unless your app can parse Perl.

QuoteFrom my sample jpg I get a value of "1" and even though it is not in the key/val list, the Print Converted value is "+1".  How do I know 1 is a valid value when it is not in the list?

ExifTool has a mechanism to allow an alternate conversion to be applied to values not in the list.  Again, revealing useful details of this for you would be very difficult.

- Phil
Title: Re: How to get the count of values for a tag when using the -X -n options?
Post by: Curtis on November 02, 2013, 10:52:02 PM
Thanks Phil for the quick reply.... I was probably too optimistic that additional info could be put into the -listx output...

Possibly I can look at the Print Converted output in addition to the -listx info  for a given tag to infer some more info about how to properly accept input for a tag value.  I'll have to rethink my strategy on this...
(the 'build my own database' does not sound real appealing as you have already done that very well and I could not imagine doing it myself!)

Glad I could give you a few things to think about....   :D

Curtis