ビジュアルは、しばしば見落とされがちだが、とても大事な概念である。 おおまかにいって、ビジュアルは、ハードウェアの一部がイメージの内容を 保管するために使うメモリの使い方???を定義する。 X は、存在する異なる種類のハードウェアに合わせるため、 異なる種類のビジュアルをサポートしている。
Visuals are a very important concept that is often overlooked. Roughly, a visual defines the memory representation that a piece of hardware uses to store the contents of an image. X supports different kinds of visuals to suit the different kinds of hardware out there.
三つの基本的な種類のビジュアルがあり、それぞれは二つのクラスに分けられる。
There are three basic kinds of visuals, each divided into two classes:
Grayscale ビジュアルは、色情報に一つのチャネルを使うディスプレイに使われる。 白黒やグレイスケールのモニタ(こはく色と緑色のモニタも含む)が、 このタイプのビジュアルを使うであろう。これらのビジュアルは、 static gray か grayscale のどちらかである。
Grayscale visuals are used for displays that use a single channel of color information. Black and white or grayscale monitors (including amber and green monitors) may use this type of visual. These visuals can be either static gray or grayscale.
static gray ビジュアルでは、ハードウェアのグレーの強度を変えられない。 プレーンモノクロ(白黒)ディスプレイや、4-グレーディスプレイが、 static gray の類である。 grayscale ビジュアルでは、ハードウェアに使用されているグレーの強度を 変えることができる。 グレーの強度を変えることができる、 外国産の12ビットグレースケールディスプレイ(医療での視覚化に使われる)は、 grayscale の類である。
Static gray visuals are those in which you cannot change the gray intensities of the hardware. Plain monochrome (B/W) displays or fixed 4-gray displays may be of the static gray kind. Grayscale visuals are those in which you can change the gray intensities used by the hardware. Exotic 12-bit grayscale displays (as used for medical visualization) that let you change the gray intensities may be of the grayscale type.
Indexed ビジュアルは、「番号により描く」概念を使っている。それぞれのピクセルの値は、 カラーテーブルのインデックスである整数である。すなわち、0 は黒を表現し、 1 はピンクを表現し、2 はブルーを表現し、といった具合である。 このビジュアルは、static color か、 pseudo color のどちらかである。
Indexed visuals use the "paint-by-number" concept: each pixel value is an integer that indexes a table of colors. So 0 may represent black, 1 may represent pink, 2 may represent blue, etc. These visuals can be either static color or pseudo color.
static color ビジュアルでは、インデックスが指す実際の色を変えることが できない。昔あった、グラフィックモードで四つの固定された色だけを持つ CGA カードを覚えているだろうか? これらのカードは static color タイプであると 見なすことができる。pseudo color ビジュアルでは、インデックスが指す 実際の色を変えることができる。それぞれのインデックスは、 スクリーンに表示されるであろう色を定義する RGB の三つ組をマップしている。 あなたはそれぞれのインデックスに対して、 これらの RGB の三つ組の値を変えることができる。 pseudo color ビジュアルは、グラフィックカードの中で、とても一般的である。 あなたが変えることのできる 256 色を表示可能なグラフィックカード、 例えば VGA カードは pseudo color の類である。
Static color visuals are those in which you cannot change the actual colors that the indexes correspond to. Remember the old CGA cards with four fixed colors in graphics mode? These could be considered of the static color type. Pseudo color visuals are those in which you can change the actual colors that the indexes correspond to. Each index maps to an RGB triplet that defines the color that will be displayed on the screen. You can change these RGB triplets for each index. Pseudo color visuals are very common in graphics cards. Graphics cards with 256 colors that you can change, for example, VGA cards, are of the pseudo color type.
Colorビジュアルは、「でかくて、デブなやつ」である。 このビジュアルは普通、ハードウェアから引き出せる最高のクオリティを提供する。 そして、スピードとメモリの点で最大の資源を消費する。 このビジュアルは、indexed ビジュアルのように単一の値を保管するのではなく、 すべてのピクセルについて RGB の値そのものを保管する。 color ビジュアルは、true colorか、direct color のどちらかである。
Color visuals are the "big fat ones". They usually provide the highest quality you can get from the hardware, and they also consume the largest amount of resources in terms of speed and memory. Color visuals store explicit RGB values for every pixel, instead of storing a single value like indexed visuals. Color visuals can be either true color or direct color.
true color と direct color の特徴は、 最初は把握するのに少し難しいかもしれない。 結局、どちらのビジュアルもそれぞれのピクセルにつき三つの値を使う。 他にあなたは何を求めるのだろう? これらの違いは、true color ビジュアルでは、あなたがスクリーンに表示する色として あるピクセルに指定した正確な値が使われる。ほとんどの true color SVGA カードはこの類である。
The distinction between true color and direct color may be a bit difficult to grasp at first. After all, both visual types use three values for every pixel. What more could you ask for? The difference is that true color visuals use the exact values you specified for a pixel as the color that gets displayed on the screen for that pixel. Most "true color" SVGA cards are of this kind.
しかし、direct color ビジュアルは、ディスプレイに送られる前に遠まわりな ステップを経る。 Eachあなたが指定した R、G、B それぞれの値は独立のテーブルのインデックスであり、 これらのテーブルは変換後の値を含んでいる。だから、RGB の三つ組は RGB の三つ組に変換される。すなわち、三つのテーブル合わせて、 f(r, g, b) -> (r', g', b') という関数を定義していることになる。 ほとんどの目的のため、あなたのテーブルは恒等関数で埋められ、 それぞれの RGB のチャネル で、あなたは線形に増加する輝度の値を得るであろう。 しかし、もしテーブルを非線形なマッピングに修正すれば非常に面白くなる。 もしあなたがテーブルを指数関数で埋めれば、あなたはハードウェアでの 色補正??? を行なうことができる。例えば、(うぇー)。 ほとんどのハイエンドなハードウェア(SUN/HP/SGI のグラフィックハードウェア) は 高い奇妙さと柔軟性のため、direct color ビジュアルをサポートしている。
However, the values in a direct color visual go through an indirection step before being sent to the display. Each of the R/G/B values you specify is an index in separate tables, and those tables contain a translated value. So an RGB triplet gets translated into an R'G'B' triplet, i.e. the three tables together define an f(r, g, b) -> (r', g', b') function. For most purposes, your tables will be filled by the identity function and you will get linearly increasing intensity values for each of the RGB channels. Things can become quite interesting, however, when you modify the tables to have a nonlinear mapping. If you fill them using an exponential function, you can do color correction on hardware, for example (wheeee!). Most high-end hardware (Sun/HP/SGI graphics hardware) supports direct color visuals for high weirdness and flexibility.
これらが X でサポートされている六つのビジュアルクラスである( static gray, grayscale, static color, pseudo color, true color, direct color)。 なんで常に RGB の三つ組を直接扱わないの? とあなたは尋ねるかもしれない。 実際それはプログラミングを簡単にする。 その理由は、 全てのハードウェアが RGB の三つ組という見方で考えているのではないし、 X はこの点では金属のように振舞うので、私たちはそれを扱わざるを得ない。 好運なことに、これはそれほど苦しいものではない。
These are the six visual classes supported by X (static gray, grayscale, static color, pseudo color, true color, direct color). Why not deal directly with RGB triplets all the time, you may ask? Indeed that would make programming easier. The reason is that not all hardware thinks in terms of RGB triplets, and X acts close to the metal in this respect, so we are forced to deal with it. Fortunately, this is not too hard to do.
異なるビジュアルクラスが何を意味しているかを覚えるために、 static gray、static color、true color は読み専用の輝度のマップを持ち、 grayscale、pseudo color、direct color は読み書き可のマップを持っている点で、 考えなさい。
To remind yourself of what the different visual classes mean, think in terms of static gray, static color, and true color having read-only intensity mappings, and grayscale, pseudo color, and direct color having read/write mappings.
ビジュアルクラスに加え、それぞれのビジュアルにはビットデプスがある。 これは、それぞれのピクセルの値をエンコードするのに使われている、 意味のあるビットの数である。 ほとんどの256色の PC のビデオカードは、8ビットの pseudocolor ビジュアルで 動作する。優れたビデオカードは、それぞれの経路につき8ビットを使う、 24ビットの true color ビジュアルで動作する。 いくつかの Amiga のビデオカードは 12ビットの pseudocolor ビジュアルで 動作する。これは 4096個の indexed color のパレットとなる。 いくつかの外国産のハードウェアは 8ビットの truecolor ビジュアルを使う。 これは RGB のチャネルそれぞれにつき、3/3/2 ビットを使う。
In addition to the visual class, each visual has a bit depth. This is the number of significant bits that are used to encode the value of every pixel. Most 256-color PC video cards operate on an 8-bit pseudocolor visual. Better video cards operate on 24-bit true color visuals, with eight bits of information per channel. Some Amiga video cards operate on 12-bit pseudocolor visuals, which leads to a palette of 4096 indexed colors. Some exotic hardware uses 8-bit truecolor visuals, using 3/3/2 bits for the RGB channels, respectively.
あなたのハードウェアがサポートするビジュアルタイプについて最良の方法は、 xdypinfo コマンドを実行することである。あなたは興味深い情報を見るであろう。
The best way to know about the visual types your hardware supports is to run the xdpyinfo command. You will get a load of interesting information.
前のセクションで言及したように、 ドロウアブルのプロパティの一つはそのビジュアルクラスである。 これは、ドロウアブルに描く時に使われるイメージフォーマットを定義する。
As we mentioned in the previous section, one of the properties of a drawable is its visual class. This defines the image format that must be used to paint stuff on the drawable.
ほとんどのローエンドのハードウェアは、全てのドロウアブルに使われている 単一のビジュアルクラスをサポートしている。 例えば、SVGA カードは 8ビットの pseudocolor か 24ビットの truecolor で動く。 これはどちらか一方であり、同時に両方ということではない。
< > Most low-end hardware supports a single visual class that is used for all the drawables. For example, a SVGA card may run either in 8-bit pseudocolor or 24-bit truecolor; it is one or the other but not both at the same time.しかしハイエンドのハードウェアは、同時に異なるビジュアルタイプをサポートする。 例えば、多くの Sun と SGI の ビデオカードは 8ビットの pseudocolor と 24ビットの truecolor ビジュアルを同時に扱うことができる。 これは、あなたが同時に異なるビジュアルタイプのウィンドウで作業できる ということを意味する。 SGI マシンのところに行き、xterm を実行し、xwininfo を xterm ウィンドウの上で 実行しなさい。多分 8ビットの pseudocolor ビジュアルが使われているであろう。 今度は xv や Electric Eyes を実行させれば、24ビットの truecolor ビジュアルが 使われているのが分かるであろう。 このハードウェアは、pseudocolor と truecolor の情報のために、 ビデオメモリを異なった領域に分割できるほど賢いのだ。
Higher-end hardware, however, may support different simultaneous visual types. For example, many Sun and SGI video cards can handle 8-bit pseudocolor and 24-bit truecolor visuals simultaneously. This means you can operate on windows with different visual types at the same time. Go to an SGI box and run an xterm and run xwininfo on the xterm window; it will probably be using an 8-bit pseudocolor visual. Now run xv or Electric Eyes, and you may see that it uses a 24-bit truecolor visual. The hardware is smart enough to split its video memory in different areas for the pseudocolor and truecolor information, for example.
同時に異なるビジュアルタイプのドロウアブルを持つのが便利である理由は、 パフォーマンスである。 例えば、pseudocolor ビジュアルでのイメージの情報は、 truecolor ビジュアルより、はるかに小さいスペースを占有する(一般的な例では、 それぞれ、ピクセルあたり8ビットに対し、ピクセルあたり24ビット)。 より少ないメモリを使うということは、取り扱う情報量が少ないので より速く描くことができるということを意味する。 これが、 グラフィックが強烈なアプリケーションが低質のビジュアルで動作するのに対し、 高い質のイメージを要求するプログラムは truecolor や direct color の様な、 巨大なビジュアルで動作する理由である。
The reason why it is convenient to have drawables with different visual types at the same time is performance. For example, image information on pseudocolor visuals usually takes up much less space than that on truecolor visuals (a common example is 8 bits per pixel versus 24 bits per pixel, respectively). Using less memory also means that you can paint things faster, as there is less information to push around. This is why most applications which are not graphics-intensive run in lower-quality visuals while programs that require high-quality images run on the fat visuals like truecolor and direct color.
同時に異なるビジュアルタイプを持つことは、微妙な利点もある。 全てのピクセルに対して pseudocolor と truecolor の情報プラス余分な1ビット を保管するのに十分なメモリを持つビデオハードウェアの一部のことを考えてみよう。 このビットは、pseudocolor か truecolor のメモリ領域のどちらからピクセルを 描画するか選択するフラグである。例えば、truecolor のウィンドウをいくつか持つ、 再描画が遅い(例えば、3D レンダリング)、 [メモリを???] 渇望しているアプリケーションがあるとしよう。 もし、このアプリケーションがすぐに消えるメニューをポップアップさせなければ ならないなら、メニューを pseudocolor ビジュアルでメニューを生成し、 関係する領域のトグルビットを、truecolor の代わりに pseudocolor ビジュアルを使うと示すようセットするのが都合がいい。 truecolor のメモリ領域の情報は消去されず、表示されないだけなので、 X サーバーは、メニューが終れば、単にトグルビットを truecolor に戻すだけで、 素早くメニューをアンポップさせることができる。 すなわち、このアプリケーションにその領域の再描画を要求しなくてよい。 これは、可能な限り速いということを意味している。
Having different simultaneous visual types also has subtler advantages. Let us consider a piece of video hardware with enough memory to store pseudocolor and truecolor information for every pixel, plus one extra bit. This bit is a flag that selects whether to paint the pixel from the pseudocolor or truecolor memory regions. Say there is a hungry application with some windows on the truecolor visual that are slow to repaint (for example, a 3D rendering). If the application needs to pop up a menu that will soon go away, it is convenient to create the menu on the pseudocolor visual, and set all the toggle bits on the corresponding region to indicate that it will use the pseudocolor visual instead of the truecolor one. Since the information on the truecolor memory region is not erased, only not displayed, the X server can quickly un-pop the menu when it is done by simply switching the toggle bits back to the truecolor indication; there will be no need to request a repaint of that region to the application. This means things will be as fast as possible.