본문 바로가기

개발 개발/Android

fb2png fb를 png로

32bit framebuffer를 png로 바꾸는 perl script

ex) cat /dev/graphics/fb0 > /sdcard/fb0.dat

./fb2png 768 1024  < fb0 > screen3.png

#!/usr/bin/perl -w

 $w = shift || 240; 

 $h = shift || 320; 

 $pixels = $w * $h; 

 open OUT, "|pnmtopng" or die "Can't pipe pnmtopng: $!\n"; 

 printf OUT "P6%d %d\n255\n", $w, $h; 

 while ((read STDIN, $raw, 4) and $pixels--) { 

   $long = unpack('L', $raw); 

   print OUT pack("C3",

    ($long & 0x000000ff),

    ($long & 0x0000ff00) >> 8,

    ($long & 0x00ff0000) >> 16,

    ); 

 } 

 

 close OUT;