Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / include / freerdp / codec / rfx.h
1 /**
2  * FreeRDP: A Remote Desktop Protocol client.
3  * RemoteFX Codec
4  *
5  * Copyright 2011 Vic Lee
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #ifndef __RFX_H
21 #define __RFX_H
22
23 #include <freerdp/api.h>
24 #include <freerdp/types.h>
25 #include <freerdp/utils/stream.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 enum _RLGR_MODE
32 {
33         RLGR1,
34         RLGR3
35 };
36 typedef enum _RLGR_MODE RLGR_MODE;
37
38 enum _RFX_PIXEL_FORMAT
39 {
40         RFX_PIXEL_FORMAT_BGRA,
41         RFX_PIXEL_FORMAT_RGBA,
42         RFX_PIXEL_FORMAT_BGR,
43         RFX_PIXEL_FORMAT_RGB,
44         RFX_PIXEL_FORMAT_BGR565_LE,
45         RFX_PIXEL_FORMAT_RGB565_LE,
46         RFX_PIXEL_FORMAT_PALETTE4_PLANER,
47         RFX_PIXEL_FORMAT_PALETTE8
48 };
49 typedef enum _RFX_PIXEL_FORMAT RFX_PIXEL_FORMAT;
50
51 struct _RFX_RECT
52 {
53         uint16 x;
54         uint16 y;
55         uint16 width;
56         uint16 height;
57 };
58 typedef struct _RFX_RECT RFX_RECT;
59
60 struct _RFX_TILE
61 {
62         uint16 x;
63         uint16 y;
64         uint8* data;
65 };
66 typedef struct _RFX_TILE RFX_TILE;
67
68 struct _RFX_MESSAGE
69 {
70         /**
71          * The rects array represents the updated region of the frame. The UI
72          * requires to clip drawing destination base on the union of the rects.
73          */
74         uint16 num_rects;
75         RFX_RECT* rects;
76
77         /**
78          * The tiles array represents the actual frame data. Each tile is always
79          * 64x64. Note that only pixels inside the updated region (represented as
80          * rects described above) are valid. Pixels outside of the region may
81          * contain arbitrary data.
82          */
83         uint16 num_tiles;
84         RFX_TILE** tiles;
85 };
86 typedef struct _RFX_MESSAGE RFX_MESSAGE;
87
88 typedef struct _RFX_CONTEXT_PRIV RFX_CONTEXT_PRIV;
89
90 struct _RFX_CONTEXT
91 {
92         uint16 flags;
93         uint16 properties;
94         uint16 width;
95         uint16 height;
96         RLGR_MODE mode;
97         uint32 version;
98         uint32 codec_id;
99         uint32 codec_version;
100         RFX_PIXEL_FORMAT pixel_format;
101         uint8 bits_per_pixel;
102
103         /* color palette allocated by the application */
104         const uint8* palette;
105
106         /* temporary data within a frame */
107         uint32 frame_idx;
108         boolean header_processed;
109         uint8 num_quants;
110         uint32* quants;
111         uint8 quant_idx_y;
112         uint8 quant_idx_cb;
113         uint8 quant_idx_cr;
114
115         /* routines */
116         void (*decode_ycbcr_to_rgb)(sint16* y_r_buf, sint16* cb_g_buf, sint16* cr_b_buf);
117         void (*encode_rgb_to_ycbcr)(sint16* y_r_buf, sint16* cb_g_buf, sint16* cr_b_buf);
118         void (*quantization_decode)(sint16* buffer, const uint32* quantization_values);
119         void (*quantization_encode)(sint16* buffer, const uint32* quantization_values);
120         void (*dwt_2d_decode)(sint16* buffer, sint16* dwt_buffer);
121         void (*dwt_2d_encode)(sint16* buffer, sint16* dwt_buffer);
122
123         /* private definitions */
124         RFX_CONTEXT_PRIV* priv;
125 };
126 typedef struct _RFX_CONTEXT RFX_CONTEXT;
127
128 FREERDP_API RFX_CONTEXT* rfx_context_new(void);
129 FREERDP_API void rfx_context_free(RFX_CONTEXT* context);
130 FREERDP_API void rfx_context_set_cpu_opt(RFX_CONTEXT* context, uint32 cpu_opt);
131 FREERDP_API void rfx_context_set_pixel_format(RFX_CONTEXT* context, RFX_PIXEL_FORMAT pixel_format);
132 FREERDP_API void rfx_context_reset(RFX_CONTEXT* context);
133
134 FREERDP_API RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, uint8* data, uint32 length);
135 FREERDP_API uint16 rfx_message_get_tile_count(RFX_MESSAGE* message);
136 FREERDP_API RFX_TILE* rfx_message_get_tile(RFX_MESSAGE* message, int index);
137 FREERDP_API uint16 rfx_message_get_rect_count(RFX_MESSAGE* message);
138 FREERDP_API RFX_RECT* rfx_message_get_rect(RFX_MESSAGE* message, int index);
139 FREERDP_API void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message);
140
141 FREERDP_API void rfx_compose_message_header(RFX_CONTEXT* context, STREAM* s);
142 FREERDP_API void rfx_compose_message(RFX_CONTEXT* context, STREAM* s,
143         const RFX_RECT* rects, int num_rects, uint8* image_data, int width, int height, int rowstride);
144
145 #ifdef __cplusplus
146 }
147 #endif
148
149 #endif /* __RFX_H */