~ubuntu-branches/ubuntu/vivid/freerdp/vivid

« back to all changes in this revision

Viewing changes to libfreerdp/codec/rfx_decode.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-11-11 12:20:50 UTC
  • mfrom: (1.2.5)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20141111122050-7z628f4ab38qxad5
Tags: upstream-1.1.0~git20140921.1.440916e+dfsg1
ImportĀ upstreamĀ versionĀ 1.1.0~git20140921.1.440916e+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * FreeRDP: A Remote Desktop Protocol Implementation
 
3
 * RemoteFX Codec Library - Decode
 
4
 *
 
5
 * Copyright 2011 Vic Lee
 
6
 * Copyright 2011 Norbert Federa <nfedera@thinstuff.com>
 
7
 *
 
8
 * Licensed under the Apache License, Version 2.0 (the "License");
 
9
 * you may not use this file except in compliance with the License.
 
10
 * You may obtain a copy of the License at
 
11
 *
 
12
 *     http://www.apache.org/licenses/LICENSE-2.0
 
13
 *
 
14
 * Unless required by applicable law or agreed to in writing, software
 
15
 * distributed under the License is distributed on an "AS IS" BASIS,
 
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
17
 * See the License for the specific language governing permissions and
 
18
 * limitations under the License.
 
19
 */
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include "config.h"
 
23
#endif
 
24
 
 
25
#include <stdio.h>
 
26
#include <stdlib.h>
 
27
#include <string.h>
 
28
 
 
29
#include <winpr/stream.h>
 
30
#include <freerdp/primitives.h>
 
31
 
 
32
#include "rfx_types.h"
 
33
#include "rfx_rlgr.h"
 
34
#include "rfx_differential.h"
 
35
#include "rfx_quantization.h"
 
36
#include "rfx_dwt.h"
 
37
 
 
38
#include "rfx_decode.h"
 
39
 
 
40
/* stride is bytes between rows in the output buffer. */
 
41
static void rfx_decode_format_rgb(INT16* r_buf, INT16* g_buf, INT16* b_buf,
 
42
        RDP_PIXEL_FORMAT pixel_format, BYTE* dst_buf, int stride)
 
43
{
 
44
        primitives_t *prims = primitives_get();
 
45
        INT16* r = r_buf;
 
46
        INT16* g = g_buf;
 
47
        INT16* b = b_buf;
 
48
        INT16* pSrc[3];
 
49
        static const prim_size_t roi_64x64 = { 64, 64 };
 
50
        BYTE* dst = dst_buf;
 
51
        int x, y;
 
52
        
 
53
        switch (pixel_format)
 
54
        {
 
55
                case RDP_PIXEL_FORMAT_B8G8R8A8:
 
56
                        pSrc[0] = r;  pSrc[1] = g;  pSrc[2] = b;
 
57
                        prims->RGBToRGB_16s8u_P3AC4R(
 
58
                                (const INT16 **) pSrc, 64*sizeof(INT16),
 
59
                                dst, stride, &roi_64x64);
 
60
                        break;
 
61
                case RDP_PIXEL_FORMAT_R8G8B8A8:
 
62
                        pSrc[0] = b;  pSrc[1] = g;  pSrc[2] = r;
 
63
                        prims->RGBToRGB_16s8u_P3AC4R(
 
64
                                (const INT16 **) pSrc, 64*sizeof(INT16),
 
65
                                dst, stride, &roi_64x64);
 
66
                        break;
 
67
                case RDP_PIXEL_FORMAT_B8G8R8:
 
68
                        for (y=0; y<64; y++)
 
69
                        {
 
70
                                for (x=0; x<64; x++)
 
71
                                {
 
72
                                        *dst++ = (BYTE) (*b++);
 
73
                                        *dst++ = (BYTE) (*g++);
 
74
                                        *dst++ = (BYTE) (*r++);
 
75
                                }
 
76
                                dst += stride - (64*3);
 
77
                        }
 
78
                        break;
 
79
                case RDP_PIXEL_FORMAT_R8G8B8:
 
80
                        for (y=0; y<64; y++)
 
81
                        {
 
82
                                for (x=0; x<64; x++)
 
83
                                {
 
84
                                        *dst++ = (BYTE) (*r++);
 
85
                                        *dst++ = (BYTE) (*g++);
 
86
                                        *dst++ = (BYTE) (*b++);
 
87
                                }
 
88
                                dst += stride - (64*3);
 
89
                        }
 
90
                        break;
 
91
                default:
 
92
                        break;
 
93
        }
 
94
}
 
