Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BMPFile.h
00001 // ==================================================== Mar 04 2015, kayeks == 00002 // BMPFile.h 00003 // =========================================================================== 00004 // File library for Bitmap images (*.bmp, *.dib). 00005 00006 #ifndef BMPFILE_H_ 00007 #define BMPFILE_H_ 00008 00009 #include "mbed.h" 00010 00011 #define ALIGN_BY_4(x) (((x) + 3) / 4 * 4) 00012 00013 struct BMPFile { 00014 /** Object status. 00015 * This indicates the error type when reading/parsing file is failed. */ 00016 enum Status { 00017 Success /** Read successfully. (no errors) */ 00018 , NullFilename /** File name string is missing. */ 00019 , NoSuchFile /** File is missing or cannot be opened. */ 00020 , NotABitmapFile /** File is not a bitmap image. (wrong magic number) */ 00021 , UnsupportedFormat /** Unsupported bitmap format type. */ 00022 , UnsupportedDepth /** Unsupported color depth configuration. 00023 This library does not support any indexed color depth (1/4/8 bpp). */ 00024 , AllocationFailed /** Data space allocation failed. */ 00025 }; 00026 00027 /** Bitmap format type. */ 00028 enum Format { 00029 OS2_V1 /** OS/2 bitmap version 1. header size is 12 bytes. */ 00030 , OS2_V2 /** OS/2 bitmap version 2. header size is 64 bytes. */ 00031 , Windows_V3 /** Windows bitmap version 3. header size is 40 bytes. */ 00032 , Windows_V4 /** Windows bitmap version 4. header size is 108 bytes. */ 00033 , Windows_V5 /** Windows bitmap version 5. header size is 124 bytes. */ 00034 , Unknown /** Unknown bitmap format type. */ 00035 }; 00036 static const char* StatusString[]; 00037 static const char* FormatString[]; 00038 00039 /** The object status. */ 00040 Status status; 00041 00042 /** The bitmap format type. */ 00043 Format format; 00044 00045 /** The image file size in bytes, including its header part. */ 00046 uint32_t fileSize; 00047 00048 /** The image palette size in bytes. */ 00049 uint32_t paletteSize; 00050 00051 /** The image data part size in bytes. */ 00052 uint32_t dataSize; 00053 00054 /** The image stride (size per line) in bytes. */ 00055 uint32_t stride; 00056 00057 /** The image width in pixels. */ 00058 uint32_t width; 00059 00060 /** The image height in pixels. */ 00061 uint32_t height; 00062 00063 /** The color depth of the image in bit-per-pixel. */ 00064 uint16_t colorDepth; 00065 00066 /** The indexed color palette of the image (raw array). */ 00067 uint8_t* palette; 00068 00069 /** The data part of image (raw array). */ 00070 uint8_t* data; 00071 00072 /** Constructor of struct BMPFile. 00073 * @param filename Input file name string. 00074 * @param fetchData Fetch image data on construct. Default value: true. 00075 */ 00076 BMPFile(const char* filename, bool fetchData=true); 00077 /** Constructor of struct BMPFile. 00078 * @param fp Input file pointer. 00079 * @param fetchData Fetch image data on construct. Default value: true. 00080 */ 00081 BMPFile(FILE* fp, bool fetchData=true); 00082 00083 /** Destructor of struct BMPFile. */ 00084 ~BMPFile(); 00085 00086 /** Get red value of specified pixel. 00087 * @param x X-coordinate of the pixel. 00088 * @param y Y-coordinate of the pixel. 00089 */ 00090 int32_t red(uint32_t x, uint32_t y); 00091 00092 /** Get green value of specified pixel. 00093 * This method returns -1 for outranged pixels. 00094 * @param x X-coordinate of the pixel. 00095 * @param y Y-coordinate of the pixel. 00096 */ 00097 int32_t green(uint32_t x, uint32_t y); 00098 00099 /** Get blue value of specified pixel. 00100 * This method returns -1 for outranged pixels. 00101 * @param x X-coordinate of the pixel. 00102 * @param y Y-coordinate of the pixel. 00103 */ 00104 int32_t blue(uint32_t x, uint32_t y); 00105 00106 /** Get red value from palette. 00107 * This method returns -1 for non-indexed image or outranged indexes. 00108 * @param index Palette color index. 00109 */ 00110 int32_t paletteRed(uint8_t index); 00111 00112 /** Get green value from palette. 00113 * This method returns -1 for non-indexed image or outranged indexes. 00114 * @param index Palette color index. 00115 */ 00116 int32_t paletteGreen(uint8_t index); 00117 00118 /** Get blue value from palette. 00119 * This method returns -1 for non-indexed image or outranged indexes. 00120 * @param index Palette color index. 00121 */ 00122 int32_t paletteBlue(uint8_t index); 00123 00124 private: 00125 void readFile(FILE* fp, bool fetchData); 00126 void readImageData(FILE* fp); 00127 static uint32_t paletteElemSize(Format format); 00128 }; 00129 00130 #endif
Generated on Wed Jul 13 2022 23:09:00 by
1.7.2