API仕様 (画像バッファへのアクセス)

imgIndex = mdi_img_layer( layerImgIndex )

アクティブなドキュメントを操作する為の、画像バッファへのインデックスを取得します。layerImgIndexには、レイヤ番号を指定してください。mdiapp内では、N個レイヤーが存在する場合、一番下のレイヤが0, 一番上のレイヤがN-1になります。取得したimgIndexを使って、mdi_imgxx_xxxxx( imgIndex ... といった形で操作してください。

imgIndex = mdi_img_offscreen( offscreenImgIndex )

オフスクリーンの画像バッファへのindexを取得します。レイヤー画像と、オフスクリーン画像は、相互に転送を行えます。

API仕様 (32bpp画像操作)

mdi_img32_copy( destImgIndex, srcImgIndex )

destImgIndexのバッファに、srcImgIndexの画像をコピーします。コピーされる側のバッファは、自動的にコピー元のサイズに変更されます。

mdi_img32_resize( imgIndex, width, height )

imgIndexバッファの画像を、幅width 高さheightにリサイズします。リサイズ後の画像内容は初期化されます。

w,h = mdi_img32_size( imgIndex )

imgIndexバッファの画像サイズ(幅と高さ)を取得します。

r,g,b,a = mdi_img32_pixelget( imgIndex, x,y )

imgIndexバッファの画素 (r,g,b,a) を取得します。

mdi_img32_pixelset( imgIndex, x,y, r,g,b,a )

imgIndexバッファの画像に、r,g,b,aをブレンドして画素を置きます。転送先α、転送元αが考慮されます。

mdi_img32_pixelcopy( imgIndex, x,y, r,g,b,a )

imgIndexバッファの画像に、r,g,b,aを完全に上書きし画素をセットします。ブレンドされません。

API仕様 (32bpp画像操作・応用)

mdi_img32_rect( imgIndex, x,y, w,h, r,g,b,a )

imgIndexバッファを矩形塗りつぶしします。この際、転送先の画像はr,g,b,aでブレンド合成されます。

mdi_img32_ellipse( imgIndex, x,y, w,h, r,g,b,a )

imgIndexバッファを楕円塗りつぶしします。r,g,b,aで通常ブレンド合成されます。

mdi_img32_gaussblur( destIndex, srcIndex, r )

destIndexの画像に対して、srcIndexの画像を、半径rピクセルガウスぼかしをかけて転送します。

mdi_img32_level( imgIndex, inMin, inMax, outMin, outMax, gamma )

画像をレベル補正します。inMinからinMaxの範囲 (0〜255) を、outMinからoutMaxの範囲(0〜255) に、ガンマ (gamma。1.0ガンマ指定なし) 補正をしてマッピングします。

mdi_img32_fit( destImgIndex, srcImgIndex )

destImgIndex画像に、srcImgIndex画像をフィットさせ転送します。縮小用に使ってください。ピクセル面積比を計算し(重いけど)、比較的綺麗に縮小を行います。

mdi_img32_fill( imgIndex, r,g,b,a )

imgIndex画像を、r,g,b,aで完全に塗りつぶします。ブレンドはせず、完全に上書きです。

mdi_img32_filter( imgIndex, type, x,y,w,h, r,g,b,a )

imgIndex画像に、論理演算処理を行います。x,y,w,h範囲を、type指定で、r,g,b,aを使って論理演算処理を行います。typeは、"or", "and", "not", "xor" を文字列で渡して指定ください。"not" の場合はr,g,b,aパラメータは使いません。

mdi_img32_filter_( imgIndex, type, r,g,b,a )

mdi_img32_filterの画像全体版です。

mdi_img32_polygon( imgIndex, r,g,b,a )

頂点バッファ情報を元に、多角形を描画します。

mdi_img32_blob( imgIndex, r,g,b,a )

頂点バッファ情報を元に、ぶよぶよ形状(なんだそれw)を描画します。

mdi_img32_stroke( imgIndex, r,g,b,a, width, p0,p1,p2 )

頂点バッファ情報を元に、幅のある線を描画します。widthは線の幅を示します。p0,p1,p2は始点・中間点・終点の幅を正規化して指定します。例えば、段々細くなる表現なら、mdi_img32_stroke( imgIndex, r,g,b,a, width, 1.0, 0.5, 0.0 ) といった具合になります。後で仕様変更するかも。

API仕様 (矩形転送API)

mdi_img32_blt( destImgIndex, dx,dy, srcImgIndex, sx,sy,sw,sh )

destImgIndexバッファのdx,dy位置に、srcImgIndexバッファのsx,sy位置からsw,shサイズの矩形を転送します。転送モードは、mdi_img32_bltmode_xxxxx APIで指定します。

mdi_img32_blt_( destImgIndex, dx,dy, srcImgIndex )

mdi_img32_bltの、転送元サイズを指定しない(転送元画像全体を転送)版です。

mdi_img32_bltstr( destImgIndex, dx,dy,dw,dh, srcImgIndex, sx,sy,sw,sh )

destImgIndexバッファのdx,dy位置に、srcImgIndexバッファのsx,sy位置からsw,shサイズを、dw,dhサイズに拡大縮小して矩形転送します。転送モードは、mdi_img32_bltmode_xxxxx APIで指定します。

mdi_img32_bltstr_( destImgIndex, dx,dy,dw,dh, srcImgIndex )

mdi_img32_bltstrの、転送元サイズを指定しない(転送元画像全体を転送)版です。

mdiappスクリプト (仮称) とは?

mdiappから呼び出せるスクリプトです。オープンソーススクリプトエンジン、Lua上で動いています。ので、文法についてはLuaを参照ください。そこにmdiappを操作するAPIを加えたLuaの拡張言語(?)となっています。

スクリプト概要

画像バッファへのアクセス

グラフィックツールなんですから、何はともあれ画像へのアクセスが必須になります。現在、

  • オフスクリーン画像
  • レイヤ画像

の二種類の画像バッファにアクセスできます。画像操作を行う際には、"mdi_img32_xxxxxxx" などの、mdi_img32から始まるAPIを呼び出す事になります。これらのAPIには、画像バッファへのインデックス情報が必要になります。インデックスを取得するには、

  • local imgIndex = mdi_img_layer( layerImgIndex )
  • local imgIndex = mdi_img_offscreen( offscreenImgIndex )

というAPIを呼び出す必要があります。mdi_img_layerの場合、取得したいアクティブなドキュメントのレイヤ番号を指定します。アクティブなレイヤを指定するなら、mdi_layer_active() で取得した値を渡すことになります。

オフスクリーン画像バッファを確保したい場合は、mdi_img_offscreenを呼び出してください。画像バッファの数は有限個なので、無茶な数は指定しないようにお願いします(笑)。

画像バッファについて

  • オフスクリーン画像バッファは、スクリプト終了の際に破棄されます。
  • 実際に描画処理を行うまで、メモリは殆ど食わない仕様になっています。
  • オフスクリーン画像は、現状1024個作成する事ができます。

アンドゥ対応

既存のドキュメントに対して画像操作を行う場合、アンドゥ命令を発行しなければいけません。アンドゥ命令には、

  • mdi_undo_layer()
  • mdi_undo_all()

があり、前者の場合、アクティブなレイヤの編集を保護し、アンドゥで復帰できるようになります。後者の場合、アクティブなレイヤ以外、何処のレイヤが編集されてもアンドゥで復帰する事ができます。編集したにも関わらず、アンドゥ命令を発行しないと、ドキュメントが破綻する場合があります。

頂点命令について

  • mdi_vertex_add( x, y )
  • mdi_vertex_clear()

命令を組み合わせて、頂点情報を使った描画が行えます。頂点バッファは一つだけです。頂点バッファにpushされている情報を使って、

  • mdi_img32_polygon
  • mdi_img32_blob
  • mdi_img32_stroke

などの命令を使った描画が行えます。詳しくはAPIの仕様をご覧ください。

形状の回転描画について

  • mdi_img32_rect
  • mdi_img32_ellipse

は、あらかじめ回転角を設定しておく事で、回転描画が行えます。回転角の指定には、以下のAPIを用います。

  • mdi_shape_setrad( rad )
  • mdi_shape_setdeg( deg )

サンプルスクリプト

いきなりAPIを羅列するよりも、サンプルスクリプトを見た方が「あぁなるほど」と納得して頂けると思いますので :D

(1) 適当な画像を作り、コピーし、ドキュメントの作成

local w = 512
local h = 300
local idx = mdi_img_offscreen( 0 ) -- offscreenバッファの取得
mdi_img32_resize( idx, w,h ) -- ↑のリサイズ

for j = 0,h do
  for i = 0,w do
    local r = i
    local g = j
    local b = r * g / 255
    mdi_img32_pixelset( idx, i,j, r,g,b,255 )
  end
end

local idx2 = mdi_img_offscreen( 1 ) -- 意味も無く新規バッファを作り、
mdi_img32_copy( idx2, idx ) -- そこにコピーして、

mdi_new_img32( idx2 ) -- 画像から新規作成

(2) 32bppレイヤーのネガポジ反転 (重いので小さな画像限定で…)

mdi_undo_layer(); -- レイヤを操作するので、Undoに保存

local w = mdi_width();
local h = mdi_height();

local li = mdi_layer_active();
local bpp = mdi_layer_type( li );
local idx = mdi_img_layer( li );

for j = 0,h do
  for i = 0,w do
    -- 32bppの場合
    if bpp == 32 then
      local r,g,b,a = mdi_img32_pixelget( idx, i,j );
      mdi_img32_pixelset( idx, i,j, 255-r,255-g,255-b,a );
    end
  end
end

(3) アクティブな32bppレイヤに、矩形と楕円を描画する

mdi_undo_layer();

local w = mdi_width();
local h = mdi_height();

local bw = w / 100;
local bh = h / 100;
local li = mdi_layer_active();
local bpp = mdi_layer_type( li );
local idx = mdi_img_layer( li );

for j = 0,bh do
  for i = 0,bw do

    -- こういう判定は、本来for,forの外で行うのがいいんですが :D
    -- 1bppレイヤの場合
    if bpp == 1 then
      mdi_img1_rect( idx, i*100,j*100, 80,80, 1 );
      mdi_img1_ellipse( idx, i*100+10,j*100+10, 60,60, 0 );
    end

    -- 8bppレイヤの場合
    if bpp == 8 then
      mdi_img8_rect( idx, i*100,j*100, 80,80, 255,255 );
      mdi_img8_ellipse( idx, i*100+10,j*100+10, 60,60, 0,128 );
    end

    -- 32bppレイヤの場合
    if bpp == 32 then
      local r = math.random() * 255;
      local g = math.random() * 255;
      local b = math.random() * 255;

      mdi_img32_rect( idx, i*100,j*100, 80,80, r,g,b, 255 );
      mdi_img32_ellipse( idx, i*100+10,j*100+10, 60,60, 255-r,255-g,255-b, 255 );
    end
  end
end

(4) かんたん絵画風フィルタ (id:XELFさんのスクリプトが元ネタ)

mdi_undo_all();

local act = mdi_layer_active() -- アクティブなレイヤ
local sourceImage = mdi_img_layer( act ) -- 参照元レイヤとする
local newLayer = mdi_layer_add( 32 ) -- レイヤを追加し、
local destImage = mdi_img_layer( newLayer ); -- 追加した新規レイヤに対して描画する

math.randomseed( mdi_ms() ) -- 乱数シードの初期化

local w, h = mdi_width(), mdi_height();
local n = w * h / 20

for i = 0,n do
  local x = math.random() * w
  local y = math.random() * h
  local r,g,b,a = mdi_img32_pixelget( sourceImage, x, y )

  local r2 = 5 + math.random()*4
  mdi_img32_ellipse( destImage, x,y, r2,r2, r,g,b,a );
end

(5) 8bpp画像を使って、32bpp画像から不透明度を抜く

mdi_undo_layer()

local idx0 = mdi_img_offscreen( 0 )
local idx1 = mdi_img_layer( 0 )
local w, h = mdi_width(), mdi_height();
mdi_img8_resize( idx0, w, h )

-- 8bpp画像に、円を描画する
for i=0,200 do
  local x = math.random() * w
  local y = math.random() * h
  local r2 = 10 + math.random()*40
  mdi_img8_ellipse( idx0, x,y, r2,r2, 255,255 );
end

-- 32bppレイヤ画像から、8bpp画像を不透明度として引く
mdi_img8_sub32( idx1, idx0 )
||<

** (6) 選択範囲内だけ、ネガポジ反転をする

>||
mdi_undo_layer(); -- レイヤを操作するので、Undoに保存

local w = mdi_width();
local h = mdi_height();

local li = mdi_layer_active(); -- アクティブなIndex
local bpp = mdi_layer_type( li ); -- そのレイヤのbpp取得
local idx = mdi_img_layer( li ); -- そのレイヤの画像バッファのIndex取得

local sx,sy,sw,sh = mdi_select_range() -- 選択範囲の有効範囲を取得

-- 有効範囲のみ処理 (選択範囲がない場合は、全体になる)
for j = sy,sy+sh do
  for i = sx,sx+sw do
    -- 32bppの場合
    if bpp == 32 then
      local v = mdi_select_pixelget( i,j ) -- 選択範囲情報の取得
      local r,g,b,a = mdi_img32_pixelget( idx, i,j ); -- レイヤ色の取得
      mdi_img32_pixelset( idx, i,j, 255-r,255-g,255-b, v ); -- 選択範囲の濃度を元に色反転
    end
  end
end

(7) 警告そして終了、ガウスぼかしで華やかな画に

-- モード警告
local num = mdi_layer_num()
if num == 0 then
  mdi_halt( "This script needs 32bpp layer" )
end

mdi_undo_all()

-- レイヤを新規作成して、加算モードに
local idx0 = mdi_img_layer( 0 )
local li = mdi_layer_add( 32 )
mdi_layer_setmode( li, "add" )

local idx1 = mdi_img_layer( li )
local idx2 = mdi_img_offscreen( 1 )

-- コピーを作り、レベル補正で高輝度抽出
mdi_img32_copy( idx2, idx0 )
mdi_img32_level( idx2, 128,255, 0,255, 1.0 )

-- それをガウスぼかしして、新規レイヤへ
mdi_img32_gaussblur( idx1, idx2, 5 )

(8) aobench (数十秒以上掛かります)

http://twitter.com/aobench


--------------------------------------------
-- vec.pde
--------------------------------------------

function vec_zero()
  local res = {}
  res.x = 0
  res.y = 0
  res.z = 0
  return res
end

function vec_new( x, y, z )
  local res = {}
  res.x = x
  res.y = y
  res.z = z
  return res
end

function vec_copy( vec )
  local res = {}
  res.x = vec.x
  res.y = vec.y
  res.z = vec.z
  return res
end

function vec_sub( vec, vecSub )
  local res = {}
  res.x = vec.x - vecSub.x
  res.y = vec.y - vecSub.y
  res.z = vec.z - vecSub.z
  return res
end

function vec_cross( vec1, vec2 )
  local res = {}
  res.x = vec1.y * vec2.z - vec2.y * vec1.z
  res.y = vec1.z * vec2.x - vec2.z * vec1.x
  res.z = vec1.x * vec2.y - vec2.x * vec1.y
  return res
end

function vec_len( vec )
  local res = vec.x*vec.x + vec.y*vec.y + vec.z*vec.z
  if res ~= 0 then
    res = math.sqrt( res )
  end
  return res
end

function vec_dot( vec1, vec2 )
  local res = vec1.x*vec2.x + vec1.y*vec2.y + vec1.z*vec2.z
  return res
end

function vec_normalize( vec )
  local res = vec_copy( vec )
  local d = vec_len( res )

  if math.abs( d ) > 1.0e-6 then
    local invlen = 1.0 / d
    res.x = res.x * invlen
    res.y = res.y * invlen
    res.z = res.z * invlen
    return res
  end

  return res
end

--------------------------------------------
-- geometry.pde
--------------------------------------------

function ray_new( org, dir )
  local res = {}
  res.org = vec_copy( org )
  res.dir = vec_copy( dir )
  return res
end

function ray_copy( ray )
  local res = {}
  res.org = vec_copy( ray.org )
  res.dir = vec_copy( ray.dir )
  return res
end

function intersection_new()
  local res = {}
  res.hit = false
  res.t = 1.0e+30
  res.n = vec_zero()
  res.p = vec_zero()
  return res
end

function intersection_copy( isec )
  local res = {}
  res.hit = isec.hit
  res.t = isec.t
  res.n = vec_copy( isec.n )
  res.p = vec_copy( isec.p )
  return res
end

function sphere_new( center, radius )
  local res = {}
  res.center = vec_copy( center )
  res.radius = radius
  return res
end

function sphere_copy( sphere )
  local res = {}
  res.center = vec_copy( sphere.center )
  res.radius = sphere.radius
  return res
end

function sphere_intersect( isect, sphere, ray )
  local rs = vec_sub( ray.org, sphere.center )
  local B = vec_dot( rs, ray.dir )
  local C = vec_dot( rs, rs ) - ( sphere.radius * sphere.radius )
  local D = B * B - C

  if D > 0.0 then
    local t = -B - math.sqrt( D )
    if (t > 0.0) and (t < isect.t) then
      isect.t = t
      isect.hit = true

      local p = vec_new( ray.org.x + ray.dir.x * t, ray.org.y + ray.dir.y * t, ray.org.z + ray.dir.z * t )
      local n = vec_sub( p, sphere.center )
      n = vec_normalize( n )
      isect.n = vec_copy( n )
      isect.p = vec_copy( p )
    end
  end 
end

function plane_new( p, n )
  local res = {}
  res.p = vec_copy( p )
  res.n = vec_copy( n )
  return res
end

function plane_intersect( isect, plane, ray )
  local d = -vec_dot( plane.p, plane.n )
  local v = vec_dot( ray.dir, plane.n )

  if math.abs(v) < 1.0e-6 then 
    return
  end

  local t = -(vec_dot( ray.org, plane.n ) + d) / v
  if (t > 0) and (t < isect.t) then
    isect.hit = true
    isect.t = t
    isect.n = vec_copy( plane.n )
    isect.p = vec_new( ray.org.x + t * ray.dir.x, ray.org.y + t * ray.dir.y, ray.org.z + t * ray.dir.z )
  end
end

--------------------------------------------
-- ao.pde
--------------------------------------------

local NAO_SAMPLES = 8

local sphere = {}
sphere[0] = sphere_new( vec_new( -2.0, 0.0, -3.5 ), 0.5 )
sphere[1] = sphere_new( vec_new( -0.5, 0.0, -3.0 ), 0.5 )
sphere[2] = sphere_new( vec_new( 1.0, 0.0, -2.2 ), 0.5 )

local plane = plane_new( vec_new( 0.0, -0.5, 0.0 ), vec_new( 0.0, 1.0, 0.0 ) )

function clamp( f )
  local i = f * 255.5
  if i < 0 then 
    i = 0 
  end
  if i > 255 then 
    i = 255 
  end
  return i  
end

function orthoBasis( basis, n )

  basis[2] = vec_copy( n )
  basis[1] = vec_zero()
  basis[0] = vec_zero()

  if (n.x < 0.6) and (n.x > -0.6) then
    basis[1].x = 1.0
  elseif (n.y < 0.6) and (n.y > -0.6) then
    basis[1].y = 1.0
  elseif (n.z < 0.6) and (n.z > -0.6) then
    basis[1].z = 1.0
  else
    basis[1].x = 1.0
  end

  basis[0] = vec_cross( basis[1], basis[2] )
  basis[0] = vec_normalize( basis[0] )

  basis[1] = vec_cross( basis[2], basis[0] )
  basis[1] = vec_normalize( basis[1] )
end

function ambientOcclusion( isect )
  local i,j
  local ntheta = NAO_SAMPLES
  local nphi = NAO_SAMPLES
  local eps = 0.0001

  local p = vec_new( isect.p.x + eps * isect.n.x, isect.p.y + eps * isect.n.y, isect.p.z + eps * isect.n.z )

  local basis = {}
  orthoBasis( basis, isect.n )

  local occlusion = 0.0

  for j=0,ntheta-1 do
    for i=0,nphi-1 do
      local r = math.random()
      local phi = 2.0 * math.pi * math.random()

      local x = math.cos(phi) * math.sqrt(1.0 - r)
      local y = math.sin(phi) * math.sqrt(1.0 - r)
      local z = math.sqrt(r)

      local rx = x * basis[0].x + y * basis[1].x + z * basis[2].x
      local ry = x * basis[0].y + y * basis[1].y + z * basis[2].y
      local rz = x * basis[0].z + y * basis[1].z + z * basis[2].z

      local raydir = vec_new( rx, ry, rz )
      local ray = ray_new( p, raydir )

      local occIsect = intersection_new()
      sphere_intersect( occIsect, sphere[0], ray )
      sphere_intersect( occIsect, sphere[1], ray )
      sphere_intersect( occIsect, sphere[2], ray )
      plane_intersect( occIsect, plane, ray )

      if occIsect.hit then
        occlusion = occlusion + 1.0
      end
    end
  end

  occlusion = (ntheta * nphi - occlusion) / (ntheta * nphi)
  return vec_new( occlusion, occlusion, occlusion )
end

function render( width, height, y, nsubsamples )
  local fimg = {}

  local i,j, u,v
  for i=0,width do
    
    fimg[3 * i + 0] = 0
    fimg[3 * i + 1] = 0
    fimg[3 * i + 2] = 0

    for v=0,nsubsamples-1 do
      for u=0,nsubsamples-1 do
        local px = (i + (u / nsubsamples) - (width / 2.0)) / (width / 2.0)
        local py = (y + (v / nsubsamples) - (height / 2.0)) / (height / 2.0)
        py = -py

        local t = 10000.0
        local eye = vec_new( px, py, -1.0 )
        eye = vec_normalize( eye )

        local ray = ray_new( vec_zero(), eye )

        local isect = intersection_new()
        sphere_intersect( isect, sphere[0], ray )
        sphere_intersect( isect, sphere[1], ray )
        sphere_intersect( isect, sphere[2], ray )
        plane_intersect( isect, plane, ray )

        if isect.hit then
          t = isect.t
          local col = ambientOcclusion( isect )
          fimg[3 * i + 0] = fimg[3 * i + 0] + col.x
          fimg[3 * i + 1] = fimg[3 * i + 1] + col.y
          fimg[3 * i + 2] = fimg[3 * i + 2] + col.z
        end
      end
    end

    fimg[3 * i + 0] = fimg[3 * i + 0] / (nsubsamples * nsubsamples)
    fimg[3 * i + 1] = fimg[3 * i + 1] / (nsubsamples * nsubsamples)
    fimg[3 * i + 2] = fimg[3 * i + 2] / (nsubsamples * nsubsamples)
  end

  return fimg
end

--------------------------------------------
-- main
--------------------------------------------
local IMAGE_WIDTH = 64
local IMAGE_HEIGHT = 64
local NSUBSAMPLES = 2

local idx = mdi_img_offscreen( 0 )
mdi_img32_resize( idx, IMAGE_WIDTH, IMAGE_HEIGHT )

for y=0,IMAGE_HEIGHT-1 do
  local fimg = render( IMAGE_WIDTH, IMAGE_HEIGHT, y, NSUBSAMPLES )
  local i
  for i=0,IMAGE_WIDTH-1 do
    local r = clamp( fimg[3*i + 0] )
    local g = clamp( fimg[3*i + 1] )
    local b = clamp( fimg[3*i + 2] )
    mdi_img32_pixelset( idx, i,y, r,g,b,255 )
  end
end

mdi_new_img32( idx )

API仕様 (雑用系)

mdi_ms()

OSを立ち上げてから経過した時間を、ミリ秒で取得します。

pixel = mdi_cm2pixel( dpi, cm )

dpiを指定して、cmからpixel変換をします。

cm = mdi_pixel2cm( dpi, pixel )

dpiを指定して、pixelからcm変換をします。

mdi_setaa( aa )

描画処理において、アンチエイリアシングを有効にするか指定します。aaが 1なら有効、0なら無効。

mdi_sleep( milisec )

milisecミリ秒、スリープ処理をさせます。

mdi_halt( caption )

caption文字列 (ASCII) をダイアログ表示し、スクリプト処理を終了させます。mdi_terminate( caption ) でも行けます。

API仕様 (頂点命令)

mdi_vertex_add( x, y )

頂点バッファに、頂点を追加します

mdi_vertex_clear()

頂点バッファをクリアします。

mdi_shape_setrad( rad )

rect,polygon描画時の角度をrad単位で指定します。

mdi_shape_setdeg( deg )

rect,polygon描画時の角度をdeg単位で指定します。

API仕様 (新規ウィンドウ生成)

mdi_new_style( width, height, dpi, bpp )

幅width, 高さheight, 解像度dpiのドキュメントを作成します。bppは整数指定で、初期レイヤーの型を指定します。32bppの場合32, 8bppの場合は8, 1bppは1, Vectorレイヤは0を指定します。

mdi_new_img32( imgIndex )

32bpp画像バッファのindexを指定して、その画像を初期レイヤとして、ドキュメントの新規作成をします。

mdi_new_img8( imgIndex )

未対応。

API仕様 (レイヤ情報)

num = mdi_layer_num()

レイヤー数を返します

activeIndex = mdi_layer_active()

アクティブなレイヤー番号を返します

bpp = mdi_layer_type()

レイヤーのbppを返します

w,h = mdi_layer_size()

レイヤーの幅・高さを返します

ofsx,ofsy = mdi_layer_offset()

レイヤーのオフセットを返します。レイヤを上下左右移動させた場合、オフセット値がずれている場合(必ずマイナス値)があります。

idx = mdi_layer_add( bpp )

レイヤーを追加します。アクティブなレイヤのインデックスが1の場合、その上 (2) の位置にレイヤーを追加します。2の位置にあったレイヤーは、3の位置に押し出されます。idxには、追加された位置のインデックス値を返します。bppは作成するレイヤのbpp数を指定します。1,8,32の場合は各bppを、0の場合はVectorレイヤ追加します。

mdi_layer_insert( destIndex, srcIndex )

srcIndexのレイヤを、destIndex位置に挿入します。

mdi_layer_setname( layerIndex, caption )

layerIndex番目のレイヤーの名前を、captionにセットします。Luaの仕様上、漢字は使えません (ASCIIに限定)

mdi_layer_setvisible( layerIndex, visible )

layerIndex番目のレイヤーの可視・不可視を設定します。0なら不可視、1なら可視です。

mdi_layer_setmode( layerIndex, mode )

layerIndex番目のレイヤーのモードを設定します。modeは文字列で、"normal" なら通常レイヤ、"add" なら加算レイヤ、"mul" なら乗算レイヤになります。

API仕様 (8bpp画像操作)

mdi_img8_copy( destImgIndex, srcImgIndex )

destImgIndexのバッファに、srcImgIndexの画像をコピーします。コピーされる側のバッファは、自動的にコピー元のサイズに変更されます。

mdi_img8_resize( imgIndex, width, height )

imgIndexバッファの画像を、幅width 高さheightにリサイズします。リサイズ後の画像内容は初期化されます。

w,h = mdi_img8_size( imgIndex )

imgIndexバッファの画像サイズ(幅と高さ)を取得します。

value = mdi_img8_pixelget( imgIndex, x,y )

imgIndexバッファの画素を取得します。

mdi_img8_pixelset( imgIndex, x,y, value,alpha )

imgIndexバッファの画像に、valueを不透明度alphaでブレンドして画素を置きます。

mdi_img8_pixelcopy( imgIndex, x,y, value )

imgIndexバッファの画像に、valueを完全に上書きし画素をセットします。ブレンドされません。

API仕様 (選択範囲)

res = mdi_select_enabled( alpha )

選択範囲が有効かどうか返します。1なら有効、0なら無効です。

value = mdi_select_pixelget( x, y )

選択範囲の画素 (8bpp) を取得します。選択範囲が無効なら、常に255が返ります。選択されている部分は255, されていない部分は0が返ります(中間値はアンチエイリアス処理されてる部分)。

x,y,w,h = mdi_select_range()

選択範囲が有効な範囲を取得します。選択範囲が設定されてなければ、画像全範囲になります。

API仕様 (ダイアログ表示)

mdi_dialog_ok( caption )

captionを表示する、情報ダイアログを表示します。

res = mdi_dialog_yesno( caption )

captionを表示する、情報ダイアログを表示します。yesの場合は0, noの場合は1, その他の場合は-1が戻り値になります。

res = mdi_dialog_yesnocancel( caption )

captionを表示する、情報ダイアログを表示します。yesの場合は0, noの場合は1, cancelの場合は2, その他の場合は-1が戻り値になります。