From fb29f601f1d5e4c74af9c0d7f53cdf9b57f2cb85 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 5 Jan 2014 00:02:53 +1000 Subject: Start of GFILE module --- include/gfile/gfile.h | 185 ++++++++++++++++++++++++++++++++++++++++++++++++ include/gfile/options.h | 114 +++++++++++++++++++++++++++++ 2 files changed, 299 insertions(+) create mode 100644 include/gfile/gfile.h create mode 100644 include/gfile/options.h (limited to 'include') diff --git a/include/gfile/gfile.h b/include/gfile/gfile.h new file mode 100644 index 00000000..675342fb --- /dev/null +++ b/include/gfile/gfile.h @@ -0,0 +1,185 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gfile/gfile.h + * @brief GFILE - File IO Routines header file. + * + * @addtogroup GFILE + * + * @brief Module which contains Operating system independent FILEIO + * + * @{ + */ + +#ifndef _GFILE_H +#define _GFILE_H + +#include "gfx.h" + +#if GFX_USE_GMISC || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Type definitions */ +/*===========================================================================*/ + +/** + * @brief A file pointer + */ + +typedef struct GFILE { + const struct GFILEVMT * vmt; + uint16_t flags; + #define GFILEFLG_OPEN 0x0001 + #define GFILEFLG_READ 0x0002 + #define GFILEFLG_WRITE 0x0004 + #define GFILEFLG_APPEND 0x0008 + #define GFILEFLG_CANSEEK 0x0010 + #define GFILEFLG_DELONCLOSE 0x0020 + #define GFILEFLG_FAILONBLOCK 0x0040 + short err; + void * obj; + long int pos; +} GFILE; + +typedef struct GFILEVMT { + const struct GFILEVMT * next; + char prefix; + uint16_t flags; + #define GFSFLG_WRITEABLE 0x0001 + #define GFSFLG_CASESENSITIVE 0x0002 + #define GFSFLG_SEEKABLE 0x0004 + #define GFSFLG_FAST 0x0010 + #define GFSFLG_SMALL 0x0020 + bool_t del(const char *fname); + bool_t exists(const char *fname); + long int filesize(const char *fname); + bool_t ren(const char *oldname, const char *newname); + bool_t open(GFILE *f, const char *fname, const char *mode); + void close(GFILE *f); + int read(GFILE *f, char *buf, int size); + int write(GFILE *f, char *buf, int size); + bool_t setpos(GFILE *f, long int pos); + long int getsize(GFILE *f); + bool_t eof(GFILE *f); +} GFILEVMT; + +typedef void GFILE; + +extern GFILE *gfileStdIn; +extern GFILE *gfileStdErr; +extern GFILE *gfileStdOut; + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +//TODO +//FILE * tmpfile ( void ); // Auto-deleting +//char * tmpnam ( char * str ); +//L_tmpnam - Minimum length for temporary file name +//FILENAME_MAX - Maximum length of file names (constant ) +// FOPEN_MAX - Potential limit of simultaneous open streams (constant ) +// TMP_MAX - Number of temporary files (constant ) +//FILE * freopen ( const char * filename, const char * mode, FILE * stream ); +//setbuf +//setvbuf +//fflush +//fscanf +//scanf +//sscanf +//vscanf +//vsscanf +//fgetc +//fgets +//fputc +//fputs +//getc +//getchar +//puts +//ungetc +//void perror (const char * str); + +//"r" read: Open file for input operations. The file must exist. +//"w" write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file. +//"a" append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek, fsetpos, rewind) are ignored. The file is created if it does not exist. +//"r+" read/update: Open a file for update (both for input and output). The file must exist. +//"w+" write/update: Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file. +//"a+" append/update: Open a file for update (both for input and output) with all output operations writing data at the end of the file. Repositioning operations (fseek, fsetpos, rewind) affects the next input operations, but output operations move the position back to the end of file. The file is created if it does not exist. +//"...b" A binary stream +//"...x" Added to "w" - fail if file exists + + +#ifdef __cplusplus +extern "C" { +#endif + + bool_t gfileExists(const char *fname); + bool_t gfileDelete(const char *fname); + long int gfileGetFilesize(const char *fname); + bool_t gfileRename(const char *oldname, const char *newname); + GFILE *gfileOpen(const char *fname, const char *mode); + void gfileClose(GFILE *f); + size_t gfileRead(GFILE *f, char *buf, size_t len); + size_t gfileWrite(GFILE *f, const char *buf, size_t len); + long int gfileGetPos(GFILE *f); + bool_t gfileSetPos(GFILE *f, long int pos); + long int gfileGetSize(GFILE *f); + + int vfnprintg(GFILE *f, size_t maxlen, const char *fmt, va_list arg); + int fnprintg(GFILE *f, size_t maxlen, const char *fmt, ...); + #define vfprintg(f,m,a) vfnprintg(f,0,m,a) + #define fprintg(f,m,...) fnprintg(f,0,m,...) + #define vprintg(m,a) vfnprintg(gfileStdOut,0,m,a) + #define printg(m,...) fnprintg(gfileStdOut,0,m,...) + + int vsnprintg(char *buf, size_t maxlen, const char *fmt, va_list arg); + int snprintg(char *buf, size_t maxlen, const char *fmt, ...); + #define vsprintg(s,m,a) vsnprintg(s,0,m,a) + #define sprintg(s,m,...) snprintg(s,0,m,...) + + #if GFILE_NEED_STDIO && !defined(GFILE_IMPLEMENTATION) + #define FILE GFILE + #define fopen(n,m) gfileOpen(n,m) + #define fclose(f) gfileClose(f) + size_t fread(void * ptr, size_t size, size_t count, FILE *f); + size_t fwrite(const void * ptr, size_t size, size_t count, FILE *f); + int fseek(FILE *f, size_t offset, int origin); + #define SEEK_SET 0 + #define SEEK_CUR 1 + #define SEEK_END 2 + #define remove(n) (!gfileDelete(n)) + #define rename(o,n) (!gfileRename(o,n)) + #define fflush(f) (0) + #define ftell(f) gfileGetPos(f) + typedef long int fpos_t; + int fgetpos(FILE *f, fpos_t *pos); + #define fsetpos(f, pos) (!gfileSetPos(f, *pos)) + #define rewind(f) gfileSetPos(f, 0); + #define clearerr(f) do {f->err = 0; } while(0) + #define feof(f) (f->flags & GFILEFLG_EOF) + #define ferror(f) (f->err) + + #define vfprintf(f,m,a) vfnprintg(f,0,m,a) + #define fprintf(f,m,...) fnprintg(f,0,m,...) + #define vprintf(m,a) vfnprintg(gfileStdOut,0,m,a) + #define printf(m,...) fnprintg(gfileStdOut,0,m,...) + #define vsnprintf(s,n,m,a) vsnprintg(s,n,m,a) + #define snprintf(s,n,m,...) snprintg(s,n,m,...) + #define vsprintf(s,m,a) vsnprintg(s,0,m,a) + #define sprintf(s,m,...) snprintg(s,0,m,...) + #endif + +#ifdef __cplusplus +} +#endif + +#endif /* GFX_USE_MISC */ + +#endif /* _GMISC_H */ +/** @} */ + diff --git a/include/gfile/options.h b/include/gfile/options.h new file mode 100644 index 00000000..176c6270 --- /dev/null +++ b/include/gfile/options.h @@ -0,0 +1,114 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gfile/options.h + * @brief GFILE - File IO options header file. + * + * @addtogroup GFILE + * @{ + */ + +#ifndef _GFILE_OPTIONS_H +#define _GFILE_OPTIONS_H + +/** + * @name GFILE Functionality to be included + * @{ + */ + /** + * @brief Include printg, fprintg, sprintg etc functions + * @details Defaults to FALSE + */ + #ifndef GFILE_NEED_PRINTG + #define GFILE_NEED_PRINTG FALSE + #endif + /** + * @brief Include scang, fscang, sscang etc functions + * @details Defaults to FALSE + */ + #ifndef GFILE_NEED_SCANG + #define GFILE_NEED_SCANG FALSE + #endif + /** + * @brief Map all the stdio functions to their GFILE equivalent + * @details Defaults to FALSE + * @note This replaces the functions in stdio.h with equivalents + * - Do not include stdio.h as it has different conflicting definitions. + */ + #ifndef GFILE_NEED_STDIO + #define GFILE_NEED_STDIO FALSE + #endif + /** + * @brief Include the ROM file system + * @details Defaults to FALSE + * @note To ensure that you are opening a file on the ROM file system, prefix + * its name with "S|" (the letter 'S', followed by a vertical bar). + * @note This requires a file called romfs_files.h to be included in the + * users project. This file includes all the files converted to .h files + * using the file2c utility using the "-r" flag. + */ + #ifndef GFILE_NEED_ROMFS + #define GFILE_NEED_ROMFS FALSE + #endif + /** + * @brief Include the RAM file system + * @details Defaults to FALSE + * @note To ensure that you are opening a file on the RAM file system, prefix + * its name with "R|" (the letter 'R', followed by a vertical bar). + * @note You must also define GFILE_RAMFS_SIZE with the size of the file system + * to be allocated in RAM. + */ + #ifndef GFILE_NEED_RAMFS + #define GFILE_NEED_RAMFS FALSE + #endif + /** + * @brief Include the FAT file system driver + * @details Defaults to FALSE + * @note To ensure that you are opening a file on the FAT file system, prefix + * its name with "F|" (the letter 'F', followed by a vertical bar). + * @note You must separately include the FATFS library and code. + */ + #ifndef GFILE_NEED_FATFS + #define GFILE_NEED_FATFS FALSE + #endif + /** + * @brief Include the operating system's native file system + * @details Defaults to FALSE + * @note To ensure that you are opening a file on the native file system, prefix + * its name with "N|" (the letter 'N', followed by a vertical bar). + * @note If defined then the gfileStdOut and gfileStdErr handles + * use the operating system equivalent stdio and stderr. + * If it is not defined the gfileStdOut and gfileStdErr io is discarded. + */ + #ifndef GFILE_NEED_NATIVEFS + #define GFILE_NEED_NATIVEFS FALSE + #endif +/** + * @} + * + * @name GFILE Optional Parameters + * @{ + */ + /** + * @brief The maximum number of open files + * @note This count excludes gfileStdIn, gfileStdOut and gfileStdErr + * (if open by default). + */ + #ifndef GFILE_MAX_GFILES + #define GFILE_MAX_GFILES 3 + #endif + /** + * @brief The size in bytes of the RAM file system + */ + #ifndef GFILE_RAMFS_SIZE + #define GFILE_RAMFS_SIZE 0 + #endif +/** @} */ + +#endif /* _GFILE_OPTIONS_H */ +/** @} */ -- cgit v1.2.3 From ca8ca49825c01cc7698c8b363b022b7d35b912cf Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 9 Jan 2014 08:52:26 +1000 Subject: Increase size of gwin flags to 32 bits. --- include/gwin/gwin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/gwin/gwin.h b/include/gwin/gwin.h index e964bc3a..f97919e5 100644 --- a/include/gwin/gwin.h +++ b/include/gwin/gwin.h @@ -42,7 +42,7 @@ typedef struct GWindowObject { coord_t x, y; // @< Screen relative position coord_t width, height; // @< Dimensions of this window color_t color, bgcolor; // @< The current drawing colors - uint16_t flags; // @< Window flags (the meaning is private to the GWIN class) + uint32_t flags; // @< Window flags (the meaning is private to the GWIN class) #if GDISP_NEED_TEXT font_t font; // @< The current font #endif -- cgit v1.2.3 From c5ab2adbf0c14a6d0d4e2245a616d01de4b88214 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 24 Jan 2014 19:33:28 +1000 Subject: More code for GFile --- include/gfile/gfile.h | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/gfile/gfile.h b/include/gfile/gfile.h index 675342fb..5b49a6b3 100644 --- a/include/gfile/gfile.h +++ b/include/gfile/gfile.h @@ -34,13 +34,17 @@ typedef struct GFILE { const struct GFILEVMT * vmt; uint16_t flags; - #define GFILEFLG_OPEN 0x0001 - #define GFILEFLG_READ 0x0002 - #define GFILEFLG_WRITE 0x0004 - #define GFILEFLG_APPEND 0x0008 - #define GFILEFLG_CANSEEK 0x0010 - #define GFILEFLG_DELONCLOSE 0x0020 - #define GFILEFLG_FAILONBLOCK 0x0040 + #define GFILEFLG_OPEN 0x0001 // File is open + #define GFILEFLG_READ 0x0002 // Read the file + #define GFILEFLG_WRITE 0x0004 // Write the file + #define GFILEFLG_APPEND 0x0008 // Append on each write + #define GFILEFLG_BINARY 0x0010 // Treat as a binary file + #define GFILEFLG_DELONCLOSE 0x0020 // Delete on close + #define GFILEFLG_CANSEEK 0x0040 // Seek operations are valid + #define GFILEFLG_FAILONBLOCK 0x0080 // Fail on a blocking call + #define GFILEFLG_MUSTEXIST 0x0100 // On open file must exist + #define GFILEFLG_MUSTNOTEXIST 0x0200 // On open file must not exist + #define GFILEFLG_TRUNC 0x0400 // On open truncate the file short err; void * obj; long int pos; @@ -48,18 +52,18 @@ typedef struct GFILE { typedef struct GFILEVMT { const struct GFILEVMT * next; - char prefix; - uint16_t flags; + uint8_t flags; #define GFSFLG_WRITEABLE 0x0001 #define GFSFLG_CASESENSITIVE 0x0002 #define GFSFLG_SEEKABLE 0x0004 #define GFSFLG_FAST 0x0010 #define GFSFLG_SMALL 0x0020 + char prefix; bool_t del(const char *fname); bool_t exists(const char *fname); long int filesize(const char *fname); bool_t ren(const char *oldname, const char *newname); - bool_t open(GFILE *f, const char *fname, const char *mode); + bool_t open(GFILE *f, const char *fname); void close(GFILE *f); int read(GFILE *f, char *buf, int size); int write(GFILE *f, char *buf, int size); @@ -104,16 +108,6 @@ extern GFILE *gfileStdOut; //ungetc //void perror (const char * str); -//"r" read: Open file for input operations. The file must exist. -//"w" write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file. -//"a" append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek, fsetpos, rewind) are ignored. The file is created if it does not exist. -//"r+" read/update: Open a file for update (both for input and output). The file must exist. -//"w+" write/update: Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file. -//"a+" append/update: Open a file for update (both for input and output) with all output operations writing data at the end of the file. Repositioning operations (fseek, fsetpos, rewind) affects the next input operations, but output operations move the position back to the end of file. The file is created if it does not exist. -//"...b" A binary stream -//"...x" Added to "w" - fail if file exists - - #ifdef __cplusplus extern "C" { #endif -- cgit v1.2.3 From 5bba108949ed1f97b18f1ea732553da369e8beb0 Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 29 Jan 2014 00:37:16 +1000 Subject: More GFile code --- include/gfile/gfile.h | 70 ++++++++++++++++++++++++++++--------------------- include/gfile/options.h | 47 ++++++++++++++++++++++++++++----- 2 files changed, 81 insertions(+), 36 deletions(-) (limited to 'include') diff --git a/include/gfile/gfile.h b/include/gfile/gfile.h index 5b49a6b3..bc476956 100644 --- a/include/gfile/gfile.h +++ b/include/gfile/gfile.h @@ -45,7 +45,6 @@ typedef struct GFILE { #define GFILEFLG_MUSTEXIST 0x0100 // On open file must exist #define GFILEFLG_MUSTNOTEXIST 0x0200 // On open file must not exist #define GFILEFLG_TRUNC 0x0400 // On open truncate the file - short err; void * obj; long int pos; } GFILE; @@ -58,6 +57,7 @@ typedef struct GFILEVMT { #define GFSFLG_SEEKABLE 0x0004 #define GFSFLG_FAST 0x0010 #define GFSFLG_SMALL 0x0020 + #define GFSFLG_TEXTMODES 0x0040 char prefix; bool_t del(const char *fname); bool_t exists(const char *fname); @@ -66,7 +66,7 @@ typedef struct GFILEVMT { bool_t open(GFILE *f, const char *fname); void close(GFILE *f); int read(GFILE *f, char *buf, int size); - int write(GFILE *f, char *buf, int size); + int write(GFILE *f, const char *buf, int size); bool_t setpos(GFILE *f, long int pos); long int getsize(GFILE *f); bool_t eof(GFILE *f); @@ -112,37 +112,46 @@ extern GFILE *gfileStdOut; extern "C" { #endif - bool_t gfileExists(const char *fname); - bool_t gfileDelete(const char *fname); - long int gfileGetFilesize(const char *fname); - bool_t gfileRename(const char *oldname, const char *newname); - GFILE *gfileOpen(const char *fname, const char *mode); - void gfileClose(GFILE *f); - size_t gfileRead(GFILE *f, char *buf, size_t len); - size_t gfileWrite(GFILE *f, const char *buf, size_t len); + bool_t gfileExists(const char *fname); + bool_t gfileDelete(const char *fname); + long int gfileGetFilesize(const char *fname); + bool_t gfileRename(const char *oldname, const char *newname); + GFILE * gfileOpen(const char *fname, const char *mode); + void gfileClose(GFILE *f); + size_t gfileRead(GFILE *f, char *buf, size_t len); + size_t gfileWrite(GFILE *f, const char *buf, size_t len); long int gfileGetPos(GFILE *f); - bool_t gfileSetPos(GFILE *f, long int pos); + bool_t gfileSetPos(GFILE *f, long int pos); long int gfileGetSize(GFILE *f); + bool_t gfileEOF(GFILE *f); + + #if GFILE_NEED_PRINTG + int vfnprintg(GFILE *f, int maxlen, const char *fmt, va_list arg); + int fnprintg(GFILE *f, int maxlen, const char *fmt, ...); + #define vfprintg(f,m,a) vfnprintg(f,0,m,a) + #define fprintg(f,m,...) fnprintg(f,0,m,...) + #define vprintg(m,a) vfnprintg(gfileStdOut,0,m,a) + #define printg(m,...) fnprintg(gfileStdOut,0,m,...) + + #if GFILE_NEED_STRINGS + int vsnprintg(char *buf, int maxlen, const char *fmt, va_list arg); + int snprintg(char *buf, int maxlen, const char *fmt, ...); + #define vsprintg(s,m,a) vsnprintg(s,0,m,a) + #define sprintg(s,m,...) snprintg(s,0,m,...) + #endif + #endif - int vfnprintg(GFILE *f, size_t maxlen, const char *fmt, va_list arg); - int fnprintg(GFILE *f, size_t maxlen, const char *fmt, ...); - #define vfprintg(f,m,a) vfnprintg(f,0,m,a) - #define fprintg(f,m,...) fnprintg(f,0,m,...) - #define vprintg(m,a) vfnprintg(gfileStdOut,0,m,a) - #define printg(m,...) fnprintg(gfileStdOut,0,m,...) - - int vsnprintg(char *buf, size_t maxlen, const char *fmt, va_list arg); - int snprintg(char *buf, size_t maxlen, const char *fmt, ...); - #define vsprintg(s,m,a) vsnprintg(s,0,m,a) - #define sprintg(s,m,...) snprintg(s,0,m,...) #if GFILE_NEED_STDIO && !defined(GFILE_IMPLEMENTATION) #define FILE GFILE #define fopen(n,m) gfileOpen(n,m) #define fclose(f) gfileClose(f) - size_t fread(void * ptr, size_t size, size_t count, FILE *f); - size_t fwrite(const void * ptr, size_t size, size_t count, FILE *f); - int fseek(FILE *f, size_t offset, int origin); + size_t gstdioRead(void * ptr, size_t size, size_t count, FILE *f); + size_t gstdioWrite(const void * ptr, size_t size, size_t count, FILE *f); + #define fread(p,sz,cnt,f) gstdioRead(p,sz,cnt,f) + #define fwrite(p,sz,cnt,f) gstdioWrite(p,sz,cnt,f) + int gstdioSeek(FILE *f, size_t offset, int origin); + #define fseek(f,ofs,org) gstdioSeek(f,ofs,org) #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 @@ -150,13 +159,14 @@ extern "C" { #define rename(o,n) (!gfileRename(o,n)) #define fflush(f) (0) #define ftell(f) gfileGetPos(f) - typedef long int fpos_t; - int fgetpos(FILE *f, fpos_t *pos); + #define fpos_t long int + int gstdioGetpos(FILE *f, long int *pos); + #define fgetpos(f,pos) gstdioGetpos(f,pos) #define fsetpos(f, pos) (!gfileSetPos(f, *pos)) #define rewind(f) gfileSetPos(f, 0); - #define clearerr(f) do {f->err = 0; } while(0) - #define feof(f) (f->flags & GFILEFLG_EOF) - #define ferror(f) (f->err) + #define clearerr(f) (0) + #define feof(f) gfileEOF(f) + //#define ferror(f) (0) #define vfprintf(f,m,a) vfnprintg(f,0,m,a) #define fprintf(f,m,...) fnprintg(f,0,m,...) diff --git a/include/gfile/options.h b/include/gfile/options.h index 176c6270..a64937f1 100644 --- a/include/gfile/options.h +++ b/include/gfile/options.h @@ -21,12 +21,28 @@ * @{ */ /** - * @brief Include printg, fprintg, sprintg etc functions + * @brief Include printg, fprintg etc functions * @details Defaults to FALSE */ #ifndef GFILE_NEED_PRINTG #define GFILE_NEED_PRINTG FALSE #endif + /** + * @brief Include scang, fscang etc functions + * @details Defaults to FALSE + */ + #ifndef GFILE_NEED_SCANG + #define GFILE_NEED_SCANG FALSE + #endif + /** + * @brief Include the string sprintg/sscang functions + * @details Defaults to FALSE + * @pre To get sprintg functions you also need to define @p GFILE_NEED_PRINTG + * @pre To get sscang functions you also need to define @p GFILE_NEED_SCANG + */ + #ifndef GFILE_NEED_STRINGS + #define GFILE_NEED_STRINGS FALSE + #endif /** * @brief Include scang, fscang, sscang etc functions * @details Defaults to FALSE @@ -35,7 +51,7 @@ #define GFILE_NEED_SCANG FALSE #endif /** - * @brief Map all the stdio functions to their GFILE equivalent + * @brief Map many stdio functions to their GFILE equivalent * @details Defaults to FALSE * @note This replaces the functions in stdio.h with equivalents * - Do not include stdio.h as it has different conflicting definitions. @@ -46,7 +62,8 @@ /** * @brief Include the ROM file system * @details Defaults to FALSE - * @note To ensure that you are opening a file on the ROM file system, prefix + * @note If GFILE_ALLOW_DEVICESPECIFIC is on then you can ensure that you are + * opening a file on the ROM file system by prefixing * its name with "S|" (the letter 'S', followed by a vertical bar). * @note This requires a file called romfs_files.h to be included in the * users project. This file includes all the files converted to .h files @@ -58,7 +75,8 @@ /** * @brief Include the RAM file system * @details Defaults to FALSE - * @note To ensure that you are opening a file on the RAM file system, prefix + * @note If GFILE_ALLOW_DEVICESPECIFIC is on then you can ensure that you are + * opening a file on the RAM file system by prefixing * its name with "R|" (the letter 'R', followed by a vertical bar). * @note You must also define GFILE_RAMFS_SIZE with the size of the file system * to be allocated in RAM. @@ -69,7 +87,8 @@ /** * @brief Include the FAT file system driver * @details Defaults to FALSE - * @note To ensure that you are opening a file on the FAT file system, prefix + * @note If GFILE_ALLOW_DEVICESPECIFIC is on then you can ensure that you are + * opening a file on the FAT file system by prefixing * its name with "F|" (the letter 'F', followed by a vertical bar). * @note You must separately include the FATFS library and code. */ @@ -79,7 +98,8 @@ /** * @brief Include the operating system's native file system * @details Defaults to FALSE - * @note To ensure that you are opening a file on the native file system, prefix + * @note If GFILE_ALLOW_DEVICESPECIFIC is on then you can ensure that you are + * opening a file on the native file system by prefixing * its name with "N|" (the letter 'N', followed by a vertical bar). * @note If defined then the gfileStdOut and gfileStdErr handles * use the operating system equivalent stdio and stderr. @@ -94,6 +114,21 @@ * @name GFILE Optional Parameters * @{ */ + /** + * @brief Add floating point support to printg/scang etc. + */ + #ifndef GFILE_ALLOW_FLOATS + #define GFILE_ALLOW_FLOATS + #endif + /** + * @brief Can the device be specified as part of the file name. + * @note If this is on then a device letter and a vertical bar can be + * prefixed on a file name to specify that it must be on a + * specific device. + */ + #ifndef GFILE_ALLOW_DEVICESPECIFIC + #define GFILE_ALLOW_DEVICESPECIFIC FALSE + #endif /** * @brief The maximum number of open files * @note This count excludes gfileStdIn, gfileStdOut and gfileStdErr -- cgit v1.2.3 From 79d913f16dbaa17520521c645176cdbbffbb746a Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 3 Feb 2014 18:16:22 +1000 Subject: More gFile stuff --- include/gfile/gfile.h | 75 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 30 deletions(-) (limited to 'include') diff --git a/include/gfile/gfile.h b/include/gfile/gfile.h index bc476956..9d171050 100644 --- a/include/gfile/gfile.h +++ b/include/gfile/gfile.h @@ -82,32 +82,6 @@ extern GFILE *gfileStdOut; /* External declarations. */ /*===========================================================================*/ -//TODO -//FILE * tmpfile ( void ); // Auto-deleting -//char * tmpnam ( char * str ); -//L_tmpnam - Minimum length for temporary file name -//FILENAME_MAX - Maximum length of file names (constant ) -// FOPEN_MAX - Potential limit of simultaneous open streams (constant ) -// TMP_MAX - Number of temporary files (constant ) -//FILE * freopen ( const char * filename, const char * mode, FILE * stream ); -//setbuf -//setvbuf -//fflush -//fscanf -//scanf -//sscanf -//vscanf -//vsscanf -//fgetc -//fgets -//fputc -//fputs -//getc -//getchar -//puts -//ungetc -//void perror (const char * str); - #ifdef __cplusplus extern "C" { #endif @@ -136,13 +110,32 @@ extern "C" { #if GFILE_NEED_STRINGS int vsnprintg(char *buf, int maxlen, const char *fmt, va_list arg); int snprintg(char *buf, int maxlen, const char *fmt, ...); - #define vsprintg(s,m,a) vsnprintg(s,0,m,a) - #define sprintg(s,m,...) snprintg(s,0,m,...) + #define vsprintg(s,m,a) vsnprintg(s,0,m,a) + #define sprintg(s,m,...) snprintg(s,0,m,...) #endif #endif + #if GFILE_NEED_SCANG + int vfscang(GFILE *f, const char *fmt, va_list arg); + int fscang(GFILE *f, const char *fmt, ...); + #define vscang(f,a) vfscang(gfileStdIn,f,a) + #define scang(f,...) fscang(gfileStdIn,f,...) + + #if GFILE_NEED_STRINGS + int vsscang(const char *buf, const char *fmt, va_list arg); + int sscang(const char *buf, const char *fmt, ...); + #endif + #endif #if GFILE_NEED_STDIO && !defined(GFILE_IMPLEMENTATION) + #define stdin gfileStdIn + #define stdout gfileStdOut + #define stderr gfileStdErr + #define FILENAME_MAX 256 // Use a relatively small number for an embedded platform + #define L_tmpnam FILENAME_MAX + #define FOPEN_MAX GFILE_MAX_GFILES + #define TMP_MAX GFILE_MAX_GFILES + #define P_tmpdir "/tmp/" #define FILE GFILE #define fopen(n,m) gfileOpen(n,m) #define fclose(f) gfileClose(f) @@ -164,9 +157,7 @@ extern "C" { #define fgetpos(f,pos) gstdioGetpos(f,pos) #define fsetpos(f, pos) (!gfileSetPos(f, *pos)) #define rewind(f) gfileSetPos(f, 0); - #define clearerr(f) (0) #define feof(f) gfileEOF(f) - //#define ferror(f) (0) #define vfprintf(f,m,a) vfnprintg(f,0,m,a) #define fprintf(f,m,...) fnprintg(f,0,m,...) @@ -176,6 +167,30 @@ extern "C" { #define snprintf(s,n,m,...) snprintg(s,n,m,...) #define vsprintf(s,m,a) vsnprintg(s,0,m,a) #define sprintf(s,m,...) snprintg(s,0,m,...) + //TODO + //void clearerr ( FILE * stream ); + //int ferror ( FILE * stream ); + //FILE * tmpfile ( void ); // Auto-deleting + //char * tmpnam ( char * str ); + //char * mktemp (char *template); + //FILE * freopen ( const char * filename, const char * mode, FILE * stream ); + //setbuf + //setvbuf + //fflush + //fscanf + //scanf + //sscanf + //vscanf + //vsscanf + //fgetc + //fgets + //fputc + //fputs + //getc + //getchar + //puts + //ungetc + //void perror (const char * str); #endif #ifdef __cplusplus -- cgit v1.2.3 From 888a5d065640ff601e07bc35710daec2c4e6cc0b Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 5 Feb 2014 08:45:28 +1000 Subject: Update file2c tool to enable creation of directory entries for the ROM file system. --- include/gfile/gfile.h | 5 ----- include/gfile/options.h | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/gfile/gfile.h b/include/gfile/gfile.h index 9d171050..6cd2d9ad 100644 --- a/include/gfile/gfile.h +++ b/include/gfile/gfile.h @@ -177,11 +177,6 @@ extern "C" { //setbuf //setvbuf //fflush - //fscanf - //scanf - //sscanf - //vscanf - //vsscanf //fgetc //fgets //fputc diff --git a/include/gfile/options.h b/include/gfile/options.h index a64937f1..55c37f8e 100644 --- a/include/gfile/options.h +++ b/include/gfile/options.h @@ -65,9 +65,9 @@ * @note If GFILE_ALLOW_DEVICESPECIFIC is on then you can ensure that you are * opening a file on the ROM file system by prefixing * its name with "S|" (the letter 'S', followed by a vertical bar). - * @note This requires a file called romfs_files.h to be included in the - * users project. This file includes all the files converted to .h files - * using the file2c utility using the "-r" flag. + * @note This requires a file called romfs_files.h to be in the + * users project include path. This file should include all the files + * converted to .h files using the file2c utility (using flags "-dbcs"). */ #ifndef GFILE_NEED_ROMFS #define GFILE_NEED_ROMFS FALSE -- cgit v1.2.3 From e72e2705381558ff2347543ed21b853a1168858c Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Feb 2014 01:34:38 +1000 Subject: Add support for GFILEs based on BaseFileStreams and Memory Pointers --- include/gfile/gfile.h | 13 ++++++++++--- include/gfile/options.h | 35 ++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/gfile/gfile.h b/include/gfile/gfile.h index 6cd2d9ad..b615cb8a 100644 --- a/include/gfile/gfile.h +++ b/include/gfile/gfile.h @@ -21,7 +21,7 @@ #include "gfx.h" -#if GFX_USE_GMISC || defined(__DOXYGEN__) +#if GFX_USE_GFILE || defined(__DOXYGEN__) /*===========================================================================*/ /* Type definitions */ @@ -99,6 +99,13 @@ extern "C" { long int gfileGetSize(GFILE *f); bool_t gfileEOF(GFILE *f); + #if GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS + GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode); + #endif + #if GFILE_NEED_MEMFS + GFILE * gfileOpenMemory(void *memptr, const char *mode); + #endif + #if GFILE_NEED_PRINTG int vfnprintg(GFILE *f, int maxlen, const char *fmt, va_list arg); int fnprintg(GFILE *f, int maxlen, const char *fmt, ...); @@ -192,8 +199,8 @@ extern "C" { } #endif -#endif /* GFX_USE_MISC */ +#endif /* GFX_USE_GFILE */ -#endif /* _GMISC_H */ +#endif /* _GFILE_H */ /** @} */ diff --git a/include/gfile/options.h b/include/gfile/options.h index 55c37f8e..d73af02c 100644 --- a/include/gfile/options.h +++ b/include/gfile/options.h @@ -43,13 +43,6 @@ #ifndef GFILE_NEED_STRINGS #define GFILE_NEED_STRINGS FALSE #endif - /** - * @brief Include scang, fscang, sscang etc functions - * @details Defaults to FALSE - */ - #ifndef GFILE_NEED_SCANG - #define GFILE_NEED_SCANG FALSE - #endif /** * @brief Map many stdio functions to their GFILE equivalent * @details Defaults to FALSE @@ -108,6 +101,28 @@ #ifndef GFILE_NEED_NATIVEFS #define GFILE_NEED_NATIVEFS FALSE #endif + /** + * @brief Include ChibiOS BaseFileStream support + * @details Defaults to FALSE + * @pre This is only relevant on the ChibiOS operating system. + * @note Use the @p gfileOpenBaseFileStream() call to open a GFILE based on a + * BaseFileStream. The BaseFileStream must already be open. + * @note A GFile of this type cannot be opened by filename. The BaseFileStream + * must be pre-opened using the operating system. + */ + #ifndef GFILE_NEED_CHIBIOSFS + #define GFILE_NEED_CHIBIOSFS FALSE + #endif + /** + * @brief Include raw memory pointer support + * @details Defaults to FALSE + * @note Use the @p gfileOpenMemory() call to open a GFILE based on a + * memory pointer. The GFILE opened appears to be of unlimited size. + * @note A GFile of this type cannot be opened by filename. + */ + #ifndef GFILE_NEED_MEMFS + #define GFILE_NEED_MEMFS FALSE + #endif /** * @} * @@ -137,12 +152,6 @@ #ifndef GFILE_MAX_GFILES #define GFILE_MAX_GFILES 3 #endif - /** - * @brief The size in bytes of the RAM file system - */ - #ifndef GFILE_RAMFS_SIZE - #define GFILE_RAMFS_SIZE 0 - #endif /** @} */ #endif /* _GFILE_OPTIONS_H */ -- cgit v1.2.3 From d667fab32579fb9208fff2bc78bec8e01ffa753e Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Feb 2014 01:35:31 +1000 Subject: Integrate gfile build files --- include/gfx.h | 12 ++++++++++-- include/gfx_rules.h | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/gfx.h b/include/gfx.h index d261a6ce..f8a5ebc3 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -150,6 +150,13 @@ #ifndef GFX_USE_GMISC #define GFX_USE_GMISC FALSE #endif + /** + * @brief GFX File API + * @details Defaults to FALSE + */ + #ifndef GFX_USE_GFILE + #define GFX_USE_GFILE FALSE + #endif /** @} */ /** @@ -157,6 +164,7 @@ * */ #include "gos/options.h" +#include "gfile/options.h" #include "gmisc/options.h" #include "gqueue/options.h" #include "gevent/options.h" @@ -169,7 +177,7 @@ #include "gaudout/options.h" /** - * Inter-dependancy safety checks on the sub-systems. + * Interdependency safety checks on the sub-systems. * */ #include "gfx_rules.h" @@ -178,6 +186,7 @@ * Include the sub-system header files */ #include "gos/gos.h" +#include "gfile/options.h" #include "gmisc/gmisc.h" #include "gqueue/gqueue.h" #include "gevent/gevent.h" @@ -208,7 +217,6 @@ extern "C" { * @brief The one call to end it all * * @note This will deinitialise each sub-system that has been turned on. - * @note Do not call this without a previous @p gfxInit(); * * @api */ diff --git a/include/gfx_rules.h b/include/gfx_rules.h index a129ef76..817ff749 100644 --- a/include/gfx_rules.h +++ b/include/gfx_rules.h @@ -187,6 +187,15 @@ #undef GDISP_INCLUDE_FONT_UI2 #define GDISP_INCLUDE_FONT_UI2 TRUE #endif + #if GDISP_NEED_IMAGE + #if !GFX_USE_GFILE + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GDISP: GFX_USE_GFILE is required when GDISP_NEED_IMAGE is TRUE. It has been turned on for you." + #endif + #undef GFX_USE_GFILE + #define GFX_USE_GFILE TRUE + #endif + #endif #endif #if GFX_USE_GAUDIN @@ -230,5 +239,8 @@ #if GFX_USE_GMISC #endif +#if GFX_USE_GFILE +#endif + #endif /* _GFX_H */ /** @} */ -- cgit v1.2.3 From 71aeb15d58dc306b3cf5027ca151be40cf5a5890 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Feb 2014 01:36:31 +1000 Subject: Start changing GDISP images to use a simpler API based on GFILE's. --- include/gdisp/image.h | 190 ++++++++++++++++---------------------------------- 1 file changed, 61 insertions(+), 129 deletions(-) (limited to 'include') diff --git a/include/gdisp/image.h b/include/gdisp/image.h index ff2e9d85..f8c5f6a1 100644 --- a/include/gdisp/image.h +++ b/include/gdisp/image.h @@ -40,6 +40,7 @@ typedef uint16_t gdispImageError; #define GDISP_IMAGE_ERR_UNSUPPORTED (GDISP_IMAGE_ERR_UNRECOVERABLE+3) #define GDISP_IMAGE_ERR_UNSUPPORTED_OK 3 #define GDISP_IMAGE_ERR_NOMEMORY (GDISP_IMAGE_ERR_UNRECOVERABLE+4) + #define GDISP_IMAGE_ERR_NOSUCHFILE (GDISP_IMAGE_ERR_UNRECOVERABLE+5) /** * @brief Image flags @@ -116,59 +117,78 @@ typedef struct gdispImage { extern "C" { #endif - /** - * @brief Sets the io fields in the image structure to routines - * that support reading from an image stored in RAM or Flash. - * - * @return TRUE if the IO open function succeeds - * - * @param[in] img The image structure - * @param[in] memimage A pointer to the image in RAM or Flash - * - * @note Always returns TRUE for a Memory Reader - */ - bool_t gdispImageSetMemoryReader(gdispImage *img, const void *memimage); + gdispImageError DEPRECATED("If possible please use gdispImageOpenFile(), gdispImageOpenMemory() or gdispImageOpenBaseFileStream() instead") + gdispImageOpen(gdispImage *img); + bool_t DEPRECATED("Use gdispImageOpenMemory() instead. GFX_USE_GFILE, GFILE_NEED_MEMFS must also be TRUE") gdispImageSetMemoryReader(gdispImage *img, const void *memimage); + #if GFX_USE_OS_CHIBIOS + bool_t DEPRECATED("Use gdispImageOpenBaseFileStream() instead. GFX_USE_GFILE, GFILE_NEED_CHIBIOSFS must also be TRUE") gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr); + #endif + #if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_LINUX || GFX_USE_OS_OSX + bool_t DEPRECATED("Please use gdispImageOpenFile() instead. GFX_USE_GFILE must also be TRUE") + gdispImageSetFileReader(gdispImage *img, const char *filename); + #define gdispImageSetSimulFileReader(img, fname) gdispImageSetFileReader(img, fname) + #endif - #if GFX_USE_OS_CHIBIOS || defined(__DOXYGEN__) + #if GFX_USE_GFILE || defined(__DOXYGEN__) /** - * @brief Sets the io fields in the image structure to routines - * that support reading from an image stored on a BaseFileStream (eg SDCard). + * @brief Open an image in a file and get it ready for drawing + * @details Determine the image format and get ready to decode the first image frame + * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. * - * @return TRUE if the IO open function succeeds + * @pre GFX_USE_GFILE must be TRUE and you must have included the file-system support + * you want to use. * - * @param[in] img The image structure - * @param[in] BaseFileStreamPtr A pointer to the (open) BaseFileStream object. + * @param[in] img The image structure + * @param[in] filename The filename to open * + * @note This determines which decoder to use and then initialises all other fields + * in the gdispImage structure. + * @note The image background color is set to White. + * @note There are three types of return - everything OK, partial success and unrecoverable + * failures. For everything OK it returns GDISP_IMAGE_ERR_OK. A partial success can + * be distinguished from a unrecoverable failure by testing the GDISP_IMAGE_ERR_UNRECOVERABLE + * bit in the error code. + * A partial success return code means an image can still be drawn but perhaps with + * reduced functionality eg only the first page of a multi-page image. + * @note @p gdispImageClose() should be called even after a partial failure in order to + * properly close the file. */ - bool_t gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr); + gdispImageError gdispImageOpenFile(gdispImage *img, const char *filename); #endif - - #if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_LINUX || GFX_USE_OS_OSX || defined(__DOXYGEN__) + + #if GFX_USE_OS_CHIBIOS || defined(__DOXYGEN__) /** - * @brief Sets the io fields in the image structure to routines - * that support reading from an image stored in Win32 simulators native - * file system. - * @pre Only available on the Win32 simulator + * @brief Open an image in a ChibiOS basefilestream and get it ready for drawing + * @details Determine the image format and get ready to decode the first image frame + * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. * - * @return TRUE if the IO open function succeeds + * @pre This only makes sense on the ChibiOS operating system. * - * @param[in] img The image structure - * @param[in] filename The filename to open + * @param[in] img The image structure + * @param[in] BaseFileStreamPtr A pointer to an open BaseFileStream * + * @note This determines which decoder to use and then initialises all other fields + * in the gdispImage structure. + * @note The image background color is set to White. + * @note There are three types of return - everything OK, partial success and unrecoverable + * failures. For everything OK it returns GDISP_IMAGE_ERR_OK. A partial success can + * be distinguished from a unrecoverable failure by testing the GDISP_IMAGE_ERR_UNRECOVERABLE + * bit in the error code. + * A partial success return code means an image can still be drawn but perhaps with + * reduced functionality eg only the first page of a multi-page image. + * @note @p gdispImageClose() should be called even after a partial failure in order to + * properly close the file. */ - bool_t gdispImageSetFileReader(gdispImage *img, const char *filename); - /* Old definition */ - #define gdispImageSetSimulFileReader(img, fname) gdispImageSetFileReader(img, fname) + gdispImageError gdispImageOpenBaseFileStream(gdispImage *img, void *BaseFileStreamPtr); #endif - + /** - * @brief Open an image ready for drawing + * @brief Open an image in memory and get it ready for drawing * @details Determine the image format and get ready to decode the first image frame * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. * - * @param[in] img The image structure - * - * @pre The io fields should be filled in before calling gdispImageOpen() + * @param[in] img The image structure + * @param[in] memimage A pointer to the image bytes in memory * * @note This determines which decoder to use and then initialises all other fields * in the gdispImage structure. @@ -179,17 +199,17 @@ extern "C" { * bit in the error code. * A partial success return code means an image can still be drawn but perhaps with * reduced functionality eg only the first page of a multi-page image. - * @note @p gdispImageClose() can be called even after a failure to open the image to ensure - * that the IO close routine gets called. + * @note @p gdispImageClose() should be called even after a partial failure in order to + * properly close the file. */ - gdispImageError gdispImageOpen(gdispImage *img); - + gdispImageError gdispImageOpenMemory(gdispImage *img, const void *memimage); + /** * @brief Close an image and release any dynamically allocated working storage. * * @param[in] img The image structure * - * @pre gdispImageOpen() must have returned successfully. + * @pre gdispImageOpenFile() must have returned successfully. * * @note Also calls the IO close function (if it hasn't already been called). */ @@ -282,94 +302,6 @@ extern "C" { */ delaytime_t gdispImageNext(gdispImage *img); - #if GDISP_NEED_IMAGE_NATIVE - /** - * @brief The image drawing routines for a NATIVE format image. - * - * @note Only use these functions if you absolutely know the format - * of the image you are decoding. Generally you should use the - * generic functions and it will auto-detect the format. - * @note A NATIVE format image is defined as an 8 byte header described below, immediately - * followed by the bitmap data. The bitmap data is stored in the native format for - * the display controller. If the pixel format specified in the header does not - * match the controller native format then the image is rejected. - * @note The 8 byte header: - * { 'N', 'I', width.hi, width.lo, height.hi, height.lo, format.hi, format.lo } - * The format word = GDISP_PIXELFORMAT - * @{ - */ - gdispImageError gdispImageOpen_NATIVE(gdispImage *img); - void gdispImageClose_NATIVE(gdispImage *img); - gdispImageError gdispImageCache_NATIVE(gdispImage *img); - gdispImageError gdispGImageDraw_NATIVE(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy); - delaytime_t gdispImageNext_NATIVE(gdispImage *img); - /* @} */ - #endif - - #if GDISP_NEED_IMAGE_GIF - /** - * @brief The image drawing routines for a GIF image. - * @note Only use these functions if you absolutely know the format - * of the image you are decoding. Generally you should use the - * generic functions and it will auto-detect the format. - * @{ - */ - gdispImageError gdispImageOpen_GIF(gdispImage *img); - void gdispImageClose_GIF(gdispImage *img); - gdispImageError gdispImageCache_GIF(gdispImage *img); - gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy); - delaytime_t gdispImageNext_GIF(gdispImage *img); - /* @} */ - #endif - - #if GDISP_NEED_IMAGE_BMP - /** - * @brief The image drawing routines for a BMP image. - * @note Only use these functions if you absolutely know the format - * of the image you are decoding. Generally you should use the - * generic functions and it will auto-detect the format. - * @{ - */ - gdispImageError gdispImageOpen_BMP(gdispImage *img); - void gdispImageClose_BMP(gdispImage *img); - gdispImageError gdispImageCache_BMP(gdispImage *img); - gdispImageError gdispGImageDraw_BMP(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy); - delaytime_t gdispImageNext_BMP(gdispImage *img); - /* @} */ - #endif - - #if GDISP_NEED_IMAGE_JPG - /** - * @brief The image drawing routines for a JPG image. - * @note Only use these functions if you absolutely know the format - * of the image you are decoding. Generally you should use the - * generic functions and it will auto-detect the format. - * @{ - */ - gdispImageError gdispImageOpen_JPG(gdispImage *img); - void gdispImageClose_JPG(gdispImage *img); - gdispImageError gdispImageCache_JPG(gdispImage *img); - gdispImageError gdispGImageDraw_JPG(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy); - delaytime_t gdispImageNext_JPG(gdispImage *img); - /* @} */ - #endif - - #if GDISP_NEED_IMAGE_PNG - /** - * @brief The image drawing routines for a PNG image. - * @note Only use these functions if you absolutely know the format - * of the image you are decoding. Generally you should use the - * generic functions and it will auto-detect the format. - * @{ - */ - gdispImageError gdispImageOpen_PNG(gdispImage *img); - void gdispImageClose_PNG(gdispImage *img); - gdispImageError gdispImageCache_PNG(gdispImage *img); - gdispImageError gdispGImageDraw_PNG(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy); - delaytime_t gdispImageNext_PNG(gdispImage *img); - /* @} */ - #endif - #ifdef __cplusplus } #endif -- cgit v1.2.3 From 1d904dccaf4e82b5a7225f004f191ebc97176b91 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Feb 2014 13:59:52 +1000 Subject: Typo in Win32 GOS --- include/gos/win32.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/gos/win32.h b/include/gos/win32.h index 2840ffcf..c704a288 100644 --- a/include/gos/win32.h +++ b/include/gos/win32.h @@ -69,11 +69,11 @@ typedef HANDLE gfxThreadHandle; #define gfxSystemTicks() GetTickCount() #define gfxMillisecondsToTicks(ms) (ms) #define gfxMutexInit(pmutex) *(pmutex) = CreateMutex(0, FALSE, 0) -#define gfxMutexDestory(pmutex) CloseHandle(*(pmutex)) +#define gfxMutexDestroy(pmutex) CloseHandle(*(pmutex)) #define gfxMutexEnter(pmutex) WaitForSingleObject(*(pmutex), INFINITE) #define gfxMutexExit(pmutex) ReleaseMutex(*(pmutex)) #define gfxSemInit(psem, val, limit) *(psem) = CreateSemaphore(0, val, limit, 0) -#define gfxSemDestory(psem) CloseHandle(*(psem)) +#define gfxSemDestroy(psem) CloseHandle(*(psem)) #define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, 0) #define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, 0) #define gfxSemCounterI(psem) gfxSemCounter(psem) -- cgit v1.2.3 From a86bab4a77ea6a4cd34e011c15535fc8da8a1ba6 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Feb 2014 14:04:43 +1000 Subject: Updates to GFILE code --- include/gfile/gfile.h | 51 +++++++-------------------------------------------- include/gfx.h | 2 +- 2 files changed, 8 insertions(+), 45 deletions(-) (limited to 'include') diff --git a/include/gfile/gfile.h b/include/gfile/gfile.h index b615cb8a..62972c47 100644 --- a/include/gfile/gfile.h +++ b/include/gfile/gfile.h @@ -31,48 +31,11 @@ * @brief A file pointer */ -typedef struct GFILE { - const struct GFILEVMT * vmt; - uint16_t flags; - #define GFILEFLG_OPEN 0x0001 // File is open - #define GFILEFLG_READ 0x0002 // Read the file - #define GFILEFLG_WRITE 0x0004 // Write the file - #define GFILEFLG_APPEND 0x0008 // Append on each write - #define GFILEFLG_BINARY 0x0010 // Treat as a binary file - #define GFILEFLG_DELONCLOSE 0x0020 // Delete on close - #define GFILEFLG_CANSEEK 0x0040 // Seek operations are valid - #define GFILEFLG_FAILONBLOCK 0x0080 // Fail on a blocking call - #define GFILEFLG_MUSTEXIST 0x0100 // On open file must exist - #define GFILEFLG_MUSTNOTEXIST 0x0200 // On open file must not exist - #define GFILEFLG_TRUNC 0x0400 // On open truncate the file - void * obj; - long int pos; -} GFILE; - -typedef struct GFILEVMT { - const struct GFILEVMT * next; - uint8_t flags; - #define GFSFLG_WRITEABLE 0x0001 - #define GFSFLG_CASESENSITIVE 0x0002 - #define GFSFLG_SEEKABLE 0x0004 - #define GFSFLG_FAST 0x0010 - #define GFSFLG_SMALL 0x0020 - #define GFSFLG_TEXTMODES 0x0040 - char prefix; - bool_t del(const char *fname); - bool_t exists(const char *fname); - long int filesize(const char *fname); - bool_t ren(const char *oldname, const char *newname); - bool_t open(GFILE *f, const char *fname); - void close(GFILE *f); - int read(GFILE *f, char *buf, int size); - int write(GFILE *f, const char *buf, int size); - bool_t setpos(GFILE *f, long int pos); - long int getsize(GFILE *f); - bool_t eof(GFILE *f); -} GFILEVMT; - -typedef void GFILE; +#ifndef GFILE_IMPLEMENTATION + typedef void GFILE; +#else + typedef struct GFILE GFILE; +#endif extern GFILE *gfileStdIn; extern GFILE *gfileStdErr; @@ -92,8 +55,8 @@ extern "C" { bool_t gfileRename(const char *oldname, const char *newname); GFILE * gfileOpen(const char *fname, const char *mode); void gfileClose(GFILE *f); - size_t gfileRead(GFILE *f, char *buf, size_t len); - size_t gfileWrite(GFILE *f, const char *buf, size_t len); + size_t gfileRead(GFILE *f, void *buf, size_t len); + size_t gfileWrite(GFILE *f, const void *buf, size_t len); long int gfileGetPos(GFILE *f); bool_t gfileSetPos(GFILE *f, long int pos); long int gfileGetSize(GFILE *f); diff --git a/include/gfx.h b/include/gfx.h index f8a5ebc3..0c922669 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -186,7 +186,7 @@ * Include the sub-system header files */ #include "gos/gos.h" -#include "gfile/options.h" +#include "gfile/gfile.h" #include "gmisc/gmisc.h" #include "gqueue/gqueue.h" #include "gevent/gevent.h" -- cgit v1.2.3 From 695bcbee5b84cd2e152baca91c58bdc2e971b0d1 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Feb 2014 14:06:08 +1000 Subject: Update GDISP image code to fully use new GFILE's --- include/gdisp/image.h | 131 ++++++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 68 deletions(-) (limited to 'include') diff --git a/include/gdisp/image.h b/include/gdisp/image.h index f8c5f6a1..bcf9c497 100644 --- a/include/gdisp/image.h +++ b/include/gdisp/image.h @@ -104,10 +104,10 @@ typedef struct gdispImage { gdispImageFlags flags; /* @< The image flags */ color_t bgcolor; /* @< The default background color */ coord_t width, height; /* @< The image dimensions */ - gdispImageIO io; /* @< The image IO functions */ + GFILE * f; /* @< The underlying GFILE */ #if GDISP_NEED_IMAGE_ACCOUNTING - uint32_t memused; /* @< How much RAM is currently allocated */ - uint32_t maxmemused; /* @< How much RAM has been allocated (maximum) */ + uint32_t memused; /* @< How much RAM is currently allocated */ + uint32_t maxmemused; /* @< How much RAM has been allocated (maximum) */ #endif const struct gdispImageHandlers * fns; /* @< Don't mess with this! */ struct gdispImagePrivate * priv; /* @< Don't mess with this! */ @@ -117,78 +117,28 @@ typedef struct gdispImage { extern "C" { #endif - gdispImageError DEPRECATED("If possible please use gdispImageOpenFile(), gdispImageOpenMemory() or gdispImageOpenBaseFileStream() instead") - gdispImageOpen(gdispImage *img); - bool_t DEPRECATED("Use gdispImageOpenMemory() instead. GFX_USE_GFILE, GFILE_NEED_MEMFS must also be TRUE") gdispImageSetMemoryReader(gdispImage *img, const void *memimage); + /** + * Deprecated Functions. + */ + gdispImageError DEPRECATED("Use gdispImageOpenGFile() instead") gdispImageOpen(gdispImage *img); + bool_t DEPRECATED("Use gdispImageOpenMemory() instead") gdispImageSetMemoryReader(gdispImage *img, const void *memimage); #if GFX_USE_OS_CHIBIOS - bool_t DEPRECATED("Use gdispImageOpenBaseFileStream() instead. GFX_USE_GFILE, GFILE_NEED_CHIBIOSFS must also be TRUE") gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr); + bool_t DEPRECATED("Use gdispImageOpenBaseFileStream() instead") gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr); #endif #if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_LINUX || GFX_USE_OS_OSX - bool_t DEPRECATED("Please use gdispImageOpenFile() instead. GFX_USE_GFILE must also be TRUE") - gdispImageSetFileReader(gdispImage *img, const char *filename); + bool_t DEPRECATED("Please use gdispImageOpenFile() instead") gdispImageSetFileReader(gdispImage *img, const char *filename); #define gdispImageSetSimulFileReader(img, fname) gdispImageSetFileReader(img, fname) #endif - #if GFX_USE_GFILE || defined(__DOXYGEN__) - /** - * @brief Open an image in a file and get it ready for drawing - * @details Determine the image format and get ready to decode the first image frame - * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. - * - * @pre GFX_USE_GFILE must be TRUE and you must have included the file-system support - * you want to use. - * - * @param[in] img The image structure - * @param[in] filename The filename to open - * - * @note This determines which decoder to use and then initialises all other fields - * in the gdispImage structure. - * @note The image background color is set to White. - * @note There are three types of return - everything OK, partial success and unrecoverable - * failures. For everything OK it returns GDISP_IMAGE_ERR_OK. A partial success can - * be distinguished from a unrecoverable failure by testing the GDISP_IMAGE_ERR_UNRECOVERABLE - * bit in the error code. - * A partial success return code means an image can still be drawn but perhaps with - * reduced functionality eg only the first page of a multi-page image. - * @note @p gdispImageClose() should be called even after a partial failure in order to - * properly close the file. - */ - gdispImageError gdispImageOpenFile(gdispImage *img, const char *filename); - #endif - - #if GFX_USE_OS_CHIBIOS || defined(__DOXYGEN__) - /** - * @brief Open an image in a ChibiOS basefilestream and get it ready for drawing - * @details Determine the image format and get ready to decode the first image frame - * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. - * - * @pre This only makes sense on the ChibiOS operating system. - * - * @param[in] img The image structure - * @param[in] BaseFileStreamPtr A pointer to an open BaseFileStream - * - * @note This determines which decoder to use and then initialises all other fields - * in the gdispImage structure. - * @note The image background color is set to White. - * @note There are three types of return - everything OK, partial success and unrecoverable - * failures. For everything OK it returns GDISP_IMAGE_ERR_OK. A partial success can - * be distinguished from a unrecoverable failure by testing the GDISP_IMAGE_ERR_UNRECOVERABLE - * bit in the error code. - * A partial success return code means an image can still be drawn but perhaps with - * reduced functionality eg only the first page of a multi-page image. - * @note @p gdispImageClose() should be called even after a partial failure in order to - * properly close the file. - */ - gdispImageError gdispImageOpenBaseFileStream(gdispImage *img, void *BaseFileStreamPtr); - #endif - /** - * @brief Open an image in memory and get it ready for drawing + * @brief Open an image using an open GFILE and get it ready for drawing * @details Determine the image format and get ready to decode the first image frame * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. - * + * * @param[in] img The image structure - * @param[in] memimage A pointer to the image bytes in memory + * @param[in] f The open GFILE stream. + * + * @pre The GFILE must be open for reading. * * @note This determines which decoder to use and then initialises all other fields * in the gdispImage structure. @@ -199,10 +149,55 @@ extern "C" { * bit in the error code. * A partial success return code means an image can still be drawn but perhaps with * reduced functionality eg only the first page of a multi-page image. - * @note @p gdispImageClose() should be called even after a partial failure in order to - * properly close the file. + * @note @p gdispImageClose() should be called when finished with the image. This will close + * the image and its underlying GFILE file. Note that images opened with partial success + * (eg GDISP_IMAGE_ERR_UNSUPPORTED_OK) + * still need to be closed when you are finished with them. + */ + gdispImageError gdispImageOpenGFile(gdispImage *img, GFILE *filename); + + /** + * @brief Open an image in a file and get it ready for drawing + * @details Determine the image format and get ready to decode the first image frame + * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. + * + * @pre You must have included the file-system support into GFILE that you want to use. + * + * @param[in] img The image structure + * @param[in] filename The filename to open + * + * @note This function just opens the GFILE using the filename and passes it to @p gdispImageOpenGFile(). + */ + #define gdispImageOpenFile(img, filename) gdispImageOpenGFile((img), gfileOpen((filename), "rb")) + + /** + * @brief Open an image in a ChibiOS basefilestream and get it ready for drawing + * @details Determine the image format and get ready to decode the first image frame + * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. + * + * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be TRUE. This only makes sense on the ChibiOS + * operating system. + * + * @param[in] img The image structure + * @param[in] BaseFileStreamPtr A pointer to an open BaseFileStream + * + * @note This function just opens the GFILE using the basefilestream and passes it to @p gdispImageOpenGFile(). + */ + #define gdispImageOpenBaseFileStream(img, BaseFileStreamPtr) gdispImageOpenGFile((img), gfileOpenBaseFileStream((BaseFileStreamPtr), "rb")) + + /** + * @brief Open an image in memory and get it ready for drawing + * @details Determine the image format and get ready to decode the first image frame + * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. + * + * @pre GFILE_NEED_MEMFS must be TRUE + * + * @param[in] img The image structure + * @param[in] ptr A pointer to the image bytes in memory + * + * @note This function just opens the GFILE using the basefilestream and passes it to @p gdispImageOpenGFile(). */ - gdispImageError gdispImageOpenMemory(gdispImage *img, const void *memimage); + #define gdispImageOpenMemory(img, ptr) gdispImageOpenGFile((img), gfileOpenMemory((void *)(ptr), "rb")) /** * @brief Close an image and release any dynamically allocated working storage. -- cgit v1.2.3 From bd4827922708efc85c878ebd17ca6a8c88bc75b5 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Feb 2014 14:07:29 +1000 Subject: Update gwin Images to properly use new GFILE based images --- include/gwin/image.h | 53 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'include') diff --git a/include/gwin/image.h b/include/gwin/image.h index 66dd0b94..66aba3d1 100644 --- a/include/gwin/image.h +++ b/include/gwin/image.h @@ -60,42 +60,51 @@ GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit); #define gwinImageCreate(w, pInit) gwinGImageCreate(GDISP, w, pInit) /** - * @brief Sets the input routines that support reading the image from memory - * in RAM or flash. - * @return TRUE if the IO open function succeeds + * @brief Opens the image using a GFILE + * @return TRUE if the image can be opened * * @param[in] gh The widget (must be an image widget) - * @param[in] memory A pointer to the image in RAM or Flash + * @param[in] f The open (for reading) GFILE to use * * @api */ -bool_t gwinImageOpenMemory(GHandle gh, const void* memory); +bool_t gwinImageOpenGFile(GHandle gh, GFILE *f); -#if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_LINUX || GFX_USE_OS_OSX || defined(__DOXYGEN__) - /** - * @brief Sets the input routines that support reading the image from a file - * @return TRUE if the IO open function succeeds - * - * @param[in] gh The widget (must be an image widget) - * @param[in] filename The filename to open - * - * @api - */ - bool_t gwinImageOpenFile(GHandle gh, const char* filename); -#endif +/** + * @brief Opens the image using the specified filename + * @return TRUE if the open succeeds + * + * @param[in] gh The widget (must be an image widget) + * @param[in] filename The filename to open + * + * @api + */ +#define gwinImageOpenFile(gh, filename) gwinImageOpenGFile((gh), gfileOpen((filename), "rb")) -#if GFX_USE_OS_CHIBIOS || defined(__DOXYGEN__) /** - * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card). + * @brief Sets the input routines that support reading the image from memory + * in RAM or flash. + * @pre GFILE_NEED_MEMFS must be TRUE * @return TRUE if the IO open function succeeds * * @param[in] gh The widget (must be an image widget) - * @param[in] streamPtr A pointer to the (open) BaseFileStream object. + * @param[in] ptr A pointer to the image in RAM or Flash * * @api */ - bool_t gwinImageOpenStream(GHandle gh, void *streamPtr); -#endif +#define gwinImageOpenMemory(gh, ptr) gwinImageOpenGFile((gh), gfileOpenMemory((void *)(ptr), "rb")) + +/** + * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card). + * @return TRUE if the IO open function succeeds + * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be TRUE + * + * @param[in] gh The widget (must be an image widget) + * @param[in] streamPtr A pointer to the (open) BaseFileStream object. + * + * @api + */ +#define gwinImageOpenStream(gh, streamPtr) gwinImageOpenGFile((gh), gfileOpenBaseFIleStream((streamPtr), "rb")) /** * @brief Cache the image. -- cgit v1.2.3 From 3ad23244f13ba4b90e954bb363dca837668c4769 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 9 Feb 2014 20:24:24 +0100 Subject: doc --- include/gdisp/image.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/gdisp/image.h b/include/gdisp/image.h index bcf9c497..77cd97e4 100644 --- a/include/gdisp/image.h +++ b/include/gdisp/image.h @@ -117,7 +117,7 @@ typedef struct gdispImage { extern "C" { #endif - /** + /* * Deprecated Functions. */ gdispImageError DEPRECATED("Use gdispImageOpenGFile() instead") gdispImageOpen(gdispImage *img); @@ -136,7 +136,7 @@ extern "C" { * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. * * @param[in] img The image structure - * @param[in] f The open GFILE stream. + * @param[in] filename The open GFILE stream. * * @pre The GFILE must be open for reading. * -- cgit v1.2.3 From bb1cd44824e0f70906c81842d7ff2852f354663e Mon Sep 17 00:00:00 2001 From: inmarket Date: Sat, 15 Feb 2014 22:23:32 +1000 Subject: Fix naming of a parameter --- include/gdisp/image.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/gdisp/image.h b/include/gdisp/image.h index 77cd97e4..607f1007 100644 --- a/include/gdisp/image.h +++ b/include/gdisp/image.h @@ -136,7 +136,7 @@ extern "C" { * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. * * @param[in] img The image structure - * @param[in] filename The open GFILE stream. + * @param[in] f The open GFILE stream. * * @pre The GFILE must be open for reading. * @@ -154,7 +154,7 @@ extern "C" { * (eg GDISP_IMAGE_ERR_UNSUPPORTED_OK) * still need to be closed when you are finished with them. */ - gdispImageError gdispImageOpenGFile(gdispImage *img, GFILE *filename); + gdispImageError gdispImageOpenGFile(gdispImage *img, GFILE *f); /** * @brief Open an image in a file and get it ready for drawing -- cgit v1.2.3