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.
images/EAImage.h@7:6cf21b018420, 2010-11-01 (annotated)
- Committer:
- richardparker
- Date:
- Mon Nov 01 13:07:40 2010 +0000
- Revision:
- 7:6cf21b018420
Embedded Artists LCD panel:- Version 0.7
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| richardparker | 7:6cf21b018420 | 1 | // Copyright 2010 Richard Parker |
| richardparker | 7:6cf21b018420 | 2 | |
| richardparker | 7:6cf21b018420 | 3 | #ifndef MBED_EAIMAGE_H |
| richardparker | 7:6cf21b018420 | 4 | #define MBED_EAIMAGE_H |
| richardparker | 7:6cf21b018420 | 5 | |
| richardparker | 7:6cf21b018420 | 6 | #include "mbed.h" |
| richardparker | 7:6cf21b018420 | 7 | #include <string> |
| richardparker | 7:6cf21b018420 | 8 | |
| richardparker | 7:6cf21b018420 | 9 | #include "EAWidget.h" |
| richardparker | 7:6cf21b018420 | 10 | |
| richardparker | 7:6cf21b018420 | 11 | class EALCD; |
| richardparker | 7:6cf21b018420 | 12 | class EAColor; |
| richardparker | 7:6cf21b018420 | 13 | |
| richardparker | 7:6cf21b018420 | 14 | /** |
| richardparker | 7:6cf21b018420 | 15 | * Class to handle loading and displaying an image. |
| richardparker | 7:6cf21b018420 | 16 | * @author Richard Parker |
| richardparker | 7:6cf21b018420 | 17 | */ |
| richardparker | 7:6cf21b018420 | 18 | class EAImage: public EAWidget |
| richardparker | 7:6cf21b018420 | 19 | { |
| richardparker | 7:6cf21b018420 | 20 | public: |
| richardparker | 7:6cf21b018420 | 21 | struct EABMPHeader { |
| richardparker | 7:6cf21b018420 | 22 | unsigned int headerSize; |
| richardparker | 7:6cf21b018420 | 23 | unsigned int width; |
| richardparker | 7:6cf21b018420 | 24 | unsigned int height; |
| richardparker | 7:6cf21b018420 | 25 | unsigned short noColorPlanes; |
| richardparker | 7:6cf21b018420 | 26 | unsigned short bitsPerPixel; |
| richardparker | 7:6cf21b018420 | 27 | unsigned int compressionType; |
| richardparker | 7:6cf21b018420 | 28 | unsigned int bmpSize; |
| richardparker | 7:6cf21b018420 | 29 | unsigned int horizontalRes; |
| richardparker | 7:6cf21b018420 | 30 | unsigned int verticalRes; |
| richardparker | 7:6cf21b018420 | 31 | unsigned int noColors; |
| richardparker | 7:6cf21b018420 | 32 | unsigned int noImportantColors; |
| richardparker | 7:6cf21b018420 | 33 | }; |
| richardparker | 7:6cf21b018420 | 34 | |
| richardparker | 7:6cf21b018420 | 35 | EAImage(); |
| richardparker | 7:6cf21b018420 | 36 | ~EAImage(); |
| richardparker | 7:6cf21b018420 | 37 | |
| richardparker | 7:6cf21b018420 | 38 | bool load(const std::string& path); |
| richardparker | 7:6cf21b018420 | 39 | void unload(); |
| richardparker | 7:6cf21b018420 | 40 | |
| richardparker | 7:6cf21b018420 | 41 | inline const std::string& path() const { return _path; } |
| richardparker | 7:6cf21b018420 | 42 | |
| richardparker | 7:6cf21b018420 | 43 | inline bool isValid() const { return (_path.empty() == false); } |
| richardparker | 7:6cf21b018420 | 44 | |
| richardparker | 7:6cf21b018420 | 45 | virtual void paint(EALCD& lcd); |
| richardparker | 7:6cf21b018420 | 46 | virtual void paint(EALCD& lcd, unsigned int x, unsigned int y, unsigned int w, unsigned int h); |
| richardparker | 7:6cf21b018420 | 47 | |
| richardparker | 7:6cf21b018420 | 48 | inline const EABMPHeader& info() { return _header; } |
| richardparker | 7:6cf21b018420 | 49 | |
| richardparker | 7:6cf21b018420 | 50 | inline bool isMask() { return _mask; } |
| richardparker | 7:6cf21b018420 | 51 | inline void setMask(bool value) { _mask = value; } |
| richardparker | 7:6cf21b018420 | 52 | |
| richardparker | 7:6cf21b018420 | 53 | private: |
| richardparker | 7:6cf21b018420 | 54 | std::string _path; |
| richardparker | 7:6cf21b018420 | 55 | EAColor* _palette; |
| richardparker | 7:6cf21b018420 | 56 | unsigned int _dataOffset; |
| richardparker | 7:6cf21b018420 | 57 | EABMPHeader _header; |
| richardparker | 7:6cf21b018420 | 58 | bool _mask; |
| richardparker | 7:6cf21b018420 | 59 | |
| richardparker | 7:6cf21b018420 | 60 | bool _loadHeader(const string& path); |
| richardparker | 7:6cf21b018420 | 61 | bool _loadPalette(FILE* fp); |
| richardparker | 7:6cf21b018420 | 62 | |
| richardparker | 7:6cf21b018420 | 63 | int _wordsInRow(); |
| richardparker | 7:6cf21b018420 | 64 | int _wordForX(unsigned int x); |
| richardparker | 7:6cf21b018420 | 65 | int _xWordOffset(unsigned int x); |
| richardparker | 7:6cf21b018420 | 66 | unsigned short _getColourAtOffset(unsigned int word, int offset); |
| richardparker | 7:6cf21b018420 | 67 | |
| richardparker | 7:6cf21b018420 | 68 | int _fseek(FILE* stream, long int offset, int origin); |
| richardparker | 7:6cf21b018420 | 69 | size_t _fread(void* ptr, size_t size, size_t count, FILE* stream); |
| richardparker | 7:6cf21b018420 | 70 | int _feof(FILE* stream); |
| richardparker | 7:6cf21b018420 | 71 | }; |
| richardparker | 7:6cf21b018420 | 72 | |
| richardparker | 7:6cf21b018420 | 73 | #endif |