トップ «前の日記(2009/12/21) 最新 次の日記(2009/12/24)» 編集

SikabaneWorksが関係するコンテンツ(主に*band系ローグライク)の開発近況・補足から全く個人的な雑記まで。

[WEB:屍の見える丘公園]| [RSS]

Angband | Badiashimshe | C# | CRAUZEL | D'angband/小説草稿 | D'angband/開発 | DarkSouls | Demon'sSouls | DungeonCrawl | ElvenUteruses | Haskell | Hengband | J9シリーズ | LEGO | LineDrawing | MISC | MTG | Mac | Math | Moria | R-18 | Roguelike | Rough | RoughSketch | Ruby | SDL | UNIX | VMware | WarHammer | Zangband | アタシラヂョウヲウ | イラスト | ガジェット | ゲーム | ゲーム紹介 | ゲーム製作技術 | ゲーム論 | スケッチ | ツクール | テクノロジー | ニコニコ動画 | ファルコム | ファンタジー | マリオ | ヴィーヤウトゥムノ | 別記事追加予定 | 変愚蛮怒 | 変愚蛮怒/スポイラー | 変愚蛮怒/元ネタ探訪 | 変愚蛮怒/攻略 | 変愚蛮怒/開発 | 宗教 | 情報 | 政治 | 文字コード | 日ペ昔話 | 東方 | 東方ワンドロ | 東方外法漢女 | 歴史 | 漫画製作 | 版権絵 | 画像処理 | 翻訳 | 自然言語 | 艦隊これくしょん | 落書き | 言語解析 | 読書 | 超人ロック | 追記予定 | 通信 | 鉄獄旅慕情 | 阿片窟 | 馬鹿馬鹿蛮怒/開発 | 魔法少女まどか☆マギカ | 魚類版深夜の真剣お絵描き60分一本勝負


2009/12/22

[画像処理]簡単な畳み込みフィルタリングのつもり

だったはずなのだが、Ruby/SDL上のSurfaceをいじる処理云々で色々手間取って妙に時間がかかってしまった。 一応左下から順に移動平均フィルタ、ラプラシアンフィルタ、先鋭化フィルタを使った結果。

require 'sdl'

auto_lock = true
SDL.init(SDL::INIT_EVERYTHING)

def filtering(surface, filter)
  p = SDL::Surface.new(SDL::HWSURFACE ||
                               SDL::SRCALPHA, surface.w, surface.h, 32,
                               0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff)

  1.upto(surface.h-2) do |h|
    1.upto(surface.w-2) do |w|
      r = 0
      g = 0
      b = 0

      pix = surface.format.getRGBA(surface[w-1, h-1])
      r += (pix[0]*filter[0][0]).round
      g += (pix[1]*filter[0][0]).round
      b += (pix[2]*filter[0][0]).round

      pix = surface.format.getRGBA(surface[w  , h-1])
      r += (pix[0]*filter[0][1]).round
      g += (pix[1]*filter[0][1]).round
      b += (pix[2]*filter[0][1]).round

      pix = surface.format.getRGBA(surface[w+1, h-1])
      r += (pix[0]*filter[0][2]).round
      g += (pix[1]*filter[0][2]).round
      b += (pix[2]*filter[0][2]).round

      pix = surface.format.getRGBA(surface[w-1, h])
      r += (pix[0]*filter[1][0]).round
      g += (pix[1]*filter[1][0]).round
      b += (pix[2]*filter[1][0]).round

      pix = surface.format.getRGBA(surface[w  , h])
      r += (pix[0]*filter[1][1]).round
      g += (pix[1]*filter[1][1]).round
      b += (pix[2]*filter[1][1]).round

      pix = surface.format.getRGBA(surface[w+1, h])
      r += (pix[0]*filter[1][2]).round
      g += (pix[1]*filter[1][2]).round
      b += (pix[2]*filter[1][2]).round

      pix = surface.format.getRGBA(surface[w-1, h+1])
      r += (pix[0]*filter[2][0]).round
      g += (pix[1]*filter[2][0]).round
      b += (pix[2]*filter[2][0]).round

      pix = surface.format.getRGBA(surface[w  , h+1])
      r += (pix[0]*filter[2][1]).round
      g += (pix[1]*filter[2][1]).round
      b += (pix[2]*filter[2][1]).round

      pix = surface.format.getRGBA(surface[w+1, h+1])
      r += (pix[0]*filter[2][2]).round
      g += (pix[1]*filter[2][2]).round
      b += (pix[2]*filter[2][2]).round

      p[w,h] = [r,g,b,255]
    end
  end

  return p
end

graphics = Array.new
graphics.push(SDL::Surface.load("AngelFish.png"))

graphics.push(filtering(graphics[0],
                      [[0.11, 0.11, 0.11], [0.11, 0.11, 0.11], [0.11, 0.11, 0.11]]))
graphics.push(filtering(graphics[0],
                      [[   0,  1.0,    0], [ 1.0, -4.0,  1.0], [   0,  1.0,    0]]))
graphics.push(filtering(graphics[0],
                      [[   0, -1.0,    0], [-1.0,  5.0, -1.0], [   0, -1.0,    0]]))

screen = SDL::Screen.open(graphics[0].w * 2, graphics[0].h * 2, 32, 0)

while true

    while event = SDL::Event2.poll

      case event
        when SDL::Event2::Quit
          exit

        when SDL::Event2::KeyDown
          exit if event.sym == SDL::Key::ESCAPE

        when SDL::Event2::KeyUp

      end
    end

    screen.put(graphics[0], 0, 0)
    screen.put(graphics[1], graphics[1].w, 0)
    screen.put(graphics[2], 0, graphics[2].h)
    screen.put(graphics[3], graphics[3].w, graphics[3].h)
    screen.updateRect(0,0,0,0)
end

画像処理