![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Graphical demo for the LPC4088 Experiment Base Board with one of the Display Expansion Kits. This program decodes decodes and shows two png images.
PictureDemo.cpp@0:b567d56a59d7, 2014-10-03 (annotated)
- Committer:
- embeddedartists
- Date:
- Fri Oct 03 13:30:09 2014 +0000
- Revision:
- 0:b567d56a59d7
First version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:b567d56a59d7 | 1 | /****************************************************************************** |
embeddedartists | 0:b567d56a59d7 | 2 | * Includes |
embeddedartists | 0:b567d56a59d7 | 3 | *****************************************************************************/ |
embeddedartists | 0:b567d56a59d7 | 4 | |
embeddedartists | 0:b567d56a59d7 | 5 | #include "mbed.h" |
embeddedartists | 0:b567d56a59d7 | 6 | |
embeddedartists | 0:b567d56a59d7 | 7 | #include "LcdController.h" |
embeddedartists | 0:b567d56a59d7 | 8 | #include "EaLcdBoard.h" |
embeddedartists | 0:b567d56a59d7 | 9 | #include "PictureDemo.h" |
embeddedartists | 0:b567d56a59d7 | 10 | |
embeddedartists | 0:b567d56a59d7 | 11 | #include "Image.h" |
embeddedartists | 0:b567d56a59d7 | 12 | |
embeddedartists | 0:b567d56a59d7 | 13 | extern const unsigned char eaLogo_image[]; |
embeddedartists | 0:b567d56a59d7 | 14 | extern int eaLogo_image_sz; |
embeddedartists | 0:b567d56a59d7 | 15 | |
embeddedartists | 0:b567d56a59d7 | 16 | extern const unsigned char splash_image[]; |
embeddedartists | 0:b567d56a59d7 | 17 | extern int splash_image_sz; |
embeddedartists | 0:b567d56a59d7 | 18 | |
embeddedartists | 0:b567d56a59d7 | 19 | /****************************************************************************** |
embeddedartists | 0:b567d56a59d7 | 20 | * Typedefs and defines |
embeddedartists | 0:b567d56a59d7 | 21 | *****************************************************************************/ |
embeddedartists | 0:b567d56a59d7 | 22 | |
embeddedartists | 0:b567d56a59d7 | 23 | /****************************************************************************** |
embeddedartists | 0:b567d56a59d7 | 24 | * Local variables |
embeddedartists | 0:b567d56a59d7 | 25 | *****************************************************************************/ |
embeddedartists | 0:b567d56a59d7 | 26 | |
embeddedartists | 0:b567d56a59d7 | 27 | /****************************************************************************** |
embeddedartists | 0:b567d56a59d7 | 28 | * External variables |
embeddedartists | 0:b567d56a59d7 | 29 | *****************************************************************************/ |
embeddedartists | 0:b567d56a59d7 | 30 | |
embeddedartists | 0:b567d56a59d7 | 31 | |
embeddedartists | 0:b567d56a59d7 | 32 | /****************************************************************************** |
embeddedartists | 0:b567d56a59d7 | 33 | * Local functions |
embeddedartists | 0:b567d56a59d7 | 34 | *****************************************************************************/ |
embeddedartists | 0:b567d56a59d7 | 35 | |
embeddedartists | 0:b567d56a59d7 | 36 | void PictureDemo::drawCentered(const unsigned char* pData, int size, uint32_t delayMs) |
embeddedartists | 0:b567d56a59d7 | 37 | { |
embeddedartists | 0:b567d56a59d7 | 38 | Image::ImageData_t data; |
embeddedartists | 0:b567d56a59d7 | 39 | int result = Image::decode(pData, size, &data); |
embeddedartists | 0:b567d56a59d7 | 40 | if (result == 0) |
embeddedartists | 0:b567d56a59d7 | 41 | { |
embeddedartists | 0:b567d56a59d7 | 42 | // Draw the image centered on the screen |
embeddedartists | 0:b567d56a59d7 | 43 | unsigned int xoff = (windowX - data.width)/2; |
embeddedartists | 0:b567d56a59d7 | 44 | unsigned int yoff = (windowY - data.height)/2; |
embeddedartists | 0:b567d56a59d7 | 45 | for (int y = 0; y < data.height; y++) |
embeddedartists | 0:b567d56a59d7 | 46 | { |
embeddedartists | 0:b567d56a59d7 | 47 | memcpy(this->pFrmBuf1 + (y+yoff)*windowX + xoff, |
embeddedartists | 0:b567d56a59d7 | 48 | data.pixels + y*data.width, |
embeddedartists | 0:b567d56a59d7 | 49 | data.width*2); |
embeddedartists | 0:b567d56a59d7 | 50 | } |
embeddedartists | 0:b567d56a59d7 | 51 | |
embeddedartists | 0:b567d56a59d7 | 52 | free(data.pixels); |
embeddedartists | 0:b567d56a59d7 | 53 | } |
embeddedartists | 0:b567d56a59d7 | 54 | else |
embeddedartists | 0:b567d56a59d7 | 55 | { |
embeddedartists | 0:b567d56a59d7 | 56 | printf("Failed to decode image\n"); |
embeddedartists | 0:b567d56a59d7 | 57 | } |
embeddedartists | 0:b567d56a59d7 | 58 | } |
embeddedartists | 0:b567d56a59d7 | 59 | |
embeddedartists | 0:b567d56a59d7 | 60 | /****************************************************************************** |
embeddedartists | 0:b567d56a59d7 | 61 | * Public functions |
embeddedartists | 0:b567d56a59d7 | 62 | *****************************************************************************/ |
embeddedartists | 0:b567d56a59d7 | 63 | PictureDemo::PictureDemo(uint8_t *pFrameBuf, uint16_t dispWidth, uint16_t dispHeight) |
embeddedartists | 0:b567d56a59d7 | 64 | { |
embeddedartists | 0:b567d56a59d7 | 65 | this->windowX = dispWidth; |
embeddedartists | 0:b567d56a59d7 | 66 | this->windowY = dispHeight; |
embeddedartists | 0:b567d56a59d7 | 67 | this->pFrmBuf = (uint16_t *)pFrameBuf; |
embeddedartists | 0:b567d56a59d7 | 68 | this->pFrmBuf1 = (uint16_t *)pFrameBuf; |
embeddedartists | 0:b567d56a59d7 | 69 | this->pFrmBuf2 = (uint16_t *)((uint32_t)pFrameBuf + dispWidth*dispHeight*2); |
embeddedartists | 0:b567d56a59d7 | 70 | this->pFrmBuf3 = (uint16_t *)((uint32_t)pFrameBuf + dispWidth*dispHeight*4); |
embeddedartists | 0:b567d56a59d7 | 71 | } |
embeddedartists | 0:b567d56a59d7 | 72 | |
embeddedartists | 0:b567d56a59d7 | 73 | void PictureDemo::run(EaLcdBoardGPIO& lcdBoard, int image, uint32_t delayMs) |
embeddedartists | 0:b567d56a59d7 | 74 | { |
embeddedartists | 0:b567d56a59d7 | 75 | printf("PictureDemo, image %d, %dms delay\n", image, delayMs); |
embeddedartists | 0:b567d56a59d7 | 76 | |
embeddedartists | 0:b567d56a59d7 | 77 | memset(this->pFrmBuf1, 0xff, windowX*windowY*2); |
embeddedartists | 0:b567d56a59d7 | 78 | switch (image) |
embeddedartists | 0:b567d56a59d7 | 79 | { |
embeddedartists | 0:b567d56a59d7 | 80 | case 1: |
embeddedartists | 0:b567d56a59d7 | 81 | drawCentered(eaLogo_image, eaLogo_image_sz, delayMs); |
embeddedartists | 0:b567d56a59d7 | 82 | break; |
embeddedartists | 0:b567d56a59d7 | 83 | |
embeddedartists | 0:b567d56a59d7 | 84 | default: |
embeddedartists | 0:b567d56a59d7 | 85 | drawCentered(splash_image, splash_image_sz, delayMs); |
embeddedartists | 0:b567d56a59d7 | 86 | break; |
embeddedartists | 0:b567d56a59d7 | 87 | } |
embeddedartists | 0:b567d56a59d7 | 88 | |
embeddedartists | 0:b567d56a59d7 | 89 | //update framebuffer |
embeddedartists | 0:b567d56a59d7 | 90 | lcdBoard.setFrameBuffer((uint32_t)this->pFrmBuf1); |
embeddedartists | 0:b567d56a59d7 | 91 | |
embeddedartists | 0:b567d56a59d7 | 92 | wait_ms(delayMs); |
embeddedartists | 0:b567d56a59d7 | 93 | } |
embeddedartists | 0:b567d56a59d7 | 94 |