95
 
 
96
static void rfx_decode_component(RFX_CONTEXT* context, const UINT32* quantization_values,
 
97
        const BYTE* data, int size, INT16* buffer)
 
98
{
 
99
        INT16* dwt_buffer;
 
100
 
 
101
        dwt_buffer = BufferPool_Take(context->priv->BufferPool, -1); /* dwt_buffer */
 
102
 
 
103
        PROFILER_ENTER(context->priv->prof_rfx_decode_component);
 
104
 
 
105
        PROFILER_ENTER(context->priv->prof_rfx_rlgr_decode);
 
106
                context->rlgr_decode(context->mode, data, size, buffer, 4096);
 
107
        PROFILER_EXIT(context->priv->prof_rfx_rlgr_decode);
 
108
 
 
109
        PROFILER_ENTER(context->priv->prof_rfx_differential_decode);
 
110
                rfx_differential_decode(buffer + 4032, 64);
 
111
        PROFILER_EXIT(context->priv->prof_rfx_differential_decode);
 
112
 
 
113
        PROFILER_ENTER(context->priv->prof_rfx_quantization_decode);
 
114
                context->quantization_decode(buffer, quantization_values);
 
115
        PROFILER_EXIT(context->priv->prof_rfx_quantization_decode);
 
116
 
 
117
        PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_decode);
 
118
                context->dwt_2d_decode(buffer, dwt_buffer);
 
119
        PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_decode);
 
120
 
 
121
        PROFILER_EXIT(context->priv->prof_rfx_decode_component);
 
122
 
 
123
        BufferPool_Return(context->priv->BufferPool, dwt_buffer);
 
124
}
 
125
 
 
126
/* rfx_decode_ycbcr_to_rgb code now resides in the primitives library. */
 
127
 
 
128
struct _RFX_COMPONENT_WORK_PARAM
 
129
{
 
130
        int size;
 
131
        INT16* buffer;
 
132
        const BYTE* data;
 
133
        RFX_CONTEXT* context;
 
134
        const UINT32* quantization_values;
 
135
};
 
136
typedef struct _RFX_COMPONENT_WORK_PARAM RFX_COMPONENT_WORK_PARAM;
 
137
 
 
138
void CALLBACK rfx_decode_component_work_callback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work)
 
139
{
 
140
        RFX_COMPONENT_WORK_PARAM* param = (RFX_COMPONENT_WORK_PARAM*) context;
 
141
        rfx_decode_component(param->context, param->quantization_values, param->data, param->size, param->buffer);
 
142
}
 
143
 
 
144
/* stride is bytes between rows in the output buffer. */
 
145
BOOL rfx_decode_rgb(RFX_CONTEXT* context, wStream* data_in,
 
146
        int y_size, const UINT32* y_quants,
 
147
        int cb_size, const UINT32* cb_quants,
 
148
        int cr_size, const UINT32* cr_quants, BYTE* rgb_buffer, int stride)
 
