Showing posts with label convert. Show all posts
Showing posts with label convert. Show all posts

Wednesday, April 6, 2016

Framebuffer screen dumps to PNG and back

I've got a nice card with an Atmel AVR32 processor and a nice big 320x240 (monochrome!) screen. :)
I can put data on the screen from buildroot linux by writing directly to the framebuffer, /dev/fb0. However the data there is in raw format. Here is how to dump from screen. Then convert, using ffmpeg, the raw data to a PNG and then back to raw data after editing:

  1. Get a screenshot of the framebuffer using cat /dev/fb0 > screendump.bin.
  2. Convert to PNG using ffmpeg: ffmpeg   -vcodec rawvideo   -f rawvideo   -pix_fmt monow   -s 320x240   -i screendump.bin     -f image2   -vcodec png screendump.png
    This will read raw video from the screendump.bin, handle it as pixel monochrome data from a 320x240 screen and save as sreendump PNG file.
  3. Next, open in Gimp or similar to edit. Save as PNG afterwards.
  4. Convert to rawvideo binary again using ffmpeg: ffmpeg -vcodec png -i savedimage.png -vcodec rawvideo -f rawvideo -pix_fmt monow savedimage.bin
  5. Put the data on the screen: cat savedimage.bin > /dev/fb0
Use ffmpeg -pix_fmts to see other raw video types to convert from/to.

Sources: Check out these great sites for more:
http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs
http://forum.videohelp.com/threads/334333-Help-with-lossless-ffmpeg-command-%5Bvideo-png-back-to-video%5D
http://stackoverflow.com/questions/3781549/how-to-convert-16-bit-rgb-frame-buffer-to-a-viewable-format
https://community.freescale.com/docs/DOC-100347

Friday, November 20, 2009

Character sets UTF-8 and ISO-8859-1 in HTML and PHP

Character sets can bring much agony to programming for the web. Here are some useful functions and ideas about handling charsets.

There are two main charsets: UTF-8(Unicode) and ISO-8859-1. UTF-8 lets one handle more characters than ISO-8859-1 (such as arabic and chinese characters).

HTML files that should handle unicode characters must have this set in the header:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

Here one could also use 'iso-8859-1' instead.

If you need to convert between ISO-8859-1 and UTF-8 in PHP the functions utf8_encode and utf8_decode are useful. utf8_encode will convert from ISO-8859-1 to UTF-8 and utf8_decode from UTF-8 to ISO-8859-1.
The use of the functions is:
$utf8string = utf8_encode( $iso-8859-1string );
$iso-8859-1string = utf8_decode( $utf8string );


In addition to UTF-8 there are two other Unicode standards UTF-16 and UTF-32. The difference is how many bytes are used to store a character and thus how many different characters can be stored. UTF-32 is in little use, and so is UTF-16, but UTF-16 is used in more places.

To convert between these Unicode charsets use iconv. It is used like this:
$utf16string = iconv("utf-8", "utf-16", $utf8str);
or
$utf8string = iconv("utf-16", "utf-8", $utf16str);

incov can also be used to convert from other character sets such as ISO-8859-1 like this:
$utf16string = iconv("iso-8859-1", "utf-16", $iso-8859-1string);

Solutions found at: http://www.php.net/manual/en/function.utf8-decode.php, http://php.net/manual/en/function.utf8-encode.php, http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_21916597.html, and http://www.php.net/manual/en/function.iconv.php.