#include <fcntl.h>
#include <linux/fb.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define HEIGHT 480//600
#define WIDTH 640//800
#define BPP 16
#define LINE_LEN ((((WIDTH * BPP + 7)/ 8) + 31) / 32 * 32)
#define VIDEO_MEM_SIZE (HEIGHT * LINE_LEN)
#define CROSS_LEN 4//40
static int FBHandle = -1;
static int Width, Height, LineLen, FrameSize;
static unsigned char *FrameAddr;
void ui_cursor_show(unsigned short x, unsigned short y, unsigned short color)
{
unsigned short i, j;
unsigned short *tmp = (unsigned short*)(FrameAddr + y * LineLen + x*2);
printf("%s: x[%d] y[%d]\n", __FUNCTION__, x, y);
#if 0
if((x>CROSS_LEN/2) && (x<WIDTH-CROSS_LEN/2) && (y>CROSS_LEN/2) && (y<HEIGHT-CROSS_LEN/2))
{
//for(j=0; j<3; j++)
{
//tmp += j*LineLen;
tmp -= CROSS_LEN/2;
for(i=0; i<CROSS_LEN; i++)
{
tmp[i] |= color;
}
}
tmp += CROSS_LEN/2;
tmp -= CROSS_LEN/2*LineLen/2;
for(j=0; j<CROSS_LEN; j++)
{
tmp += LineLen/2;
tmp[0] |= color;
}
return ;
}
#endif
if(x<=CROSS_LEN/2)
{
tmp -= x;
for(i=0; i<CROSS_LEN/2+x; i++)
{
tmp[i] += color;
}
tmp += x;
}
else if(x>=WIDTH-CROSS_LEN/2)
{
tmp -= CROSS_LEN/2;
for(i=0; i<WIDTH-x+CROSS_LEN/2; i++)
{
tmp[i] += color;
}
tmp += CROSS_LEN/2;
}
else
{
tmp -= CROSS_LEN/2;
for(i=0; i<CROSS_LEN; i++)
{
tmp[i] += color;
}
tmp += CROSS_LEN/2;
}
if(y<=CROSS_LEN/2)
{
tmp -= y*LineLen/2;
for(j=0; j<CROSS_LEN/2+y; j++)
{
tmp += LineLen/2;
tmp[0] += color;
}
}
else if(y>=HEIGHT-CROSS_LEN/2)
{
#if 0
tmp -= CROSS_LEN/2*LineLen/2;
for(j=0; j<HEIGHT-y+CROSS_LEN/2; j++)
{
tmp += LineLen/2;
tmp[0] += color;
}
#endif
}
else
{
tmp -= CROSS_LEN/2*LineLen/2;
for(j=0; j<CROSS_LEN; j++)
{
tmp += LineLen/2;
tmp[0] += color;
}
}
}
void ui_cursor_hide(unsigned short x, unsigned short y, unsigned short color)
{
unsigned short i, j;
unsigned short *tmp = (unsigned short*)(FrameAddr + y * LineLen + x*2);
#if 0
if((x>CROSS_LEN/2) && (x<WIDTH-CROSS_LEN/2) && (y>CROSS_LEN/2) && (y<HEIGHT-CROSS_LEN/2))
{
//for(j=0; j<3; j++)
{
//tmp += j*LineLen;
tmp -= CROSS_LEN/2;
for(i=0; i<CROSS_LEN; i++)
{
tmp[i] -= color;
}
}
tmp += CROSS_LEN/2;
tmp -= CROSS_LEN/2*LineLen/2;
for(j=0; j<CROSS_LEN; j++)
{
tmp += LineLen/2;
tmp[0] -= color;
}
}
#endif
if(x<=CROSS_LEN/2)
{
tmp -= x;
for(i=0; i<CROSS_LEN/2+x; i++)
{
tmp[i] -= color;
}
tmp += x;
}
else if(x>=WIDTH-CROSS_LEN/2)
{
tmp -= CROSS_LEN/2;
for(i=0; i<WIDTH-x+CROSS_LEN/2; i++)
{
tmp[i] -= color;
}
tmp += CROSS_LEN/2;
}
else
{
tmp -= CROSS_LEN/2;
for(i=0; i<CROSS_LEN; i++)
{
tmp[i] -= color;
}
tmp += CROSS_LEN/2;
}
if(y<=CROSS_LEN/2)
{
tmp -= y*LineLen/2;
for(j=0; j<CROSS_LEN/2+y; j++)
{
tmp += LineLen/2;
tmp[0] -= color;
}
}
else if(y>=HEIGHT-CROSS_LEN/2)
{
tmp -= CROSS_LEN/2*LineLen/2;
for(j=0; j<HEIGHT-y+CROSS_LEN/2; j++)
{
tmp += LineLen/2;
tmp[0] -= color;
}
}
else
{
tmp -= CROSS_LEN/2*LineLen/2;
for(j=0; j<CROSS_LEN; j++)
{
tmp += LineLen/2;
tmp[0] -= color;
}
}
}
void ui_line_show(unsigned short fx, unsigned short fy, unsigned short tx, unsigned short ty, unsigned short color)
{
unsigned short i;
unsigned short *tmp;
short dx, dy;
float dxy;
unsigned short tempx, tempy;
printf("%s: fx[%d] fy[%d] tx[%d] ty[%d]\n", __FUNCTION__, fx, fy, tx, ty);
if((fx>WIDTH) || (fy>HEIGHT) || (tx>WIDTH) || (ty>HEIGHT))
{
printf("%s: ERROR++++++++ERROR\n", __FUNCTION__);exit(0);
return ;
}
if(fy == ty) // V line
{
if(fx > tx)
{
tempx = fx;
fx = tx;
tx = tempx;
}
tmp = (unsigned short*)(FrameAddr + fy * LineLen);
for(i=fx; i<tx; i++)
{
tmp[i] += color;
}
}
else if(fx == tx) // H line
{
if(fy > ty)
{
tempy = fy;
fy = ty;
ty = tempy;
}
tmp = (unsigned short*)(FrameAddr + fy * LineLen + fx*2);
for(i=0; i<ty-fy; i++)
{
tmp[0] += color;
tmp += LineLen/2;
}
}
else
{
dx = tx - fx;
dy = ty - fy;
if(abs(dx) > abs(dy))
{
dxy = (float)abs(dy)/abs(dx);
// printf("%s: dx[%d] dy[%d] dxy[%f]\n", __FUNCTION__, dx, dy, dxy);
tmp = (unsigned short*)FrameAddr;
for(i=0; i<abs(dx); i++)
{
if(dy rel='nofollow' onclick='return false;'> 0)
tempy = fy + (unsigned short)(dxy*i);
else if (fy > (unsigned short)(dxy*i))
tempy = fy - (unsigned short)(dxy*i);
else
tempy = 0;
if(tempy >= Height)
{
tempy = Height -1;
printf("%s: Height++++++++Height\n", __FUNCTION__);
}
if(dx > 0)
{
tempx = fx + i;
}
else
{
tempx = fx - i;
}
if(tempx >= Width)
{
tempx = Width -1;
printf("%s: Width++++++++Width\n", __FUNCTION__);
}
// printf("%s: tempx[%d] tempy[%d]\n", __FUNCTION__, tempx, tempy);
if((tempx>=Width) || (tempy>=Height))
{
printf("%s: Width++++++++Height\n", __FUNCTION__);exit(0);
}
tmp[tempy*LineLen/2 + tempx] += color;
}
if(tempy != ty)
tmp[ty*LineLen/2 + tx] += color;
}
else
{
dxy = (float)abs(dx)/abs(dy);
// printf("%s: dx[%d] dy[%d] dxy[%f] abs(dxy)[%d]\n", __FUNCTION__, dx, dy, dxy, abs(dxy));
tmp = (unsigned short*)FrameAddr;
for(i=0; i<abs(dy); i++)
{
if(dx rel='nofollow' onclick='return false;'> 0)
tempx = fx + (unsigned short)(dxy*i);
else if (fx > (unsigned short)(dxy*i))
tempx = fx - (unsigned short)(dxy*i);
else
tempx = 0;
if(tempx >= Width)
{
tempx = Width -1;
printf("%s: Width++++++++Width\n", __FUNCTION__);
}
if(dy > 0)
{
tempy = fy + i;
}
else
{
tempy = fy - i;
}
if(tempy >= Height)
{
tempy = Height -1;
printf("%s: Height++++++++Height\n", __FUNCTION__);
}
// printf("%s: tempx[%d] tempy[%d]\n", __FUNCTION__, tempx, tempy);
if((tempx>=Width) || (tempy>=Height))
{
printf("%s: Width++++++++Height\n", __FUNCTION__);exit(0);
}
tmp[tempy*LineLen/2 + tempx] += color;
}
if(tempx != tx)
tmp[ty*LineLen/2 + tx] += color;
}
}
}
void ui_line_hide(unsigned short fx, unsigned short fy, unsigned short tx, unsigned short ty, unsigned short color)
{
unsigned short i;
unsigned short *tmp;
printf("%s: fx[%d] fy[%d] tx[%d] ty[%d]\n", __FUNCTION__, fx, fy, tx, ty);
if((fx>WIDTH) || (fy>HEIGHT) || (tx>WIDTH) || (ty>HEIGHT) || (fx>tx) || (fy>ty))
return ;
if(fy == ty) // V line
{
tmp = (unsigned short*)(FrameAddr + fy * LineLen);
for(i=fx; i<tx; i++)
{
tmp[i] -= color;
}
}
else if(fx == tx) // H line
{
tmp = (unsigned short*)(FrameAddr + fy * LineLen + fx*2);
for(i=0; i<ty-fy; i++)
{
tmp[0] -= color;
tmp += LineLen/2;
}
}
}
void ui_area_show(unsigned short x, unsigned short y, unsigned short w, unsigned short h, unsigned short color)
{
printf("%s: x[%d] y[%d] w[%d] h[%d] color[0x%04x]\n", __FUNCTION__, x, y, w, h, color);
if((x+w > WIDTH) || (y+h > HEIGHT))
{
return ;
}
ui_line_show(x, y, x, y+h, color);
ui_line_show(x, y, x+w, y, color);
ui_line_show(x+w, y, x+w, y+h, color);
ui_line_show(x, y+h, x+w, y+h, color);
}
void ui_area_hide(unsigned short x, unsigned short y, unsigned short w, unsigned short h, unsigned short color)
{
printf("%s: x[%d] y[%d] w[%d] h[%d] color[0x%04x]\n", __FUNCTION__, x, y, w, h, color);
if((x+w > WIDTH) || (y+h > HEIGHT))
{
return ;
}
ui_line_hide(x, y, x, y+h, color);
ui_line_hide(x, y, x+w, y, color);
ui_line_hide(x+w, y, x+w, y+h, color);
ui_line_hide(x, y+h, x+w, y+h, color);
}
void