DMフォーマット

提供: Eospedia
2015年4月6日 (月) 04:07時点におけるTacyas (トーク | 投稿記録)による版

移動: 案内検索

GATAN DIgital Micrographのフォーマットです。 開発の際に、[http://www.er-c.org/cbb/info/dmformat/] にある情報を理解するためにこちらにまとめました。

DM3

 画像は、ヘッダー、タグディレクトリ、ファイルの最後を示したNULL(8文字)からなっている。タグディレクトリは、タグか複数のタグディレクトリを階層構造として持つ事ができる。

 画像は、"ImageList"と名付けられたtag directoryに格納されている。一つ以上の画像を格納できる。

Header

 version   i4be    DM version = 3
 rootlen   i4be    Size of root tag directory in bytes = file length - 16
 byteord   i4be    Byte order, 0 = big endian (Mac) order,
                               1 = little endian (PC) order

Root tag directory

 sortf     i1      Sorted, 1 = sorted (normally = 1)
 closef    i1      Closed, 1 = open (normally = 0)
 ntags     i4be    Number of tags in root directory (12h = 18)

Tags and tag directories in root tag directory

下記が繰り返される

 tag       i1      tag, 14h or 15h or 0 for end of file (0x14, 0x15, 0x00)
 ltname    i2be    tag name length in bytes, may be 0
 tname     a       tag name (length ltname), may be absent
 ...               tag directory or tag data

ファイルの最後

 8*00     End of file is marked with 8 nulls


ファイル全体の構造

(例)

 00 00 00 03  バージョン                                          dmFileHeaderTailRead
 00 22 59 b9    ファイルサイズ - 16                            dmFile3HeaderRead
 00 00 00 00  バイトオーダー
 01                      Root tag: Stored                                dmFile3TagDirectoryHeaderRead
 00                      Root tag: Closed
 00 00 00 12  Root tagの数
 15       TagID                                                  dmFile3TagHeaderRead
 00 11                TagNameのバイト数  
 41 70 70  6c 69 63 61  74 69 6f 6e 
                          TagName("Application")                    --> Tags
 ......
 14       TagID                                                  dmFile3TagHeaderRead 
 00 11                TagNameのバイト数  
 41 70 70  6c 69 63 61  74 69 6f 6e 
                          TagName("Application")                     --> Tag Directories
 ......

00 00 00 00 00 00 00 00  ファイルの終わり              dmFileHeaderTailRead

Tag directories と Tags

Root tag directoryや下位層のtag directoriesにおいて、その内部構造としてタグ、もしくは、タグディレクトリがあることの判断をする部分

 0x14 = 20 : タグディレクトリ(更に下位にタグディレクトリがある)
 0x15 = 21 : タグ
 0x00 = 00 : ファイルの終了

Tag directories

 14   00 12   44 6f 63 75 6d 65 6e 74 4f 62 6a 65 63 74 4c 69 73 74
 00   00   00 00 00 01
 ......
 14             i1      identifies tag directory (14h = 20)
 00 12        i2be    bytes in tag name (ltname), may be 0
 44 6f 63 75  6d 65 6e 74  4f 62 6a 65  63 74 4c 69  73 74
                a       tag name, length ltname "DocumentObjectList"  ここまでは共通
 00             i1      1 = sorted? (can be 0 or 1) タグディレクトリの場合には下記が入ってくる
 00             i1      0 = closed?, 1 = open (normally = 0)
 00 00 00 01    i4be    number of tags in tag directory (01h = 1). Can be 0

Tags

i1                  identifies tag (15h = 21)
i2be              ltname, bytes in tag name, may be 0 
a                   tag name, length ltname           ここまでは共通
a4                 string "%%%%"               タグの場合のセパレータ
i4be              ninfo, size of info array following (=1) 
i4be*ninfo     info(ninfo), array of ninfo integers contains tag data type(s) for tag values 
xx* * ninfo     tag values (byte order set by byte order flag) byte lengths specified in info(ninfo)

単純なタグ

Example

 15   00 0e   41 6e 6e 6f 74 61 74 69 6f 6e 54 79 70 65
 25 25 25 25   00 00 00 01   00 00 00 03   00 00 00 14


 15             i1      identifies tag (15h = 21)
 00 0e          i2be    bytes in tag name (ltname), may be 0
 41 6e 6e 6f  74 61 74 69  6f 6e 54 79  70 65
                a       tag name, length ltname "AnnotationType" ここまでは共通
 25 25 25 25    a4      "%%%%"
 00 00 00 01    i4be    ninfo, size of info array following (=1) 個数をチェック
 00 00 00 03    i4be    info(ninfo), array of ninfo i4 integers, in this case just 1
                        contains tag data type (3 = signed i4*)    此処がデータの型
 00 00 00 14    i4*     tag value, 14h = 20

一つだけデータを持つ場合には

 ninfo = 1
 info(1) = tag data type(データの型)

構造体として指定

 15 0006 4f6666736574  25252525 00000007 0000000f 00000000 00000002
                       00000000 00000006 00000000 00000006
                       00000000 00000000


 15             i1      identifies tag (15h = 21)
 00 06          i2be    bytes in tag name (ltname), may be 0
 4f 66 66 73 65 74
                a       tag name, length ltname "Offset" ここまでは一緒
 25 25 25 25    a4      "%%%%"
 00 00 00 07    i4be    ninfo, size of info array following (=7)         このタグの情報の数              
                        info(ninfo):
 00 00 00 0f    i4be    info(1) tag data type (0fh = group of data)       データ型:0xF (構造体) 0
 00 00 00 00    i4be    info(2) length of groupname? (always = 0)                    
 00 00 00 02    i4be    info(3) ngroup, number of entries in group (=2)               構造体の要素数                  2
 00 00 00 00    i4be    info(4) length of fieldname? (always = 0)
 00 00 00 06    i4be    info(5) tag data type for value 1 (06h = f4)        型          4
 00 00 00 00    i4be    info(6) length of fieldname? (always = 0)
 00 00 00 06    i4be    info(7) tag data type for value 2 (06h = f4)        型
                        tag values:
 00 00 00 00    f4*     value(1)
 00 00 00 00    f4*     value(2)

For group tags

ninfo = size of info array info(1) = 0fh info(2) = 0 normally info(3) = ngroup, number of members in group info(2*i+3) = tag data type for value i Other info entries are always zero

配列を含むタグ

Example, an image tag

15 0004 44617461 25252525 00000003 00000014 00000002 00000024

                fdff feff ffff 0000 0100 0200 0300 0400 0500
                fdff feff ffff 0000 0100 0200 0300 0400 0500
                fdff feff ffff 0000 0100 0200 0300 0400 0500
                fdff feff ffff 0000 0100 0200 0300 0400 0500


 15             i1      identifies tag (15h = 21)
 00 04          i2be    bytes in tag name (ltname)
 44 61 74 61    a       tag name, length ltname "Data" ここまでは共通
 25 25 25 25    a4      "%%%%" セパレータ
 00 00 00 03    i4be    ninfo, size of info array following (=3)
                        info(ninfo):
 00 00 00 14    i4be    info(1), tag data type (14h = array)            配列か構造体か、単純なタグかの判断
 00 00 00 02    i4be    info(2), tag data type for array members (02h = i2 signed)
 00 00 00 24    i4be    info(3) = info(ninfo), narray, size of array (=36)
                        tag values:
 fd ff          i2*     value(1)
 fe ff          i2*     value(2)
 ....                   etc to value(36)

For array tags

ninfo = 3 info(1) = 14h info(2) = tag data type for all array members info(3) = info(ninfo), narray, size of array


構造体の配列を含むタグ

15 0004 434c5554 25252525 0000000b 00000014 0000000f 00000000 00000003

                00000000 00000002 00000000 00000002 00000000 00000002
                00000100
                0000 0000 0000
                0101 0101 0101
                0202 0202 0202
                0303 0303 0303
                .....
 15             i1      identifies tag (15h = 21)
 00 04          i2be    bytes in tag name (ltname)
 43 4c 55 54    a       tag name, length ltname "CLUT"
 25 25 25 25    a4      "%%%%"
 00 00 00 0b    i4be    ninfo, size of info array following (=11)
                        info(ninfo):
 00 00 00 14    i4be    info(1), tag data type (14h = array)            ここで配列であることが分かる
 00 00 00 0f    i4be    info(2), tag data type for array members (0fh = group) ここで、構造体の配列であることが分かる
 00 00 00 00    i4be    info(3), length of groupname? (always = 0)
 00 00 00 03    i4be    info(4), ngroup, number of entries in group (=3)
 00 00 00 00    i4be    info(5), length of fieldname? (always = 0)
 00 00 00 02    i4be    info(6), tag data type for value 1 (02h = i2)
 00 00 00 00    i4be    info(7), length of fieldname? (always = 0)
 00 00 00 02    i4be    info(8), tag data type for value 2 (02h = i2)
 00 00 00 00    i4be    info(9), length of fieldname? (always = 0)
 00 00 00 02    i4be    info(10), tag data type for value 3 (02h = i2)
 00 00 01 00    i4be    info(11) = info(ninfo), narray, size of array (=256)
                        tag values:
 0000 0000 0000 3i2*    3 values for first element of array
 0101 0101 0101 3i2*    3 values for second element of array
 ....

構造体の配列に関する情報

ninfo = size of info array
info(1) = 14h
info(2) = 0fh
info(3) = 0 normally
info(4) = ngroup, number of values in group
info(2*i+4) = tag data type for value i
info(ninfo) = narray, size of info array

タグのデータ型

Tag data types

 02h =  2  i2* signed    (short)
 03h =  3  i4* signed    (long)
 04h =  4  i2* unsigned  (ushort) or unicode string
 05h =  5  i4* unsigned  (ulong)
 06h =  6  f4*           (float)
 07h =  7  f8*           (double)
 08h =  8  i1            (boolean)
 09h =  9  a1            (char)
 0ah = 10  i1
 0bh = 11  i8* ?         (long long) not sure if signed or unsigned
 0fh = 15  group of data (struct)
           info(2) = 0
           info(3) = ngroup, number in group
           info(2*n+4) = 0
           info(2*n+5) data type for each value in group
 12h = 18  a             (string)
 14h = 20  array of numbers or groups
           info(ninfo) = narray, number of array members
           info(2) is then treated as info(1) above
 15h = 21  array of groups (struct)

一般的な説明

構造体(type-15)の長さを知る簡単な方法はなく、その構造体を理解して、それぞれのデータ型に併せてバイト数を明らかにする必要がある。

画像自身は、"Data"という名前のtype-15の構造体の中に存在しており、画像を長さと数のタグとして見出してくることは難しい。一つの可能性としては、 "15h 0004h Data%%%%"という文字列を探し出すと、この16バイト後ろから画像の情報が始まっているということである。

ファイルの中には、一つ以上の画像が入っているかも知れない。それぞれの画像毎に"Data"タグをもっている。画像は、0からナンバリングされている。

サムネイル画像が、画像の前後に含まれている場合がある。サムネール"Data"タグの画像の数は、Thumbnails::ImageIndexタグで与えられている。

下記のタグが有効なタグである。

Description info in the notes box (not always present) Data the image itself DataType as in DM2. Note this is different from the tag data type above.

                  These values are only for the image data and must be
                  consistent with the tag data type for the Data tag.
                  There are a number of other DataTypes defined that I've
                  never seen in images
  0            null
  1     i2     2 byte integer signed ("short")
  2     f4     4 byte real (IEEE 754)
  3     c8     8 byte complex (real, imaginary)
  4            obsolete
  5     c4     4 byte packed complex (see DM2)
  6    ui1     1 byte integer unsigned ("byte")
  7     i4     4 byte integer signed ("long")
  8  4*ui1     rgb, 4 bytes/pixel, unused, red, green, blue
  9     i1     1 byte integer signed
 10    ui2     2 byte integer unsigned
 11    ui4     4 byte integer unsigned
 12     f8     8 byte real
 13     c16   16 byte complex
 14     i1     1 byte binary (ie 0 or 1)
 23  4*ui1     rgba, 4 bytes/pixel, 0, red, green, blue. Used for thumbnail images


Dimensions a type 14 tag containing 2 type 15s with no names

                  (irritatingly) which are image width and height

PixelDepth bytes/pixel

For CCD images (these follow the tags above)

Acquisition Date image acquisition date and time, unfortunatley both Acquisition Time as strings. Worse still, the date string can be

                  in either UK/international or US order depending on the
                  date settings on the mac or PC. It is thus impossible
                  to unambiguously determine the date from the date string.

ImageIndex Image number of thumbnail image Unfortunately the tags describing the image are after the image itself, this is particularly annoying for the image dimensions.

DM4

 DM4フォーマットは、DM3フォーマットに非常によく似ている。4バイト整数ではなく、8バイト整数を用い、2Gバイトを超えたファイルにも対応している。それぞれのタグのバイト数をもつことにより、知らないタグに関しても無視することができる。

Header

version i4be
rootLength i8be
byteOrder i4be