Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
2DGL_BMPExport.c
00001 /********************************************************************* 00002 * SEGGER Microcontroller GmbH * 00003 * Solutions for real time microcontroller applications * 00004 ********************************************************************** 00005 * * 00006 * (c) 1996 - 2018 SEGGER Microcontroller GmbH * 00007 * * 00008 * Internet: www.segger.com Support: support@segger.com * 00009 * * 00010 ********************************************************************** 00011 00012 ** emWin V5.48 - Graphical user interface for embedded applications ** 00013 All Intellectual Property rights in the Software belongs to SEGGER. 00014 emWin is protected by international copyright laws. Knowledge of the 00015 source code may not be used to write a similar product. This file may 00016 only be used in accordance with the following terms: 00017 00018 The software has been licensed to Cypress Semiconductor Corporation, 00019 whose registered office is situated at 198 Champion Ct. San Jose, CA 00020 95134 USA solely for the purposes of creating libraries for Cypress 00021 PSoC3 and PSoC5 processor-based devices, sublicensed and distributed 00022 under the terms and conditions of the Cypress End User License 00023 Agreement. 00024 Full source code is available at: www.segger.com 00025 00026 We appreciate your understanding and fairness. 00027 ---------------------------------------------------------------------- 00028 Licensing information 00029 Licensor: SEGGER Microcontroller Systems LLC 00030 Licensed to: Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA 00031 Licensed SEGGER software: emWin 00032 License number: GUI-00319 00033 License model: Services and License Agreement, signed June 10th, 2009 00034 Licensed platform: Any Cypress platform (Initial targets are: PSoC3, PSoC5) 00035 ---------------------------------------------------------------------- 00036 Support and Update Agreement (SUA) 00037 SUA period: 2009-06-12 - 2022-07-27 00038 Contact to extend SUA: sales@segger.com 00039 ---------------------------------------------------------------------- 00040 File : 2DGL_BMPExport.c 00041 Purpose : Demonstrates the use of GUI_BMP_Serialize 00042 Requirements: WindowManager - ( ) 00043 MemoryDevices - ( ) 00044 AntiAliasing - ( ) 00045 VNC-Server - ( ) 00046 PNG-Library - ( ) 00047 TrueTypeFonts - ( ) 00048 00049 Can be used in a MS Windows environment only! 00050 ---------------------------END-OF-HEADER------------------------------ 00051 */ 00052 00053 #ifndef SKIP_TEST 00054 00055 #ifdef WIN32 00056 #include "windows.h" 00057 #else 00058 #include "FS.h" 00059 #endif 00060 #include "DIALOG.h" 00061 00062 /********************************************************************* 00063 * 00064 * Externals 00065 * 00066 ********************************************************************** 00067 */ 00068 00069 /********************************************************************* 00070 * 00071 * Defines 00072 * 00073 ********************************************************************** 00074 */ 00075 // 00076 // Recommended memory to run the sample with adequate performance 00077 // 00078 #define RECOMMENDED_MEMORY (1024L * 5) 00079 #define BUFFER_SIZE (4096ul) 00080 00081 #ifdef WIN32 00082 #define FILE_DEST_PATH "c:\\GUI_BMP_Serialize.bmp" 00083 #else 00084 #define FILE_DEST_PATH "GUI_BMP_Serialize.bmp" 00085 #endif 00086 00087 /********************************************************************* 00088 * 00089 * Types 00090 * 00091 ********************************************************************** 00092 */ 00093 typedef struct { 00094 #ifdef WIN32 00095 HANDLE hFile; 00096 #else 00097 FS_FILE * pFile; 00098 #endif 00099 char acBuffer[BUFFER_SIZE]; 00100 U32 BytesWritten; 00101 } WRITE_BUFFER; 00102 00103 /********************************************************************* 00104 * 00105 * Static data 00106 * 00107 ********************************************************************** 00108 */ 00109 static const GUI_POINT _aPointStar[] = { 00110 { 0, -36 }, 00111 { 8, -8 }, 00112 { 36, 0 }, 00113 { 8, 8 }, 00114 { 0, 36 }, 00115 { -8, 8 }, 00116 { -36, 0 }, 00117 { -8, -8 } 00118 }; 00119 00120 static const GUI_POINT _aPointHexagon[] = { 00121 { 0, -30 }, 00122 { 26, -15 }, 00123 { 26, 15 }, 00124 { 0, 30 }, 00125 { -26, 15 }, 00126 { -26, -15 }, 00127 }; 00128 00129 /********************************************************************* 00130 * 00131 * Static code 00132 * 00133 ********************************************************************** 00134 */ 00135 /********************************************************************* 00136 * 00137 * _DrawSomething 00138 * 00139 * Function description 00140 * Draws something to LCD 00141 */ 00142 static void _DrawSomething(void) { 00143 int xSize; 00144 int ySize; 00145 00146 xSize = LCD_GetXSize(); 00147 ySize = LCD_GetYSize(); 00148 GUI_SetFont(&GUI_Font24_ASCII); 00149 GUI_SetTextMode(GUI_TM_TRANS); 00150 GUI_DispStringHCenterAt("Demo of GUI_BMP_Serialize", xSize / 2, (ySize - GUI_GetFontSizeY()) / 2); 00151 GUI_SetColor(GUI_GREEN); 00152 GUI_FillPolygon (&_aPointHexagon[0], GUI_COUNTOF(_aPointHexagon), xSize / 2, ySize / 5); 00153 GUI_SetColor(GUI_RED); 00154 GUI_FillPolygon (&_aPointStar[0], GUI_COUNTOF(_aPointStar), xSize / 2, ySize / 5 * 4); 00155 } 00156 00157 /********************************************************************* 00158 * 00159 * _FlushBuffer 00160 * 00161 * Function description 00162 * Flushs the write buffer. 00163 */ 00164 static void _FlushBuffer(WRITE_BUFFER * pWriteBuffer) { 00165 #ifdef WIN32 00166 U32 nWritten; 00167 00168 WriteFile(pWriteBuffer->hFile, pWriteBuffer->acBuffer, pWriteBuffer->BytesWritten, &nWritten, NULL); 00169 #else 00170 FS_Write(pWriteBuffer->pFile, pWriteBuffer->acBuffer, pWriteBuffer->BytesWritten); 00171 #endif 00172 pWriteBuffer->BytesWritten = 0; 00173 } 00174 00175 /********************************************************************* 00176 * 00177 * _WriteByte2File 00178 * 00179 * Function description 00180 * This function will be called by GUI_BMP_Serialize to write the 00181 * bytes to the file 00182 */ 00183 static void _WriteByte2File(U8 Data, void * p) { 00184 WRITE_BUFFER * pWriteBuffer; 00185 00186 #ifdef WIN32 00187 pWriteBuffer = (WRITE_BUFFER *)p; 00188 if (pWriteBuffer->BytesWritten < BUFFER_SIZE) { 00189 pWriteBuffer->acBuffer[pWriteBuffer->BytesWritten++] = Data; 00190 } else { 00191 _FlushBuffer(pWriteBuffer); 00192 pWriteBuffer->acBuffer[pWriteBuffer->BytesWritten++] = Data; 00193 } 00194 #else 00195 pWriteBuffer = (WRITE_BUFFER *)p; 00196 if (pWriteBuffer->BytesWritten < BUFFER_SIZE) { 00197 pWriteBuffer->acBuffer[pWriteBuffer->BytesWritten++] = Data; 00198 } else { 00199 _FlushBuffer(pWriteBuffer); 00200 pWriteBuffer->acBuffer[pWriteBuffer->BytesWritten++] = Data; 00201 } 00202 #endif 00203 } 00204 00205 /********************************************************************* 00206 * 00207 * _ExportToFile 00208 * 00209 * Function description 00210 * Demonstrates the use of GUI_BMP_Serialize 00211 */ 00212 static void _ExportToFile(void) { 00213 WRITE_BUFFER WriteBuffer = { 0 }; 00214 #ifdef WIN32 00215 WriteBuffer.hFile = CreateFile(FILE_DEST_PATH, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); 00216 GUI_BMP_Serialize(_WriteByte2File, (void *)&WriteBuffer); 00217 _FlushBuffer(&WriteBuffer); 00218 CloseHandle(WriteBuffer.hFile); 00219 #else 00220 WriteBuffer.pFile = FS_FOpen(FILE_DEST_PATH, "w"); 00221 GUI_BMP_Serialize(_WriteByte2File, (void *)&WriteBuffer); 00222 _FlushBuffer(&WriteBuffer); 00223 FS_FClose(WriteBuffer.pFile); 00224 #endif 00225 } 00226 00227 /********************************************************************* 00228 * 00229 * Public code 00230 * 00231 ********************************************************************** 00232 */ 00233 /********************************************************************* 00234 * 00235 * MainTask 00236 */ 00237 void MainTask(void) { 00238 int xSize; 00239 int ySize; 00240 #ifndef WIN32 00241 char acVolumeName[10]; 00242 #endif 00243 00244 GUI_Init(); 00245 // 00246 // Check if recommended memory for the sample is available 00247 // 00248 if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) { 00249 GUI_ErrorOut("Not enough memory available."); 00250 return; 00251 } 00252 _DrawSomething(); 00253 #ifdef WIN32 00254 _ExportToFile(); 00255 #else 00256 FS_Init(); 00257 FS_FAT_SupportLFN(); 00258 FS_GetVolumeName(0, acVolumeName, sizeof(acVolumeName)); 00259 if (FS_Mount(acVolumeName) > 0) { 00260 _ExportToFile(); 00261 } 00262 #endif 00263 GUI_Delay(500); 00264 GUI_Clear(); 00265 xSize = LCD_GetXSize(); 00266 ySize = LCD_GetYSize(); 00267 GUI_SetColor(GUI_MAKE_COLOR(0xF06060)); 00268 GUI_DispStringHCenterAt("The image was stored in\n " FILE_DEST_PATH, xSize >> 1, ySize >> 1); 00269 while (1) { 00270 GUI_Delay(200); 00271 } 00272 } 00273 00274 #endif 00275 00276 /*************************** End of file ****************************/
Generated on Thu Jul 14 2022 12:58:38 by
