Last update 1999/08/07
(C)平山直之
無断転載は禁止、リンクはフリー
誤字脱字の指摘は歓迎
VAFXImgでは、Windows非依存にするために、windows.hなどで定義されている幾つかの構造体を独自に定義し直しています。
byte/word/dword
それぞれWindowsのBYTE/WORD/DWORDと同じです。
BGRQuad
struct BGRQuad { byte Blue; byte Green; byte Red; byte Alpha; };ピクセルの色情報をあらわす構造体です。WindowsのRGBQuadとほぼ同じ構造をしています。Windows非依存にするために置き換えたものです。
BitmapFileHeader/BitmapInfoHeader
struct BitmapFileHeader { word Type; dword Size; word Reserved1; word Reserved2; dword OffBits; }; struct BitmapInfoHeader { dword Size; long Width; long Height; word Planes; word BitCount; dword Compression; dword SizeImage; long XPelsPerMeter; long YPelsPerMeter; dword ClrUsed; dword ClrImportant; };ビットマップファイル・データの構造をあらわすヘッダです。それぞれ、BitmapFileHeader/BitmapInfoHeaderとほぼ同じ構造をしています。
後述のアルゴリズムを適用することのできるインターフェイスを備えたクラスです。アルゴリズムの適用対象は必ずしもこれらのクラスでなくても構いません(アルゴリズムがテンプレート関数になっているので継承する必要もありません)が、同じようなインターフェイスを備えていなければなりません(詳しくはVAFXImg入門をご覧ください)。
template <int Bits> class Pixel;ピクセルを抽象化したクラスです。ピクセルレベルでのフォーマット変換などをサポートしています。
template <int Bits> class Image;非圧縮のビットマップイメージを抽象化したクラスです。インターフェイス的にはPixelの集約のような扱いになっています。内部実装敵にはWindowsのDIBのフォーマットと同じです。
後述のイメージ操作アルゴリズム上ではsectionとして扱われます。
class Palette;
ビットマップパレットを抽象化したクラスです。インターフェイス的にはBGRQuadの集約のような扱いになっています。
単一イメージ処理
クリッピング
template <class Section,class Processor> void ClipPixel(Section& section,const st2d::Point& p,Processor& processor);ある1点に対してクリッピングを行い、その点がSectionの範囲内にある場合だけprocessorを適用する関数です。
1点1点適用すると低速になるため、他のアルゴリズムでは可能な限り避けるようにしています。
全体
template <class Section,class Processor> void ProcessOverall(Section& section,Processor processor);sectionに含まれるすべてのピクセルに対してprocessorを適用します。
水平線
template <class Section,class Processor> void ProcessHorizontalLine( Section& section, st2d::Point left, int width, Processor processor);sectionの点leftから右側(widthがマイナスの場合は左側)に幅widthの水平線上のピクセルに対しprocessorを適用します。
垂直線
template <class Section,class Processor> inline void ProcessVerticalLine( Section& section, st2d::Point top, int height, Processor processor);sectionの点topから下側(heightがマイナスの場合は上側)に幅heightの垂直線上のピクセルに対しprocessorを適用します。
直線
template <class Section,class Processor> void ProcessLine( Section& section, const st2d::Point& p1, const st2d::Point& p2, Processor processor);sectionの点p1から点p2までの直線上のピクセルに対しprocessorを適用します。
矩形(面)
template <class Section,class Processor> void ProcessBoxFill(Section& section,st2d::Rect rect,Processor processor);sectionの矩形rect内の全てのピクセルに対しprocessorを適用します。
矩形(境界)
template <class Section,class Processor> void ProcessBox(Section& section,st2d::Rect rect,Processor processor);sectionの矩形rectの境界上のピクセルに対しprocessorを適用します。
楕円(面)
template <class Section,class Processor> void ProcessEllipse( Section& section, st2d::Rect rect, Processor processor);sectionの矩形rectを最少外接矩形とする楕円形内の全てのピクセルに対しprocessorを適用します。
楕円(境界)
template <class Section,class Processor> void ProcessEllipseFill( Section& section, st2d::Rect rect, Processor processor);sectionの矩形rectを最少外接矩形とする楕円形の境界上のピクセルに対しprocessorを適用します。
連続直線
template <class Section1,class Processor> void ProcessPolyLine( Section1& section, const std::vector<st2d::Point>& v, Processor processor);sectionのvで表わされる連続する直線上のピクセルに対しprocessorを適用します。
塗りつぶし
template <class Section,class Checker,class Processor> void ProcessFloodFill( Section& section, st2d::Point start, Checker checker, Processor processor);sectionの点startからシードフィル状にprocessorを適用します。境界判定にはcheckerが用いられます。checkerのフォーマットについては後述のEqualを参照してください。
凹ポリゴン描画
template <class Section,class Processor> void ProcessPolygon( Section& section, const std::vector<st2d::Point>& points, Processor processor);sectionのpointsで表わされる凹ポリゴン上にprocessorを適用します。
2つのイメージ間の処理
矩形のコピー(元先同一可)
template <class Section1,class Section2,class Mapper> void MoveRect( Section1& dest, st2d::Point dest_point, Section2& src, st2d::Rect src_rect, Mapper mapper);srcのsrc_rectからdestのdest_pointを左上とするsrc_rectと同サイズの矩形に対して、mapper(dest_pixel,src_pixel)を適用します。
dest/srcは同じでも構いません。
矩形のコピー(元先同一不可)
template <class Section1,class Section2,class Mapper> void CopyRect( Section1& dest, st2d::Point dest_point, Section2& src, st2d::Rect src_rect, Mapper mapper);srcのsrc_rectからdestのdest_pointを左上とするsrc_rectと同サイズの矩形に対して、mapper(dest_pixel,src_pixel)を適用します。
dest/srcは同じではいけません。
矩形のコピー(90°単位の回転可)
template <class Section1,class Section2,class Mapper> void MapRect( Section1& dest, st2d::Point dest_point, Section2& src, st2d::Rect src_rect, int rotate_n, Mapper mapper);srcのsrc_rectからdestのdest_pointを左上とするsrc_rectと同サイズの矩形に対して、mapper(dest_pixel,src_pixel)を適用します。
rotate_nで回転角度(単位は直角)を指定できます。たとえば、3を指定すると270℃回転します。方向は数学と同じです。
dest/srcは同じではいけません。
矩形のタイリング
template <class Section1,class Section2,class Mapper> void TileMapRect( Section1& dest, st2d::Rect dest_rect, Section2& src, st2d::Rect src_rect, st2d::Offset offset, Mapper mapper);srcのsrc_rect内の各点をdest_rectに敷き詰めるようにmapper(dest_pixel,src_pixel)を適用します。
offsetは、dest_rectの左上がsrc_rectのどの点に当たるかを示します。
dest/srcは同じではいけません。
矩形の拡大縮小コピー
template <class Section1,class Section2,class Mapper> void ZoomCopyRect( Section1& dest, st2d::Rect dest_rect, Section2& src , st2d::Rect src_rect, Mapper mapper);srcのsrc_rect内の各点をdest_rectにフィットするように拡大(縮小)してmapper(dest_pixel,src_pixel)を適用します。
dest/srcは同じではいけません。矩形の拡大縮小コピー(90°単位の回転可)
template <class Section1,class Section2,class Mapper> void ZoomMapRect( Section1& dest, st2d::Rect dest_rect, Section2& src , st2d::Rect src_rect, int aRotation, Mapper mapper)srcのsrc_rect内の各点をdest_rectにフィットするように拡大(縮小)してmapper(dest_pixel,src_pixel)を適用します。
rotate_nで回転角度(単位は直角)を指定できます。たとえば、3を指定すると270℃回転します。方向は数学と同じです。
dest/srcは同じではいけません。矩形の回転拡大縮小コピー
template <class Section1,class Section2,class Mapper,class Decimal> void RotateZoomMapRect( Section1& dest,const st2d::Point& dest_center,st2d::Rect dest_rect, Section2& src, const st2d::Point& src_center, st2d::Rect src_rect, Mapper mapper, Decimal theta,Decimal xscale=1.0,Decimal yscale=1.0);srcのsrc_rect内の各点を、destのdest_centerにsrcのsrc_centerが来るように回転角度theta・横方向の拡大率xscale・縦方向の拡大率yscaleで変換してmapper(dest_pixel,src_pixel)を適用します。
xscale・yscaleは倍率を示し、同サイズのときを1.0とします。
thetaは回転角度を示し、単位はラジアン(360°=2π)です。
dest/srcは同じではいけません。
シードフィルのマッピング
template <class Section1,class Section2,class Checker,class Mapper> void MapFloodFill( Section1& dest_section, st2d::Point dest_start, Section2& src_section, st2d::Point src_start, Checker checker, Mapper mapper);ProcessFloodFillと同じような処理をしますが、srcで行った調査を元にsrc_startがdest_startにずれるような感じでmapper(dest_pixel,src_pixel)を適用します。
dest/srcは同じではいけません。
※テンプレートパラメータの「T」にはそのMapper/Processorが扱うピクセルの型を指定します。たとえば、vafximg::Image<24>からvafximg::Image<24>に単純な転送を行いたい場合は、Mapperとして「CopyPixel<vafximg::Pixel<24> >()」をアルゴリズムに渡します。
説明はoperator()の内容です。
単一イメージ処理アルゴリズムでProcessorとして利用できる描画クラス
template <class T> class SetPixel;コンストラクタで指定したピクセルをdestに代入します。
template <class T> class SetSkippingPixel;コンストラクタで指定したピクセルを、
コンストラクタで指定したaDraw回描画
コンストラクタで指定したaBlank回スキップ
と交互に繰り返しながらdestに代入します。
template <class T> class AlphaSetPixel;コンストラクタで指定したピクセルを、コンストラクタで指定した不透明度でdestとα合成し、その結果をdestに代入します。
template <class T> class FastAlphaSetPixel;コンストラクタで指定したピクセルを、50%の不透明度でdestとα合成し、その結果をdestに代入します。
template <class T> class TransparentPixel;何もしません。template <class T> class AddToIndexedPixel;コンストラクタで指定した値をdestに加算します。
template <class T> class AddToRGBPixel;destをvafximg::Pixel型(もしくは同等のインターフェイスを持つクラス)とみなし、24ビットピクセルとしてコンストラクタで指定したピクセルとの加色合成を行います。
2つのイメージを処理するアルゴリズムでMapperとして利用できる描画クラス
template <class T> struct CopyPixel;destへsrcを代入します。template <class T> class TransparentCopyPixel;srcがコンストラクタで指定した透明色と!=の場合のみdestへsrcを代入します。
template <class T> class AlphaCopyPixel;コンストラクタで渡した整数(0〜100)をsrcの不透明度とみなして、srcとdestのα合成を行い、その結果をdestに代入します。
template <class T> class FastAlphaCopyPixel;不透明度50%(固定)でsrcとdestのα合成を行い、その結果をdestに代入します。
template <class T> class AddCopyToIndexdPixel;srcとdestを加算します。template <class T> class AddCopyToRGBPixel;dest・srcをvafximg::Pixel型(もしくは同等のインターフェイスを持つクラス)とみなし、24ビットピクセルとして加色合成を行います。
inline dword Sqrt(dword x);高速な整数の√です(http://demo.and.or.jp/makedemo/effect/math/sqrt/index.htmより)。
inline dword Hypot(long lx,long ly)高速な整数の2距離の距離です(http://demo.and.or.jp/makedemo/effect/math/hypot/index.htmより)。
template <class T> class Equal { public: Equal(void){} bool operator()(const T& x,const T& y){return x==y;} };ProcessFloodFill、MapFloodFillでCheckerとして使います。
template <class T,class U> void LinearInterPolation(T& aDest,const U& aSrc,InterPolateOption ip);線形補完を行います。T、Uにはst2d::Pointを要素とするSTLのシーケンス(もしくはそれと同等のインターフェイスを持つもの)を用いてください。
ipには以下の値のいずれかを設定できます。
ipXAxis // X方向に補完 ipYAxis // Y方向に補完 ipAutoWhole // 全体を見て自動判断 ipAutoEach // 部分ごとに自動判断template <class T,class U> void BezierInterPolation(T& aDest,const U& aSrc,int dv);ベジェ補完を行います。T、Uにはst2d::Pointを要素とするSTLのシーケンス(もしくはそれと同等のインターフェイスを持つもの)を用いてください。
dvは分解能を示します。
ベジェ補完の特長として、間があいていたり点が重複していたりするシーケンスが返されますので、必要に応じて線形補完で補うなどしてください。
(C) 1998 Naoyuki Hirayama. All rights reserved.