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@5:f4de114c31c3, 2014-12-21 (annotated)
- Committer:
- embeddedartists
- Date:
- Sun Dec 21 13:53:07 2014 +0100
- Revision:
- 5:f4de114c31c3
- Parent:
- 3:3fabfe3339b8
- Child:
- 17:6e2abf107800
- Added support for RAW images
- Added SlideShow + App for it
- Moved App-specific stuff out from the AppLauncher and into main
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 1:46c8df4608c8 | 1 | /* |
embeddedartists | 1:46c8df4608c8 | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 1:46c8df4608c8 | 3 | * |
embeddedartists | 1:46c8df4608c8 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 1:46c8df4608c8 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 1:46c8df4608c8 | 6 | * You may obtain a copy of the License at |
embeddedartists | 1:46c8df4608c8 | 7 | * |
embeddedartists | 1:46c8df4608c8 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 1:46c8df4608c8 | 9 | * |
embeddedartists | 1:46c8df4608c8 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 1:46c8df4608c8 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 1:46c8df4608c8 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 1:46c8df4608c8 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 1:46c8df4608c8 | 14 | * limitations under the License. |
embeddedartists | 1:46c8df4608c8 | 15 | */ |
embeddedartists | 0:4977187e90c7 | 16 | |
embeddedartists | 0:4977187e90c7 | 17 | #ifndef IMAGE_H |
embeddedartists | 0:4977187e90c7 | 18 | #define IMAGE_H |
embeddedartists | 0:4977187e90c7 | 19 | |
embeddedartists | 3:3fabfe3339b8 | 20 | #include "mbed.h" |
embeddedartists | 5:f4de114c31c3 | 21 | #include "rtos.h" |
embeddedartists | 3:3fabfe3339b8 | 22 | |
embeddedartists | 0:4977187e90c7 | 23 | /** |
embeddedartists | 1:46c8df4608c8 | 24 | * Image example |
embeddedartists | 0:4977187e90c7 | 25 | * |
embeddedartists | 0:4977187e90c7 | 26 | * @code |
embeddedartists | 0:4977187e90c7 | 27 | * #include "mbed.h" |
embeddedartists | 0:4977187e90c7 | 28 | * #include "Image.h" |
embeddedartists | 0:4977187e90c7 | 29 | * |
embeddedartists | 0:4977187e90c7 | 30 | * const unsigned char cube_image1[] = { 137,80,78,71, ... }; |
embeddedartists | 0:4977187e90c7 | 31 | * int cube_image1_sz = sizeof(cube_image1); |
embeddedartists | 0:4977187e90c7 | 32 | * |
embeddedartists | 0:4977187e90c7 | 33 | * int main(void) { |
embeddedartists | 0:4977187e90c7 | 34 | * // initialize the display |
embeddedartists | 0:4977187e90c7 | 35 | * ... |
embeddedartists | 0:4977187e90c7 | 36 | * |
embeddedartists | 0:4977187e90c7 | 37 | * // decode an image from an array |
embeddedartists | 0:4977187e90c7 | 38 | * Image::ImageData_t img; |
embeddedartists | 0:4977187e90c7 | 39 | * if (Image::decode(cube_image1, cube_image1_sz, &img) == 0) { |
embeddedartists | 0:4977187e90c7 | 40 | * // draw on display using img.pixels, img.width and img.height |
embeddedartists | 0:4977187e90c7 | 41 | * ... |
embeddedartists | 0:4977187e90c7 | 42 | * free(img.pixels); |
embeddedartists | 0:4977187e90c7 | 43 | * } |
embeddedartists | 0:4977187e90c7 | 44 | * |
embeddedartists | 0:4977187e90c7 | 45 | * // decode an image from a file |
embeddedartists | 0:4977187e90c7 | 46 | * if (Image::decode("/ram/image.png", &img) == 0) { |
embeddedartists | 0:4977187e90c7 | 47 | * // draw on display using img.pixels, img.width and img.height |
embeddedartists | 0:4977187e90c7 | 48 | * ... |
embeddedartists | 0:4977187e90c7 | 49 | * free(img.pixels); |
embeddedartists | 0:4977187e90c7 | 50 | * } |
embeddedartists | 0:4977187e90c7 | 51 | * } |
embeddedartists | 0:4977187e90c7 | 52 | * @endcode |
embeddedartists | 0:4977187e90c7 | 53 | */ |
embeddedartists | 0:4977187e90c7 | 54 | class Image { |
embeddedartists | 0:4977187e90c7 | 55 | public: |
embeddedartists | 0:4977187e90c7 | 56 | |
embeddedartists | 0:4977187e90c7 | 57 | enum Type { |
embeddedartists | 0:4977187e90c7 | 58 | BMP = 0, |
embeddedartists | 0:4977187e90c7 | 59 | PNG, |
embeddedartists | 5:f4de114c31c3 | 60 | RAW, /* Image prepared with the img_conv.jar tool */ |
embeddedartists | 0:4977187e90c7 | 61 | UNKNOWN |
embeddedartists | 0:4977187e90c7 | 62 | }; |
embeddedartists | 0:4977187e90c7 | 63 | |
embeddedartists | 0:4977187e90c7 | 64 | enum Resolution { |
embeddedartists | 0:4977187e90c7 | 65 | RES_16BIT, |
embeddedartists | 0:4977187e90c7 | 66 | RES_24BIT |
embeddedartists | 0:4977187e90c7 | 67 | }; |
embeddedartists | 0:4977187e90c7 | 68 | |
embeddedartists | 0:4977187e90c7 | 69 | typedef struct { |
embeddedartists | 0:4977187e90c7 | 70 | uint16_t* pixels; |
embeddedartists | 0:4977187e90c7 | 71 | uint32_t width; |
embeddedartists | 0:4977187e90c7 | 72 | uint32_t height; |
embeddedartists | 0:4977187e90c7 | 73 | Resolution res; |
embeddedartists | 5:f4de114c31c3 | 74 | void* pointerToFree; |
embeddedartists | 0:4977187e90c7 | 75 | } ImageData_t; |
embeddedartists | 0:4977187e90c7 | 76 | |
embeddedartists | 0:4977187e90c7 | 77 | /** Decodes the specified image data |
embeddedartists | 0:4977187e90c7 | 78 | * |
embeddedartists | 0:4977187e90c7 | 79 | * Note that if this function returns a zero, indicating success, |
embeddedartists | 0:4977187e90c7 | 80 | * the pixels member of the pDataOut structure must be |
embeddedartists | 1:46c8df4608c8 | 81 | * deallocated using free() when no longer needed. |
embeddedartists | 0:4977187e90c7 | 82 | * |
embeddedartists | 0:4977187e90c7 | 83 | * @param pDataIn the image data |
embeddedartists | 0:4977187e90c7 | 84 | * @param sizeIn the number of bytes in the pDataIn array |
embeddedartists | 1:46c8df4608c8 | 85 | * @param res the format of the display |
embeddedartists | 0:4977187e90c7 | 86 | * @param pDataOut the decoded image (only valid if 0 is returned) |
embeddedartists | 0:4977187e90c7 | 87 | * |
embeddedartists | 0:4977187e90c7 | 88 | * @returns |
embeddedartists | 0:4977187e90c7 | 89 | * 0 on success |
embeddedartists | 0:4977187e90c7 | 90 | * 1 on failure |
embeddedartists | 0:4977187e90c7 | 91 | */ |
embeddedartists | 0:4977187e90c7 | 92 | static int decode(const unsigned char* pDataIn, unsigned int sizeIn, Resolution res, ImageData_t* pDataOut); |
embeddedartists | 0:4977187e90c7 | 93 | |
embeddedartists | 1:46c8df4608c8 | 94 | /** Reads the specified file and decodes the image data |
embeddedartists | 1:46c8df4608c8 | 95 | * |
embeddedartists | 1:46c8df4608c8 | 96 | * Note that if this function returns a zero, indicating success, |
embeddedartists | 1:46c8df4608c8 | 97 | * the pixels member of the pDataOut structure must be |
embeddedartists | 1:46c8df4608c8 | 98 | * deallocated using free() when no longer needed. |
embeddedartists | 1:46c8df4608c8 | 99 | * |
embeddedartists | 1:46c8df4608c8 | 100 | * @param filename the file name and path |
embeddedartists | 1:46c8df4608c8 | 101 | * @param res the format of the display |
embeddedartists | 1:46c8df4608c8 | 102 | * @param pDataOut the decoded image (only valid if 0 is returned) |
embeddedartists | 5:f4de114c31c3 | 103 | * @param pLock an optional mutex to prevent multiple access to file operations |
embeddedartists | 1:46c8df4608c8 | 104 | * |
embeddedartists | 1:46c8df4608c8 | 105 | * @returns |
embeddedartists | 1:46c8df4608c8 | 106 | * 0 on success |
embeddedartists | 1:46c8df4608c8 | 107 | * 1 on failure |
embeddedartists | 1:46c8df4608c8 | 108 | */ |
embeddedartists | 5:f4de114c31c3 | 109 | static int decode(const char* filename, Resolution res, ImageData_t* pDataOut, Mutex* pLock=NULL); |
embeddedartists | 0:4977187e90c7 | 110 | |
embeddedartists | 0:4977187e90c7 | 111 | private: |
embeddedartists | 0:4977187e90c7 | 112 | |
embeddedartists | 0:4977187e90c7 | 113 | /** No instance needed |
embeddedartists | 0:4977187e90c7 | 114 | * |
embeddedartists | 0:4977187e90c7 | 115 | */ |
embeddedartists | 0:4977187e90c7 | 116 | Image(); |
embeddedartists | 0:4977187e90c7 | 117 | |
embeddedartists | 0:4977187e90c7 | 118 | static Type imageType(const unsigned char* pDataIn, unsigned int sizeIn); |
embeddedartists | 0:4977187e90c7 | 119 | |
embeddedartists | 0:4977187e90c7 | 120 | static uint32_t fileSize(FILE* f); |
embeddedartists | 0:4977187e90c7 | 121 | }; |
embeddedartists | 0:4977187e90c7 | 122 | |
embeddedartists | 0:4977187e90c7 | 123 | #endif |