/[rdesktop]/sourceforge.net/trunk/rdesktop/xwin.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/xwin.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 311 by jsorg71, Wed Feb 5 14:16:33 2003 UTC revision 319 by astrand, Mon Feb 10 13:02:57 2003 UTC
# Line 71  typedef struct Line 71  typedef struct
71  }  }
72  PropMotifWmHints;  PropMotifWmHints;
73    
74    typedef struct
75    {
76            uint32 red;
77            uint32 green;
78            uint32 blue;
79    }
80    PixelColour;
81    
82  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
83  { \  { \
# Line 115  static int rop2_map[] = { Line 122  static int rop2_map[] = {
122  #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); }  #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); }
123  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }
124    
125  void  static void
126  mwm_hide_decorations(void)  mwm_hide_decorations(void)
127  {  {
128          PropMotifWmHints motif_hints;          PropMotifWmHints motif_hints;
# Line 137  mwm_hide_decorations(void) Line 144  mwm_hide_decorations(void)
144                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
145  }  }
146    
147  uint32  static PixelColour
148  colour16to24(uint32 colour)  split_colour15(uint32 colour)
149  {  {
150          int r;          PixelColour rv;
151          int g;          rv.red = (colour & 0x7c00) >> 10;
152          int b;          rv.red = (rv.red * 0xff) / 0x1f;
153          r = (colour & 0xf800) >> 11;          rv.green = (colour & 0x03e0) >> 5;
154          r = (r * 0xff) / 0x1f;          rv.green = (rv.green * 0xff) / 0x1f;
155          g = (colour & 0x07e0) >> 5;          rv.blue = (colour & 0x1f);
156          g = (g * 0xff) / 0x3f;          rv.blue = (rv.blue * 0xff) / 0x1f;
157          b = (colour & 0x001f);          return rv;
158          b = (b * 0xff) / 0x1f;  }
159          return (r << 16) | (g << 8) | b;  
160    static PixelColour
161    split_colour16(uint32 colour)
162    {
163            PixelColour rv;
164            rv.red = (colour & 0xf800) >> 11;
165            rv.red = (rv.red * 0xff) / 0x1f;
166            rv.green = (colour & 0x07e0) >> 5;
167            rv.green = (rv.green * 0xff) / 0x3f;
168            rv.blue = (colour & 0x001f);
169            rv.blue = (rv.blue * 0xff) / 0x1f;
170            return rv;
171    }
172    
173    static PixelColour
174    split_colour24(uint32 colour)
175    {
176            PixelColour rv;
177            rv.blue = (colour & 0xff0000) >> 16;
178            rv.green = (colour & 0xff00) >> 8;
179            rv.red = (colour & 0xff);
180            return rv;
181  }  }
182    
183  uint32  static uint32
184  colour16to32(uint32 colour)  make_colour16(PixelColour pc)
185  {  {
186          return colour16to24(colour);          pc.red = (pc.red * 0x1f) / 0xff;
187            pc.green = (pc.green * 0x3f) / 0xff;
188            pc.blue = (pc.blue * 0x1f) / 0xff;
189            return (pc.red << 11) | (pc.green << 5) | pc.blue;
190  }  }
191    
192  uint32  static uint32
193  colour24to32(uint32 colour)  make_colour24(PixelColour pc)
194  {  {
195          return colour;          return (pc.red << 16) | (pc.green << 8) | pc.blue;
196    }
197    
198    static uint32
199    make_colour32(PixelColour pc)
200    {
201            return (pc.red << 16) | (pc.green << 8) | pc.blue;
202  }  }
203    
204  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
# Line 174  translate_colour(uint32 colour) Line 211  translate_colour(uint32 colour)
211  {  {
212          switch (server_bpp)          switch (server_bpp)
213          {          {
214                    case 15:
215                            switch (bpp)
216                            {
217                                    case 16:
218                                            colour = make_colour16(split_colour15(colour));
219                                            break;
220                                    case 24:
221                                            colour = make_colour24(split_colour15(colour));
222                                            break;
223                                    case 32:
224                                            colour = make_colour32(split_colour15(colour));
225                                            break;
226                            }
227                            break;
228                  case 16:                  case 16:
229                          switch (bpp)                          switch (bpp)
230                          {                          {
231                                  case 16:                                  case 16:
232                                          break;                                          break;
233                                  case 24:                                  case 24:
234                                          colour = colour16to24(colour);                                          colour = make_colour24(split_colour16(colour));
235                                          break;                                          break;
236                                  case 32:                                  case 32:
237                                          colour = colour16to32(colour);                                          colour = make_colour32(split_colour16(colour));
238                                          break;                                          break;
239                          }                          }
240                          break;                          break;
241                  case 24:                  case 24:
242                          switch (bpp)                          switch (bpp)
243                          {                          {
244                                    case 16:
245                                            colour = make_colour16(split_colour24(colour));
246                                            break;
247                                  case 24:                                  case 24:
248                                          break;                                          break;
249                                  case 32:                                  case 32:
250                                          colour = colour24to32(colour);                                          colour = make_colour32(split_colour24(colour));
251                                          break;                                          break;
252                          }                          }
253                          break;                          break;
# Line 233  translate8to16(uint8 * data, uint16 * ou Line 287  translate8to16(uint8 * data, uint16 * ou
287                  *(out++) = (uint16) colmap[*(data++)];                  *(out++) = (uint16) colmap[*(data++)];
288  }  }
289    
290    /* little endian - conversion happens when colourmap is built */
291  static void  static void
292  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate8to24(uint8 * data, uint8 * out, uint8 * end)
293  {  {
294            uint32 value;
295    
296          while (out < end)          while (out < end)
297                  *(out++) = (uint16) translate_colour(*(data++));          {
298                    value = colmap[*(data++)];
299                    *(out++) = value;
300                    *(out++) = value >> 8;
301                    *(out++) = value >> 16;
302            }
303  }  }
304    
 /* little endian - conversion happens when colourmap is built */  
305  static void  static void
306  translate8to24(uint8 * data, uint8 * out, uint8 * end)  translate8to32(uint8 * data, uint32 * out, uint32 * end)
307    {
308            while (out < end)
309                    *(out++) = colmap[*(data++)];
310    }
311    
312    /* todo the remaining translate function might need some big endian check ?? */
313    
314    static void
315    translate15to16(uint16 * data, uint16 * out, uint16 * end)
316    {
317            while (out < end)
318                    *(out++) = (uint16) make_colour16(split_colour15(*(data++)));
319    }
320    
321    static void
322    translate15to24(uint16 * data, uint8 * out, uint8 * end)
323  {  {
324          uint32 value;          uint32 value;
325    
326          while (out < end)          while (out < end)
327          {          {
328                  value = colmap[*(data++)];                  value = make_colour24(split_colour15(*(data++)));
329                  *(out++) = value;                  *(out++) = value;
330                  *(out++) = value >> 8;                  *(out++) = value >> 8;
331                  *(out++) = value >> 16;                  *(out++) = value >> 16;
# Line 256  translate8to24(uint8 * data, uint8 * out Line 333  translate8to24(uint8 * data, uint8 * out
333  }  }
334    
335  static void  static void
336    translate15to32(uint16 * data, uint32 * out, uint32 * end)
337    {
338            while (out < end)
339                    *(out++) = make_colour32(split_colour15(*(data++)));
340    }
341    
342    static void
343    translate16to16(uint16 * data, uint16 * out, uint16 * end)
344    {
345            while (out < end)
346                    *(out++) = (uint16) (*(data++));
347    }
348    
349    
350    static void
351  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
352  {  {
353          uint32 value;          uint32 value;
354    
355          while (out < end)          while (out < end)
356          {          {
357                  value = translate_colour(*(data++));                  value = make_colour24(split_colour16(*(data++)));
358                  *(out++) = value;                  *(out++) = value;
359                  *(out++) = value >> 8;                  *(out++) = value >> 8;
360                  *(out++) = value >> 16;                  *(out++) = value >> 16;
# Line 270  translate16to24(uint16 * data, uint8 * o Line 362  translate16to24(uint16 * data, uint8 * o
362  }  }
363    
364  static void  static void
365  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint32 * out, uint32 * end)
366  {  {
367          while (out < end)          while (out < end)
368                  *(out++) = colmap[*(data++)];                  *(out++) = make_colour32(split_colour16(*(data++)));
369  }  }
370    
371  static void  static void
372  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate24to16(uint8 * data, uint16 * out, uint16 * end)
373  {  {
374            uint32 pixel = 0;
375          while (out < end)          while (out < end)
376                  *(out++) = translate_colour(*(data++));          {
377                    pixel = *(data++) << 16;
378                    pixel |= *(data++) << 8;
379                    pixel |= *(data++);
380                    *(out++) = (uint16) make_colour16(split_colour24(pixel));
381            }
382    }
383    
384    static void
385    translate24to24(uint8 * data, uint8 * out, uint8 * end)
386    {
387            while (out < end)
388            {
389                    *(out++) = (*(data++));
390            }
391    }
392    
393    static void
394    translate24to32(uint8 * data, uint32 * out, uint32 * end)
395    {
396            uint32 pixel = 0;
397            while (out < end)
398            {
399                    memcpy(&pixel, data, 3);
400                    data += 3;
401                    *(out++) = pixel;
402            }
403  }  }
404    
405  static uint8 *  static uint8 *
# Line 290  translate_image(int width, int height, u Line 409  translate_image(int width, int height, u
409          uint8 *out = xmalloc(size);          uint8 *out = xmalloc(size);
410          uint8 *end = out + size;          uint8 *end = out + size;
411    
412          if (server_bpp == 16)          switch (server_bpp)
         {  
                 if (bpp == 16)  
                         translate16to16((uint16 *) data, (uint16 *) out, (uint16 *) end);  
                 else if (bpp == 24)  
                         translate16to24((uint16 *) data, out, end); /* todo, check this one */  
                 else if (bpp == 32)  
                         translate16to32((uint16 *) data, (uint32 *) out, (uint32 *) end);  
                 return out;  
         }  
         /* todo needs server_bpp == 24 */  
         switch (bpp)  
413          {          {
414                  case 8:                  case 24:
415                          translate8to8(data, out, end);                          switch (bpp)
416                            {
417                                    case 32:
418                                            translate24to32(data, (uint32 *) out, (uint32 *) end);
419                                            break;
420                                    case 24:
421                                            translate24to24(data, out, end);
422                                            break;
423                                    case 16:
424                                            translate24to16(data, (uint16 *) out, (uint16 *) end);
425                                            break;
426                            }
427                          break;                          break;
   
428                  case 16:                  case 16:
429                          translate8to16(data, (uint16 *) out, (uint16 *) end);                          switch (bpp)
430                            {
431                                    case 32:
432                                            translate16to32((uint16 *) data, (uint32 *) out,
433                                                            (uint32 *) end);
434                                            break;
435                                    case 24:
436                                            translate16to24((uint16 *) data, out, end);
437                                            break;
438                                    case 16:
439                                            translate16to16((uint16 *) data, (uint16 *) out,
440                                                            (uint16 *) end);
441                                            break;
442                            }
443                          break;                          break;
444                    case 15:
445                  case 24:                          switch (bpp)
446                          translate8to24(data, out, end);                          {
447                                    case 32:
448                                            translate15to32((uint16 *) data, (uint32 *) out,
449                                                            (uint32 *) end);
450                                            break;
451                                    case 24:
452                                            translate15to24((uint16 *) data, out, end);
453                                            break;
454                                    case 16:
455                                            translate15to16((uint16 *) data, (uint16 *) out,
456                                                            (uint16 *) end);
457                                            break;
458                            }
459                          break;                          break;
460                    case 8:
461                  case 32:                          switch (bpp)
462                          translate8to32(data, (uint32 *) out, (uint32 *) end);                          {
463                                    case 8:
464                                            translate8to8(data, out, end);
465                                            break;
466                                    case 16:
467                                            translate8to16(data, (uint16 *) out, (uint16 *) end);
468                                            break;
469                                    case 24:
470                                            translate8to24(data, out, end);
471                                            break;
472                                    case 32:
473                                            translate8to32(data, (uint32 *) out, (uint32 *) end);
474                                            break;
475                            }
476                          break;                          break;
477          }          }
   
478          return out;          return out;
479  }  }
480    
# Line 448  ui_init(void) Line 603  ui_init(void)
603                  IM = XOpenIM(display, NULL, NULL, NULL);                  IM = XOpenIM(display, NULL, NULL, NULL);
604    
605          xkeymap_init();          xkeymap_init();
606    
607            /* todo take this out when high colour is done */
608            printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth);
609    
610          return True;          return True;
611  }  }
612    

Legend:
Removed from v.311  
changed lines
  Added in v.319

  ViewVC Help
Powered by ViewVC 1.1.26