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