Skip to content

Commit

Permalink
Re-formatted code by indent
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Sep 22, 2022
1 parent 7bc73c1 commit 86a2d26
Showing 1 changed file with 63 additions and 63 deletions.
126 changes: 63 additions & 63 deletions rpi_framebuffer/rpi_fb10.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ typedef struct fb_fix_screeninfo ModeInfo;
* (postacuje byt ve skupine 'video' ci pouziti su/sudo)
*/
int readFramebufferInfo(int framebufferDevice,
FramebufferInfo *framebufferInfoPtr,
ModeInfo *modeInfoPtr)
FramebufferInfo * framebufferInfoPtr,
ModeInfo * modeInfoPtr)
{
/* Pokud operace ioctl probehne v poradku, vrati se 0 */
if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, framebufferInfoPtr)) {
Expand All @@ -64,8 +64,8 @@ int readFramebufferInfo(int framebufferDevice,
* Funkce line() platna pro nezname graficke rezimy.
*/
void lineNull(const int x1, const int y1, const int x2, const int y2,
const unsigned char r, const unsigned char g, const unsigned char b,
char *pixels, const int line_length)
const unsigned char r, const unsigned char g,
const unsigned char b, char *pixels, const int line_length)
{
}

Expand All @@ -77,40 +77,40 @@ void lineNull(const int x1, const int y1, const int x2, const int y2,
* Funkcni naproklad pro graficke karty Intel.
*/
void lineBGRA(const int x1, const int y1, const int x2, const int y2,
const unsigned char r, const unsigned char g, const unsigned char b,
char *pixels, const int line_length)
const unsigned char r, const unsigned char g,
const unsigned char b, char *pixels, const int line_length)
{
/* vypocet adresy zapisu dat */
/* pocitame v 32bitovych slovech, tj. line_length je nutne podelit ctyrmi */
unsigned int index = x1 + (y1*line_length >> 2);
unsigned int index = x1 + (y1 * line_length >> 2);
/* >> 2 nahrazuje deleni ctyrmi */

/* vlastni provedeni vykresleni usecky */
int x = x1;
int y = y1;
/* zrcadleni algoritmu pro dalsi oktanty */
int dx = ABS(x2-x1), sx = x1<x2 ? 1 : -1;
int dy = ABS(y2-y1), sy = y1<y2 ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2;
int dx = ABS(x2 - x1), sx = x1 < x2 ? 1 : -1;
int dy = ABS(y2 - y1), sy = y1 < y2 ? 1 : -1;
int err = (dx > dy ? dx : -dy) / 2, e2;

/* uplna barva v jednom slove */
__u32 color = (r<<16) | (g<<8) | b;
__u32 *pixels32 = (__u32*)pixels;
__u32 color = (r << 16) | (g << 8) | b;
__u32 *pixels32 = (__u32 *) pixels;

/* pri posunu po x-ove ose se index musi zvysit ci snizit o 4 (bajty) tj. o 1 32-bitove slovo */
int offsetX = x1<x2 ? 1: -1;
int offsetX = x1 < x2 ? 1 : -1;
/* pri posunu po y-ove ose se index musi zvysit ci snizit o delku radku (ve slovech) */
int offsetY = y1<y2 ? (line_length >> 2) : - (line_length >> 2);
int offsetY = y1 < y2 ? (line_length >> 2) : -(line_length >> 2);

while (1) {
/* vlastni provedeni zapisu barvy pixelu */
*(pixels32+index) = color;
*(pixels32 + index) = color;

if (x==x2 && y==y2) {
if (x == x2 && y == y2) {
break;
}
e2 = err;
if (e2 >-dx) {
if (e2 > -dx) {
/* prepocet kumulovane chyby */
err -= dy;
/* posun na predchozi ci dalsi pixel na radku */
Expand All @@ -135,8 +135,8 @@ void lineBGRA(const int x1, const int y1, const int x2, const int y2,
* Funkcni pro Raspberry Pi s poradim bajtu R,G,B,A.
*/
void lineRGBA(const int x1, const int y1, const int x2, const int y2,
const unsigned char r, const unsigned char g, const unsigned char b,
char *pixels, const int line_length)
const unsigned char r, const unsigned char g,
const unsigned char b, char *pixels, const int line_length)
{
lineBGRA(x1, y1, x2, y2, b, g, r, pixels, line_length);
}
Expand All @@ -148,8 +148,8 @@ void lineRGBA(const int x1, const int y1, const int x2, const int y2,
* s formatem 5-6-5.
*/
void line565(const int x1, const int y1, const int x2, const int y2,
const unsigned char r, const unsigned char g, const unsigned char b,
char *pixels, const int line_length)
const unsigned char r, const unsigned char g,
const unsigned char b, char *pixels, const int line_length)
{
#define RED_OFFSET 11
#define GREEN_OFFSET 5
Expand All @@ -160,41 +160,41 @@ void line565(const int x1, const int y1, const int x2, const int y2,
/* vypocet barvy pixelu, v zavorce nejdrive snizime bitovou sirku
* rezervovanou pro jednotlive barvove slozky a posleze bity, ktere
* reprezentuji barvovou slozku posuneme do spravne pozice ve slove */
unsigned int pixel_value = (r >> RED_LOST_BITS) << RED_OFFSET |
(g >> GREEN_LOST_BITS) << GREEN_OFFSET |
(b >> BLUE_LOST_BITS) << BLUE_OFFSET;
unsigned int pixel_value = (r >> RED_LOST_BITS) << RED_OFFSET |
(g >> GREEN_LOST_BITS) << GREEN_OFFSET |
(b >> BLUE_LOST_BITS) << BLUE_OFFSET;

/* prevod na dvojici bajtu */
unsigned char byte1 = pixel_value & 0xff;
unsigned char byte2 = pixel_value >> 8;

/* vypocet adresy zapisu dat */
unsigned int index = (x1<<1) + y1*line_length;
unsigned int index = (x1 << 1) + y1 * line_length;
/* << 1 nahrazuje nasobeni dvema */

/* vykresleni usecky */
int x = x1;
int y = y1;
/* zrcadleni algoritmu pro dalsi oktanty */
int dx = ABS(x2-x1), sx = x1<x2 ? 1 : -1;
int dy = ABS(y2-y1), sy = y1<y2 ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2;
int dx = ABS(x2 - x1), sx = x1 < x2 ? 1 : -1;
int dy = ABS(y2 - y1), sy = y1 < y2 ? 1 : -1;
int err = (dx > dy ? dx : -dy) / 2, e2;

/* pri posunu po x-ove ose se index musi zvysit ci snizit o 2 (bajty) */
int offsetX = x1<x2 ? 2: -2;
int offsetX = x1 < x2 ? 2 : -2;
/* pri posunu po y-ove ose se index musi zvysit ci snizit o delku radku (v bajtech) */
int offsetY = y1<y2 ? line_length : - line_length;
int offsetY = y1 < y2 ? line_length : -line_length;

while (1) {
/* vlastni provedeni zapisu barvy pixelu */
*(pixels+index) = byte1;
*(pixels+index+1) = byte2;
*(pixels + index) = byte1;
*(pixels + index + 1) = byte2;

if (x==x2 && y==y2) {
if (x == x2 && y == y2) {
break;
}
e2 = err;
if (e2 >-dx) {
if (e2 > -dx) {
/* prepocet kumulovane chyby */
err -= dy;
/* posun na predchozi ci dalsi pixel na radku */
Expand All @@ -217,16 +217,17 @@ void line565(const int x1, const int y1, const int x2, const int y2,
* Novy datovy typ - ukazatel na (libovolnou) funkci line.
*/
typedef void (*LineFunction)(const int, const int, const int, const int,
const unsigned char, const unsigned char, const unsigned char,
char*, const int);
const unsigned char, const unsigned char,
const unsigned char, char *, const int);




/*
* Funkce, ktera vraci korektni funkci pro operaci line().
*/
LineFunction getProperLineFunction(int bits_per_pixel, int type, int visual, int redOffset)
LineFunction getProperLineFunction(int bits_per_pixel, int type,
int visual, int redOffset)
{
/* umime rozeznat pouze format bez bitovych rovin a bez palety */
if (type == FB_TYPE_PACKED_PIXELS && visual == FB_VISUAL_TRUECOLOR) {
Expand All @@ -236,8 +237,7 @@ LineFunction getProperLineFunction(int bits_per_pixel, int type, int visual, int
if (bits_per_pixel == 32) {
if (redOffset == 16) {
return lineBGRA;
}
else {
} else {
return lineRGBA;
}
}
Expand All @@ -251,52 +251,52 @@ LineFunction getProperLineFunction(int bits_per_pixel, int type, int visual, int
* Vykresleni testovaciho obrazku s vyuzitim funkce line.
*/
void drawTestImage(int framebufferDevice,
FramebufferInfo *framebufferInfoPtr,
ModeInfo *modeInfoPtr)
FramebufferInfo * framebufferInfoPtr,
ModeInfo * modeInfoPtr)
{
#define OFFSET 300
/* casto pouzivane konstanty */
const int buffer_length = modeInfoPtr->smem_len;
const int pitch = modeInfoPtr->line_length;

/* ziskame spravnou verzi funkce line */
LineFunction line = getProperLineFunction(framebufferInfoPtr->bits_per_pixel,
modeInfoPtr->type,
modeInfoPtr->visual,
framebufferInfoPtr->red.offset);
LineFunction line =
getProperLineFunction(framebufferInfoPtr->bits_per_pixel,
modeInfoPtr->type,
modeInfoPtr->visual,
framebufferInfoPtr->red.offset);

/* ziskat primy pristup do framebufferu */
char *pixels = (char*)mmap(0, buffer_length,
PROT_READ | PROT_WRITE,
MAP_SHARED, framebufferDevice,
0);
char *pixels = (char *) mmap(0, buffer_length,
PROT_READ | PROT_WRITE,
MAP_SHARED, framebufferDevice,
0);

if (pixels != MAP_FAILED) {
int i;
int r, g, b;
/* nejprve vymazeme cely framebuffer */
memset(pixels, 0, buffer_length);

/* vykreslime nekolik usecek s ruznym sklonem a barvou*/
for (i=0; i<256; i++) {
/* vykreslime nekolik usecek s ruznym sklonem a barvou */
for (i = 0; i < 256; i++) {
r = i;
g = i;
b = 255-i;
line(i*3, 0, i*3, 100, r, g, b, pixels, pitch);
b = 255 - i;
line(i * 3, 0, i * 3, 100, r, g, b, pixels, pitch);
r = 255;
g = i;
b = 255-i;
line(i*4, 150, i*5, 250, r, g, b, pixels, pitch);
b = 255 - i;
line(i * 4, 150, i * 5, 250, r, g, b, pixels, pitch);
}
for (i=0; i<=300; i+=10) {
for (i = 0; i <= 300; i += 10) {
line(0, 300 + i, i, 300 + 300, 255, 255, 255, pixels, pitch);

line(300, 300, 600, 300 + i, 128, 128, 255, pixels, pitch);
}
getchar();
munmap(pixels, buffer_length);
}
else {
} else {
perror("Nelze pristupovat k framebufferu");
}
}
Expand All @@ -307,23 +307,24 @@ void drawTestImage(int framebufferDevice,
int main(int argc, char **argv)
{
FramebufferInfo framebufferInfo;
ModeInfo modeInfo;
ModeInfo modeInfo;
int framebufferDevice = 0;

/* Ze zarizeni potrebujeme cist i zapisovat.*/
/* Ze zarizeni potrebujeme cist i zapisovat. */
framebufferDevice = open("/dev/fb0", O_RDWR);

/* Pokud otevreni probehlo uspesne, nacteme
* a nasledne vypiseme informaci o framebufferu.*/
if (framebufferDevice != -1) {
/* Precteni informaci o framebufferu a test, zda se vse podarilo */
if (readFramebufferInfo(framebufferDevice, &framebufferInfo, &modeInfo)) {
if (readFramebufferInfo
(framebufferDevice, &framebufferInfo, &modeInfo)) {
drawTestImage(framebufferDevice, &framebufferInfo, &modeInfo);
}
close(framebufferDevice);
return 0;
}
/* Otevreni se nezadarilo, vypiseme tudiz pouze chybove hlaseni.*/
/* Otevreni se nezadarilo, vypiseme tudiz pouze chybove hlaseni. */
else {
perror("Nelze otevrit ovladac /dev/fb0");
return 1;
Expand All @@ -333,4 +334,3 @@ int main(int argc, char **argv)


/* finito */

0 comments on commit 86a2d26

Please sign in to comment.