~ubuntu-branches/ubuntu/raring/freerdp/raring-proposed

« back to all changes in this revision

Viewing changes to client/Windows/wf_graphics.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt, Jeremy Bicha, Jean-Louis Dupond, Martin Pitt
  • Date: 2012-01-31 10:02:14 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120131100214-jaok3uwvni7sqxth
Tags: 1.0.0-0git1
Upload current Debian packaging git to get this rolling for precise.

[ Jeremy Bicha ]
* New upstream release. Closes: #647498.
* Updated symbols and bumped soname
* debian/control:
  - Added new build dependencies
  - Bump Standards-Version to 3.9.2
* debian/source/format: Set to 3.0 (quilt)
* debian/rules: Turn on strict symbols checking
* debian/watch: Watch github

[ Jean-Louis Dupond ]
* debian/control: Updated homepage
* debian/copyright: Reflect upstream switch to the Apache license

[ Martin Pitt ]
* debian/libfreerdp0.symbols: Fix version number, should
  be 1.0~beta5, not 1.0-beta5.
* debian/control: Add libavcodec-dev build dependency, upstream build system
  checks for that. Thanks Jean-Louis Dupond!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * FreeRDP: A Remote Desktop Protocol Client
 
3
 * Windows Graphical Objects
 
4
 *
 
5
 * Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
 
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
#include <freerdp/utils/memory.h>
 
21
#include <freerdp/codec/bitmap.h>
 
22
 
 
23
#include "wf_gdi.h"
 
24
#include "wf_graphics.h"
 
25
 
 
26
HBITMAP wf_create_dib(wfInfo* wfi, int width, int height, int bpp, uint8* data, uint8** pdata)
 
27
{
 
28
        HDC hdc;
 
29
        int negHeight;
 
30
        HBITMAP bitmap;
 
31
        BITMAPINFO bmi;
 
32
        uint8* cdata = NULL;
 
33
 
 
34
        /**
 
35
         * See: http://msdn.microsoft.com/en-us/library/dd183376
 
36
         * if biHeight is positive, the bitmap is bottom-up
 
37
         * if biHeight is negative, the bitmap is top-down
 
38
         * Since we get top-down bitmaps, let's keep it that way
 
39
         */
 
40
 
 
41
        negHeight = (height < 0) ? height : height * (-1);
 
42
 
 
43
        hdc = GetDC(NULL);
 
44
        bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
 
45
        bmi.bmiHeader.biWidth = width;
 
46
        bmi.bmiHeader.biHeight = negHeight;
 
47
        bmi.bmiHeader.biPlanes = 1;
 
48
        bmi.bmiHeader.biBitCount = 24;
 
49
        bmi.bmiHeader.biCompression = BI_RGB;
 
50
        bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**) &cdata, NULL, 0);
 
51
 
 
52
        if (data != NULL)
 
53
                freerdp_image_convert(data, cdata, width, height, bpp, 24, wfi->clrconv);
 
54
 
 
55
        if (pdata != NULL)
 
56
                *pdata = cdata;
 
57
 
 
58
        ReleaseDC(NULL, hdc);
 
59
        GdiFlush();
 
60
 
 
61
        return bitmap;
 
62
}
 
63
 
 
64
wfBitmap* wf_image_new(wfInfo* wfi, int width, int height, int bpp, uint8* data)
 
65
{
 
66
        HDC hdc;
 
67
        wfBitmap* image;
 
68
 
 
69
        hdc = GetDC(NULL);
 
70
        image = (wfBitmap*) malloc(sizeof(wfBitmap));
 
71
        image->hdc = CreateCompatibleDC(hdc);
 
72
 
 
73
        if (data == NULL)
 
74
                image->bitmap = CreateCompatibleBitmap(hdc, width, height);
 
75
        else
 
76
                image->bitmap = wf_create_dib(wfi, width, height, bpp, data, &(image->pdata));
 
77
 
 
78
        image->org_bitmap = (HBITMAP) SelectObject(image->hdc, image->bitmap);
 
79
        ReleaseDC(NULL, hdc);
 
80
        
 
81
        return image;
 
82
}
 
83
 
 
84
wfBitmap* wf_bitmap_new(wfInfo* wfi, int width, int height, int bpp, uint8* data)
 
85
{
 
86
        HDC hdc;
 
87
        wfBitmap* bitmap;
 
88
 
 
89
        hdc = GetDC(NULL);
 
90
        bitmap = (wfBitmap*) malloc(sizeof(wfBitmap));
 
91
        bitmap->hdc = CreateCompatibleDC(hdc);
 
92
        bitmap->bitmap = wf_create_dib(wfi, width, height, bpp, data, &(bitmap->pdata));
 
93
        bitmap->org_bitmap = (HBITMAP) SelectObject(bitmap->hdc, bitmap->bitmap);
 
94
        ReleaseDC(NULL, hdc);
 
95
        
 
96
        return bitmap;
 
97
}
 
98
 
 
99
void wf_image_free(wfBitmap* image)
 
100
{
 
101
        if (image != 0)
 
102
        {
 
103
                SelectObject(image->hdc, image->org_bitmap);
 
104
                DeleteObject(image->bitmap);
 
105
                DeleteDC(image->hdc);
 
106
                free(image);
 
107
        }
 
108
}
 
109
 
 
110
/* Bitmap Class */
 
