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-03-04
- Revision:
- 1:f04bcaea1d60
- Parent:
- 0:839ecbf5cb2a
- Child:
- 6:4fe6f365cbeb
File content as of revision 1:f04bcaea1d60:
// 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; }
    
private:
    char* _path;
    EAColor* _palette;
    unsigned int _dataOffset;
    EABMPHeader _header;
    bool _mask;
    
    bool _loadHeader(const char* path);
    bool _loadPalette(FILE* fp);
    
    int _wordsInRow();
    int _wordForX(unsigned int x);
    int _xWordOffset(unsigned int x);
    unsigned short _getColourAtOffset(unsigned int word, int offset);
    
};
#endif