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 EmbeddedArtists AB

Committer:
embeddedartists
Date:
Fri Dec 19 09:12:51 2014 +0100
Revision:
3:3fabfe3339b8
Parent:
1:46c8df4608c8
Child:
5:f4de114c31c3
- Fixed bug in Clickable
- Fixed missing include in Image
- Updated to match the new TouchPanel interface

Who changed what in which revision?

UserRevisionLine numberNew 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 3:3fabfe3339b8 21
embeddedartists 0:4977187e90c7 22 /**
embeddedartists 1:46c8df4608c8 23 * Image example
embeddedartists 0:4977187e90c7 24 *
embeddedartists 0:4977187e90c7 25 * @code
embeddedartists 0:4977187e90c7 26 * #include "mbed.h"
embeddedartists 0:4977187e90c7 27 * #include "Image.h"
embeddedartists 0:4977187e90c7 28 *
embeddedartists 0:4977187e90c7 29 * const unsigned char cube_image1[] = { 137,80,78,71, ... };
embeddedartists 0:4977187e90c7 30 * int cube_image1_sz = sizeof(cube_image1);
embeddedartists 0:4977187e90c7 31 *
embeddedartists 0:4977187e90c7 32 * int main(void) {
embeddedartists 0:4977187e90c7 33 * // initialize the display
embeddedartists 0:4977187e90c7 34 * ...
embeddedartists 0:4977187e90c7 35 *
embeddedartists 0:4977187e90c7 36 * // decode an image from an array
embeddedartists 0:4977187e90c7 37 * Image::ImageData_t img;
embeddedartists 0:4977187e90c7 38 * if (Image::decode(cube_image1, cube_image1_sz, &img) == 0) {
embeddedartists 0:4977187e90c7 39 * // draw on display using img.pixels, img.width and img.height
embeddedartists 0:4977187e90c7 40 * ...
embeddedartists 0:4977187e90c7 41 * free(img.pixels);
embeddedartists 0:4977187e90c7 42 * }
embeddedartists 0:4977187e90c7 43 *
embeddedartists 0:4977187e90c7 44 * // decode an image from a file
embeddedartists 0:4977187e90c7 45 * if (Image::decode("/ram/image.png", &img) == 0) {
embeddedartists 0:4977187e90c7 46 * // draw on display using img.pixels, img.width and img.height
embeddedartists 0:4977187e90c7 47 * ...
embeddedartists 0:4977187e90c7 48 * free(img.pixels);
embeddedartists 0:4977187e90c7 49 * }
embeddedartists 0:4977187e90c7 50 * }
embeddedartists 0:4977187e90c7 51 * @endcode
embeddedartists 0:4977187e90c7 52 */
embeddedartists 0:4977187e90c7 53 class Image {
embeddedartists 0:4977187e90c7 54 public:
embeddedartists 0:4977187e90c7 55
embeddedartists 0:4977187e90c7 56 enum Type {
embeddedartists 0:4977187e90c7 57 BMP = 0,
embeddedartists 0:4977187e90c7 58 PNG,
embeddedartists 0:4977187e90c7 59 UNKNOWN
embeddedartists 0:4977187e90c7 60 };
embeddedartists 0:4977187e90c7 61
embeddedartists 0:4977187e90c7 62 enum Resolution {
embeddedartists 0:4977187e90c7 63 RES_16BIT,
embeddedartists 0:4977187e90c7 64 RES_24BIT
embeddedartists 0:4977187e90c7 65 };
embeddedartists 0:4977187e90c7 66
embeddedartists 0:4977187e90c7 67 typedef struct {
embeddedartists 0:4977187e90c7 68 uint16_t* pixels;
embeddedartists 0:4977187e90c7 69 uint32_t width;
embeddedartists 0:4977187e90c7 70 uint32_t height;
embeddedartists 0:4977187e90c7 71 Resolution res;
embeddedartists 0:4977187e90c7 72 } ImageData_t;
embeddedartists 0:4977187e90c7 73
embeddedartists 0:4977187e90c7 74 /** Decodes the specified image data
embeddedartists 0:4977187e90c7 75 *
embeddedartists 0:4977187e90c7 76 * Note that if this function returns a zero, indicating success,
embeddedartists 0:4977187e90c7 77 * the pixels member of the pDataOut structure must be
embeddedartists 1:46c8df4608c8 78 * deallocated using free() when no longer needed.
embeddedartists 0:4977187e90c7 79 *
embeddedartists 0:4977187e90c7 80 * @param pDataIn the image data
embeddedartists 0:4977187e90c7 81 * @param sizeIn the number of bytes in the pDataIn array
embeddedartists 1:46c8df4608c8 82 * @param res the format of the display
embeddedartists 0:4977187e90c7 83 * @param pDataOut the decoded image (only valid if 0 is returned)
embeddedartists 0:4977187e90c7 84 *
embeddedartists 0:4977187e90c7 85 * @returns
embeddedartists 0:4977187e90c7 86 * 0 on success
embeddedartists 0:4977187e90c7 87 * 1 on failure
embeddedartists 0:4977187e90c7 88 */
embeddedartists 0:4977187e90c7 89 static int decode(const unsigned char* pDataIn, unsigned int sizeIn, Resolution res, ImageData_t* pDataOut);
embeddedartists 0:4977187e90c7 90
embeddedartists 1:46c8df4608c8 91 /** Reads the specified file and decodes the image data
embeddedartists 1:46c8df4608c8 92 *
embeddedartists 1:46c8df4608c8 93 * Note that if this function returns a zero, indicating success,
embeddedartists 1:46c8df4608c8 94 * the pixels member of the pDataOut structure must be
embeddedartists 1:46c8df4608c8 95 * deallocated using free() when no longer needed.
embeddedartists 1:46c8df4608c8 96 *
embeddedartists 1:46c8df4608c8 97 * @param filename the file name and path
embeddedartists 1:46c8df4608c8 98 * @param res the format of the display
embeddedartists 1:46c8df4608c8 99 * @param pDataOut the decoded image (only valid if 0 is returned)
embeddedartists 1:46c8df4608c8 100 *
embeddedartists 1:46c8df4608c8 101 * @returns
embeddedartists 1:46c8df4608c8 102 * 0 on success
embeddedartists 1:46c8df4608c8 103 * 1 on failure
embeddedartists 1:46c8df4608c8 104 */
embeddedartists 0:4977187e90c7 105 static int decode(const char* filename, Resolution res, ImageData_t* pDataOut);
embeddedartists 0:4977187e90c7 106
embeddedartists 0:4977187e90c7 107 private:
embeddedartists 0:4977187e90c7 108
embeddedartists 0:4977187e90c7 109 /** No instance needed
embeddedartists 0:4977187e90c7 110 *
embeddedartists 0:4977187e90c7 111 */
embeddedartists 0:4977187e90c7 112 Image();
embeddedartists 0:4977187e90c7 113
embeddedartists 0:4977187e90c7 114 static Type imageType(const unsigned char* pDataIn, unsigned int sizeIn);
embeddedartists 0:4977187e90c7 115
embeddedartists 0:4977187e90c7 116 static uint32_t fileSize(FILE* f);
embeddedartists 0:4977187e90c7 117 };
embeddedartists 0:4977187e90c7 118
embeddedartists 0:4977187e90c7 119 #endif