149
{
 
150
        INT16* pSrcDst[3];
 
151
        static const prim_size_t roi_64x64 = { 64, 64 };
 
152
        const primitives_t *prims = primitives_get();
 
153
 
 
154
        PROFILER_ENTER(context->priv->prof_rfx_decode_rgb);
 
155
 
 
156
        pSrcDst[0] = (INT16*)((BYTE*)BufferPool_Take(context->priv->BufferPool, -1) + 16); /* y_r_buffer */
 
157
        pSrcDst[1] = (INT16*)((BYTE*)BufferPool_Take(context->priv->BufferPool, -1) + 16); /* cb_g_buffer */
 
158
        pSrcDst[2] = (INT16*)((BYTE*)BufferPool_Take(context->priv->BufferPool, -1) + 16); /* cr_b_buffer */
 
159
 
 
160
#if 0
 
161
        if (context->priv->UseThreads)
 
162
        {
 
163
                PTP_WORK work_objects[3];
 
164
                RFX_COMPONENT_WORK_PARAM params[3];
 
165
 
 
166
                params[0].context = context;
 
167
                params[0].quantization_values = y_quants;
 
168
                params[0].buffer = Stream_Pointer(data_in);
 
169
                params[0].capacity = y_size;
 
170
                params[0].buffer = pSrcDst[0];
 
171
                Stream_Seek(data_in, y_size);
 
172
 
 
173
                params[1].context = context;
 
174
                params[1].quantization_values = cb_quants;
 
175
                params[1].buffer = Stream_Pointer(data_in);
 
176
                params[1].capacity = cb_size;
 
177
                params[1].buffer = pSrcDst[1];
 
178
                Stream_Seek(data_in, cb_size);
 
179
 
 
180
                params[2].context = context;
 
181
                params[2].quantization_values = cr_quants;
 
182
                params[2].buffer = Stream_Pointer(data_in);
 
183
                params[2].capacity = cr_size;
 
184
                params[2].buffer = pSrcDst[2];
 
185
                Stream_Seek(data_in, cr_size);
 
186
 
 
187
                work_objects[0] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_decode_component_work_callback,
 
188
                                (void*) &params[0], &context->priv->ThreadPoolEnv);
 
189
                work_objects[1] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_decode_component_work_callback,
 
190
                                (void*) &params[1], &context->priv->ThreadPoolEnv);
 
191
                work_objects[2] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_decode_component_work_callback,
 
192
                                (void*) &params[2], &context->priv->ThreadPoolEnv);
 
193
 
 
194
                SubmitThreadpoolWork(work_objects[0]);
 
195
                SubmitThreadpoolWork(work_objects[1]);
 
196
                SubmitThreadpoolWork(work_objects[2]);
 
197
 
 
198
                WaitForThreadpoolWorkCallbacks(work_objects[0], FALSE);
 
199
                WaitForThreadpoolWorkCallbacks(work_objects[1], FALSE);
 
200
                WaitForThreadpoolWorkCallbacks(work_objects[2], FALSE);
 
201
        }
 
202
        else
 
203
#endif
 
204
        {
 
205
                if (Stream_GetRemainingLength(data_in) < y_size + cb_size + cr_size)
 
206
                {
 
207
                        DEBUG_WARN("rfx_decode_rgb: packet too small for y_size+cb_size+cr_size");
 
208
                        return FALSE;
 
209
                }
 
210
 
 
211
                rfx_decode_component(context, y_quants, Stream_Pointer(data_in), y_size, pSrcDst[0]); /* YData */
 
212
                Stream_Seek(data_in, y_size);
 
213
 
 
214
                rfx_decode_component(context, cb_quants, Stream_Pointer(data_in), cb_size, pSrcDst[1]); /* CbData */
 
215
                Stream_Seek(data_in, cb_size);
 
216
 
 
217
                rfx_decode_component(context, cr_quants, Stream_Pointer(data_in), cr_size, pSrcDst[2]); /* CrData */
 
218
                Stream_Seek(data_in, cr_size);
 
219
        }
 
220
 
 
221
        PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb);
 
222
        prims->yCbCrToRGB_16s16s_P3P3((const INT16**) pSrcDst, 64 * sizeof(INT16),
 
223
                        pSrcDst, 64 * sizeof(INT16), &roi_64x64);
 
224
        PROFILER_EXIT(context->priv->prof_rfx_ycbcr_to_rgb);
 
225
 
 
226
        PROFILER_ENTER(context->priv->prof_rfx_decode_format_rgb);
 
227
                rfx_decode_format_rgb(pSrcDst[0], pSrcDst[1], pSrcDst[2],
 
228
                        context->pixel_format, rgb_buffer, stride);
 
229
        PROFILER_EXIT(context->priv->prof_rfx_decode_format_rgb);
 
230
        
 
231
        PROFILER_EXIT(context->priv->prof_rfx_decode_rgb);
 
232
 
 
233
        BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[0] - 16);
 
234
        BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[1] - 16);
 
235
        BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[2] - 16);
 
236
 
 
237
        return TRUE;
 
238
}