Draw streamed bitmap (Sample)
GUI_DrawStreamedBitmap.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | GUI_DrawStreamedBitmap.zip |
This sample demonstrates how streamed bitmaps can be drawn from external .dta files. It supports both the usage of Windows file system and emFile.
Code
/*********************************************************************
* SEGGER Microcontroller GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 - 2020 SEGGER Microcontroller GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
** emWin V6.10 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File : GUI_DrawStreamedBitmap.c
Purpose : Sample that demonstrates how to draw streamed bitmaps
(.dta files)
This sample supports both usage in the Windows Simulation as well
as usage on a target device using emFile.
Requirements: WindowManager - ( )
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "GUI.h"
#ifdef WIN32
#include <Windows.h>
#else
#include "FS.h"
#endif
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#ifdef WIN32
#define FILE_PATH "C:\\Work\\emWin\\Intern\\TutorialV6\\Core\\Bitmaps\\segger-logo.dta"
#else
#define FILE_PATH "segger-logo.dta"
#endif
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* APP_GetData
*/
int APP_GetData(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off) {
#ifdef WIN32
HANDLE * phFile;
DWORD NumBytesRead;
#else
FS_FILE * pFile;
int NumBytesRead;
#endif
U8 * pData;
pData = (U8 *)*ppData;
#ifdef WIN32
phFile = (HANDLE *)p;
//
// Set file pointer to the required position
//
SetFilePointer(*phFile, Off, 0, FILE_BEGIN);
//
// Read data into buffer
//
ReadFile(*phFile, pData, NumBytes, &NumBytesRead, NULL);
//
// Return number of available bytes
//
return NumBytesRead;
#else
pFile = (FS_FILE *)p;
//
// Set file pointer to the required position
//
FS_SetFilePos(pFile, Off, FS_FILE_BEGIN);
//
// Read data into buffer
//
NumBytesRead = FS_FRead(pData, 1, NumBytes, pFile);
//
// Return number of available bytes
//
return NumBytesRead;
#endif
}
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
#ifdef WIN32
HANDLE hFile;
#else
FS_FILE * pFile;
char acVolumeName[10];
#endif
//
// Init GUI.
//
GUI_Init();
#ifdef WIN32
//
// Create file handle
//
hFile = CreateFile(FILE_PATH, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
//
// Draw the png image by passing a pointer to the file handle and the GetData function
//
GUI_DrawStreamedBitmapExAuto(APP_GetData, &hFile, 10, 10);
//
// Close file handle
//
CloseHandle(hFile);
#else
//
// Start emFile
//
FS_Init();
//
// Enable long file name support
//
FS_FAT_SupportLFN();
//
// Mount volume
//
FS_GetVolumeName(0, acVolumeName, sizeof(acVolumeName));
if (FS_Mount(acVolumeName) > 0) {
//
// Open file
//
pFile = FS_FOpen(FILE_PATH, "rb");
}
//
// Draw the png image by passing a pointer to the file handle and the GetData function
//
GUI_DrawStreamedBitmapExAuto(APP_GetData, pFile, 10, 10);
//
// Close file
//
FS_FClose(pFile);
#endif
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/