1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** GUIX Component                                                        */
16 /**                                                                       */
17 /**   Synergy Simulation Display Management (Display)                     */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_dave2d_simulation_display_driver.h"
28 #include "gx_context.h"
29 #include "gx_display.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_dave2d_simulation_display_driver_565rgb_pixelmap_c_write        */
37 /*                                                        PORTABLE C      */
38 /*                                                           6.4.0        */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Ting Zhu, Microsoft Corporation                                     */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    Internal helper function that handles writing of compressed         */
46 /*    pixlemap file without alpha channel.                                */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    context                               Drawing context               */
51 /*    xpos                                  x-coord of top-left draw point*/
52 /*    ypos                                  y-coord of top-left draw point*/
53 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    None                                                                */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    GUIX Internal Code                                                  */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  12-31-2023     Ting Zhu                 Initial Version 6.4.0         */
72 /*                                                                        */
73 /**************************************************************************/
_gx_dave2d_simulation_display_driver_565rgb_pixelmap_compressed_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)74 static VOID _gx_dave2d_simulation_display_driver_565rgb_pixelmap_compressed_write(GX_DRAW_CONTEXT *context,
75                                                                                    INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
76 {
77 INT             yval;
78 INT             xval;
79 GX_CONST UCHAR *get;
80 USHORT         *put;
81 USHORT         *putrow;
82 GX_UBYTE        count;
83 USHORT          pixel;
84 GX_UBYTE        alpha;
85 
86 GX_RECTANGLE   *clip = context -> gx_draw_context_clip;
87 
88     alpha = context -> gx_draw_context_brush.gx_brush_alpha;
89 
90     get = (GX_CONST UCHAR *)pixelmap -> gx_pixelmap_data;
91 
92     /* compressed with no alpha is a one-byte count and two one-byte pixel value */
93     /* first, skip to the starting row */
94     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
95     {
96         xval = 0;
97         while (xval < pixelmap -> gx_pixelmap_width)
98         {
99             count = *get++;
100 
101             if (count & 0x80)
102             {
103                 count = (GX_UBYTE)((count & 0x7f) + 1);
104                 get += 2;      /* skip repeated pixel value */
105             }
106             else
107             {
108                 count++;
109                 get += count * 2;   /* skip raw pixel values */
110             }
111             xval += count;
112         }
113     }
114 
115     /* Now we are on the first visible row, copy pixels until we get
116        to the end of the last visible row. */
117     putrow = (USHORT *)context -> gx_draw_context_memory;
118     putrow += yval * context -> gx_draw_context_pitch;
119     putrow += xpos;
120 
121     while (yval <= clip -> gx_rectangle_bottom)
122     {
123         put = putrow;
124         xval = xpos;
125 
126         while (xval < xpos + pixelmap -> gx_pixelmap_width)
127         {
128             count = *get++;
129 
130             if (count & 0x80)
131             {
132                 /* repeated value */
133                 count = (GX_UBYTE)((count & 0x7f) + 1);
134                 pixel = *get++;
135                 pixel = (USHORT)((*get++) << 8) | pixel;
136 
137                 while (count--)
138                 {
139                     if (xval >= clip -> gx_rectangle_left &&
140                         xval <= clip -> gx_rectangle_right)
141                     {
142                         if (alpha == 0xff)
143                         {
144                             *put = pixel;
145                         }
146                         else
147                         {
148                             _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha);
149                         }
150                     }
151                     put++;
152                     xval++;
153                 }
154             }
155             else
156             {
157                 /* string of non-repeated values */
158                 count++;
159                 while (count--)
160                 {
161                     if (xval >= clip -> gx_rectangle_left &&
162                         xval <= clip -> gx_rectangle_right)
163                     {
164                         pixel = (USHORT)((*get) | (USHORT)((*(get + 1)) << 8));
165                         if (alpha == 0xff)
166                         {
167                             *put = pixel;
168                         }
169                         else
170                         {
171                             _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha);
172                         }
173                     }
174                     put++;
175                     get += 2;
176                     xval++;
177                 }
178             }
179         }
180         putrow +=  context -> gx_draw_context_pitch;
181         yval++;
182     }
183 }
184 
185 /**************************************************************************/
186 /*                                                                        */
187 /*  FUNCTION                                               RELEASE        */
188 /*                                                                        */
189 /*    _gx_dave2d_simulation_display_driver_16bpp_4444argb_pixelmap_       */
190 /*    c_alpha_write                                       PORTABLE C      */
191 /*                                                           6.4.0        */
192 /*  AUTHOR                                                                */
193 /*                                                                        */
194 /*    Ting Zhu, Microsoft Corporation                                     */
195 /*                                                                        */
196 /*  DESCRIPTION                                                           */
197 /*                                                                        */
198 /*    Internal helper function that handles writing of compressed         */
199 /*    pixlemap file with alpha channel.                                   */
200 /*                                                                        */
201 /*  INPUT                                                                 */
202 /*                                                                        */
203 /*    context                               Drawing context               */
204 /*    xpos                                  x-coord of top-left draw point*/
205 /*    ypos                                  y-coord of top-left draw point*/
206 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
207 /*                                                                        */
208 /*  OUTPUT                                                                */
209 /*                                                                        */
210 /*    None                                                                */
211 /*                                                                        */
212 /*  CALLS                                                                 */
213 /*                                                                        */
214 /*    None                                                                */
215 /*                                                                        */
216 /*  CALLED BY                                                             */
217 /*                                                                        */
218 /*    GUIX Internal Code                                                  */
219 /*                                                                        */
220 /*  RELEASE HISTORY                                                       */
221 /*                                                                        */
222 /*    DATE              NAME                      DESCRIPTION             */
223 /*                                                                        */
224 /*  12-31-2023     Ting Zhu                 Initial Version 6.4.0         */
225 /*                                                                        */
226 /**************************************************************************/
_gx_dave2d_simulation_display_driver_16bpp_4444argb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)227 static VOID _gx_dave2d_simulation_display_driver_16bpp_4444argb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT *context,
228                                                                                                  INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
229 {
230 INT             yval;
231 INT             xval;
232 GX_CONST UCHAR *get;
233 UCHAR           count;
234 USHORT          pixel;
235 UCHAR           alpha_value;
236 UCHAR           temp;
237 UCHAR           brush_alpha;
238 int             temp_alpha;
239 
240 
241 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
242 
243     get = (GX_CONST UCHAR *)pixelmap -> gx_pixelmap_data;
244     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
245 
246     /* compressed with no alpha is a one-byte count and two one-byte pixel value */
247     /* first, skip to the starting row */
248     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
249     {
250         xval = 0;
251         while (xval < pixelmap -> gx_pixelmap_width)
252         {
253             count = *get++;
254 
255             if (count & 0x80)
256             {
257                 count = (UCHAR)((count & 0x7f) + 1);
258                 get += 2;      /* skip repeated pixel value */
259             }
260             else
261             {
262                 count++;
263                 get += count * 2;   /* skip raw pixel values */
264             }
265             xval += count;
266         }
267     }
268 
269     /* Now we are on the first visible row, copy pixels until we get
270        to the end of the last visible row. */
271 
272     while (yval <= clip -> gx_rectangle_bottom)
273     {
274         xval = xpos;
275 
276         while (xval < xpos + pixelmap -> gx_pixelmap_width)
277         {
278             count = *get++;
279 
280             if (count & 0x80)
281             {
282                 /* repeated value */
283                 count = (UCHAR)((count & 0x7f) + 1);
284                 pixel = 0;
285                 /*two one-byte ,first byte is ra , second is bg*/
286                 /*first byte , 0xf0 --> g , 0x0f --> b */
287                 alpha_value = (*(get + 1)) & 0xf0;
288                 temp_alpha = alpha_value * brush_alpha;
289                 temp_alpha /= 255;
290                 alpha_value = (UCHAR)temp_alpha;
291 
292                 if (alpha_value)
293                 {
294                     temp  = (*get) & 0xf0;
295                     pixel = (USHORT)(temp << 3) | pixel;
296                     temp = (*get++) & 0x0f;
297                     pixel = (USHORT)(temp << 1) | pixel;
298                     /*second byte , 0xf0 --> a , 0x0f --> r */
299                     temp  = (*get++) & 0x0f;
300                     pixel = (USHORT)(temp << 12) | pixel;
301                     while (count--)
302                     {
303                         if (xval >= clip -> gx_rectangle_left &&
304                             xval <= clip -> gx_rectangle_right)
305                         {
306                             if (alpha_value == 0xf0)
307                             {
308                                 _gx_display_driver_16bpp_pixel_write(context, xval, yval, pixel);
309                             }
310                             else
311                             {
312                                 _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha_value);
313                             }
314                         }
315                         xval++;
316                     }
317                 }
318                 else
319                 {
320                     get += 2;
321                     while (count--)
322                     {
323                         xval++;
324                     }
325                 }
326             }
327             else
328             {
329                 /* string of non-repeated values */
330                 count++;
331                 while (count--)
332                 {
333                     if (xval >= clip -> gx_rectangle_left &&
334                         xval <= clip -> gx_rectangle_right)
335                     {
336                         /*second byte , 0xf0 --> a , 0x0f --> r */
337                         temp  = (*(get + 1)) & 0xf0;
338                         alpha_value = temp;
339 
340                         temp_alpha = alpha_value * brush_alpha;
341                         temp_alpha /= 255;
342                         alpha_value = (UCHAR)temp_alpha;
343 
344                         pixel = 0;
345                         if (alpha_value)
346                         {
347                             /*first byte , 0xf0 --> g , 0x0f --> b */
348 
349                             temp  = (*get) & 0xf0;
350                             pixel = (USHORT)(temp << 3) | pixel;
351                             temp  = (*get) & 0x0f;
352                             pixel = (USHORT)(temp << 1) | pixel;
353                             /*second byte , 0xf0 --> a , 0x0f --> r */
354                             temp  = (*(get + 1)) & 0x0f;
355                             pixel = (USHORT)(temp << 12) | pixel;
356                             if (alpha_value == 0xf0)
357                             {
358                                 _gx_display_driver_16bpp_pixel_write(context, xval, yval, pixel);
359                             }
360                             else
361                             {
362                                 _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha_value);
363                             }
364                         }
365                     }
366 
367                     get += 2;
368                     xval++;
369                 }
370             }
371         }
372         yval++;
373     }
374 }
375 
376 /**************************************************************************/
377 /*                                                                        */
378 /*  FUNCTION                                               RELEASE        */
379 /*                                                                        */
380 /*    _gx_dave2d_simulation_display_driver_16bpp_4444bgra_pixelmap_       */
381 /*    compressed_alpha_write                              PORTABLE C      */
382 /*                                                           6.4.0        */
383 /*  AUTHOR                                                                */
384 /*                                                                        */
385 /*    Ting Zhu, Microsoft Corporation                                     */
386 /*                                                                        */
387 /*  DESCRIPTION                                                           */
388 /*                                                                        */
389 /*    Internal helper function that handles writing of compressed         */
390 /*    pixlemap file with alpha channel.                                   */
391 /*                                                                        */
392 /*  INPUT                                                                 */
393 /*                                                                        */
394 /*    context                               Drawing context               */
395 /*    xpos                                  x-coord of top-left draw point*/
396 /*    ypos                                  y-coord of top-left draw point*/
397 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
398 /*                                                                        */
399 /*  OUTPUT                                                                */
400 /*                                                                        */
401 /*    None                                                                */
402 /*                                                                        */
403 /*  CALLS                                                                 */
404 /*        _gx_display_driver_16bpp_pixel_write                            */
405 /*        _gx_display_driver_565rgb_pixel_blend                           */
406 /*                                                                        */
407 /*  CALLED BY                                                             */
408 /*                                                                        */
409 /*    GUIX Internal Code                                                  */
410 /*                                                                        */
411 /*  RELEASE HISTORY                                                       */
412 /*                                                                        */
413 /*    DATE              NAME                      DESCRIPTION             */
414 /*                                                                        */
415 /*  12-31-2023     Ting Zhu                 Initial Version 6.4.0         */
416 /*                                                                        */
417 /**************************************************************************/
_gx_dave2d_simulation_display_driver_16bpp_4444bgra_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)418 static VOID _gx_dave2d_simulation_display_driver_16bpp_4444bgra_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT *context,
419                                                                                                  INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
420 {
421 INT             yval;
422 INT             xval;
423 GX_CONST UCHAR *get;
424 UCHAR           count;
425 USHORT          pixel;
426 GX_UBYTE        alpha_value;
427 GX_UBYTE        temp;
428 int             temp_alpha;
429 GX_UBYTE        brush_alpha;
430 
431 GX_RECTANGLE   *clip = context -> gx_draw_context_clip;
432 
433     get = (GX_CONST UCHAR *)pixelmap -> gx_pixelmap_data;
434     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
435 
436     /* compressed with no alpha is a one-byte count and two one-byte pixel value */
437     /* first, skip to the starting row */
438     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
439     {
440         xval = 0;
441         while (xval < pixelmap -> gx_pixelmap_width)
442         {
443             count = *get++;
444 
445             if (count & 0x80)
446             {
447                 count = (UCHAR)((count & 0x7f) + 1);
448                 get += 2;      /* skip repeated pixel value */
449             }
450             else
451             {
452                 count++;
453                 get += count * 2;   /* skip raw pixel values */
454             }
455             xval += count;
456         }
457     }
458 
459     /* Now we are on the first visible row, copy pixels until we get
460        to the end of the last visible row. */
461 
462     while (yval <= clip -> gx_rectangle_bottom)
463     {
464         xval = xpos;
465 
466         while (xval < xpos + pixelmap -> gx_pixelmap_width)
467         {
468             count = *get++;
469 
470             if (count & 0x80)
471             {
472                 /* repeated value */
473                 count = (UCHAR)((count & 0x7f) + 1);
474                 pixel = 0;
475                 /*two one-byte ,first byte is ra , second is bg*/
476                 /*first byte , 0xf0 --> r , 0x0f --> a */
477                 temp = (*get) & 0x0f;
478                 alpha_value = (UCHAR)(temp << 4);
479 
480                 temp_alpha = alpha_value * brush_alpha;
481                 temp_alpha /= 255;
482                 alpha_value = (GX_UBYTE)temp_alpha;
483 
484                 if (alpha_value)
485                 {
486                     temp  = (*get++) & 0xf0;
487                     pixel = (USHORT)(temp << 8) | pixel;
488                     /*second byte , 0xf0 --> b , 0x0f --> g */
489                     temp  = (*get) & 0xf0;
490                     pixel = (USHORT)((temp >> 3) | pixel);
491                     temp  = (*get++) & 0x0f;
492                     pixel = (USHORT)(temp << 7) | pixel;
493 
494                     while (count--)
495                     {
496                         if (xval >= clip -> gx_rectangle_left &&
497                             xval <= clip -> gx_rectangle_right)
498                         {
499                             if (alpha_value == 0xf0)
500                             {
501                                 _gx_display_driver_16bpp_pixel_write(context, xval, yval, pixel);
502                             }
503                             else
504                             {
505                                 _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha_value);
506                             }
507                         }
508                         xval++;
509                     }
510                 }
511                 else
512                 {
513                     get += 2;
514                     while (count--)
515                     {
516                         xval++;
517                     }
518                 }
519             }
520             else
521             {
522                 /* string of non-repeated values */
523                 count++;
524                 while (count--)
525                 {
526                     if (xval >= clip -> gx_rectangle_left &&
527                         xval <= clip -> gx_rectangle_right)
528                     {
529                         pixel = 0;
530                         /*first byte , 0xf0 --> g , 0x0f --> b */
531                         temp  = (*get) & 0x0f;
532                         alpha_value = (UCHAR)(temp << 4);
533                         temp_alpha = alpha_value * brush_alpha;
534                         temp_alpha /= 255;
535                         alpha_value = (GX_UBYTE)temp_alpha;
536 
537                         if (alpha_value)
538                         {
539                             /*first byte , 0xf0 --> g , 0x0f --> b */
540                             temp  = (*get) & 0xf0;
541                             pixel = (USHORT)(temp << 8) | pixel;
542                             /*second byte , 0xf0 --> a , 0x0f --> r */
543                             temp  = (*(get + 1)) & 0xf0;
544                             pixel = (USHORT)((temp >> 3) | pixel);
545                             temp  = (*(get + 1)) & 0x0f;
546                             pixel = (USHORT)(temp << 7) | pixel;
547 
548                             if (alpha_value == 0xf0)
549                             {
550                                 _gx_display_driver_16bpp_pixel_write(context, xval, yval, pixel);
551                             }
552                             else
553                             {
554                                 _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha_value);
555                             }
556                         }
557                     }
558 
559                     get += 2;
560                     xval++;
561                 }
562             }
563         }
564         yval++;
565     }
566 }
567 /**************************************************************************/
568 /*                                                                        */
569 /*  FUNCTION                                               RELEASE        */
570 /*                                                                        */
571 /*    _gx_dave2d_simulation_display_driver_16bpp_32argb_pixelmap_         */
572 /*    compressed_write                                                    */
573 /*                                                        PORTABLE C      */
574 /*                                                           6.4.0        */
575 /*  AUTHOR                                                                */
576 /*                                                                        */
577 /*    Ting Zhu, Microsoft Corporation                                     */
578 /*                                                                        */
579 /*  DESCRIPTION                                                           */
580 /*                                                                        */
581 /*    Internal helper function that handles writing of compressed         */
582 /*    pixlemap file with alpha channel.                                   */
583 /*                                                                        */
584 /*  INPUT                                                                 */
585 /*                                                                        */
586 /*    context                               Drawing context               */
587 /*    xpos                                  x-coord of top-left draw point*/
588 /*    ypos                                  y-coord of top-left draw point*/
589 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
590 /*                                                                        */
591 /*                                                                        */
592 /*  OUTPUT                                                                */
593 /*                                                                        */
594 /*    None                                                                */
595 /*                                                                        */
596 /*  CALLS                                                                 */
597 /*                                                                        */
598 /*     _gx_display_driver_565rgb_pixel_blend                              */
599 /*                                                                        */
600 /*  CALLED BY                                                             */
601 /*                                                                        */
602 /*    GUIX Internal Code                                                  */
603 /*                                                                        */
604 /*  RELEASE HISTORY                                                       */
605 /*                                                                        */
606 /*    DATE              NAME                      DESCRIPTION             */
607 /*                                                                        */
608 /*  12-31-2023     Ting Zhu                 Initial Version 6.4.0         */
609 /*                                                                        */
610 /**************************************************************************/
_gx_dave2d_simulation_display_driver_16bpp_32argb_pixelmap_compressed_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)611 static VOID _gx_dave2d_simulation_display_driver_16bpp_32argb_pixelmap_compressed_write(GX_DRAW_CONTEXT *context,
612                                                                                          INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
613 {
614 INT             yval;
615 INT             xval;
616 GX_CONST UCHAR *get;
617 UCHAR           count;
618 USHORT          pixel;
619 GX_UBYTE        alpha_value;
620 GX_UBYTE        brush_alpha;
621 int             temp_alpha;
622 GX_BOOL         has_alpha;
623 USHORT          red;
624 USHORT          green;
625 USHORT          blue;
626 
627 GX_RECTANGLE   *clip = context -> gx_draw_context_clip;
628 
629     get = (GX_CONST UCHAR *)pixelmap -> gx_pixelmap_data;
630     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
631 
632     if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
633     {
634         has_alpha = GX_TRUE;
635     }
636     else
637     {
638         has_alpha = GX_FALSE;
639     }
640 
641     /* compressed with  alpha is a one-byte count and four one-byte pixel value */
642     /* first, skip to the starting row */
643     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
644     {
645         xval = 0;
646         while (xval < pixelmap -> gx_pixelmap_width)
647         {
648             count = *get++;
649 
650             if (count & 0x80)
651             {
652                 count = (UCHAR)((count & 0x7f) + 1);
653                 get += 4;      /* skip repeated pixel value */
654             }
655             else
656             {
657                 count++;
658                 get += count * 4;   /* skip raw pixel values */
659             }
660             xval += count;
661         }
662     }
663 
664     /* Now we are on the first visible row, copy pixels until we get
665        to the end of the last visible row. */
666 
667     while (yval <= clip -> gx_rectangle_bottom)
668     {
669         xval = xpos;
670 
671         while (xval < xpos + pixelmap -> gx_pixelmap_width)
672         {
673             count = *get++;
674 
675             if (count & 0x80)
676             {
677                 /* repeated value */
678                 count = (UCHAR)((count & 0x7f) + 1);
679                 blue = (USHORT)((*get++) & 0xf8);
680                 pixel = blue >> 3;
681                 green = (USHORT)((*get++) & 0xfc);
682                 pixel = (USHORT)(green << 3) | pixel;
683                 red = (USHORT)((*get++) & 0xf8);
684                 pixel = (USHORT)(red << 8) | pixel;
685 
686                 if (has_alpha)
687                 {
688                     alpha_value = *get++;
689                 }
690                 else
691                 {
692                     get += 1;
693                     alpha_value = 0xff;
694                 }
695                 temp_alpha = alpha_value * brush_alpha;
696                 temp_alpha /= 255;
697                 alpha_value = (GX_UBYTE)temp_alpha;
698 
699                 while (count--)
700                 {
701                     if (xval >= clip -> gx_rectangle_left &&
702                         xval <= clip -> gx_rectangle_right)
703                     {
704                         _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha_value);
705                     }
706                     xval++;
707                 }
708             }
709             else
710             {
711                 /* string of non-repeated values */
712                 count++;
713                 while (count--)
714                 {
715                     if (xval >= clip -> gx_rectangle_left &&
716                         xval <= clip -> gx_rectangle_right)
717                     {
718                         red = (USHORT)(*(get + 2) & 0xf8);
719                         green = (USHORT)(*(get + 1) & 0xfc);
720                         blue = (USHORT)(*(get) & 0xf8);
721                         pixel = (USHORT)((blue >> 3) | (green << 3) | (red << 8));
722 
723                         if (has_alpha)
724                         {
725                             alpha_value = *(get + 3);
726                         }
727                         else
728                         {
729                             alpha_value = 0xff;
730                         }
731                         temp_alpha = alpha_value * brush_alpha;
732                         temp_alpha /= 255;
733                         alpha_value = (GX_UBYTE)temp_alpha;
734                         _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha_value);
735                     }
736                     get += 4;
737                     xval++;
738                 }
739             }
740         }
741         yval++;
742     }
743 }
744 /**************************************************************************/
745 /*                                                                        */
746 /*  FUNCTION                                               RELEASE        */
747 /*                                                                        */
748 /*    _gx_dave2d_simulation_display_driver_16bpp_32argb_pixelmap          */
749 /*    _raw_write                                                          */
750 /*                                                        PORTABLE C      */
751 /*                                                           6.4.0        */
752 /*  AUTHOR                                                                */
753 /*                                                                        */
754 /*    Ting Zhu, Microsoft Corporation                                     */
755 /*                                                                        */
756 /*  DESCRIPTION                                                           */
757 /*                                                                        */
758 /*    Internal helper function that handles writing of uncompressed       */
759 /*    pixlemap file with alpha channel.                                   */
760 /*                                                                        */
761 /*  INPUT                                                                 */
762 /*                                                                        */
763 /*    context                               Drawing context               */
764 /*    xpos                                  x-coord of top-left draw point*/
765 /*    ypos                                  y-coord of top-left draw point*/
766 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
767 /*                                                                        */
768 /*  OUTPUT                                                                */
769 /*                                                                        */
770 /*    None                                                                */
771 /*                                                                        */
772 /*  CALLS                                                                 */
773 /*                                                                        */
774 /*     _gx_display_driver_565rgb_pixel_blend                              */
775 /*     _gx_display_driver_16bpp_pixel_write                               */
776 /*                                                                        */
777 /*  CALLED BY                                                             */
778 /*                                                                        */
779 /*    GUIX Internal Code                                                  */
780 /*                                                                        */
781 /*  RELEASE HISTORY                                                       */
782 /*                                                                        */
783 /*    DATE              NAME                      DESCRIPTION             */
784 /*                                                                        */
785 /*  12-31-2023     Ting Zhu                 Initial Version 6.4.0         */
786 /*                                                                        */
787 /**************************************************************************/
_gx_dave2d_simulation_display_driver_16bpp_32argb_pixelmap_raw_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)788 static VOID _gx_dave2d_simulation_display_driver_16bpp_32argb_pixelmap_raw_write(GX_DRAW_CONTEXT *context,
789                                                                                   INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
790 {
791 INT                skipcount;
792 INT                xval;
793 INT                yval;
794 GX_COLOR          *getrow;
795 GX_CONST GX_COLOR *get;
796 GX_DISPLAY        *display;
797 GX_RECTANGLE      *clip;
798 VOID               (*blend_function)(GX_DRAW_CONTEXT *context, INT xcoord, INT ycoord, GX_COLOR fcolor, GX_UBYTE alpha);
799 VOID               (*write_function)(GX_DRAW_CONTEXT *context, INT xcoord, INT ycoord, GX_COLOR color);
800 GX_UBYTE           alpha;
801 GX_UBYTE           brush_alpha;
802 int                temp_alpha;
803 USHORT             color;
804 GX_UBYTE           r;
805 GX_UBYTE           g;
806 GX_UBYTE           b;
807 
808 
809     display = context -> gx_draw_context_display;
810     blend_function = display -> gx_display_driver_pixel_blend;
811     write_function = display -> gx_display_driver_pixel_write;
812 
813     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
814 
815     clip = context -> gx_draw_context_clip;
816     skipcount = (pixelmap -> gx_pixelmap_width) * (clip -> gx_rectangle_top - ypos);
817     skipcount += (clip -> gx_rectangle_left - xpos);
818 
819     getrow = (GX_COLOR *)(pixelmap -> gx_pixelmap_data);
820     getrow += skipcount;
821 
822     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
823     {
824         get = getrow;
825 
826         for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
827         {
828             alpha = (GX_UBYTE)(((*get) & 0xff000000) >> 24);
829             temp_alpha = alpha * brush_alpha;
830             temp_alpha /= 255;
831             alpha = (GX_UBYTE)temp_alpha;
832 
833             r = (GX_UBYTE)((REDVAL_24BPP(*get) & 0xf8) >> 3);
834             g = (GX_UBYTE)((GREENVAL_24BPP(*get) & 0xfc) >> 2);
835             b = (GX_UBYTE)((BLUEVAL_24BPP(*get) & 0xf8) >> 3);
836             color = (USHORT)ASSEMBLECOLOR_16BPP((INT)r, (INT)g, (INT)b);
837             if (alpha == 0xff)
838             {
839                 write_function(context, xval, yval, color);
840             }
841             else
842             {
843                 blend_function(context, xval, yval, color, alpha);
844             }
845             get++;
846         }
847 
848         getrow += pixelmap -> gx_pixelmap_width;
849     }
850 }
851 /**************************************************************************/
852 /*                                                                        */
853 /*  FUNCTION                                               RELEASE        */
854 /*                                                                        */
855 /*    _gx_dave2d_simulation_display_driver_565rgb_pixelmap_blend          */
856 /*                                                        PORTABLE C      */
857 /*                                                           6.4.0        */
858 /*  AUTHOR                                                                */
859 /*                                                                        */
860 /*    Ting Zhu, Microsoft Corporation                                     */
861 /*                                                                        */
862 /*  DESCRIPTION                                                           */
863 /*                                                                        */
864 /*    565rgb , 4444argb and 4444bgra screen driver pixelmap drawing       */
865 /*    function that handles compressed or uncompress, without alpha       */
866 /*    channel.                                                            */
867 /*                                                                        */
868 /*  INPUT                                                                 */
869 /*                                                                        */
870 /*    context                               Drawing context               */
871 /*    xpos                                  x-coord of top-left draw point*/
872 /*    ypos                                  y-coord of top-left draw point*/
873 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
874 /*    alpha                                 Blending alpha                */
875 /*                                                                        */
876 /*  OUTPUT                                                                */
877 /*                                                                        */
878 /*    None                                                                */
879 /*                                                                        */
880 /*  CALLS                                                                 */
881 /*                                                                        */
882 /*     _gx_dave2d_simulation_display_driver_16bpp_32argb_pixelmap_r_write */
883 /*     _gx_dave2d_simulation_display_driver_16bpp_32argb_pixelmap_c_write */
884 /*     _gx_dave2d_simulation_display_driver_16bpp_4444argb_pixelmap       */
885 /*         _compressed_alpha_write                                        */
886 /*     _gx_dave2d_simulation_display_driver_565rgb_pixelmap_c_write       */
887 /*     _gx_display_driver_565rgb_pixelmap_draw                            */
888 /*                                                                        */
889 /*  CALLED BY                                                             */
890 /*                                                                        */
891 /*    GUIX Internal Code                                                  */
892 /*                                                                        */
893 /*  RELEASE HISTORY                                                       */
894 /*                                                                        */
895 /*    DATE              NAME                      DESCRIPTION             */
896 /*                                                                        */
897 /*  12-31-2023     Ting Zhu                 Initial Version 6.4.0         */
898 /*                                                                        */
899 /**************************************************************************/
_gx_dave2d_simulation_display_driver_565rgb_pixelmap_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)900 VOID _gx_dave2d_simulation_display_driver_565rgb_pixelmap_blend(GX_DRAW_CONTEXT *context,
901                                                                  INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
902 {
903 GX_BOOL synergy_specific_format = GX_FALSE;
904 GX_BOOL drawn = GX_FALSE;
905 
906     if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TARGA &&
907         pixelmap -> gx_pixelmap_format != GX_COLOR_FORMAT_8BIT_PALETTE)
908     {
909         synergy_specific_format = GX_TRUE;
910     }
911 
912     switch (pixelmap -> gx_pixelmap_format)
913     {
914     case GX_COLOR_FORMAT_565RGB:
915     case GX_COLOR_FORMAT_565BGR:
916         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
917         {
918             /* compressed with no alpha */
919             _gx_dave2d_simulation_display_driver_565rgb_pixelmap_compressed_write(context, xpos, ypos, pixelmap);
920             drawn = GX_TRUE;
921         }
922         break;
923 
924     case GX_COLOR_FORMAT_4444ARGB:
925         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
926         {
927             /* compressed with alpha */
928             _gx_dave2d_simulation_display_driver_16bpp_4444argb_pixelmap_compressed_alpha_write(context, xpos, ypos, pixelmap);
929             drawn = GX_TRUE;
930         }
931         break;
932 
933     case GX_COLOR_FORMAT_4444BGRA:
934         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
935         {
936             /* compressed with alpha */
937             _gx_dave2d_simulation_display_driver_16bpp_4444bgra_pixelmap_compressed_alpha_write(context, xpos, ypos, pixelmap);
938             drawn = GX_TRUE;
939         }
940         break;
941 
942     case GX_COLOR_FORMAT_32ARGB:
943     case GX_COLOR_FORMAT_24XRGB:
944         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
945         {
946             /* compressed with alpha */
947             _gx_dave2d_simulation_display_driver_16bpp_32argb_pixelmap_compressed_write(context, xpos, ypos, pixelmap);
948             drawn = GX_TRUE;
949         }
950         else
951         {
952             _gx_dave2d_simulation_display_driver_16bpp_32argb_pixelmap_raw_write(context, xpos, ypos, pixelmap);
953             drawn = GX_TRUE;
954         }
955         break;
956 
957     default:
958         break;
959     }
960 
961     if (!synergy_specific_format && !drawn)
962     {
963         if (alpha == 0xff)
964         {
965             _gx_display_driver_565rgb_pixelmap_draw(context, xpos, ypos, pixelmap);
966         }
967         else
968         {
969             _gx_display_driver_565rgb_pixelmap_blend(context, xpos, ypos, pixelmap, alpha);
970         }
971     }
972 }
973 
974 /**************************************************************************/
975 /*                                                                        */
976 /*  FUNCTION                                               RELEASE        */
977 /*                                                                        */
978 /*    _gx_dave2d_simulation_display_driver_16bpp_pixelmap_draw            */
979 /*                                                        PORTABLE C      */
980 /*                                                           6.4.0        */
981 /*  AUTHOR                                                                */
982 /*                                                                        */
983 /*    Ting Zhu, Microsoft Corporation                                     */
984 /*                                                                        */
985 /*  DESCRIPTION                                                           */
986 /*                                                                        */
987 /*    565rgb , 4444argb and 4444bgra screen driver pixelmap drawing       */
988 /*    function that handles compressed or uncompress, without alpha       */
989 /*    channel.                                                            */
990 /*                                                                        */
991 /*  INPUT                                                                 */
992 /*                                                                        */
993 /*    context                               Drawing context               */
994 /*    xpos                                  x-coord of top-left draw point*/
995 /*    ypos                                  y-coord of top-left draw point*/
996 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
997 /*                                                                        */
998 /*  OUTPUT                                                                */
999 /*                                                                        */
1000 /*    None                                                                */
1001 /*                                                                        */
1002 /*  CALLS                                                                 */
1003 /*                                                                        */
1004 /*     _gx_dave2d_simulation_display_driver_565rgb_pixelmap_blend         */
1005 /*                                                                        */
1006 /*  CALLED BY                                                             */
1007 /*                                                                        */
1008 /*    GUIX Internal Code                                                  */
1009 /*                                                                        */
1010 /*  RELEASE HISTORY                                                       */
1011 /*                                                                        */
1012 /*    DATE              NAME                      DESCRIPTION             */
1013 /*                                                                        */
1014 /*  12-31-2023     Ting Zhu                 Initial Version 6.4.0         */
1015 /*                                                                        */
1016 /**************************************************************************/
_gx_dave2d_simulation_display_driver_16bpp_pixelmap_draw(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1017 VOID _gx_dave2d_simulation_display_driver_16bpp_pixelmap_draw(GX_DRAW_CONTEXT *context,
1018                                                                INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1019 {
1020     _gx_dave2d_simulation_display_driver_565rgb_pixelmap_blend(context, xpos, ypos, pixelmap, context -> gx_draw_context_brush.gx_brush_alpha);
1021 }
1022 
1023