Merge to XFA: Use stdint.h types throughout PDFium.
[pdfium.git] / core / src / fxcodec / lbmp / fx_bmp.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include <setjmp.h>\r
8 \r
9 #include "../../../include/fxcrt/fx_basic.h"\r
10 \r
11 #define BMP_SUPPORT_BITFIELD\r
12 #define BMP_WIDTHBYTES(width,bitCount)  ((width*bitCount) + 31)/32*4\r
13 #define BMP_PAL_ENCODE(a,r,g,b) (((FX_DWORD)(a) << 24) | ((r) << 16) | ((g) << 8) | (b))\r
14 #define BMP_D_STATUS_HEADER             0x01\r
15 #define BMP_D_STATUS_PAL                0x02\r
16 #define BMP_D_STATUS_DATA_PRE   0x03\r
17 #define BMP_D_STATUS_DATA               0x04\r
18 #define BMP_D_STATUS_TAIL               0x00\r
19 #define BMP_SIGNATURE   0x4D42\r
20 #define BMP_PAL_NEW             0\r
21 #define BMP_PAL_OLD             1\r
22 #define RLE_MARKER              0\r
23 #define RLE_EOL                 0\r
24 #define RLE_EOI                 1\r
25 #define RLE_DELTA               2\r
26 #define BMP_RGB                 0L\r
27 #define BMP_RLE8                1L\r
28 #define BMP_RLE4                2L\r
29 #define BMP_BITFIELDS   3L\r
30 #define BMP_BIT_555             0\r
31 #define BMP_BIT_565             1\r
32 #define BMP_MAX_ERROR_SIZE      256\r
33 #pragma pack(1)\r
34 typedef struct tagBmpFileHeader {\r
35     FX_WORD             bfType;\r
36     FX_DWORD    bfSize;\r
37     FX_WORD             bfReserved1;\r
38     FX_WORD             bfReserved2;\r
39     FX_DWORD    bfOffBits;\r
40 } BmpFileHeader, *BmpFileHeaderPtr;\r
41 typedef struct tagBmpCoreHeader {\r
42     FX_DWORD   bcSize;\r
43     FX_WORD    bcWidth;\r
44     FX_WORD    bcHeight;\r
45     FX_WORD    bcPlanes;\r
46     FX_WORD    bcBitCount;\r
47 } BmpCoreHeader, *BmpCoreHeaderPtr;\r
48 typedef struct tagBmpInfoHeader {\r
49     FX_DWORD    biSize;\r
50     int32_t     biWidth;\r
51     int32_t     biHeight;\r
52     FX_WORD             biPlanes;\r
53     FX_WORD             biBitCount;\r
54     FX_DWORD    biCompression;\r
55     FX_DWORD    biSizeImage;\r
56     int32_t     biXPelsPerMeter;\r
57     int32_t     biYPelsPerMeter;\r
58     FX_DWORD    biClrUsed;\r
59     FX_DWORD    biClrImportant;\r
60 } BmpInfoHeader, *BmpInfoHeaderPtr;\r
61 #pragma pack()\r
62 typedef struct tag_bmp_decompress_struct bmp_decompress_struct;\r
63 typedef bmp_decompress_struct *bmp_decompress_struct_p;\r
64 typedef bmp_decompress_struct_p *bmp_decompress_struct_pp;\r
65 struct tag_bmp_decompress_struct {\r
66     jmp_buf                     jmpbuf;\r
67     FX_LPSTR            err_ptr;\r
68     void                        (*_bmp_error_fn)(bmp_decompress_struct_p gif_ptr, FX_LPCSTR err_msg);\r
69 \r
70     void*                       context_ptr;\r
71 \r
72     BmpFileHeaderPtr    bmp_header_ptr;\r
73     BmpInfoHeaderPtr    bmp_infoheader_ptr;\r
74     int32_t             width;\r
75     int32_t             height;\r
76     FX_DWORD            compress_flag;\r
77     int32_t             components;\r
78     int32_t             src_row_bytes;\r
79     int32_t             out_row_bytes;\r
80     FX_LPBYTE           out_row_buffer;\r
81     FX_WORD                     bitCounts;\r
82     FX_DWORD            color_used;\r
83     FX_BOOL                     imgTB_flag;\r
84     int32_t             pal_num;\r
85     int32_t             pal_type;\r
86     FX_DWORD*           pal_ptr;\r
87     FX_DWORD            data_size;\r
88     FX_DWORD            img_data_offset;\r
89     FX_DWORD            img_ifh_size;\r
90     int32_t             row_num;\r
91     int32_t             col_num;\r
92     int32_t             dpi_x;\r
93     int32_t             dpi_y;\r
94 #ifdef BMP_SUPPORT_BITFIELD\r
95     FX_DWORD            mask_red;\r
96     FX_DWORD            mask_green;\r
97     FX_DWORD            mask_blue;\r
98 #endif\r
99 \r
100     FX_BOOL                     (*_bmp_get_data_position_fn)(bmp_decompress_struct_p bmp_ptr, FX_DWORD cur_pos);\r
101     void                        (*_bmp_get_row_fn)(bmp_decompress_struct_p bmp_ptr, int32_t row_num, FX_LPBYTE row_buf);\r
102     FX_LPBYTE           next_in;\r
103     FX_DWORD            avail_in;\r
104     FX_DWORD            skip_size;\r
105     int32_t             decode_status;\r
106 };\r
107 void _bmp_error(bmp_decompress_struct_p bmp_ptr, FX_LPCSTR err_msg);\r
108 bmp_decompress_struct_p _bmp_create_decompress();\r
109 void _bmp_destroy_decompress(bmp_decompress_struct_pp bmp_ptr_ptr);\r
110 int32_t _bmp_read_header(bmp_decompress_struct_p bmp_ptr);\r
111 int32_t _bmp_decode_image(bmp_decompress_struct_p bmp_ptr);\r
112 int32_t _bmp_decode_rgb(bmp_decompress_struct_p bmp_ptr);\r
113 int32_t _bmp_decode_rle8(bmp_decompress_struct_p bmp_ptr);\r
114 int32_t _bmp_decode_rle4(bmp_decompress_struct_p bmp_ptr);\r
115 FX_LPBYTE _bmp_read_data(bmp_decompress_struct_p bmp_ptr, FX_LPBYTE* des_buf_pp, FX_DWORD data_size);\r
116 void _bmp_save_decoding_status(bmp_decompress_struct_p bmp_ptr, int32_t status);\r
117 void _bmp_input_buffer(bmp_decompress_struct_p bmp_ptr, FX_LPBYTE src_buf, FX_DWORD src_size);\r
118 FX_DWORD _bmp_get_avail_input(bmp_decompress_struct_p bmp_ptr, FX_LPBYTE* avial_buf_ptr);\r
119 #define BMP_PTR_NOT_NULL(ptr,bmp_ptr)   if(ptr == NULL){                                                \\r
120         _bmp_error(bmp_ptr,"Out Of Memory");\\r
121         return 0;                                                       \\r
122     }\r
123 typedef struct tag_bmp_compress_struct bmp_compress_struct;\r
124 typedef bmp_compress_struct *bmp_compress_struct_p;\r
125 typedef bmp_compress_struct_p *bmp_compress_struct_pp;\r
126 struct tag_bmp_compress_struct {\r
127     BmpFileHeader       file_header;\r
128     BmpInfoHeader       info_header;\r
129     FX_LPBYTE           src_buf;\r
130     FX_DWORD            src_pitch;\r
131     FX_DWORD            src_row;\r
132     uint8_t                     src_bpp;\r
133     FX_DWORD            src_width;\r
134     FX_BOOL                     src_free;\r
135     FX_DWORD*           pal_ptr;\r
136     FX_WORD                     pal_num;\r
137 #ifdef BMP_SUPPORT_BITFIELD\r
138     uint8_t                     bit_type;\r
139 #endif\r
140 };\r
141 bmp_compress_struct_p _bmp_create_compress();\r
142 void _bmp_destroy_compress(bmp_compress_struct_p bmp_ptr);\r
143 FX_BOOL _bmp_encode_image(bmp_compress_struct_p bmp_ptr, FX_LPBYTE& dst_buf, FX_DWORD& dst_size);\r