111
 
 
112
void wf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
 
113
{
 
114
        HDC hdc;
 
115
        wfBitmap* wf_bitmap = (wfBitmap*) bitmap;
 
116
        wfInfo* wfi = ((wfContext*) context)->wfi;
 
117
 
 
118
        wf_bitmap = (wfBitmap*) bitmap;
 
119
 
 
120
        hdc = GetDC(NULL);
 
121
        wf_bitmap->hdc = CreateCompatibleDC(hdc);
 
122
 
 
123
        if (bitmap->data == NULL)
 
124
                wf_bitmap->bitmap = CreateCompatibleBitmap(hdc, bitmap->width, bitmap->height);
 
125
        else
 
126
                wf_bitmap->bitmap = wf_create_dib(wfi, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, NULL);
 
127
 
 
128
        wf_bitmap->org_bitmap = (HBITMAP) SelectObject(wf_bitmap->hdc, wf_bitmap->bitmap);
 
129
        ReleaseDC(NULL, hdc);
 
130
}
 
131
 
 
132
void wf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
 
133
{
 
134
        wfBitmap* wf_bitmap = (wfBitmap*) bitmap;
 
135
        
 
136
        if (wf_bitmap != 0)
 
137
        {
 
138
                SelectObject(wf_bitmap->hdc, wf_bitmap->org_bitmap);
 
139
                DeleteObject(wf_bitmap->bitmap);
 
140
                DeleteDC(wf_bitmap->hdc);
 
141
        }
 
142
}
 
143
 
 
144
void wf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
 
145
{
 
146
        int width, height;
 
147
        wfBitmap* wf_bitmap = (wfBitmap*) bitmap;
 
148
        wfInfo* wfi = ((wfContext*) context)->wfi;
 
149
 
 
150
        width = bitmap->right - bitmap->left + 1;
 
151
        height = bitmap->bottom - bitmap->top + 1;
 
152
 
 
153
        BitBlt(wfi->primary->hdc, bitmap->left, bitmap->top,
 
154
                width, height, wf_bitmap->hdc, 0, 0, SRCCOPY);
 
155
 
 
156
        wf_invalidate_region(wfi, bitmap->left, bitmap->top, width, height);
 
157
}
 
158
 
 
159
void wf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
 
160
                uint8* data, int width, int height, int bpp, int length, boolean compressed)
 
161
{
 
162
        uint16 size;
 
163
 
 
164
        size = width * height * (bpp / 8);
 
165
 
 
166
        if (bitmap->data == NULL)
 
167
                bitmap->data = (uint8*) xmalloc(size);
 
168
        else
 
169
                bitmap->data = (uint8*) xrealloc(bitmap->data, size);
 
170
 
 
171
        if (compressed)
 
172
        {
 
173
                boolean status;
 
174
 
 
175
                status = bitmap_decompress(data, bitmap->data, width, height, length, bpp, bpp);
 
176
 
 
177
                if (status != true)
 
178
                {
 
179
                        printf("Bitmap Decompression Failed\n");
 
180
                }
 
181
        }
 
182
        else
 
183
        {
 
184
                freerdp_image_flip(data, bitmap->data, width, height, bpp);
 
185
        }
 
186
 
 
187
        bitmap->compressed = false;
 
188
        bitmap->length = size;
 
189
        bitmap->bpp = bpp;
 
190
}
 
191
 
 
192
void wf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, boolean primary)
 
193
{
 
194
        wfInfo* wfi = ((wfContext*) context)->wfi;
 
195
 
 
196
        if (primary)
 
197
                wfi->drawing = wfi->primary;
 
198
        else
 
199
                wfi->drawing = (wfBitmap*) bitmap;
 
200
}
 
201
 
 
202
/* Pointer Class */
 
203
 
 
204
void wf_Pointer_New(rdpContext* context, rdpPointer* pointer)
 
205
{
 
206
 
 
207
}
 
208
 
 
209
void wf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
 
210
{
 
211
 
 
212
}
 
213
 
 
214
void wf_Pointer_Set(rdpContext* context, rdpPointer* pointer)
 
215
{
 
216
 
 
217
}
 
218
 
 
219
/* Graphics Module */
 
220
 
 
221
void wf_register_graphics(rdpGraphics* graphics)
 
222
{
 
223
        rdpBitmap bitmap;
 
224
        rdpPointer pointer;
 
225
 
 
226
        memset(&bitmap, 0, sizeof(rdpBitmap));
 
227
        bitmap.size = sizeof(wfBitmap);
 
228
        bitmap.New = wf_Bitmap_New;
 
229
        bitmap.Free = wf_Bitmap_Free;
 
230
        bitmap.Paint = wf_Bitmap_Paint;
 
231
        bitmap.Decompress = wf_Bitmap_Decompress;
 
232
        bitmap.SetSurface = wf_Bitmap_SetSurface;
 
233
 
 
234
        memset(&pointer, 0, sizeof(rdpPointer));
 
235
        pointer.size = sizeof(wfPointer);
 
236
        pointer.New = wf_Pointer_New;
 
237
        pointer.Free = wf_Pointer_Free;
 
238
        pointer.Set = wf_Pointer_Set;
 
239
 
 
240
        graphics_register_bitmap(graphics, &bitmap);
 
241
        graphics_register_pointer(graphics, &pointer);
 
242
}