File library for Bitmap images (*.bmp, *.dib). Currently supports only Windows V3 format with 24-bit-per-pixel color depth.
BMPFile.h@0:4617bf407fe5, 2015-03-04 (annotated)
- Committer:
- kayekss
- Date:
- Wed Mar 04 00:29:12 2015 +0000
- Revision:
- 0:4617bf407fe5
- Child:
- 1:8cf4beca9695
Initial release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kayekss | 0:4617bf407fe5 | 1 | // ==================================================== Mar 04 2015, kayeks == |
kayekss | 0:4617bf407fe5 | 2 | // BMPFile.h |
kayekss | 0:4617bf407fe5 | 3 | // =========================================================================== |
kayekss | 0:4617bf407fe5 | 4 | // File library for Bitmap images (*.bmp, *.dib). |
kayekss | 0:4617bf407fe5 | 5 | |
kayekss | 0:4617bf407fe5 | 6 | #ifndef BMPFILE_H_ |
kayekss | 0:4617bf407fe5 | 7 | #define BMPFILE_H_ |
kayekss | 0:4617bf407fe5 | 8 | |
kayekss | 0:4617bf407fe5 | 9 | #include "mbed.h" |
kayekss | 0:4617bf407fe5 | 10 | |
kayekss | 0:4617bf407fe5 | 11 | struct BMPFile { |
kayekss | 0:4617bf407fe5 | 12 | /** Object status. |
kayekss | 0:4617bf407fe5 | 13 | * This indicates the error type when reading/parsing file is failed. */ |
kayekss | 0:4617bf407fe5 | 14 | enum Status { |
kayekss | 0:4617bf407fe5 | 15 | Success /** Read successfully. (no errors) */ |
kayekss | 0:4617bf407fe5 | 16 | , NullFilename /** File name string is missing. */ |
kayekss | 0:4617bf407fe5 | 17 | , NoSuchFile /** File is missing or cannot be opened. */ |
kayekss | 0:4617bf407fe5 | 18 | , NotABitmapFile /** File is not a bitmap image. (wrong magic number) */ |
kayekss | 0:4617bf407fe5 | 19 | , UnsupportedFormat /** Unsupported bitmap format type. */ |
kayekss | 0:4617bf407fe5 | 20 | , UnsupportedDepth /** Unsupported color depth configuration. |
kayekss | 0:4617bf407fe5 | 21 | This library does not support any indexed color depth (1/4/8 bpp). */ |
kayekss | 0:4617bf407fe5 | 22 | , AllocationFailed /** Data space allocation failed. */ |
kayekss | 0:4617bf407fe5 | 23 | }; |
kayekss | 0:4617bf407fe5 | 24 | |
kayekss | 0:4617bf407fe5 | 25 | /** Bitmap format type. */ |
kayekss | 0:4617bf407fe5 | 26 | enum Format { |
kayekss | 0:4617bf407fe5 | 27 | Windows_V3 /** Windows bitmap version 3. header size is 40 bytes. */ |
kayekss | 0:4617bf407fe5 | 28 | , Windows_V4 /** Windows bitmap version 4. header size is 108 bytes. */ |
kayekss | 0:4617bf407fe5 | 29 | , Windows_V5 /** Windows bitmap version 5. header size is 124 bytes. */ |
kayekss | 0:4617bf407fe5 | 30 | , OS2_V1 /** OS/2 bitmap version 1. header size is 12 bytes. */ |
kayekss | 0:4617bf407fe5 | 31 | , OS2_V2 /** OS/2 bitmap version 2. header size is 64 bytes. */ |
kayekss | 0:4617bf407fe5 | 32 | , Unknown /** Unknown bitmap format type. */ |
kayekss | 0:4617bf407fe5 | 33 | }; |
kayekss | 0:4617bf407fe5 | 34 | static const char* StatusString[]; |
kayekss | 0:4617bf407fe5 | 35 | static const char* FormatString[]; |
kayekss | 0:4617bf407fe5 | 36 | |
kayekss | 0:4617bf407fe5 | 37 | /** The object status. */ |
kayekss | 0:4617bf407fe5 | 38 | Status status; |
kayekss | 0:4617bf407fe5 | 39 | |
kayekss | 0:4617bf407fe5 | 40 | /** The bitmap format type. */ |
kayekss | 0:4617bf407fe5 | 41 | Format format; |
kayekss | 0:4617bf407fe5 | 42 | |
kayekss | 0:4617bf407fe5 | 43 | /** The image file size in bytes, including its header part. */ |
kayekss | 0:4617bf407fe5 | 44 | uint32_t fileSize; |
kayekss | 0:4617bf407fe5 | 45 | |
kayekss | 0:4617bf407fe5 | 46 | /** The image data part size in bytes. */ |
kayekss | 0:4617bf407fe5 | 47 | uint32_t dataSize; |
kayekss | 0:4617bf407fe5 | 48 | |
kayekss | 0:4617bf407fe5 | 49 | /** The image width in pixels. */ |
kayekss | 0:4617bf407fe5 | 50 | uint32_t width; |
kayekss | 0:4617bf407fe5 | 51 | |
kayekss | 0:4617bf407fe5 | 52 | /** The image height in pixels. */ |
kayekss | 0:4617bf407fe5 | 53 | uint32_t height; |
kayekss | 0:4617bf407fe5 | 54 | |
kayekss | 0:4617bf407fe5 | 55 | /** The color depth of the image in bit-per-pixel. */ |
kayekss | 0:4617bf407fe5 | 56 | uint16_t colorDepth; |
kayekss | 0:4617bf407fe5 | 57 | |
kayekss | 0:4617bf407fe5 | 58 | /** The data part of image (raw array). */ |
kayekss | 0:4617bf407fe5 | 59 | uint8_t* data; |
kayekss | 0:4617bf407fe5 | 60 | |
kayekss | 0:4617bf407fe5 | 61 | /** Constructor of struct BMPFile. |
kayekss | 0:4617bf407fe5 | 62 | * @param filename Input file name string. |
kayekss | 0:4617bf407fe5 | 63 | */ |
kayekss | 0:4617bf407fe5 | 64 | BMPFile(const char* filename); |
kayekss | 0:4617bf407fe5 | 65 | |
kayekss | 0:4617bf407fe5 | 66 | /** Destructor of struct BMPFile. */ |
kayekss | 0:4617bf407fe5 | 67 | ~BMPFile(); |
kayekss | 0:4617bf407fe5 | 68 | }; |
kayekss | 0:4617bf407fe5 | 69 | |
kayekss | 0:4617bf407fe5 | 70 | #endif |