source: trunk/user/display/display.c @ 690

Last change on this file since 690 was 676, checked in by alain, 3 years ago

Introduce chat application to test the named pipes.

File size: 3.4 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////////
2//  file   : display.c 
3//  date   : may 2014
4//  author : Alain Greiner
5///////////////////////////////////////////////////////////////////////////////////////
6//  This file describes the single thread "display" application that simply
7//  open a file containing a raw image stored on disk, ans distplay it on the
8//  Frame Buffer without using the ALMOS-MKH windows manager.
9///////////////////////////////////////////////////////////////////////////////////////
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <fcntl.h>
14#include <unistd.h>
15#include <almosmkh.h>
16
17#define PATH_NAME   "misc/images_128.ram"
18
19#define FBF_TYPE    420         
20#define NPIXELS     128
21#define NLINES      128
22
23/////////// Global variables  ///////////////////////////////////////
24
25char    buffer[NPIXELS * NLINES] __attribute__((aligned(512)));
26
27/////////////////////////
28void build( char * base )
29{
30    int    line;
31    int    pixel;
32    char * buf;
33
34    for( line = 0 ; line < NLINES ; line++ )
35    {
36        for( pixel = 0 ;  pixel < NPIXELS ; pixel++ )
37        {
38            buf = base + (line * NPIXELS) + pixel;
39
40            *buf = ( ((pixel <  (NPIXELS>>1)) && (line <  (NLINES>>1))) ||
41                     ((pixel >= (NPIXELS>>1)) && (line >= (NLINES>>1))) ) ? 0xFF : 0;
42        }
43    }
44}
45
46//////////////////////////////////////     
47void print_block( unsigned int * buf )
48{
49    int offset;    // word index in array of words
50   
51    printf("\n***** content of buffer %x *****\n", buf );
52    for( offset = 0 ; offset < 128 ; offset += 8 )
53    {
54        printf(" - %d\t: %x | %x | %x | %x | %x | %x | %x | %x\n",
55        offset<<2, buf[offset+0], buf[offset+1], buf[offset+2], buf[offset+3], 
56                   buf[offset+4], buf[offset+5], buf[offset+6], buf[offset+7] );
57    }
58}       
59
60////////////////
61int main( void )
62{
63
64    unsigned int    fbf_width;
65    unsigned int    fbf_height;
66    unsigned int    fbf_type;
67    unsigned int    nbytes;
68    int             val;
69    int             error;
70    char            pathname[PATH_MAX_LENGHT];
71
72    // check frame buffer size
73    fbf_get_config( &fbf_width , &fbf_height , &fbf_type );
74
75    if( (NPIXELS != fbf_width) || (NLINES != fbf_height) )
76    {
77        printf("\n[display error] FBF size [%d,%d] does not fit image size[%d,%d]\n",
78        fbf_width, fbf_height, NPIXELS, NLINES );
79        exit( 0 );
80    }
81
82    // check pixel encoding type
83    if( fbf_type != FBF_TYPE )
84    {
85        printf("\n[display error] FBF type [%d] does not fit image type [%d]\n",
86        fbf_type, FBF_TYPE);
87        exit( 0 );
88    }
89
90    // open file
91    int fd = open( PATH_NAME , O_RDONLY , 0 );
92    if( fd < 0 )
93    {
94        printf("\n[display error] Cannot open file <%s>\n", pathname );
95        exit( 0 );
96    }
97
98    printf("\n[display] open file <%s>\n", pathname );
99
100    // load buffer from file
101    nbytes = read( fd , buffer , NPIXELS * NLINES );
102
103    if( nbytes != NPIXELS * NLINES )
104    {
105        printf("\n[display error] Cannot load image \n" );
106        exit( 0 );
107    }
108
109    printf("\n[display] load image in buffer %x\n", buffer );
110 
111    // display image
112    error = fbf_write( buffer , NPIXELS * NLINES , 0 );
113
114    if( error )
115    {
116        printf("\n[display error] Cannot access frame buffer\n");
117        exit( 0 );
118    }
119
120    printf("\n[display] display image\n");
121
122    // close file
123    close( fd );
124   
125    exit(0);
126
127    return 0;
128}
Note: See TracBrowser for help on using the repository browser.