About this Blog

This Blog has English posts and Japanese posts. About Mac, iOS, Objective-C, and so on.

2012年12月8日土曜日

xcf.txtの日本語訳 2. FORMAT CONCEPTS AND DATATYPES

This post is a personal translation of Henning Makholm's xcf.txt to Japanese. : Index here
アプリを作る際に作成した、xcf.txtの日本語訳です。目次及び使用上の注意はこちら

2. FORMAT CONCEPTS AND DATATYPES
================================
An XCF file is a sequence of bytes. It contains a series of data
structures, the order of which is in general not significant.  The
exception to this is that the main image structure must come at the
very beginning of the files, and that the tile data blocks for each
drawable must follow each other directly.

XCFファイルは、バイト列から成ります。一連なりのデータ構造を含みますが、基本的にその順番に意味はありません。例外としては、メインイメージ構造が、ファイルの先頭に来ないといけません。例外として、main image structureがファイルの先頭にあること、tile dataのかたまりは、連続していることが必要です。

References _between_ structures in the XCF file take the form of
32-bit "pointers" that count the number of bytes between the beginning
of the XCF file and the beginning of the pointed-to structure.

XCFファイル内のデータ構造(structures)の位置を指し示す時には、32-bitの「pointer」が使われます。これは、ファイルの先頭から数えて、そのデータ構造何バイト目からはじまるかということを表します。

Each structure is designed to be written and read sequentially; many
contain items of variable length and the concept of an offset _within_
a data structure is not often relevant.

個々のデータ構造は、シーケンシャルに読み込み・書き込みができるようにデザインされています。そのため、変数の長さやデータ構造内のオフセットは妥当とは限りません。

Basic data types
----------------
A WORD is a 32-bit integer stored as 4 bytes in network byte order,
i.e. with the most significant byte first. The word is not necessarily
aligned to an offset within the XCF file that is a multiple of
4. Depending on the context the word can be unsigned or (2's
complement) signed. In this specification unsigned words are denoted
"uint32" and signed words are denoted "int32".

WORDは、ネットワークバイトオーダーで4bytesのデータを収めた、32bitの整数です。したがって、最も特徴的なバイトが先に来ます。XCFファイルにおける文字列は、必ずしも4の倍数として[ファイル内での]オフセットが揃っている必要はありません。

A FLOAT is stored as a 32-bit IEEE 754 single-precision floating-point
number in network byte order.

FLOAT:(未訳)

A STRING is stored as follows:
  uint32   n+1  The number of bytes that follow, including the zero byte
  byte[n]  ...  The string data in Unicode, encoded using UTF-8
  byte     0    A terminating zero byte

uint32 n+1 後に続く文字列の長さ+byte 0[区切り]
UTF-8エンコーディングの文字列。長さはnバイト
ゼロ終端

Exception: the empty string is stored simply as an uint32 with the
value 0.

例外:空文字列は、単純に32ビット長の整数値0として格納されます。

Properties
----------
As an extension mechanism, most kinds of structures in an XCF file
include a variable-length series of variable-length PROPERTY records
which have the following general format

機能拡張のための仕組みとして、XCFファイルの多くの種類の構造体は、可変長のPROPERTYの、可変長のリストを持っています。
PROPERTYは、以下に示す基本的なフォーマットを持っています。 include a variable-length series of variable-length

  uint32   t    A magic number that identifies the type of property
  uint32   n    They payload length (but BEWARE! see below)
  byte[n]  ...  Payload - interpretation depends on the type

uint32 t PROPERTYのタイプを表すマジックナンバー
uint32 n payloadの長さ
実際のデータ

The authoritative source for property type numbers is the file
app/xcf/xcf-private.h in the GIMP sources.

property typeと番号の対応については、ソースコードのapp/xcf/xcf-private.hを見てください。

The number of properties in a property list is not stored explicitly;
the last property in the list is identified by having type 0; it must
have length 0.

property listのpropertyの数は、明示的にファイルに現れません。そこで、listの最後に、type=0を持つ、長さが0のpropertyを格納することでリストの終了を示します。

XCF readers must skip and ignore property records of unrecognized
type, and the length word is there to support such skipping. However,
GIMP's own XCF reader will _ignore_ the length word of most
properties that it _does_ recognize, and instead reads the amount of
payload it knows this property to have. This means that a property
record is not itself extensible: one cannot piggyback extra data onto
an existing property record by increasing its length. Also, some
historical versions of GIMP actually stored the wrong length for
some properties, so there are XCF files with misleading property
length information in circulation. For maximal compatibility, an XCF
reader should endeavor to know the native lengths of as many
properties as possible and fall back to the length word only for truly
unknown property types.

XCF readerは、不明なtypeのpropertyについてはスキップして無視すべきです。データの長さが明示されているので、そのことが可能です。しかし、GIMP内のXCF readerは、typeが判明したpropertyでは、殆どの場合、propertyの長さ情報を無視します。そして、payloadのデータを(そのタイプのpropertyィが持つはずのbyte長分)読みます。このことは、プロパティレコードには拡張性がないということを意味します。誰かがあるpropertyにbyteを追加して余分な情報を保存するといったことはできないのです。また、以前のバージョンのGIMPは、実は、あるpropertyについて間違った長さ情報を保存していました。つまり、間違った長さ情報を持ったpropertyを含むXCFファイルが世の中には存在しているということです。最大限の互換性を目指して、XCF readerは、propertyのtypeとpayloadサイズについての情報をできるだけ多く記録しておき、本当に不明なtypeのpropertyについてのみ、ファイルに書かれている長さ情報を使用するべきです。

There is not supposed to be more than one instance of each property in
a property list, but some versions of GIMP will erroneously emit
duplicate properties. An XCF reader that meets a duplicated property
should let the contents of the later instance take precedence, except
for properties that contain lists of subitems, in which the lists
should generally be concatenated. An XCF writer should never
deliberately duplicate properties within a single property list.

1つのproperty listに、同じtypeのpropertyが存在してはいけません。が、そのような重複をしてしまうバージョンのGIMPもあります。一般的にXCF readerは、後から出てきたpropertyを優先すべきですが、propertyがサブアイテムのリストを保持している場合は、その限りではありません。(一般的にリストにおいて連結されるサブアイテム)>XCF writerは決してpropertyを重複させないように実装してください。

Parasites
---------
A second level of extensibility is provided by the "parasite"
concept. A parasite is analogous to a property (and is usually stored
in a special property in the XCF file) but is identified by a string
rather than a number. This makes a larger namespace available for
parasites.  Gimp plug-ins can access the parasites of an image
component through a generic API and can define their own parasite
names which will be ignored by other plug-ins. In contrast, only the
Gimp itself should define new property types.

第二レベルの拡張性は、「parasite」として提供されています。parasiteは、プロパティと似ていますが、(XCFファイルの特別なpropertyとして格納されます)typeの番号ではなく文字列によって区別されます。したがって、parasiteはより大きな名前空間を利用できます。GIMPのプラグインは、APIを通して画像のparasiteにアクセスすることができ、独自の名前空間で、parasiteを定義することができます。反対に、propertyのtypeははGIMP自身しか定義できません。

A list of known parasites and their data formats can be found in the
file devel-doc/parasites.txt of the GIMP source tree.

判明しているparasiteの名前とデータ形式は、GIMPソースコード内のdevel-doc/parasites.txt で見ることができます。

0 件のコメント:

コメントを投稿