[commit] r2427 - trunk/user/fbview
dslinux_sonny_jim at dslinux.in-berlin.de
dslinux_sonny_jim at dslinux.in-berlin.de
Mon Aug 10 12:15:23 CEST 2009
Author: dslinux_sonny_jim
Date: Mon Aug 10 12:15:22 2009
New Revision: 2427
Log:
Updating fbview to 1.03 as per http://www.dslinux.org/f0rums/viewtopic.php?p=3802
Modified:
trunk/user/fbview/Makefile
trunk/user/fbview/ds_png.c
trunk/user/fbview/ds_png.h
trunk/user/fbview/fbview.c
trunk/user/fbview/framebuffer.c
trunk/user/fbview/framebuffer.h
trunk/user/fbview/keyboard.c
trunk/user/fbview/keyboard.h
trunk/user/fbview/types.h
Modified: trunk/user/fbview/Makefile
==============================================================================
--- trunk/user/fbview/Makefile (original)
+++ trunk/user/fbview/Makefile Mon Aug 10 12:15:22 2009
@@ -1,28 +1,16 @@
-LIBFLAGS = -lpng -lm -lz
-OBJS = bitmap.o framebuffer.o keyboard.o ds_png.o
+LIBFLAGS = -lpng -lm -lz -ljpeg -lgpm
+TARGET = fbview
all: fbview
-fbview: ${OBJS}
- ${CC} -o fbview ${CFLAGS} ${LDFLAGS} ${OBJS} ${LIBFLAGS} fbview.c
+fbview:
+ ${CC} ${TARGET}.c ${CFLAGS} ${LDFLAGS} ${LIBFLAGS} -o ${TARGET}
install:
cp ${TARGET} /usr/bin/
clean:
- rm -f fbview fbview.gdb ${OBJS}
-
-bitmap.o:
- ${CC} -c -o bitmap.o ${CFLAGS} ${LDFLAGS} bitmap.c
-
-ds_png.o:
- ${CC} -c -o ds_png.o ${CFLAGS} ${LDFLAGS} ds_png.c
-
-framebuffer.o:
- ${CC} -c -o framebuffer.o ${CFLAGS} ${LDFLAGS} framebuffer.c
-
-keyboard.o:
- ${CC} -c -o keyboard.o ${CFLAGS} ${LDFLAGS} keyboard.c
+ rm -f ${TARGET} ${TARGET}.gdb
romfs:
$(ROMFSINST) fbview /usr/bin
Modified: trunk/user/fbview/ds_png.c
==============================================================================
--- trunk/user/fbview/ds_png.c (original)
+++ trunk/user/fbview/ds_png.c Mon Aug 10 12:15:22 2009
@@ -1,12 +1,25 @@
+/*
+ * (C) Copyright 2008-2009 Kamil Kopec <kamil_kopec at poczta.onet.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
#include <stdio.h>
#include <malloc.h>
#include <png.h>
#include "ds_png.h"
-#include "framebuffer.h"
-#include "keyboard.h"
-
/* Read a PNG file. You may want to return an error code if the read
* fails (depending upon the failure). There are two "prototypes" given
@@ -15,225 +28,119 @@
* some or all of the magic bytes read - see comments above).
*/
-unsigned int width;
-unsigned int height;
-
-unsigned int png_position_x;
-unsigned int png_position_y;
-
-fb_pixel * png_load(char *file_name) /* We need to open the file */
+/**
+ * load png file to fb_pixmap
+ * @param filename name of bmp file on the disk to load
+ * @param fb_pixmap pointer to the memory for pixmap
+ * @param w width of loaded image
+ * @param h height of loaded image
+ * @return 0 if success, 1 if failure.
+ */
+int png2fb_pixmap(char * filename, fb_pixel ** fb_pixmap, Uint16 * w, Uint16 * h) /* We need to open the file */
{
- fb_pixel * bmp_buffer;
- fb_pixel ** pixel;
- unsigned short i,j;
-
- png_structp png_ptr;
- png_infop info_ptr;
- unsigned int sig_read = 0;
- int bit_depth, color_type, interlace_type;
- FILE *fp;
-
- if ((fp = fopen(file_name, "rb")) == NULL)
- return NULL;
-
- /* Create and initialize the png_struct with the desired error handler
- * functions. If you want to use the default stderr and longjump method,
- * you can supply NULL for the last three parameters. We also supply the
- * the compiler header file version, so that we know if the application
- * was compiled with a compatible version of the library. REQUIRED
- */
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-
- if (png_ptr == NULL)
- {
- fclose(fp);
- return NULL;
- }
-
- /* Allocate/initialize the memory for image information. REQUIRED. */
- info_ptr = png_create_info_struct(png_ptr);
- if (info_ptr == NULL)
- {
- fclose(fp);
- png_destroy_read_struct(&png_ptr, NULL, NULL);
- return NULL;
- }
-
- /* Set error handling if you are using the setjmp/longjmp method (this is
- * the normal method of doing things with libpng). REQUIRED unless you
- * set up your own error handlers in the png_create_read_struct() earlier.
- */
-
- if (setjmp(png_jmpbuf(png_ptr)))
- {
- /* Free all of the memory associated with the png_ptr and info_ptr */
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
- fclose(fp);
- /* If we get here, we had a problem reading the file */
- return NULL;
- }
-
- /* One of the following I/O initialization methods is REQUIRED */
- /* Set up the input control if you are using standard C streams */
- png_init_io(png_ptr, fp);
-
-
- /* If we have already read some of the signature */
- png_set_sig_bytes(png_ptr, sig_read);
-
- /*
- * If you have enough memory to read in the entire image at once,
- * and you need to specify only transforms that can be controlled
- * with one of the PNG_TRANSFORM_* bits (this presently excludes
- * dithering, filling, setting background, and doing gamma
- * adjustment), then you can read the entire image (including
- * pixels) into the info structure with this call:
- */
- png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_STRIP_16, NULL);
-
- /* At this point you have read the entire image */
-
-
-/*After you have called png_read_png(), you can retrieve the image data with
-
- row_pointers = png_get_rows(png_ptr, info_ptr);
-
-where row_pointers is an array of pointers to the pixel data for each row:
-
- png_bytep row_pointers[height];
-
-If you know your image size and pixel size ahead of time, you can allocate row_pointers prior to calling png_read_png() with
-
- row_pointers = png_malloc(png_ptr,
- height*sizeof(png_bytep));
- for (int i=0; i<height, i++)
- row_pointers[i]=png_malloc(png_ptr,
- width*pixel_size);
- png_set_rows(png_ptr, info_ptr, &row_pointers);
-
-Alternatively you could allocate your image in one big block and define row_pointers[i] to point into the proper places in your block.
-
-If you use png_set_rows(), the application is responsible for freeing row_pointers (and row_pointers[i], if they were separately allocated).
-
-If you don't allocate row_pointers ahead of time, png_read_png() will do it, and it'll be free'ed when you call png_destroy_*().*/
-
- width = info_ptr->width;
- height = info_ptr->height;
- png_position_x = 0;
- png_position_y = 0;
-
- bmp_buffer = (fb_pixel*)malloc(width * height * pixelsize);
- if (bmp_buffer == NULL)
- {
- // error while allocating memory
- fclose(fp);
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
- return NULL;
- }
-
- pixel = png_get_rows(png_ptr, info_ptr);
-
- for (j = 0; j < height; j++)
- {
- for (i = 0; i < width; i++) {
- fb_setpixel(bmp_buffer+((i+j*width)*pixelsize), *((*pixel)+i*3+0), *((*pixel)+i*3+1), *((*pixel)+i*3+2));
+ /* Memory to place the raw image data */
+ fb_pixel ** pixel;
+ unsigned short i,j;
+
+ /* png file headers */
+ png_structp png_ptr;
+ png_infop info_ptr;
+
+ unsigned int sig_read = 0;
+ FILE *fp;
+
+ /* Opening the image file */
+ if ((fp = fopen(filename, "rb")) == NULL) return 1;
+
+ /* Create and initialize the png_struct with the desired error handler
+ * functions. If you want to use the default stderr and longjump method,
+ * you can supply NULL for the last three parameters. We also supply the
+ * the compiler header file version, so that we know if the application
+ * was compiled with a compatible version of the library. REQUIRED
+ */
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+
+ /* if image file is corrupt, return an error */
+ if (png_ptr == NULL) {
+ fclose(fp);
+ return -1;
}
- pixel++;
- }
-
- /* clean up after the read, and free any memory allocated - REQUIRED */
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
-
- /* close the file */
- fclose(fp);
-
- /* that's it */
- return bmp_buffer;
-}
-
-
-
-void png_render(fb_pixel * bmp_buffer)
-{
- Uint32 j;
- Uint32 copy_mem_size;
- Uint32 bmp_line_size;
- Uint32 fb_line_size;
- Uint16 max_j;
-
- fb_pixel * tmp_screen;
- fb_pixel * tmp_bmp;
-
- bmp_line_size = width*pixelsize;
- fb_line_size = fb_xres*pixelsize;
- tmp_bmp = bmp_buffer + png_position_y*bmp_line_size + png_position_x*pixelsize - bmp_line_size;
- tmp_screen = screen - fb_line_size;
- copy_mem_size = (fb_xres > width ? bmp_line_size : fb_line_size);
- max_j = (fb_yres > height ? height : fb_yres);
-
- for(j = 0; j < max_j ;j++)
- memcpy(tmp_screen+=fb_line_size, tmp_bmp+=bmp_line_size, copy_mem_size);
-}
-
-
-
-/*
-void png_free(fb_pixel * bmp_buffer)
-{
- if (bmp_buffer) free(bmp_buffer);
-}
-*/
-
-
-
-int png_play(char * filename)
-{
- char ch;
-
- if (fb_init())
- {
- printf ("Unable to init framebuffer device\n");
- return 2;
- }
-
- fb_pixel * bmp_buffer;
-
- if ((bmp_buffer = png_load(filename)) == NULL)
- {
- fb_uninit();
- printf ("Error while reading png file\n");
- return 1;
- }
-
- fb_clear_screen(screen);
-
- png_render(bmp_buffer);
-
- init_keyboard();
+
+ /* Allocate/initialize the memory for image information. REQUIRED. */
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL) {
+ fclose(fp);
+ png_destroy_read_struct(&png_ptr, NULL, NULL);
+ return 1;
+ }
+
+ /* Set error handling if you are using the setjmp/longjmp method (this is
+ * the normal method of doing things with libpng). REQUIRED unless you
+ * set up your own error handlers in the png_create_read_struct() earlier.
+ */
+ if (setjmp(png_jmpbuf(png_ptr))) {
+
+ /* Free all of the memory associated with the png_ptr and info_ptr */
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+ fclose(fp);
- ch=0;
- while (1)
- {
- if (!kbhit())
+ /* If we get here, we had a problem reading the file */
+ return -1;
+ }
+
+ /* One of the following I/O initialization methods is REQUIRED
+ * Set up the input control if you are using standard C streams */
+ png_init_io(png_ptr, fp);
+
+ /* If we have already read some of the signature */
+ png_set_sig_bytes(png_ptr, sig_read);
+
+ /* If you have enough memory to read in the entire image at once,
+ * and you need to specify only transforms that can be controlled
+ * with one of the PNG_TRANSFORM_* bits (this presently excludes
+ * dithering, filling, setting background, and doing gamma
+ * adjustment), then you can read the entire image (including
+ * pixels) into the info structure with this call:
+ */
+ png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_STRIP_16, NULL);
+
+ /* At this point you have read the entire image */
+
+ /* save width and height of image in the variables given by parameter */
+ *w = info_ptr->width;
+ *h = info_ptr->height;
+
+ /* Allocate memory for the image */
+ *fb_pixmap = (fb_pixel*)malloc((*w) * (*h) * pixelsize);
+ if ((*fb_pixmap)==NULL)
{
- ch = readch();
- if (ch == KEY_ESC) break;
- if (ch == KEY_UP && png_position_y >= JUMP_SIZE) png_position_y-=JUMP_SIZE;
- if (ch == KEY_DOWN && fb_yres <= (height-png_position_y-JUMP_SIZE)) png_position_y+=JUMP_SIZE;
- if (ch == KEY_LEFT && png_position_x >= JUMP_SIZE) png_position_x-=JUMP_SIZE;
- if (ch == KEY_RIGHT && fb_xres <= (width-png_position_x-JUMP_SIZE)) png_position_x+=JUMP_SIZE;
- ch = 0;
- png_render(bmp_buffer);
+ /* error while allocating memory */
+ fclose(fp);
+ return -1;
}
- }
-
- close_keyboard();
-
- fflush(stdin);
-
- fb_clear_screen(screen);
+
+ /* pixel is an array of pointers to the pixel data for each row: */
+ pixel = png_get_rows(png_ptr, info_ptr);
+
+ /* Here we are reading pixel variable, and translate it into fb_pixmap.
+ * The simplest way is to use for loop.
+ */
+ for (j = 0; j < (*h); j++)
+ {
+ for (i = 0; i < (*w); i++)
+ fb_set_pixel((*fb_pixmap)+((i+j*(*w))*pixelsize), *((*pixel)+i*3+0), *((*pixel)+i*3+1), *((*pixel)+i*3+2));
- if (bmp_buffer) free(bmp_buffer);//png_free(bmp_buffer);
- fb_uninit();
- return 0;
+ /* Go to next row */
+ pixel++;
+ }
+
+ /* clean up after the read, and free any memory allocated - REQUIRED */
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+
+ /* close the file */
+ fclose(fp);
+
+ /* that's it */
+ return 0;
}
+
Modified: trunk/user/fbview/ds_png.h
==============================================================================
--- trunk/user/fbview/ds_png.h (original)
+++ trunk/user/fbview/ds_png.h Mon Aug 10 12:15:22 2009
@@ -1,10 +1,35 @@
+/*
+ * (C) Copyright 2008-2009 Kamil Kopec <kamil_kopec at poczta.onet.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
#ifndef ds_pdf_h
#define ds_pdf_h
+#include "framebuffer.h"
+#define PNG_SUPPORT
-
-extern int png_play(char * filename);
-
+/**
+ * load png file to fb_pixmap
+ * @param filename name of bmp file on the disk to load
+ * @param fb_pixmap pointer to the memory for pixmap
+ * @param w width of loaded image
+ * @param h height of loaded image
+ * @return 0 if success, 1 if failure.
+ */
+extern int png2fb_pixmap(char * filename, fb_pixel ** fb_pixmap, Uint16 * w, Uint16 * h);
#endif
Modified: trunk/user/fbview/fbview.c
==============================================================================
--- trunk/user/fbview/fbview.c (original)
+++ trunk/user/fbview/fbview.c Mon Aug 10 12:15:22 2009
@@ -1,67 +1,375 @@
+/*
+ * (C) Copyright 2008-2009 Kamil Kopec <kamil_kopec at poczta.onet.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#define USE_GPM
+
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+/* gpm support */
+#ifdef USE_GPM
+#include "ds_gpm.h"
+#include "ds_gpm.c"
+#endif
+
+/* header, that specifies variable sizes */
+#include "types.h"
-#include "bitmap.h" // bitmap codec
+/* framebuffer support */
+#include "framebuffer.h"
+
+/* pictures manipulating functions */
+#include "pixmap.h"
+
+/* keyboard support */
+#include "keyboard.h"
+
+/* bitmap codec */
+#include "ds_bmp.h"
+
+/* png file codec */
#include "ds_png.h"
-#define PNG_SUPPORT
+/* jpeg file codec */
+#include "ds_jpeg.h"
-char extension[255]; // uppercased file extension; f.e. "BMP"
-char filename[255]; // multimedia file name; f.e. "image.bmp"
-int (*play_function)(char *); // pointer to codec function
+/* i don't know why this programs has seg-faults on arm,
+ * when not compiled as a one huge file? weird...
+ * On my home pc everything works perfect,
+ * and on mobile device not. :-(
+ */
+#include "framebuffer.c"
+#include "pixmap.c"
+#include "keyboard.c"
+#include "ds_bmp.c"
+#include "ds_png.c"
+#include "ds_jpeg.c"
+
+#define JUMP_SIZE 2
+
+/** multimedia file name; f.e. "image.bmp" */
+char * filename = NULL;
+
+/** if != NULL then dumping bmp file there */
+char * dump_filename = NULL;
+
+/** pointer to codec function */
+int (*image_codec)(char *, fb_pixel **, Uint16 *, Uint16 *);
+
+/** bool for quiet mode (not viewing image) */
+unsigned char quiet = 0;
+
+/** scale value, 1.00 by default */
+float scale = 1.00;
+
+/** rotation value, allowed only 90 * x */
+Sint16 rotate = 0;
+
+/** bool for autoscalling mode - fit to screen size */
+char autoscale = 0;
+
+/** no gpm mode, if gpm library not included, then leave it */
+#ifdef GPM_SUPPORT
+char no_gpm = 0;
+#else
+char no_gpm = 1;
+#endif
-// functions decodes parameters
-// set config variables, filename and extension
+/**
+ * functions decodes parameters
+ * set config variables, filename and extension, and so on.
+ * @return 0 if parameters are correct, 1 if not.
+ */
int decode_params(int argc, char ** argv)
{
char * ext_start;
+ char * extension;
char i;
- if (argc < 2) return 1;
- strcpy(filename, argv[1]);
+ for (i = 1; i < argc; i++) {
+
+ if (!strcmp(*(argv+i), "--help") || !strcmp(*(argv+i), "-help") || !strcmp(*(argv+i), "-h") || !strcmp(*(argv+i), "--h")) {
+ printf ("fbview [-s float][-a][-r int][-d file][-m] file\n\n\
+Parameters: \n\
+-s --scale float bitmap scale; 0.01 <= scale <= 10.00\n\
+-a --autoscale fit size of bitmap to screen size\n\
+-r --rotate integer rotate; rotate = {0, 90, 180, 270}\n\
+-d --dump filename dump buffer to bmp file\n\
+-q --quiet quiet mode\n\
+-m --no-gpm disable gpm support\n\
+\n\
+While viewing image use arrows or A, S, D, W buttons\n\
+for scrolling and ESC button for quit\n\
+\n\
+You may change colour depth; use command:\n\
+fbset -depth 16 -n\n\n");
+
+return 1;
+
+ } else
+
+ if (!strcmp(*(argv+i), "--scale") || !strcmp(*(argv+i), "-s")) {
+ if (argc <= i+1) {
+ printf ("Bad parameter. After --scale option must follow float value.\n");
+ return 1;
+ }
+
+ scale = atof(*(argv+(++i)));
+ if (scale < 0.01 || scale > 10.00) {
+ printf ("Scale value sholud be 0.01 <= scale <= 10.00\n");
+ return 1;
+ }
+ } else
+
+ if (!strcmp(*(argv+i), "--autoscale") || !strcmp(*(argv+i), "-a")) {
+ autoscale = 1;
+ } else
+
+ if (!strcmp(*(argv+i), "--rotate") || !strcmp(*(argv+i), "-r")) {
+ if (argc <= i+1) {
+ printf ("Bad parameter. After --rotate option must follow integer value.\n");
+ return 1;
+ }
+
+ rotate = atoi(*(argv+(++i)));
+ if (rotate < 0) rotate = - rotate + 180;
+ rotate %= 360;
+ if (rotate % 90 != 0) {
+ printf ("Only 90*x rotation supported\n");
+ return 1;
+ }
+ } else
+
+ if (!strcmp(*(argv+i), "--dump") || !strcmp(*(argv+i), "-d")) {
+ if (argc <= i+1) {
+ printf ("Bad parameter. After --dump option must follow file name.\n");
+ return 1;
+ }
+
+ dump_filename = (char *)malloc(strlen(*(argv+(++i))) + 1);
+ if (!dump_filename) {
+ printf ("Error with memory allocation.\n");
+ return 1;
+ }
+
+ strcpy (dump_filename, *(argv+i));
+ } else
+
+ if (!strcmp(*(argv+i), "--quiet") || !strcmp(*(argv+i), "-q")) {
+ quiet = 1;
+ no_gpm = 1;
+ } else
+
+ #ifdef GPM_SUPPORT
+ if (!strcmp(*(argv+i), "--no-gpm") || !strcmp(*(argv+i), "-m")) {
+ no_gpm = 1;
+ } else
+ #endif
+
+ {
+ /* any other parameter is source file */
+
+ filename = (char *)malloc(strlen(*(argv+i)) + 1);
+ if (!filename) {
+ printf ("Error with memory allocation.\n");
+ return 1;
+ }
+ strcpy (filename, *(argv+i));
+ }
+ };
+
+ if (!filename) {
+ printf ("No image file given \n");
+ return 1;
+ }
ext_start = strrchr(filename, '.');
- if (!ext_start) return 2;
+ if (ext_start == NULL) {
+ printf ("Image file has no extension\n");
+ return 1;
+ }
+
+ extension = (char *)malloc(strlen(ext_start));
+ if (!extension) {
+ printf ("Error with memory allocation.\n");
+ return 1;
+ }
strcpy(extension, ext_start+1);
- for (i=0; extension[i]; i++)
- extension[i] = toupper(extension[i]);
+ for (i=0; *(extension+i); i++) *(extension+i) = toupper(*(extension+i));
+
+ #ifdef BMP_SUPPORT
+ if (strcmp(extension, "BMP") == 0) {
+ printf ("File decoded as \"Bitmap Image File\".\n\n");
+ image_codec = bmp2fb_pixmap;
+ } else
+ #endif
+ #ifdef PNG_SUPPORT
+ if (strcmp(extension, "PNG") == 0) {
+ printf ("File decoded as \"PNG Image File\".\n\n");
+ image_codec = png2fb_pixmap;
+ } else
+ #endif
+ #ifdef JPEG_SUPPORT
+ if (strcmp(extension, "JPG") == 0 || strcmp(extension, "JPEG") == 0) {
+ printf ("File decoded as \"JPEG Image File\".\n\n");
+ image_codec = jpeg2fb_pixmap;
+ } else
+ #endif
+ image_codec = NULL;
+
+ if (!image_codec) {
+ printf ("Unknown image extension\n");
+ return 1;
+ }
+ free(extension);
return 0;
}
-// --------------------------------------------------------------
+/* -------------------------------------------------------------- */
-int main(int argc, char ** argv)
+/**
+ * function that is running while viewing image.
+ * There is the main loop of the application.
+ * @return always 0.
+ */
+int fb_pixmap_play(fb_pixel * fb_pixmap, Uint16 width, Uint16 height)
{
- printf ("fbview - GNU frame buffer image viewer.\n");
- printf ("Supportet file formats: BMP-24bit, PNG\n");
- printf ("written by galactic, 2008\n\n");
-
- if (decode_params(argc, argv)) {
- return 1;
- }
-
- if (strcmp(extension, "BMP") == 0) {
- printf ("File decoded as \"Bitmap Image File\".\n\n");
- play_function = bitmap_play;
- } else
-
-#ifdef PNG_SUPPORT
- if (strcmp(extension, "PNG") == 0) {
- printf ("File decoded as \"PNG Image File\".\n\n");
- play_function = png_play;
- } else
-#endif
-
- play_function = NULL;
+ char ch;
+ float gpm_x, gpm_y;
+ Uint16 pos_x = 0;
+ Uint16 pos_y = 0;
+
+ fb_clear_screen(screen);
+ fb_pixmap_render(fb_pixmap, width, height, pos_x, pos_y);
+
+ init_keyboard();
+ #ifdef GPM_SUPPORT
+ /* the easiest way to flush mouse input. */
+ if (!no_gpm) gpm_is_moved();
+ #endif
+
+ ch=0;
+ while (1)
+ {
+ if (kbhit())
+ {
+ ch = readch();
+
+ if (ch == DS_KEY_ESC) break;
+ if ((ch == DS_KEY_UP || ch == DS_ARROW_UP) && pos_y >= JUMP_SIZE) pos_y-=JUMP_SIZE;
+ if ((ch == DS_KEY_DOWN || ch == DS_ARROW_DOWN) && fb_yres <= (height - pos_y-JUMP_SIZE)) pos_y+=JUMP_SIZE;
+ if ((ch == DS_KEY_LEFT || ch == DS_ARROW_LEFT) && pos_x >= JUMP_SIZE) pos_x-=JUMP_SIZE;
+ if ((ch == DS_KEY_RIGHT || ch == DS_ARROW_RIGHT) && fb_xres <= (width - pos_x-JUMP_SIZE)) pos_x+=JUMP_SIZE;
+ ch = 0;
+ fb_pixmap_render(fb_pixmap, width, height, pos_x, pos_y);
+ }
+
+ #ifdef GPM_SUPPORT
+ if (!no_gpm && gpm_is_moved()) {
+ gpm_get_position(&gpm_x, &gpm_y);
+ if (height > fb_yres) pos_y = (height - fb_yres) * gpm_y;
+ if (width > fb_xres) pos_x = (width - fb_xres) * gpm_x;
+ fb_pixmap_render(fb_pixmap, width, height, pos_x, pos_y);
+ }
+ #endif
+ }
+
+ close_keyboard();
+ fflush(stdin);
+
+ fb_clear_screen(screen);
+ return 0;
+}
- if (play_function) {
- return ((* play_function)(filename));
- } else {
- printf ("Unknown file extension \"%s\".\n", extension);
- return 3;
- }
+/* -------------------------------------------------------------- */
- return 0;
+int main(int argc, char ** argv)
+{
+ /* image sizes and map of pixels */
+ Uint16 width;
+ Uint16 height;
+ fb_pixel * fb_pixmap = NULL;
+
+ printf ("fbview-1.03 - GPL frame buffer image viewer.\n");
+ printf ("Supportet file formats: BMP-24bit, PNG, JPEG\n");
+ printf ("written by galactic, 2008, 2009\n\n");
+
+ if (decode_params(argc, argv)) {
+ return 1;
+ }
+
+ /* if quiet mode, then there is no need to load framebuffer */
+ if (!quiet && fb_init()) {
+ printf ("Unable to init framebuffer device\n");
+ return 1;
+ }
+
+ #ifdef GPM_SUPPORT
+ if (!no_gpm) {
+ if (gpm_init()) {
+ printf ("Unable to init gpm device. no-gpm mode forced.\n");
+ no_gpm = 1;
+ }
+ }
+ #endif
+
+ /* decode image using suitable codec */
+ if ((* image_codec)(filename, &fb_pixmap, &width, &height)) {
+ printf ("Error while loading image file.\n");
+ if (!quiet) fb_uninit();
+ if (filename) free(filename);
+ if (dump_filename) free(dump_filename);
+ return 1;
+ }
+
+ /* if image is not loaded (=NULL), then show message and exit. */
+ if (fb_pixmap == NULL) {
+ printf ("Image file loaded not correctly.\n");
+ if (!quiet) fb_uninit();
+ if (filename) free(filename);
+ if (dump_filename) free(dump_filename);
+ return 1;
+ }
+
+ /* execute image manipulation functions */
+ if (autoscale) scale = ((float)fb_xres / fb_yres > (float)width / height) ? (float)fb_yres / height : (float)fb_xres / width;
+ if (scale != 1.00) fb_pixmap_scale(&fb_pixmap, &width, &height, scale);
+ if (rotate != 0) fb_pixmap_rotate(&fb_pixmap, &width, &height, rotate);
+ if (dump_filename != NULL) fb_pixmap2bmp(dump_filename, fb_pixmap, width, height);
+
+ /* if not quiet mode, then run viewing */
+ if (!quiet) {
+ fb_pixmap_play(fb_pixmap, width, height);
+
+ #ifdef GPM_SUPPORT
+ if (!no_gpm) gpm_uninit();
+ #endif
+
+ fb_uninit();
+ }
+
+ /* clean the trash */
+ if (filename) free(filename);
+ if (dump_filename) free(dump_filename);
+ free(fb_pixmap);
+
+ return 0;
}
Modified: trunk/user/fbview/framebuffer.c
==============================================================================
--- trunk/user/fbview/framebuffer.c (original)
+++ trunk/user/fbview/framebuffer.c Mon Aug 10 12:15:22 2009
@@ -1,4 +1,19 @@
-//#define debug
+/*
+ * (C) Copyright 2008-2009 Kamil Kopec <kamil_kopec at poczta.onet.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
#include <linux/fb.h>
#include <malloc.h>
@@ -9,33 +24,48 @@
#include <sys/stat.h>
#include <fcntl.h>
-//#ifdef debug
#include <stdio.h>
-//#endif
#include "types.h"
#include "framebuffer.h"
-// we don't use palette for 16-bit mode
-// for 8-bit palette is always 8
-// for 4-bit palette is 2
-// other pals are ridiculus
+/* we don't use palette for 16-bit mode
+ * for 8-bit palette is always 8
+ * for 4-bit palette is 2
+ * other pals are ridiculus */
#define fb_palette_colors (1<<var_info.bits_per_pixel)
+/* variable represents screen memory */
fb_pixel * screen;
+
Uint32 buffer_size;
-Uint32 fb_line_size; // line of fb in bytes
-Uint8 have_cmap = 0; // palette allocated?
-Uint16 fb_xres, fb_yres; // screen resolution
+/* line of fb in bytes */
+Uint32 fb_line_size;
+
+/* palette allocated? */
+Uint8 have_cmap = 0;
+
+/* screen resolution */
+Uint16 fb_xres, fb_yres;
+/** framebuffer device descriptor */
Sint32 fb_dev;
+
+/** struct with framebuffer informations */
struct fb_var_screeninfo var_info;
+
+/** more framebuffer informations */
struct fb_fix_screeninfo fb_info;
-Uint8 pixelsize;
+
+/** pixelsize by default is 2 */
+Uint8 pixelsize = 2;
+
+/** old palette of framebuffer */
struct palette old_palette;
-struct palette global_pal;
+/** palette, that our application will use */
+struct palette global_pal;
struct palette
{
@@ -44,6 +74,10 @@
unsigned short *blue;
};
+
+/**
+ * Allocates memory for the palette.
+ */
void alloc_palette(struct palette *pal)
{
pal->red=malloc(sizeof(unsigned short)*fb_palette_colors);
@@ -55,7 +89,9 @@
}
}
-
+/**
+ * Clears memory allocated for palette.
+ */
void free_palette(struct palette *pal)
{
free(pal->red);
@@ -63,7 +99,9 @@
free(pal->blue);
}
-
+/**
+ * Sets current palette to one given by parameter.
+ */
void set_palette(struct palette *pal)
{
struct fb_cmap cmap;
@@ -106,7 +144,9 @@
free(r);free(g);free(b);free(t);
}
-
+/**
+ * Returns current allocated palette.
+ */
void get_palette(struct palette *pal)
{
struct fb_cmap cmap;
@@ -154,6 +194,9 @@
* 255 085 255
* 036 036 084
*/
+/**
+ * Tries to generate the best palette for the current framebuffer mode.
+ */
static void generate_palette(struct palette *palette)
{
int a;
@@ -207,20 +250,30 @@
/* stuff it in both high and low byte */
}
}
-}
+};
+/**
+ * function causes that textcursor doesn't blink.
+ */
inline void fb_hide_cursor(void)
{
printf("\033[10000B\033[10000C\033[?25l");
fflush(stdout);
-}
+};
+/**
+ * function causes that textcursor starts to blink.
+ */
inline void fb_show_cursor(void)
{
printf("\033[10000D\033[?25h");
fflush(stdout);
-}
+};
+
+/*
+Function uses for debugging.
+gives info about framebuffer state.
void fb_dump_info()
{
printf ("xres: %d\n", var_info.xres);
@@ -232,15 +285,22 @@
printf ("bits_per_pixel: %d\n", var_info.bits_per_pixel);
printf ("grayscale: %d\n", var_info.grayscale);
};
+*/
+/**
+ * Initializes the framebuffer.
+ * @return 0 if success, 1 if failure
+ */
int fb_init()
{
+ /* opening device file */
if (!(fb_dev = open("/dev/fb0", O_RDWR)))
{
printf ("Unable to read framebuffer device: /dev/fb0\n");
return 1;
};
+ /* reading screen informations */
if (ioctl (fb_dev, FBIOGET_VSCREENINFO, &var_info))
{
printf ("Unable to read screen info.\n");
@@ -259,9 +319,7 @@
*/
var_info.xoffset = 0;
var_info.yoffset = 0;
-// var_info.bits_per_pixel = 32;
-// var_info.yres_virtual = var_info.yres * 2;
-// if (ioctl (fb_dev, FBIOPAN_DISPLAY, &var_info))
+
if (ioctl (fb_dev, FBIOPUT_VSCREENINFO, &var_info))
{
printf ("Unable to change screen data\n");
@@ -290,7 +348,10 @@
return 3;
};
+ /* buffer_size = sizeof(screen) */
buffer_size = var_info.xres * var_info.yres * var_info.bits_per_pixel / 8;
+
+ /* mmap screen for framebuffer device */
if (!(screen = (Uint8 *) mmap (NULL, buffer_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb_dev, 0)))
{
printf ("Unable to map shared memory\n");
@@ -299,8 +360,8 @@
return 4;
};
- // do we need to allocate new palette?
- if (/*fb_info.visual==FB_VISUAL_PSEUDOCOLOR && */var_info.bits_per_pixel < 1<<24)
+ /* do we need to allocate new palette? */
+ if (var_info.bits_per_pixel < 1<<24)
{
have_cmap=1;
alloc_palette(&old_palette);
@@ -311,51 +372,100 @@
set_palette(&global_pal);
}
+ /* store resolutions data */
fb_xres = var_info.xres;
fb_yres = var_info.yres;
fb_line_size = var_info.xres * pixelsize;
- #ifdef debug
- fb_dump_info();
- #else
+ /* hide console cursor */
fb_hide_cursor();
- #endif
return 0;
}
+/**
+ * Uninitializes the framebuffer
+ * @return always 0
+ */
int fb_uninit()
{
+ /* unmmap screen of framebuffer device */
munmap(screen, buffer_size);
- if (have_cmap)
- {
+
+ /* have we changed the palette? */
+ if (have_cmap) {
+ /* if yes then restore the old one */
set_palette(&old_palette);
free_palette(&old_palette);
free_palette(&global_pal);
}
close(fb_dev);
- #ifndef debug
+ /* show console cursor */
fb_show_cursor();
- #endif
return 0;
}
+/**
+ * Set black colour to all pixels of the screen.
+ * @param screen pointer to pixmap with width and height same as screen.
+ * Usually is it variable screen.
+ */
void fb_clear_screen(fb_pixel * screen)
{
memset(screen, 0, buffer_size/*fb_xres*fb_yres*pixelsize*/);
}
-inline void fb_setpixel(fb_pixel * dest, Uint8 R, Uint8 G, Uint8 B)
+/**
+ * Paints a part of image on the screen. Id image is smaller than screen, function paints entire image.
+ * @param fb_pixel pixmap of image to paint on the screen
+ * @param width width od image
+ * @param height height of image
+ * @param pos_x position of the image to paint. Pixel pointed by pos_x will be drawn in the top, left corner.
+ * @param pos_y position of the image to paint. Pixel pointed by pos_y will be drawn in the top, left corner.
+ */
+void fb_pixmap_render(fb_pixel * fb_pixmap, Uint16 width , Uint16 height, Uint16 pos_x, Uint16 pos_y)
+{
+ /* This function is invoked many, many times,
+ * so it is written as fast, as it was possible
+ */
+ Uint32 j;
+ Uint32 copy_mem_size;
+ Uint32 bmp_line_size;
+ Uint32 fb_line_size;
+ Uint16 max_j;
+
+ fb_pixel * tmp_screen;
+ fb_pixel * tmp_bmp;
+
+ bmp_line_size = width*pixelsize;
+ fb_line_size = fb_xres*pixelsize;
+ tmp_bmp = fb_pixmap + pos_y*bmp_line_size + pos_x*pixelsize - bmp_line_size;
+ tmp_screen = screen - fb_line_size;
+ copy_mem_size = (fb_xres > width ? bmp_line_size : fb_line_size);
+ max_j = (fb_yres > height ? height : fb_yres);
+
+ for(j = 0; j < max_j ;j++)
+ memcpy(tmp_screen+=fb_line_size, tmp_bmp+=bmp_line_size, copy_mem_size);
+}
+
+/**
+ * Sets colour of pixel on the pixmap.
+ * @param dest memory adress of pixel
+ * @param R red value [0; 255];
+ * @param G green value [0; 255];
+ * @param B blue value [0; 255];
+ */
+inline void fb_set_pixel(fb_pixel * dest, Uint8 R, Uint8 G, Uint8 B)
{
switch (pixelsize) {
case 1:
*(dest) = 0xe0 & R | 0x1c & (G>>3) | 0x03 & (B>>6);
break;
case 2:
- *(dest+1) = 0x80 | 0xec & (B>>1) | 0x03 & (G>>6);
- *(dest) = 0xe0 & (G<<2) | 0x1F & (R>>3);
+ *(dest+1) = 0x80 | 0x7c & (B>>1) | 0x03 & (G>>6);
+ *(dest) = 0xe0 & (G<<2) | 0x1f & (R>>3);
break;
case 3: case 4:
*(dest) = B;
@@ -363,3 +473,30 @@
*(dest+2) = R;
};
}
+
+/**
+ * Reads colour of pixel and saves it to RGB variables.
+ * @param dest memory adress of pixel
+ * @param R red value [0; 255];
+ * @param G green value [0; 255];
+ * @param B blue value [0; 255];
+ */
+inline void fb_get_pixel(fb_pixel * dest, Uint8 * R, Uint8 * G, Uint8 * B)
+{
+ switch (pixelsize) {
+ case 1:
+ *R = *(dest) & 0xe0;
+ *G = (*(dest) & 0x1c) << 3;
+ *B = (*(dest) & 0x03) << 6;
+ break;
+ case 2:
+ *R = ((*dest) & 0x1f) << 3;
+ *G = (((*(dest+1)) & 0x03) << 6) | (((*dest) & 0xe0) >> 2);
+ *B = ((*(dest+1)) & 0x7c) << 1;
+ break;
+ case 3: case 4:
+ *B = *(dest);
+ *G = *(dest+1);
+ *R = *(dest+2);
+ };
+}
Modified: trunk/user/fbview/framebuffer.h
==============================================================================
--- trunk/user/fbview/framebuffer.h (original)
+++ trunk/user/fbview/framebuffer.h Mon Aug 10 12:15:22 2009
@@ -1,30 +1,94 @@
+/*
+ * (C) Copyright 2008-2009 Kamil Kopec <kamil_kopec at poczta.onet.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
#ifndef ds_framebuffer_h
#define ds_framebuffer_h
#include "types.h"
-// 4MB memery limit
+/* 4MB memery limit */
#define MEMSIZE (1024*1024*4)
-// byte per pixel for FrameBuffer device
+/* byte per pixel for framebuffer device */
#define FB_BPP (sizeof(fb_pixel)*8)
-#pragma pack(push)
-#pragma pack(1)
-
-#pragma pack(pop)
-
+/** Type of data represents pixels in framebuffer device. */
typedef Uint8 fb_pixel;
+/** Pixmap of screen. Every change of this variable will be imediatly seen by user */
extern fb_pixel * screen;
+
+/** Pixel size in bytes. Usually it is 1 or 2 */
extern Uint8 pixelsize;
+
+/** Memory size of one row. This is fb_xres * pixelsize */
extern Uint32 fb_line_size;
+
+/** Resolution of screen, in X axis */
extern Uint16 fb_xres;
+
+/** Resolution of screen, in Y axis */
extern Uint16 fb_yres;
+/**
+ * Initializes the framebuffer.
+ * @return 0 if success, 1 if failure
+ */
extern int fb_init();
+
+/**
+ * Uninitializes the framebuffer
+ * @return always 0
+ */
extern int fb_uninit();
-extern void fb_setpixel(fb_pixel * dest, Uint8 R, Uint8 G, Uint8 B);
+
+/**
+ * Set black colour to all pixels of the screen.
+ * @param screen pointer to pixmap with width and height same as screen.
+ * Usually is it variable screen.
+ */
extern void fb_clear_screen(fb_pixel * screen);
+/**
+ * Paints a part of image on the screen. Id image is smaller than screen, function paints entire image.
+ * @param fb_pixel pixmap of image to paint on the screen
+ * @param width width od image
+ * @param height height of image
+ * @param pos_x position of the image to paint. Pixel pointed by pos_x will be drawn in the top, left corner.
+ * @param pos_y position of the image to paint. Pixel pointed by pos_y will be drawn in the top, left corner.
+ */
+extern void fb_pixmap_render(fb_pixel * fb_pixmap, Uint16 width , Uint16 height, Uint16 pos_x, Uint16 pos_y);
+
+/**
+ * Sets colour of pixel on the pixmap.
+ * @param dest memory adress of pixel
+ * @param R red value [0; 255];
+ * @param G green value [0; 255];
+ * @param B blue value [0; 255];
+ */
+extern inline void fb_set_pixel(fb_pixel * dest, Uint8 R, Uint8 G, Uint8 B);
+
+/**
+ * Reads colour of pixel and saves it to RGB variables.
+ * @param dest memory adress of pixel
+ * @param R red value [0; 255];
+ * @param G green value [0; 255];
+ * @param B blue value [0; 255];
+ */
+extern inline void fb_get_pixel(fb_pixel * dest, Uint8 * R, Uint8 * G, Uint8 * B);
+
#endif
Modified: trunk/user/fbview/keyboard.c
==============================================================================
--- trunk/user/fbview/keyboard.c (original)
+++ trunk/user/fbview/keyboard.c Mon Aug 10 12:15:22 2009
@@ -1,58 +1,81 @@
+/*
+ * (C) Copyright 2008-2009 Kamil Kopec <kamil_kopec at poczta.onet.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
#include <stdio.h>
#include <termios.h>
#include <term.h>
#include <curses.h>
#include <unistd.h>
+/** old and new keyboard setting */
static struct termios initial_settings, new_settings;
-static int peek_character = -1;
+/** read stream buffer for keyboard */
+fd_set kb_rfds;
+
+/** timeval, for select's timeout */
+struct timeval kb_tv = {0};
+
+/**
+ * Initializes keyboard.
+ */
void init_keyboard()
{
- tcgetattr(0,&initial_settings);
- new_settings = initial_settings;
- new_settings.c_lflag &= ~ICANON;
- new_settings.c_lflag &= ~ECHO;
- new_settings.c_lflag &= ~ISIG;
- new_settings.c_cc[VMIN] = 1;
- new_settings.c_cc[VTIME] = 0;
- tcsetattr(0, TCSANOW, &new_settings);
+ tcgetattr(0,&initial_settings);
+ new_settings = initial_settings;
+ new_settings.c_lflag &= ~ICANON;
+ new_settings.c_lflag &= ~ECHO;
+
+ new_settings.c_lflag &= ~ISIG;
+ new_settings.c_cc[VMIN] = 1;
+ new_settings.c_cc[VTIME] = 0;
+
+ tcsetattr(0, TCSANOW, &new_settings);
}
+/**
+ * Uninitializes keyboard.
+ */
void close_keyboard()
{
- tcsetattr(0, TCSANOW, &initial_settings);
+ tcsetattr(0, TCSANOW, &initial_settings);
}
+/**
+ * Checks if user has pressed a button.
+ * @return 0 if not, 1 if he does.
+ */
int kbhit()
{
- char ch;
- int nread;
+ FD_SET (0, &kb_rfds);
- if(peek_character != -1)
- return 1;
- new_settings.c_cc[VMIN]=0;
- tcsetattr(0, TCSANOW, &new_settings);
- nread = read(0,&ch,1);
- new_settings.c_cc[VMIN]=1;
- tcsetattr(0, TCSANOW, &new_settings);
-
- if(nread == 1) {
- peek_character = ch;
- return 1;
- }
- return 0;
+ if (select(1, &kb_rfds, NULL, NULL, &kb_tv) > 0) return 1;
+ else return 0;
}
+/**
+ * Returns the last pressed button by user.
+ * @return Button code, that user has pressed.
+ */
int readch()
{
- char ch;
-
- if(peek_character != -1) {
- ch = peek_character;
- peek_character = -1;
- return ch;
- }
- read(0,&ch,1);
- return ch;
+ char ch[3];
+ int nread;
+
+ nread = read(0, &ch, 3);
+ return (nread == 1 ? ch[0] : ch[2]);
}
Modified: trunk/user/fbview/keyboard.h
==============================================================================
--- trunk/user/fbview/keyboard.h (original)
+++ trunk/user/fbview/keyboard.h Mon Aug 10 12:15:22 2009
@@ -1,19 +1,56 @@
+/*
+ * (C) Copyright 2008-2009 Kamil Kopec <kamil_kopec at poczta.onet.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
#ifndef ds_keyboard_h
#define ds_keyboard_h
#include <stdio.h>
-#define KEY_ESC 27
-#define KEY_UP 'w'
-#define KEY_DOWN 's'
-#define KEY_LEFT 'a'
-#define KEY_RIGHT 'd'
+#define DS_KEY_ESC 27
+#define DS_KEY_UP 119
+#define DS_KEY_DOWN 115
+#define DS_KEY_LEFT 97
+#define DS_KEY_RIGHT 100
-#define JUMP_SIZE 2
+#define DS_ARROW_UP 65
+#define DS_ARROW_DOWN 66
+#define DS_ARROW_LEFT 68
+#define DS_ARROW_RIGHT 67
+/**
+ * Initializes keyboard.
+ */
extern void init_keyboard();
+
+/**
+ * Uninitializes keyboard.
+ */
extern void close_keyboard();
+
+/**
+ * Checks if user has pressed a button.
+ * @return 0 if not, 1 if he does.
+ */
extern int kbhit();
+
+/**
+ * Returns the last pressed button by user.
+ * @return Button code, that user has pressed.
+ */
extern int readch();
#endif
Modified: trunk/user/fbview/types.h
==============================================================================
--- trunk/user/fbview/types.h (original)
+++ trunk/user/fbview/types.h Mon Aug 10 12:15:22 2009
@@ -1,14 +1,35 @@
+/*
+ * (C) Copyright 2008-2009 Kamil Kopec <kamil_kopec at poczta.onet.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
#ifndef ds_types_h
#define ds_types_h
-//#ifdef HAVE_SYS_TYPES_H
+#define HAVE_SYS_TYPES_H
+#define HAVE_CTYPE_H
+
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
-//#endif
+#endif
#ifdef HAVE_CTYPE_H
-//# include <ctype.h>
+# include <ctype.h>
#endif
+/* Types are the same as in SDL library */
typedef int8_t Sint8;
typedef u_int8_t Uint8;
typedef int16_t Sint16;
@@ -26,8 +47,8 @@
} Uint64, Sint64;
#endif
+/* Make sure the types really have the right sizes */
/*
-// Make sure the types really have the right sizes
#if (sizeof(Uint8) != 1) || (sizeof(Sint8) != 1)
#error Precompilation error, please post this bug id:00001 to programmer.
#endif
More information about the dslinux-commit
mailing list