Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use <code><a href="http://www.manpagez.com/man/2/open/" rel="noreferrer">open()</a></code> on the right file in <code>/dev</code> (eg. <code>/dev/fb0</code>), then use <code><a href="http://www.manpagez.com/man/2/mmap/" rel="noreferrer">mmap()</a></code> to map it into memory. Manpages will help for these syscalls if you do not know how to use them.</p> <p>Then there are some structures and constants for some <code><a href="http://www.manpagez.com/man/2/ioctl/" rel="noreferrer">ioctl()</a></code>s in <code>&lt;linux/fb.h&gt;</code>. Like many kernel headers, you can learn a lot simply browsing the file.</p> <p>Particularly interesting is the ioctl <code>FBIOGET_VSCREENINFO</code> with <code>struct fb_var_screeninfo</code>. Note this has <code>xres</code>, <code>yres</code> (resolution) and <code>bits_per_pixel</code>. Then there's <code>FBIOGET_FSCREENINFO</code> and <code>struct fb_fix_screeninfo</code> which has further information like <code>type</code> and <code>line_length</code>.</p> <p>So a pixel at (x, y) might be at <code>mmap_base_address + x * bits_per_pixel/8 + y * line_length</code>. The exact format of the pixels will depend on the structures you retrieve via ioctl; it's your job to decide how to read/write them.</p> <p>It's been a while since I've worked with this so I'm a bit hazy on more details..</p> <p>Here's a quick and dirty code sample just to illustrate how it's done... I haven't tested this.</p> <pre><code>#include &lt;sys/types.h&gt; #include &lt;sys/ioctl.h&gt; #include &lt;sys/mman.h&gt; #include &lt;linux/fb.h&gt; #include &lt;unistd.h&gt; #include &lt;fcntl.h&gt; #include &lt;stdio.h&gt; int main() { struct fb_var_screeninfo screen_info; struct fb_fix_screeninfo fixed_info; char *buffer = NULL; size_t buflen; int fd = -1; int r = 1; fd = open("/dev/fb0", O_RDWR); if (fd &gt;= 0) { if (!ioctl(fd, FBIOGET_VSCREENINFO, &amp;screen_info) &amp;&amp; !ioctl(fd, FBIOGET_FSCREENINFO, &amp;fixed_info)) { buflen = screen_info.yres_virtual * fixed_info.line_length; buffer = mmap(NULL, buflen, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (buffer != MAP_FAILED) { /* * TODO: something interesting here. * "buffer" now points to screen pixels. * Each individual pixel might be at: * buffer + x * screen_info.bits_per_pixel/8 * + y * fixed_info.line_length * Then you can write pixels at locations such as that. */ r = 0; /* Indicate success */ } else { perror("mmap"); } } else { perror("ioctl"); } } else { perror("open"); } /* * Clean up */ if (buffer &amp;&amp; buffer != MAP_FAILED) munmap(buffer, buflen); if (fd &gt;= 0) close(fd); return r; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload