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.
widgets/EAImage.h
- Committer:
- richardparker
- Date:
- 2010-05-06
- Revision:
- 6:4fe6f365cbeb
- Parent:
- 1:f04bcaea1d60
File content as of revision 6:4fe6f365cbeb:
// Copyright 2010 Richard Parker
#ifndef MBED_EAIMAGE_H
#define MBED_EAIMAGE_H
#include "mbed.h"
#include "EAWidget.h"
class EALCD;
class EAColor;
/**
 * Class to handle loading and displaying an image.
 * @author Richard Parker
 */
class EAImage: public EAWidget
{
public:
    struct EABMPHeader {
        unsigned int headerSize;
        unsigned int width;
        unsigned int height;
        unsigned short noColorPlanes;
        unsigned short bitsPerPixel;
        unsigned int compressionType;
        unsigned int bmpSize;
        unsigned int horizontalRes;
        unsigned int verticalRes;
        unsigned int noColors;
        unsigned int noImportantColors;
    };
    
    EAImage();
    ~EAImage();
    
    bool load(const char* path);
    void unload();
    
    inline const char* path() const { return _path; }
    
    inline bool isValid() const { return (_path != NULL); }
    
    virtual void paint(EALCD& lcd);
    virtual void paint(EALCD& lcd, unsigned int x, unsigned int y, unsigned int w, unsigned int h);
    
    inline const EABMPHeader& info() { return _header; }
    
    inline bool isMask() { return _mask; }
    inline void setMask(bool value) { _mask = value; }
    
    inline bool isCached() { return _cached; }
    inline void setCached(bool value) { _cached = value; }
private:
    char* _path;
    EAColor* _palette;
    unsigned int _dataOffset;
    EABMPHeader _header;
    bool _mask;
    bool _cached;
    char* _cache;
    long int _size;
    long int _pos;
    
    bool _loadHeader(const char* path);
    bool _loadCache(FILE* fp);
    bool _loadPalette(FILE* fp);
    
    int _wordsInRow();
    int _wordForX(unsigned int x);
    int _xWordOffset(unsigned int x);
    unsigned short _getColourAtOffset(unsigned int word, int offset);
    
    int _fseek(FILE* stream, long int offset, int origin);
    size_t _fread(void* ptr, size_t size, size_t count, FILE* stream);
    int _feof(FILE* stream);
};
#endif