Help us understand the problem. What is going on with this article?

BMPとRAWデータ(RGB8888/RGB565)の相互変換メモ

More than 3 years have passed since last update.

cat /dev/fb0 > fb.raw でダンプしたデータを画像に変換する機会があったので、手順をメモ

fbのサイズとビット深度を確認

サイズを確認

cat /sys/class/graphics/fb0/virtual_size
# -> 640,480

ビット深度を確認

cat /sys/class/graphics/fb0/bits_per_pixel
# -> 32 (RGB8888)
# -> 16 (RGB565)

fbの操作

fb0のダンプ

cat /dev/fb0 > fb_output.raw

fb0への出力

cat fb_input.raw > /dev/fb0

ffmpegを使用

rgb565への変換はconvertですぐに変換する方法が見当たらなかったため、ffmpegを使用した

sudo apt-get install ffmpeg

単体実行

# rgb8888 -> bmp
ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt rgb32 -s 640x480 -i fb.raw -f image2 -vcodec bmp fb.bmp

# rgb565 -> bmp
ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt rgb565 -s 640x480 -i fb.raw -f image2 -vcodec bmp fb.bmp

# bmp -> rgb8888
ffmpeg -vcodec bmp -i fb.bmp -vcodec rawvideo -f rawvideo -pix_fmt rgb32 fb.raw

# bmp -> rgb565
ffmpeg -vcodec bmp -i fb.bmp -vcodec rawvideo -f rawvideo -pix_fmt rgb565 fb.raw

カレントディレクトリ以下の全てのrawファイルに対して実行

for bmpfile in `find . -name "*.bmp"`; do ffmpeg -vcodec bmp -i ${bmpfile} -vcodec rawvideo -f rawvideo -pix_fmt rgb565 ${bmpfile%.bmp}.rgb565; done

for bmpfile in `find . -name "*.bmp"`; do ffmpeg -vcodec bmp -i ${bmpfile} -vcodec rawvideo -f rawvideo -pix_fmt rgb24 ${bmpfile%.bmp}.rgb24; done

ImageMagickを使用

bmp -> rawの変換であれば、convert コマンドでも実行可能。種別は拡張子で判別してくれる。

sudo apt-get install imagemagick

単体実行

# bmp -> raw
convert -size 640x480 fb0{.bmp,.raw};

カレントディレクトリ以下の全てのbmpファイルに対して実行

# bmp -> raw
for bmpfile in `find . -name "*.bmp"`; do convert -size 640x480 ${bmpfile%.bmp}{.bmp,.raw}; done

GIMPを使用

Gimpでrawデータを開いて変換して保存しても良いらしい

まとめ

  • 今回はbmpを指定したが、pngやjpegも指定可能。ImageMagickのほうは拡張子で判別してくれる。
  • 色変換はffmpegのほうが得意そう。
  • 拡大縮小、フィルタ、回転、クリッピング等はImageMagickのほうが簡単そう。
  • ImageMagickは多機能すぎてよくわからない。-> 使用例のコマンドを改造したほうが良さそう。
  • ffmpegもよくわからない。-> 使用例のコマンドを改造したほうが良さそう。

参考

Converting to/from RGB565 in Ubuntu using ffmpeg
ImageMagick(公式)
ffmpeg(公式)

koara-local
言語は最近は C#, Javaあたりがメイン。端末VimからIDEに移行。IntelliJすごい。Qiitaでの記事やその中の主張は、所属している企業/団体の意見を代表するものではありません。
http://koara-local.github.io/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした