As of Monday morning, so this is the code we showed at Uncraftivism.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Frame.h Source File

Frame.h

00001 
00002 // We're on an LPC2368:
00003 // http://www.standardics.nxp.com/support/documents/microcontrollers/pdf/user.manual.lpc23xx.pdf
00004 // so we have 32k of RAM available
00005 // The faster MBEDs use the 1768, with 64k of RAM
00006 
00007 // Assume we will work at 80x60, 1 byte per pixel, hence 5k/frame
00008 
00009 // This class keeps an array of reusable frames - 
00010 //   Get one with a call of Frame::allocFrame, 
00011 //   Give it back with Frame::releaseFrame
00012 
00013 #define MAX_FRAMES 10
00014 
00015 class Frame
00016 {
00017 private:
00018     Frame();
00019     ~Frame();
00020     void init( uint8_t pixelFormat, uint16_t width, uint16_t height, uint32_t frameSize );
00021 
00022 public:
00023     uint16_t getPixel( uint32_t p );
00024     void setPixel( uint32_t p, uint16_t  );
00025     void writeToFile( char *filename );
00026     static void readFromFile( char *filename, Frame **frame );
00027 
00028 
00029     // Use these methods to manage a pool of frames to avoid fragmentation
00030     static void initFrames();
00031     static void allocFrame( Frame **frame, uint8_t pixelFormat, uint16_t width, uint16_t height, uint16_t frameSize );
00032     static void releaseFrame( Frame **frame );
00033     static void cloneFrame( Frame **clone, Frame* original );
00034     
00035 private:
00036     static Frame* m_frames[MAX_FRAMES];
00037 
00038 public:
00039     uint8_t *m_pixels;
00040     uint16_t m_width;
00041     uint16_t m_height;
00042     uint8_t m_pixelFormat;
00043     uint32_t m_frameSize;
00044     uint8_t m_bitsPerPixel;
00045     uint32_t m_numPixels;
00046     bool m_deleted;
00047     bool m_bad;
00048 
00049 };