[644] | 1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // file : display.c |
---|
| 3 | // date : may 2014 |
---|
| 4 | // author : Alain Greiner |
---|
| 5 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
[676] | 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. |
---|
[644] | 9 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 10 | |
---|
| 11 | #include <stdio.h> |
---|
| 12 | #include <stdlib.h> |
---|
| 13 | #include <fcntl.h> |
---|
| 14 | #include <unistd.h> |
---|
| 15 | #include <almosmkh.h> |
---|
| 16 | |
---|
[676] | 17 | #define PATH_NAME "misc/images_128.ram" |
---|
[657] | 18 | |
---|
[644] | 19 | #define FBF_TYPE 420 |
---|
| 20 | #define NPIXELS 128 |
---|
| 21 | #define NLINES 128 |
---|
| 22 | |
---|
| 23 | /////////// Global variables /////////////////////////////////////// |
---|
| 24 | |
---|
| 25 | char buffer[NPIXELS * NLINES] __attribute__((aligned(512))); |
---|
| 26 | |
---|
| 27 | ///////////////////////// |
---|
| 28 | void 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 | ////////////////////////////////////// |
---|
| 47 | void 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 | } |
---|
[657] | 59 | |
---|
[656] | 60 | //////////////// |
---|
| 61 | int main( void ) |
---|
[644] | 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; |
---|
[657] | 70 | char pathname[PATH_MAX_LENGHT]; |
---|
[644] | 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 | |
---|
[676] | 82 | // check pixel encoding type |
---|
[644] | 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 |
---|
[676] | 91 | int fd = open( PATH_NAME , O_RDONLY , 0 ); |
---|
[657] | 92 | if( fd < 0 ) |
---|
[644] | 93 | { |
---|
[657] | 94 | printf("\n[display error] Cannot open file <%s>\n", pathname ); |
---|
[644] | 95 | exit( 0 ); |
---|
| 96 | } |
---|
| 97 | |
---|
[657] | 98 | printf("\n[display] open file <%s>\n", pathname ); |
---|
[644] | 99 | |
---|
[657] | 100 | // load buffer from file |
---|
| 101 | nbytes = read( fd , buffer , NPIXELS * NLINES ); |
---|
| 102 | |
---|
| 103 | if( nbytes != NPIXELS * NLINES ) |
---|
[644] | 104 | { |
---|
[657] | 105 | printf("\n[display error] Cannot load image \n" ); |
---|
| 106 | exit( 0 ); |
---|
| 107 | } |
---|
[644] | 108 | |
---|
[657] | 109 | printf("\n[display] load image in buffer %x\n", buffer ); |
---|
[644] | 110 | |
---|
[657] | 111 | // display image |
---|
| 112 | error = fbf_write( buffer , NPIXELS * NLINES , 0 ); |
---|
[644] | 113 | |
---|
[657] | 114 | if( error ) |
---|
| 115 | { |
---|
| 116 | printf("\n[display error] Cannot access frame buffer\n"); |
---|
| 117 | exit( 0 ); |
---|
| 118 | } |
---|
[644] | 119 | |
---|
[657] | 120 | printf("\n[display] display image\n"); |
---|
[644] | 121 | |
---|
| 122 | // close file |
---|
[657] | 123 | close( fd ); |
---|
[644] | 124 | |
---|
| 125 | exit(0); |
---|
[656] | 126 | |
---|
| 127 | return 0; |
---|
[644] | 128 | } |
---|