diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/gdisp/image.h | 211 | ||||
-rw-r--r-- | include/gfile/gfile.h | 169 | ||||
-rw-r--r-- | include/gfile/options.h | 158 | ||||
-rw-r--r-- | include/gfx.h | 12 | ||||
-rw-r--r-- | include/gfx_rules.h | 12 | ||||
-rw-r--r-- | include/gwin/image.h | 53 |
6 files changed, 449 insertions, 166 deletions
diff --git a/include/gdisp/image.h b/include/gdisp/image.h index ff2e9d85..607f1007 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 @@ -103,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! */ @@ -116,59 +117,28 @@ 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 + /* + * Deprecated Functions. */ - bool_t gdispImageSetMemoryReader(gdispImage *img, const void *memimage); - - #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 on a BaseFileStream (eg SDCard). - * - * @return TRUE if the IO open function succeeds - * - * @param[in] img The image structure - * @param[in] BaseFileStreamPtr A pointer to the (open) BaseFileStream object. - * - */ - bool_t gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr); + 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") gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr); #endif - - #if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_LINUX || GFX_USE_OS_OSX || 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 - * - * @return TRUE if the IO open function succeeds - * - * @param[in] img The image structure - * @param[in] filename The filename to open - * - */ - bool_t gdispImageSetFileReader(gdispImage *img, const char *filename); - /* Old definition */ + #if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_LINUX || GFX_USE_OS_OSX + bool_t DEPRECATED("Please use gdispImageOpenFile() instead") gdispImageSetFileReader(gdispImage *img, const char *filename); #define gdispImageSetSimulFileReader(img, fname) gdispImageSetFileReader(img, fname) #endif - + /** - * @brief Open an image 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 - * - * @pre The io fields should be filled in before calling gdispImageOpen() + * + * @param[in] img The image structure + * @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. @@ -179,17 +149,62 @@ 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 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 gdispImageOpen(gdispImage *img); - + gdispImageError gdispImageOpenGFile(gdispImage *img, GFILE *f); + + /** + * @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(). + */ + #define gdispImageOpenMemory(img, ptr) gdispImageOpenGFile((img), gfileOpenMemory((void *)(ptr), "rb")) + /** * @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 +297,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 diff --git a/include/gfile/gfile.h b/include/gfile/gfile.h new file mode 100644 index 00000000..62972c47 --- /dev/null +++ b/include/gfile/gfile.h @@ -0,0 +1,169 @@ +/* + * 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_GFILE || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Type definitions */ +/*===========================================================================*/ + +/** + * @brief A file pointer + */ + +#ifndef GFILE_IMPLEMENTATION + typedef void GFILE; +#else + typedef struct GFILE GFILE; +#endif + +extern GFILE *gfileStdIn; +extern GFILE *gfileStdErr; +extern GFILE *gfileStdOut; + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#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, 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); + 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, ...); + #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 + + #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) + 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 + #define remove(n) (!gfileDelete(n)) + #define rename(o,n) (!gfileRename(o,n)) + #define fflush(f) (0) + #define ftell(f) gfileGetPos(f) + #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 feof(f) gfileEOF(f) + + #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,...) + //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 + //fgetc + //fgets + //fputc + //fputs + //getc + //getchar + //puts + //ungetc + //void perror (const char * str); + #endif + +#ifdef __cplusplus +} +#endif + +#endif /* GFX_USE_GFILE */ + +#endif /* _GFILE_H */ +/** @} */ + diff --git a/include/gfile/options.h b/include/gfile/options.h new file mode 100644 index 00000000..d73af02c --- /dev/null +++ b/include/gfile/options.h @@ -0,0 +1,158 @@ +/* + * 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 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 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. + */ + #ifndef GFILE_NEED_STDIO + #define GFILE_NEED_STDIO FALSE + #endif + /** + * @brief Include the ROM file system + * @details Defaults to FALSE + * @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 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 + #endif + /** + * @brief Include the RAM file system + * @details Defaults to FALSE + * @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. + */ + #ifndef GFILE_NEED_RAMFS + #define GFILE_NEED_RAMFS FALSE + #endif + /** + * @brief Include the FAT file system driver + * @details Defaults to FALSE + * @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. + */ + #ifndef GFILE_NEED_FATFS + #define GFILE_NEED_FATFS FALSE + #endif + /** + * @brief Include the operating system's native file system + * @details Defaults to FALSE + * @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. + * If it is not defined the gfileStdOut and gfileStdErr io is discarded. + */ + #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 +/** + * @} + * + * @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 + * (if open by default). + */ + #ifndef GFILE_MAX_GFILES + #define GFILE_MAX_GFILES 3 + #endif +/** @} */ + +#endif /* _GFILE_OPTIONS_H */ +/** @} */ diff --git a/include/gfx.h b/include/gfx.h index d261a6ce..0c922669 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/gfile.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 */ /** @} */ 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. |