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_DrawJPEG.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_DrawJPEG.c 00041 Purpose : Sample for drawing JPEG files. 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 ---------------------------------------------------------------------- 00051 */ 00052 00053 #ifndef SKIP_TEST 00054 00055 #include <windows.h> 00056 #include <stdio.h> 00057 00058 #include "GUI.h" 00059 00060 /********************************************************************* 00061 * 00062 * Defines 00063 * 00064 ********************************************************************** 00065 */ 00066 #define NUM_IMAGES_UNTIL_HINT 5 00067 #define TITLE_HEIGHT 40 00068 #define BORDER_SIZE 5 00069 #define YPOS_IMAGE 73 00070 00071 // 00072 // Recommended memory to run the sample with adequate performance 00073 // 00074 #define RECOMMENDED_MEMORY (1024L * 200) 00075 00076 /********************************************************************* 00077 * 00078 * Static functions 00079 * 00080 ********************************************************************** 00081 */ 00082 /********************************************************************* 00083 * 00084 * _DrawJPEGs 00085 * 00086 * Function description 00087 * Draws the given JPEG image. 00088 */ 00089 static void _DrawJPEGs(const char * sFileName) { 00090 static int i; 00091 const char acError[] = "There is possibly not enough memory to display this JPEG image.\n\nPlease assign more memory to emWin in GUIConf.c."; 00092 GUI_JPEG_INFO Info; 00093 GUI_RECT Rect; 00094 HANDLE hFile; 00095 DWORD NumBytesRead; 00096 DWORD FileSize; 00097 char * pFile; 00098 int xSize, ySize; 00099 int xPos, yPos; 00100 int r; 00101 00102 xSize = LCD_GetXSize(); 00103 ySize = LCD_GetYSize(); 00104 // 00105 // Display file name. 00106 // 00107 Rect.x0 = BORDER_SIZE; 00108 Rect.y0 = TITLE_HEIGHT; 00109 Rect.x1 = xSize - BORDER_SIZE - 1; 00110 Rect.y1 = YPOS_IMAGE - 1; 00111 GUI_ClearRectEx(&Rect); 00112 GUI_SetTextMode(GUI_TM_NORMAL); 00113 GUI_SetFont(&GUI_Font8x16); 00114 GUI_DispStringInRectWrap(sFileName, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, GUI_WRAPMODE_CHAR); 00115 // 00116 // Clear the area in which the JPEG files are displayed. 00117 // 00118 Rect.x0 = BORDER_SIZE; 00119 Rect.y0 = YPOS_IMAGE; 00120 Rect.x1 = xSize - BORDER_SIZE - 1; 00121 Rect.y1 = ySize - BORDER_SIZE - 1; 00122 GUI_ClearRectEx(&Rect); 00123 // 00124 // Load image. 00125 // 00126 hFile = CreateFile(sFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 00127 FileSize = GetFileSize(hFile, NULL); 00128 pFile = malloc(FileSize); 00129 ReadFile(hFile, pFile, FileSize, &NumBytesRead, NULL); 00130 CloseHandle(hFile); 00131 // 00132 // Check if the current JPEG image fits on the screen. 00133 // 00134 GUI_JPEG_GetInfo(pFile, FileSize, &Info); 00135 xSize -= BORDER_SIZE * 2 + 1; 00136 ySize -= YPOS_IMAGE + BORDER_SIZE + 1; 00137 // 00138 // Display the image centered. 00139 // 00140 xPos = BORDER_SIZE + (xSize - Info.XSize) / 2; 00141 yPos = YPOS_IMAGE + (ySize - Info.YSize) / 2; 00142 GUI_SetClipRect(&Rect); 00143 r = GUI_JPEG_Draw(pFile, FileSize, xPos, yPos); 00144 GUI_SetClipRect(NULL); 00145 if (r) { 00146 // 00147 // The image could not be displayed successfully. Show an error message. 00148 // 00149 GUI_DispStringInRectWrap(acError, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, GUI_WRAPMODE_WORD); 00150 } else { 00151 GUI_Delay(2000); 00152 if ((Info.XSize > xSize) || (Info.YSize > ySize)) { 00153 // 00154 // Inform the user about the possibility of scaling JPEG images. 00155 // 00156 if (i == 0) { 00157 GUI_ClearRectEx(&Rect); 00158 GUI_DispStringInRectWrap("JPEG images can be scaled as it is shown in 2DGL_JPEG_DrawScaled.c.", &Rect, GUI_TA_BOTTOM | GUI_TA_HCENTER, GUI_WRAPMODE_WORD); 00159 GUI_Delay(3000); 00160 } 00161 i++; 00162 if (i == NUM_IMAGES_UNTIL_HINT) { 00163 i = 0; 00164 } 00165 } 00166 } 00167 free(pFile); 00168 } 00169 00170 /********************************************************************* 00171 * 00172 * _GetFirstBitmapDirectory 00173 * 00174 * Function description 00175 * Returns the first directory which contains one or more JPG files. 00176 */ 00177 static int _GetFirstBitmapDirectory(char * pDir, char * pBuffer) { 00178 WIN32_FIND_DATA Context; 00179 HANDLE hFind; 00180 char acMask[_MAX_PATH]; 00181 char acPath[_MAX_PATH]; 00182 00183 sprintf(acMask, "%s\\*.jpg", pDir); 00184 hFind = FindFirstFile(acMask, &Context); 00185 if (hFind != INVALID_HANDLE_VALUE) { 00186 sprintf(pBuffer, "%s\\", pDir); 00187 return 1; 00188 } 00189 sprintf(acMask, "%s\\*.", pDir); 00190 hFind = FindFirstFile(acMask, &Context); 00191 if (hFind != INVALID_HANDLE_VALUE) { 00192 do { 00193 if ((strcmp(Context.cFileName, ".") != 0) && (strcmp(Context.cFileName, "..") != 0)) { 00194 if (Context.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { 00195 sprintf(acPath, "%s\\%s", pDir, Context.cFileName); 00196 if (_GetFirstBitmapDirectory(acPath, pBuffer)) { 00197 return 1; 00198 } 00199 } 00200 } 00201 } while (FindNextFile(hFind, &Context)); 00202 } 00203 return 0; 00204 } 00205 00206 /******************************************************************* 00207 * 00208 * _DrawJPEGsFromWindowsDir 00209 * 00210 * Function description 00211 * Iterates over all JPEG files in a Windows sub folder. 00212 */ 00213 static void _DrawJPEGsFromWindowsDir(void) { 00214 WIN32_FIND_DATA Context; 00215 HANDLE hFind; 00216 char acPath[_MAX_PATH]; 00217 char acMask[_MAX_PATH]; 00218 char acFile[_MAX_PATH]; 00219 char acBuffer[_MAX_PATH]; 00220 int xSize; 00221 00222 xSize = LCD_GetXSize(); 00223 GUI_SetBkColor(GUI_BLACK); 00224 GUI_Clear(); 00225 GUI_SetColor(GUI_WHITE); 00226 GUI_SetFont(&GUI_Font24_ASCII); 00227 GUI_DispStringHCenterAt("Draw JPEG - Sample", xSize / 2, 5); 00228 GetWindowsDirectory(acBuffer, sizeof(acBuffer)); 00229 _GetFirstBitmapDirectory(acBuffer, acPath); 00230 sprintf(acMask, "%s*.jp*", acPath); 00231 hFind = FindFirstFile(acMask, &Context); 00232 if (hFind != INVALID_HANDLE_VALUE) { 00233 do { 00234 sprintf(acFile, "%s%s", acPath, Context.cFileName); 00235 _DrawJPEGs(acFile); 00236 } while (FindNextFile(hFind, &Context)); 00237 } else { 00238 GUI_DispStringHCenterAt("No JPEG files found!", 160, 60); 00239 GUI_Delay(2000); 00240 } 00241 } 00242 00243 /********************************************************************* 00244 * 00245 * Public code 00246 * 00247 ********************************************************************** 00248 */ 00249 /********************************************************************* 00250 * 00251 * MainTask 00252 */ 00253 void MainTask(void) { 00254 GUI_Init(); 00255 // 00256 // Check if recommended memory for the sample is available 00257 // 00258 if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) { 00259 GUI_ErrorOut("Not enough memory available."); 00260 return; 00261 } 00262 while (1) { 00263 _DrawJPEGsFromWindowsDir(); 00264 } 00265 } 00266 00267 #endif 00268 00269 /*************************** End of file ****************************/
Generated on Thu Jul 14 2022 12:58:38 by
