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:
Thu Dec 11 18:15:52 2014 +0000
Revision:
1:46c8df4608c8
Parent:
0:4977187e90c7
Child:
3:3fabfe3339b8
Updated documentation

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