A basic graphics package for the LPC4088 Display Module.
Dependents: lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI lpc4088_displaymodule_fs_aid ... more
Fork of DMBasicGUI by
Application/Image.h@0:4977187e90c7, 2014-12-11 (annotated)
- Committer:
- embeddedartists
- Date:
- Thu Dec 11 11:03:57 2014 +0000
- Revision:
- 0:4977187e90c7
- Child:
- 1:46c8df4608c8
First version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:4977187e90c7 | 1 | |
embeddedartists | 0:4977187e90c7 | 2 | #ifndef IMAGE_H |
embeddedartists | 0:4977187e90c7 | 3 | #define IMAGE_H |
embeddedartists | 0:4977187e90c7 | 4 | |
embeddedartists | 0:4977187e90c7 | 5 | /** |
embeddedartists | 0:4977187e90c7 | 6 | * LcdController example |
embeddedartists | 0:4977187e90c7 | 7 | * |
embeddedartists | 0:4977187e90c7 | 8 | * @code |
embeddedartists | 0:4977187e90c7 | 9 | * #include "mbed.h" |
embeddedartists | 0:4977187e90c7 | 10 | * #include "Image.h" |
embeddedartists | 0:4977187e90c7 | 11 | * |
embeddedartists | 0:4977187e90c7 | 12 | * const unsigned char cube_image1[] = { 137,80,78,71, ... }; |
embeddedartists | 0:4977187e90c7 | 13 | * int cube_image1_sz = sizeof(cube_image1); |
embeddedartists | 0:4977187e90c7 | 14 | * |
embeddedartists | 0:4977187e90c7 | 15 | * int main(void) { |
embeddedartists | 0:4977187e90c7 | 16 | * // initialize the display |
embeddedartists | 0:4977187e90c7 | 17 | * ... |
embeddedartists | 0:4977187e90c7 | 18 | * |
embeddedartists | 0:4977187e90c7 | 19 | * // decode an image from an array |
embeddedartists | 0:4977187e90c7 | 20 | * Image::ImageData_t img; |
embeddedartists | 0:4977187e90c7 | 21 | * if (Image::decode(cube_image1, cube_image1_sz, &img) == 0) { |
embeddedartists | 0:4977187e90c7 | 22 | * // draw on display using img.pixels, img.width and img.height |
embeddedartists | 0:4977187e90c7 | 23 | * ... |
embeddedartists | 0:4977187e90c7 | 24 | * free(img.pixels); |
embeddedartists | 0:4977187e90c7 | 25 | * } |
embeddedartists | 0:4977187e90c7 | 26 | * |
embeddedartists | 0:4977187e90c7 | 27 | * // decode an image from a file |
embeddedartists | 0:4977187e90c7 | 28 | * if (Image::decode("/ram/image.png", &img) == 0) { |
embeddedartists | 0:4977187e90c7 | 29 | * // draw on display using img.pixels, img.width and img.height |
embeddedartists | 0:4977187e90c7 | 30 | * ... |
embeddedartists | 0:4977187e90c7 | 31 | * free(img.pixels); |
embeddedartists | 0:4977187e90c7 | 32 | * } |
embeddedartists | 0:4977187e90c7 | 33 | * } |
embeddedartists | 0:4977187e90c7 | 34 | * @endcode |
embeddedartists | 0:4977187e90c7 | 35 | */ |
embeddedartists | 0:4977187e90c7 | 36 | class Image { |
embeddedartists | 0:4977187e90c7 | 37 | public: |
embeddedartists | 0:4977187e90c7 | 38 | |
embeddedartists | 0:4977187e90c7 | 39 | enum Type { |
embeddedartists | 0:4977187e90c7 | 40 | BMP = 0, |
embeddedartists | 0:4977187e90c7 | 41 | PNG, |
embeddedartists | 0:4977187e90c7 | 42 | UNKNOWN |
embeddedartists | 0:4977187e90c7 | 43 | }; |
embeddedartists | 0:4977187e90c7 | 44 | |
embeddedartists | 0:4977187e90c7 | 45 | enum Resolution { |
embeddedartists | 0:4977187e90c7 | 46 | RES_16BIT, |
embeddedartists | 0:4977187e90c7 | 47 | RES_24BIT |
embeddedartists | 0:4977187e90c7 | 48 | }; |
embeddedartists | 0:4977187e90c7 | 49 | |
embeddedartists | 0:4977187e90c7 | 50 | typedef struct { |
embeddedartists | 0:4977187e90c7 | 51 | uint16_t* pixels; |
embeddedartists | 0:4977187e90c7 | 52 | uint32_t width; |
embeddedartists | 0:4977187e90c7 | 53 | uint32_t height; |
embeddedartists | 0:4977187e90c7 | 54 | Resolution res; |
embeddedartists | 0:4977187e90c7 | 55 | } ImageData_t; |
embeddedartists | 0:4977187e90c7 | 56 | |
embeddedartists | 0:4977187e90c7 | 57 | /** Decodes the specified image data |
embeddedartists | 0:4977187e90c7 | 58 | * |
embeddedartists | 0:4977187e90c7 | 59 | * Note that if this function returns a zero, indicating success, |
embeddedartists | 0:4977187e90c7 | 60 | * the pixels member of the pDataOut structure must be |
embeddedartists | 0:4977187e90c7 | 61 | * deallocated using lpc_free() when no longer needed. |
embeddedartists | 0:4977187e90c7 | 62 | * |
embeddedartists | 0:4977187e90c7 | 63 | * @param pDataIn the image data |
embeddedartists | 0:4977187e90c7 | 64 | * @param sizeIn the number of bytes in the pDataIn array |
embeddedartists | 0:4977187e90c7 | 65 | * @param Resolution the format of the display |
embeddedartists | 0:4977187e90c7 | 66 | * @param pDataOut the decoded image (only valid if 0 is returned) |
embeddedartists | 0:4977187e90c7 | 67 | * |
embeddedartists | 0:4977187e90c7 | 68 | * @returns |
embeddedartists | 0:4977187e90c7 | 69 | * 0 on success |
embeddedartists | 0:4977187e90c7 | 70 | * 1 on failure |
embeddedartists | 0:4977187e90c7 | 71 | */ |
embeddedartists | 0:4977187e90c7 | 72 | static int decode(const unsigned char* pDataIn, unsigned int sizeIn, Resolution res, ImageData_t* pDataOut); |
embeddedartists | 0:4977187e90c7 | 73 | |
embeddedartists | 0:4977187e90c7 | 74 | static int decode(const char* filename, Resolution res, ImageData_t* pDataOut); |
embeddedartists | 0:4977187e90c7 | 75 | |
embeddedartists | 0:4977187e90c7 | 76 | private: |
embeddedartists | 0:4977187e90c7 | 77 | |
embeddedartists | 0:4977187e90c7 | 78 | /** No instance needed |
embeddedartists | 0:4977187e90c7 | 79 | * |
embeddedartists | 0:4977187e90c7 | 80 | */ |
embeddedartists | 0:4977187e90c7 | 81 | Image(); |
embeddedartists | 0:4977187e90c7 | 82 | |
embeddedartists | 0:4977187e90c7 | 83 | static Type imageType(const unsigned char* pDataIn, unsigned int sizeIn); |
embeddedartists | 0:4977187e90c7 | 84 | |
embeddedartists | 0:4977187e90c7 | 85 | static uint32_t fileSize(FILE* f); |
embeddedartists | 0:4977187e90c7 | 86 | }; |
embeddedartists | 0:4977187e90c7 | 87 | |
embeddedartists | 0:4977187e90c7 | 88 | #endif |
embeddedartists | 0:4977187e90c7 | 89 |