Frame Buffer. [RESOLVIDO]

1. Frame Buffer. [RESOLVIDO]

???
gokernel

(usa Linux Mint)

Enviado em 05/01/2010 - 12:46h


Olá pessoal.

Quero simplesmente desenhar 1 pixel na tela usando Frame Buffer, tentei baixar o codigo do(BootSplash) para examinar, mas não consegui fazer o download.

Alguem poderia demonstrar como fazer(um programa básico completo) para desenhar 1 PIXEL no Frame Buffer?

Grato.

gokernel
gokernel@hotmail.com



  


2. Codigo do BusyBox-1.15.3

???
gokernel

(usa Linux Mint)

Enviado em 12/01/2010 - 12:31h

Depois de pesquisar muito aprendi como fazer um programa usando o FRAME BUFFER, para criar um modulo nativo GRÁFICO para LUA.


Para quem interessar, vai o codigo.


//###################################################################
//-------------------------------------------------------------------
// Example of basic FRAME BUFFER program.
// Code from: busybox-1.15.3(fbsplash.c)
//-------------------------------------------------------------------

#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <getopt.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <stdio.h>


#define BITS_PER_PIXEL 2
#define USHORT unsigned short


struct _fbb {
struct fb_var_screeninfo info;

unsigned char *addr; // pointer to framebuffer memory
}fbb;


int FBB_base_init() {
int fd;

if ( (fd = open("/dev/fb0", O_RDWR)) < 0 ) {
printf("'/dev/fb0' NOT FOUND.\n");
return 0; // ERROR
}

ioctl(fd, FBIOGET_VSCREENINFO, &fbb.info);

// map the device in memory
fbb.addr = mmap(NULL, fbb.info.xres * fbb.info.yres * BITS_PER_PIXEL,
PROT_WRITE, MAP_SHARED, fd, 0);

close(fd); // No need.

// Only 16 Bits
if (fbb.info.bits_per_pixel == 16)
return 1;
else {
printf("ERROR: Suport only FRAME BUFFER 16 Bits.\n");
return 0;
}
}


//-------------------------------------------------------------------
// NAME: FBB_base_makecol.
// USE: color = FBB_base_makecol(255, 130, 30);
//
// DESC:
// Make a color only in 16 bits.
//
// CODE BASEAD IN:
// See file: from busybox-1.15.3: /miscutils/fbsplash.c
// Function: static void fb_drawfullrectangle(...).
// Copyright (C) 2008 Michele Sanges <michele.sanges@gmail.com>
//
// BY: gokernel
//-------------------------------------------------------------------
int FBB_base_makecol(unsigned char r, unsigned char g, unsigned char b) {
r >>= 3; // 5-bit red
g >>= 2; // 6-bit green
b >>= 3; // 5-bit blue

return b + (g << 5) + (r << (5+6));
}


// Put PIXEL
void FBB_base_putpixel(short x, short y, register unsigned short color) {
register unsigned short *pointer;

pointer = (USHORT*)(fbb.addr + (y * fbb.info.xres + x) * BITS_PER_PIXEL);

*pointer = color; // <-- Put HERE;
}


// Horizontal Lines
void FBB_base_hline(short x1, short y, short x2, register unsigned short color) {
register short count;
register unsigned short *pointer;

// horizontal lines
pointer = (USHORT*)(fbb.addr + (y * fbb.info.xres + x1) * BITS_PER_PIXEL);
count = x2 - x1;
do {
*pointer++ = color;
} while (--count >= 0);
}


// Vertical Lines
void FBB_base_vline(short x, short y1, short y2, register unsigned short color) {
register short count;
register unsigned short *pointer;

// vertical lines
pointer = (USHORT*)(fbb.addr + (y1 * fbb.info.xres + x) * BITS_PER_PIXEL);
count = y2 - y1;
do {
*pointer = color;
pointer += fbb.info.xres; // Screen HEIGHT;
} while (--count >= 0);
}


int main() {
int color;

if ( !FBB_base_init() )
return 1; // ERROR

// Color ORANGE
color = FBB_base_makecol(255, 130, 30);

FBB_base_putpixel(150, 150, color);

FBB_base_hline(100, 100, 500, color);

FBB_base_vline(100, 100, 500, color);

return 0;
}

//###################################################################







Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts