1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/src/BMPFileHeaders.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,138 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef MOZILLA_IMAGELIB_BMPHEADERS_H_ 1.9 +#define MOZILLA_IMAGELIB_BMPHEADERS_H_ 1.10 + 1.11 +namespace mozilla { 1.12 + namespace image { 1.13 + 1.14 + struct BMPFILEHEADER { 1.15 + char signature[2]; // String "BM" 1.16 + uint32_t filesize; 1.17 + int32_t reserved; // Zero 1.18 + uint32_t dataoffset; // Offset to raster data 1.19 + 1.20 + uint32_t bihsize; 1.21 + }; 1.22 + 1.23 +// The length of the bitmap file header as defined in the BMP spec. 1.24 +#define BFH_LENGTH 14 1.25 +// Internally we store the bitmap file header with an additional 4 bytes which 1.26 +// is used to store the bitmap information header size. 1.27 +#define BFH_INTERNAL_LENGTH 18 1.28 + 1.29 +#define OS2_INTERNAL_BIH_LENGTH 8 1.30 +#define WIN_V3_INTERNAL_BIH_LENGTH 36 1.31 +#define WIN_V5_INTERNAL_BIH_LENGTH 120 1.32 + 1.33 +#define OS2_BIH_LENGTH 12 // This is the real BIH size (as contained in the bihsize field of BMPFILEHEADER) 1.34 +#define WIN_V3_BIH_LENGTH 40 // This is the real BIH size (as contained in the bihsize field of BMPFILEHEADER) 1.35 +#define WIN_V5_BIH_LENGTH 124 // This is the real BIH size (as contained in the bihsize field of BMPFILEHEADER) 1.36 + 1.37 +#define OS2_HEADER_LENGTH (BFH_INTERNAL_LENGTH + OS2_INTERNAL_BIH_LENGTH) 1.38 +#define WIN_V3_HEADER_LENGTH (BFH_INTERNAL_LENGTH + WIN_V3_INTERNAL_BIH_LENGTH) 1.39 +#define WIN_V5_HEADER_LENGTH (BFH_INTERNAL_LENGTH + WIN_V5_INTERNAL_BIH_LENGTH) 1.40 + 1.41 +#ifndef LCS_sRGB 1.42 +#define LCS_sRGB 0x73524742 1.43 +#endif 1.44 + 1.45 + struct xyz { 1.46 + int32_t x, y, z; 1.47 + }; 1.48 + 1.49 + struct xyzTriple { 1.50 + xyz r, g, b; 1.51 + }; 1.52 + 1.53 + struct BITMAPV5HEADER { 1.54 + int32_t width; // Uint16 in OS/2 BMPs 1.55 + int32_t height; // Uint16 in OS/2 BMPs 1.56 + uint16_t planes; // =1 1.57 + uint16_t bpp; // Bits per pixel. 1.58 + // The rest of the header is not available in OS/2 BMP Files 1.59 + uint32_t compression; // 0=no compression 1=8bit RLE 2=4bit RLE 1.60 + uint32_t image_size; // (compressed) image size. Can be 0 if compression==0 1.61 + uint32_t xppm; // Pixels per meter, horizontal 1.62 + uint32_t yppm; // Pixels per meter, vertical 1.63 + uint32_t colors; // Used Colors 1.64 + uint32_t important_colors; // Number of important colors. 0=all 1.65 + uint32_t red_mask; // Bits used for red component 1.66 + uint32_t green_mask; // Bits used for green component 1.67 + uint32_t blue_mask; // Bits used for blue component 1.68 + uint32_t alpha_mask; // Bits used for alpha component 1.69 + uint32_t color_space; // 0x73524742=LCS_sRGB ... 1.70 + // These members are unused unless color_space == LCS_CALIBRATED_RGB 1.71 + xyzTriple white_point; // Logical white point 1.72 + uint32_t gamma_red; // Red gamma component 1.73 + uint32_t gamma_green; // Green gamma component 1.74 + uint32_t gamma_blue; // Blue gamma component 1.75 + uint32_t intent; // Rendering intent 1.76 + // These members are unused unless color_space == LCS_PROFILE_* 1.77 + uint32_t profile_offset; // Offset to profile data in bytes 1.78 + uint32_t profile_size; // Size of profile data in bytes 1.79 + uint32_t reserved; // =0 1.80 + }; 1.81 + 1.82 + struct colorTable { 1.83 + uint8_t red; 1.84 + uint8_t green; 1.85 + uint8_t blue; 1.86 + }; 1.87 + 1.88 + struct bitFields { 1.89 + uint32_t red; 1.90 + uint32_t green; 1.91 + uint32_t blue; 1.92 + uint8_t redLeftShift; 1.93 + uint8_t redRightShift; 1.94 + uint8_t greenLeftShift; 1.95 + uint8_t greenRightShift; 1.96 + uint8_t blueLeftShift; 1.97 + uint8_t blueRightShift; 1.98 + }; 1.99 + 1.100 + } // namespace image 1.101 +} // namespace mozilla 1.102 + 1.103 +#define BITFIELD_LENGTH 12 // Length of the bitfields structure in the bmp file 1.104 +#define USE_RGB 1.105 + 1.106 +// BMPINFOHEADER.compression defines 1.107 +#ifndef BI_RGB 1.108 +#define BI_RGB 0 1.109 +#endif 1.110 +#ifndef BI_RLE8 1.111 +#define BI_RLE8 1 1.112 +#endif 1.113 +#ifndef BI_RLE4 1.114 +#define BI_RLE4 2 1.115 +#endif 1.116 +#ifndef BI_BITFIELDS 1.117 +#define BI_BITFIELDS 3 1.118 +#endif 1.119 +// BI_ALPHABITFIELDS means no compression and specifies alpha bits 1.120 +// valid only for 32bpp and 16bpp 1.121 +#ifndef BI_ALPHABITFIELDS 1.122 +#define BI_ALPHABITFIELDS 4 1.123 +#endif 1.124 + 1.125 +// RLE Escape codes 1.126 +#define RLE_ESCAPE 0 1.127 +#define RLE_ESCAPE_EOL 0 1.128 +#define RLE_ESCAPE_EOF 1 1.129 +#define RLE_ESCAPE_DELTA 2 1.130 + 1.131 +/// enums for mState 1.132 +enum ERLEState { 1.133 + eRLEStateInitial, 1.134 + eRLEStateNeedSecondEscapeByte, 1.135 + eRLEStateNeedXDelta, 1.136 + eRLEStateNeedYDelta, ///< mStateData will hold x delta 1.137 + eRLEStateAbsoluteMode, ///< mStateData will hold count of existing data to read 1.138 + eRLEStateAbsoluteModePadded ///< As above, but another byte of data has to be read as padding 1.139 +}; 1.140 + 1.141 +#endif