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 /**   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_display.h"
28 
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_display_driver_24xrgb_pixelmap_raw_write        PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    Internal helper function that handles writing of uncompressed       */
43 /*    pixlemap file without alpha channel.                                */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    context                               Drawing context               */
48 /*    xpos                                  x-coord of top-left draw point*/
49 /*    ypos                                  y-coord of top-left draw point*/
50 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    None                                                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    None                                                                */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
69 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_gx_display_driver_24xrgb_pixelmap_raw_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)73 static VOID _gx_display_driver_24xrgb_pixelmap_raw_write(GX_DRAW_CONTEXT *context,
74                                                          INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
75 {
76 INT           xval;
77 INT           yval;
78 INT           width;
79 GX_COLOR     *putrow;
80 GX_COLOR     *getrow;
81 GX_COLOR     *put;
82 GX_COLOR     *get;
83 
84 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
85 
86     getrow = (GX_COLOR *)(pixelmap -> gx_pixelmap_data);
87     getrow += pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos);
88     getrow += (clip -> gx_rectangle_left - xpos);
89 
90     /* brush alpha is 0xff means draw pixelmap to memory directly. */
91     putrow = context -> gx_draw_context_memory;
92     putrow += clip -> gx_rectangle_top * context -> gx_draw_context_pitch;
93     putrow += clip -> gx_rectangle_left;
94 
95     width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
96 
97     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
98     {
99         put = putrow;
100         get = getrow;
101 
102         for (xval = 0; xval < width; xval++)
103         {
104             *put++ = *get++;
105         }
106         putrow += context -> gx_draw_context_pitch;
107         getrow += pixelmap -> gx_pixelmap_width;
108     }
109 }
110 
111 /**************************************************************************/
112 /*                                                                        */
113 /*  FUNCTION                                               RELEASE        */
114 /*                                                                        */
115 /*    _gx_display_driver_24xrgb_pixelmap_alpha_write      PORTABLE C      */
116 /*                                                           6.1.7        */
117 /*  AUTHOR                                                                */
118 /*                                                                        */
119 /*    Kenneth Maxwell, Microsoft Corporation                              */
120 /*                                                                        */
121 /*  DESCRIPTION                                                           */
122 /*                                                                        */
123 /*    Internal helper function that handles writing of uncompressed       */
124 /*    pixlemap file with alpha channel.                                   */
125 /*                                                                        */
126 /*  INPUT                                                                 */
127 /*                                                                        */
128 /*    context                               Drawing context               */
129 /*    xpos                                  x-coord of top-left draw point*/
130 /*    ypos                                  y-coord of top-left draw point*/
131 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
132 /*                                                                        */
133 /*  OUTPUT                                                                */
134 /*                                                                        */
135 /*    None                                                                */
136 /*                                                                        */
137 /*  CALLS                                                                 */
138 /*                                                                        */
139 /*    _gx_display_driver_24xrgb_pixel_blend Basic display driver pixel    */
140 /*                                            blend function for 24xrgb   */
141 /*                                            format                      */
142 /*    _gx_display_driver_32bpp_pixel_write  Basic display driver pixel    */
143 /*                                            write function for 32bpp    */
144 /*                                            color depth                 */
145 /*                                                                        */
146 /*  CALLED BY                                                             */
147 /*                                                                        */
148 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
149 /*                                                                        */
150 /*  RELEASE HISTORY                                                       */
151 /*                                                                        */
152 /*    DATE              NAME                      DESCRIPTION             */
153 /*                                                                        */
154 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
155 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
156 /*                                            resulting in version 6.1    */
157 /*  06-02-2021     Kenneth Maxwell          Modified comment(s),          */
158 /*                                            removed unused assignments, */
159 /*                                            resulting in version 6.1.7  */
160 /*                                                                        */
161 /**************************************************************************/
_gx_display_driver_24xrgb_pixelmap_alpha_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)162 static VOID _gx_display_driver_24xrgb_pixelmap_alpha_write(GX_DRAW_CONTEXT *context,
163                                                            INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
164 {
165 INT           xval;
166 INT           yval;
167 GX_COLOR      color;
168 INT           width;
169 ULONG        *get;
170 UCHAR         alpha_value;
171 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
172 
173     get = (ULONG *)((UINT)(pixelmap -> gx_pixelmap_data) + (INT)sizeof(GX_COLOR) * (UINT)(pixelmap -> gx_pixelmap_width) * (UINT)((INT)(clip -> gx_rectangle_top) - ypos));
174     get += (clip -> gx_rectangle_left - xpos);
175 
176     width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
177 
178     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
179     {
180         for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
181         {
182             alpha_value = (UCHAR)(*get >> 24);
183             if (alpha_value)
184             {
185                 color = *get & 0x00ffffff;
186                 if (alpha_value == 255)
187                 {
188                     _gx_display_driver_32bpp_pixel_write(context, xval, yval, color);
189                 }
190                 else
191                 {
192                     _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, color, alpha_value);
193                 }
194             }
195             get++;
196         }
197         get += pixelmap -> gx_pixelmap_width - width;
198     }
199 }
200 
201 /**************************************************************************/
202 /*                                                                        */
203 /*  FUNCTION                                               RELEASE        */
204 /*                                                                        */
205 /*    _gx_display_driver_24xrgb_pixelmap_compressed_write                 */
206 /*                                                        PORTABLE C      */
207 /*                                                           6.1          */
208 /*  AUTHOR                                                                */
209 /*                                                                        */
210 /*    Kenneth Maxwell, Microsoft Corporation                              */
211 /*                                                                        */
212 /*  DESCRIPTION                                                           */
213 /*                                                                        */
214 /*    Internal helper function that handles writing of compressed         */
215 /*    pixlemap file without alpha channel.                                */
216 /*                                                                        */
217 /*  INPUT                                                                 */
218 /*                                                                        */
219 /*    context                               Drawing context               */
220 /*    xpos                                  x-coord of top-left draw point*/
221 /*    ypos                                  y-coord of top-left draw point*/
222 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
223 /*                                                                        */
224 /*  OUTPUT                                                                */
225 /*                                                                        */
226 /*    None                                                                */
227 /*                                                                        */
228 /*  CALLS                                                                 */
229 /*                                                                        */
230 /*    _gx_display_driver_24xrgb_pixel_blend Basic display driver pixel    */
231 /*                                            blend function for 24xrgb   */
232 /*                                            format                      */
233 /*                                                                        */
234 /*  CALLED BY                                                             */
235 /*                                                                        */
236 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
237 /*                                                                        */
238 /*  RELEASE HISTORY                                                       */
239 /*                                                                        */
240 /*    DATE              NAME                      DESCRIPTION             */
241 /*                                                                        */
242 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
243 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
244 /*                                            resulting in version 6.1    */
245 /*                                                                        */
246 /**************************************************************************/
_gx_display_driver_24xrgb_pixelmap_compressed_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)247 static VOID _gx_display_driver_24xrgb_pixelmap_compressed_write(GX_DRAW_CONTEXT *context,
248                                                                 INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
249 {
250 INT                yval;
251 INT                xval;
252 GX_CONST GX_COLOR *get;
253 GX_COLOR          *put;
254 GX_COLOR          *putrow;
255 GX_UBYTE           count;
256 GX_COLOR           pixel;
257 GX_CONST GX_UBYTE *get_count;
258 GX_UBYTE           brush_alpha;
259 
260 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
261 
262     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
263 
264     get = (GX_CONST GX_COLOR *)pixelmap -> gx_pixelmap_data;
265     get_count = (GX_CONST GX_UBYTE *)pixelmap -> gx_pixelmap_aux_data;
266 
267     /* first, skip to the starting row */
268     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
269     {
270         xval = 0;
271         while (xval < pixelmap -> gx_pixelmap_width)
272         {
273             count = *get_count++;
274 
275             if (count & 0x80)
276             {
277                 count = (GX_UBYTE)((count & 0x7f) + 1u);
278                 get++;      /* skip repeated pixel value */
279             }
280             else
281             {
282                 count++;
283                 get += count;   /* skip raw pixel values */
284             }
285             xval += count;
286         }
287     }
288 
289     /* now we are on the first visible row, copy pixels until we get
290        to the enf of the last visible row
291      */
292     putrow = (GX_COLOR *)context -> gx_draw_context_memory;
293     putrow += yval * context -> gx_draw_context_pitch;
294     putrow += xpos;
295 
296     while (yval <= clip -> gx_rectangle_bottom)
297     {
298         put = putrow;
299         xval = xpos;
300 
301         while (xval < xpos + pixelmap -> gx_pixelmap_width)
302         {
303             count = *get_count++;
304 
305             if (count & 0x80)
306             {
307                 /* repeated value */
308                 count = (GX_UBYTE)((count & 0x7f) + 1u);
309                 pixel = (*get++) & 0x00ffffff;
310 
311                 if (brush_alpha == 0xff)
312                 {
313                     while (count--)
314                     {
315                         if (xval >= clip -> gx_rectangle_left &&
316                             xval <= clip -> gx_rectangle_right)
317                         {
318                             *put = pixel;
319                         }
320                         put++;
321                         xval++;
322                     }
323                 }
324                 else
325                 {
326                     while (count--)
327                     {
328                         if (xval >= clip -> gx_rectangle_left &&
329                             xval <= clip -> gx_rectangle_right)
330                         {
331                             _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, brush_alpha);
332                         }
333                         xval++;
334                     }
335                 }
336             }
337             else
338             {
339                 /* string of non-repeated values */
340                 count++;
341 
342                 if (brush_alpha == 0xff)
343                 {
344                     while (count--)
345                     {
346                         if (xval >= clip -> gx_rectangle_left &&
347                             xval <= clip -> gx_rectangle_right)
348                         {
349                             *put = (*get) & 0x00ffffff;
350                         }
351                         put++;
352                         get++;
353                         xval++;
354                     }
355                 }
356                 else
357                 {
358                     while (count--)
359                     {
360                         if (xval >= clip -> gx_rectangle_left &&
361                             xval <= clip -> gx_rectangle_right)
362                         {
363                             _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, *get, brush_alpha);
364                         }
365                         get++;
366                         xval++;
367                     }
368                 }
369             }
370         }
371         putrow += context -> gx_draw_context_pitch;
372         yval++;
373     }
374 }
375 
376 /**************************************************************************/
377 /*                                                                        */
378 /*  FUNCTION                                               RELEASE        */
379 /*                                                                        */
380 /*    _gx_display_driver_24xrgb_pixelmap_compressed_alpha_write           */
381 /*                                                        PORTABLE C      */
382 /*                                                           6.1          */
383 /*  AUTHOR                                                                */
384 /*                                                                        */
385 /*    Kenneth Maxwell, 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 /*                                                                        */
405 /*    _gx_display_driver_24xrgb_pixel_blend Basic display driver pixel    */
406 /*                                            blend function for 24xrgb   */
407 /*                                            format                      */
408 /*                                                                        */
409 /*  CALLED BY                                                             */
410 /*                                                                        */
411 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
412 /*                                                                        */
413 /*  RELEASE HISTORY                                                       */
414 /*                                                                        */
415 /*    DATE              NAME                      DESCRIPTION             */
416 /*                                                                        */
417 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
418 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
419 /*                                            resulting in version 6.1    */
420 /*                                                                        */
421 /**************************************************************************/
_gx_display_driver_24xrgb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)422 static VOID _gx_display_driver_24xrgb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT *context,
423                                                                       INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
424 {
425 INT                yval;
426 INT                xval;
427 GX_CONST GX_COLOR *get;
428 GX_UBYTE           count;
429 GX_COLOR           pixel;
430 GX_CONST GX_UBYTE *get_count;
431 GX_UBYTE           brush_alpha;
432 GX_UBYTE           alpha;
433 GX_UBYTE           combined_alpha;
434 
435 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
436 
437     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
438 
439     get = (GX_CONST GX_COLOR *)pixelmap -> gx_pixelmap_data;
440     get_count = (GX_CONST GX_UBYTE *)pixelmap -> gx_pixelmap_aux_data;
441 
442     /* first, skip to the starting row */
443     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
444     {
445         xval = 0;
446         while (xval < pixelmap -> gx_pixelmap_width)
447         {
448             count = *get_count++;
449 
450             if (count & 0x80)
451             {
452                 count = (GX_UBYTE)((count & 0x7f) + 1u);
453                 get++;      /* skip repeated pixel value */
454             }
455             else
456             {
457                 count++;
458                 get += count;   /* skip raw pixel values */
459             }
460             xval += count;
461         }
462     }
463 
464     /* now we are on the first visible row, copy pixels until we get
465        to the enf of the last visible row
466      */
467 
468     while (yval <= clip -> gx_rectangle_bottom)
469     {
470         xval = xpos;
471 
472         while (xval < xpos + pixelmap -> gx_pixelmap_width)
473         {
474             count = *get_count++;
475 
476             if (count & 0x80)
477             {
478                 /* repeated value */
479                 count = (GX_UBYTE)((count & 0x7f) + 1u);
480                 alpha = (GX_UBYTE)((*get) >> 24);
481                 pixel = (*get++) & 0x00ffffff;
482 
483                 combined_alpha = (GX_UBYTE)(alpha * brush_alpha / 255);
484 
485                 if (combined_alpha)
486                 {
487                     while (count--)
488                     {
489                         if (xval >= clip -> gx_rectangle_left &&
490                             xval <= clip -> gx_rectangle_right)
491                         {
492                             _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, combined_alpha);
493                         }
494                         xval++;
495                     }
496                 }
497                 else
498                 {
499                     xval += count;
500                 }
501             }
502             else
503             {
504                 /* string of non-repeated values */
505                 count++;
506 
507                 while (count--)
508                 {
509                     if (xval >= clip -> gx_rectangle_left &&
510                         xval <= clip -> gx_rectangle_right)
511                     {
512                         alpha = (GX_UBYTE)((*get) >> 24);
513                         pixel = (*get) & 0x00ffffff;
514                         combined_alpha = (GX_UBYTE)(alpha * brush_alpha / 255);
515                         _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, combined_alpha);
516                     }
517                     get++;
518                     xval++;
519                 }
520             }
521         }
522         yval++;
523     }
524 }
525 
526 /**************************************************************************/
527 /*                                                                        */
528 /*  FUNCTION                                               RELEASE        */
529 /*                                                                        */
530 /*    _gx_display_driver_24xrgb_palette_pixelmap_compressed_write         */
531 /*                                                        PORTABLE C      */
532 /*                                                           6.1          */
533 /*  AUTHOR                                                                */
534 /*                                                                        */
535 /*    Kenneth Maxwell, Microsoft Corporation                              */
536 /*                                                                        */
537 /*  DESCRIPTION                                                           */
538 /*                                                                        */
539 /*    Internal helper function that handles writing of compressed         */
540 /*    pixlemap file without transparent of palette pixelmap.              */
541 /*                                                                        */
542 /*  INPUT                                                                 */
543 /*                                                                        */
544 /*    context                               Drawing context               */
545 /*    xpos                                  x-coord of top-left draw point*/
546 /*    ypos                                  y-coord of top-left draw point*/
547 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
548 /*                                                                        */
549 /*  OUTPUT                                                                */
550 /*                                                                        */
551 /*    None                                                                */
552 /*                                                                        */
553 /*  CALLS                                                                 */
554 /*                                                                        */
555 /*    _gx_display_driver_24xrgb_pixel_blend Basic display driver pixel    */
556 /*                                            blend function for 24xrgb   */
557 /*                                            format                      */
558 /*                                                                        */
559 /*  CALLED BY                                                             */
560 /*                                                                        */
561 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
562 /*                                                                        */
563 /*  RELEASE HISTORY                                                       */
564 /*                                                                        */
565 /*    DATE              NAME                      DESCRIPTION             */
566 /*                                                                        */
567 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
568 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
569 /*                                            resulting in version 6.1    */
570 /*                                                                        */
571 /**************************************************************************/
_gx_display_driver_24xrgb_palette_pixelmap_compressed_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)572 static VOID _gx_display_driver_24xrgb_palette_pixelmap_compressed_write(GX_DRAW_CONTEXT *context,
573                                                                         INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
574 {
575 INT             yval;
576 INT             xval;
577 GX_CONST UCHAR *get;
578 UCHAR           count;
579 GX_COLOR       *put;
580 GX_COLOR       *putrow;
581 GX_COLOR        pixel;
582 GX_COLOR       *palette;
583 GX_UBYTE        brush_alpha;
584 GX_UBYTE        r;
585 GX_UBYTE        g;
586 GX_UBYTE        b;
587 GX_RECTANGLE   *clip = context -> gx_draw_context_clip;
588 
589     get = (GX_CONST UCHAR *)pixelmap -> gx_pixelmap_data;
590     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
591 
592     /* compressed with  alpha is a one-byte count and  one-byte pixel index */
593     /* first, skip to the starting row */
594     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
595     {
596         xval = 0;
597         while (xval < pixelmap -> gx_pixelmap_width)
598         {
599             count = *get++;
600 
601             if (count & 0x80)
602             {
603                 count = (UCHAR)((count & 0x7f) + 1);
604                 get++;      /* skip repeated pixel value */
605             }
606             else
607             {
608                 count++;
609                 get += count;   /* skip raw pixel values */
610             }
611             xval += count;
612         }
613     }
614 
615     /* now we are on the first visible row, copy pixels until we get
616        to the enf of the last visible row
617      */
618     putrow = (GX_COLOR *)context -> gx_draw_context_memory;
619     putrow += yval * context -> gx_draw_context_pitch;
620     putrow += xpos;
621 
622     /* Now we are on the first visible row, copy pixels until we get
623        to the end of the last visible row. */
624 
625     palette = (GX_COLOR *)pixelmap -> gx_pixelmap_aux_data;
626 
627     while (yval <= clip -> gx_rectangle_bottom)
628     {
629         xval = xpos;
630         put = putrow;
631 
632         while (xval < xpos + pixelmap -> gx_pixelmap_width)
633         {
634             count = *get++;
635 
636             if (count & 0x80)
637             {
638                 /* repeated value */
639                 count = (UCHAR)((count & 0x7f) + 1);
640 
641                 r = (GX_UBYTE)REDVAL_32BPP(palette[*get]);
642                 g = (GX_UBYTE)GREENVAL_32BPP(palette[*get]);
643                 b = (GX_UBYTE)BLUEVAL_32BPP(palette[*get++]);
644 
645                 pixel = (GX_COLOR)ASSEMBLECOLOR_24BPP(r, g, b);
646 
647                 if (brush_alpha == 0xff)
648                 {
649                     while (count--)
650                     {
651                         if (xval >= clip -> gx_rectangle_left &&
652                             xval <= clip -> gx_rectangle_right)
653                         {
654                             *put = pixel & 0x00ffffff;
655                         }
656                         put++;
657                         xval++;
658                     }
659                 }
660                 else
661                 {
662                     while (count--)
663                     {
664                         if (xval >= clip -> gx_rectangle_left &&
665                             xval <= clip -> gx_rectangle_right)
666                         {
667                             _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, brush_alpha);
668                         }
669                         xval++;
670                     }
671                 }
672             }
673             else
674             {
675                 /* string of non-repeated values */
676                 count++;
677                 if (brush_alpha == 0xff)
678                 {
679                     while (count--)
680                     {
681                         if (xval >= clip -> gx_rectangle_left &&
682                             xval <= clip -> gx_rectangle_right)
683                         {
684                             r = (GX_UBYTE)REDVAL_32BPP(palette[*get]);
685                             g = (GX_UBYTE)GREENVAL_32BPP(palette[*get]);
686                             b = (GX_UBYTE)BLUEVAL_32BPP(palette[*get]);
687                             pixel = (GX_COLOR)ASSEMBLECOLOR_24BPP(r, g, b);
688                             *put = pixel & 0x00ffffff;
689                         }
690                         get++;
691                         put++;
692                         xval++;
693                     }
694                 }
695                 else
696                 {
697                     while (count--)
698                     {
699                         if (xval >= clip -> gx_rectangle_left &&
700                             xval <= clip -> gx_rectangle_right)
701                         {
702                             r = (GX_UBYTE)REDVAL_32BPP(palette[*get]);
703                             g = (GX_UBYTE)GREENVAL_32BPP(palette[*get]);
704                             b = (GX_UBYTE)BLUEVAL_32BPP(palette[*get]);
705                             pixel = (GX_COLOR)ASSEMBLECOLOR_24BPP(r, g, b);
706                             _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, brush_alpha);
707                         }
708                         get++;
709                         xval++;
710                     }
711                 }
712             }
713         }
714         putrow += context -> gx_draw_context_pitch;
715         yval++;
716     }
717 }
718 
719 /**************************************************************************/
720 /*                                                                        */
721 /*  FUNCTION                                               RELEASE        */
722 /*                                                                        */
723 /*    _gx_display_driver_24xrgb_palette_pixelmap_write    PORTABLE C      */
724 /*                                                           6.1.7        */
725 /*  AUTHOR                                                                */
726 /*                                                                        */
727 /*    Kenneth Maxwell, Microsoft Corporation                              */
728 /*                                                                        */
729 /*  DESCRIPTION                                                           */
730 /*                                                                        */
731 /*    Internal helper function that handles writing of uncompressed       */
732 /*    pixlemap file without transparent of palette pixelmap.              */
733 /*                                                                        */
734 /*  INPUT                                                                 */
735 /*                                                                        */
736 /*    context                               Drawing context               */
737 /*    xpos                                  x-coord of top-left draw point*/
738 /*    ypos                                  y-coord of top-left draw point*/
739 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
740 /*                                                                        */
741 /*  OUTPUT                                                                */
742 /*                                                                        */
743 /*    None                                                                */
744 /*                                                                        */
745 /*  CALLS                                                                 */
746 /*                                                                        */
747 /*    None                                                                */
748 /*                                                                        */
749 /*  CALLED BY                                                             */
750 /*                                                                        */
751 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
752 /*                                                                        */
753 /*  RELEASE HISTORY                                                       */
754 /*                                                                        */
755 /*    DATE              NAME                      DESCRIPTION             */
756 /*                                                                        */
757 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
758 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
759 /*                                            resulting in version 6.1    */
760 /*  06-02-2021     Kenneth Maxwell          Modified comment(s),          */
761 /*                                            removed unused assignments, */
762 /*                                            resulting in version 6.1.7  */
763 /*                                                                        */
764 /**************************************************************************/
_gx_display_driver_24xrgb_palette_pixelmap_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)765 static VOID _gx_display_driver_24xrgb_palette_pixelmap_write(GX_DRAW_CONTEXT *context,
766                                                              INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
767 {
768 INT           xval;
769 INT           yval;
770 GX_COLOR      color;
771 INT           width;
772 GX_UBYTE     *get;
773 GX_COLOR     *palette;
774 GX_COLOR     *put;
775 GX_COLOR     *putrow;
776 GX_UBYTE      r;
777 GX_UBYTE      g;
778 GX_UBYTE      b;
779 
780 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
781 
782     yval = clip -> gx_rectangle_top;
783 
784     get = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data + pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos));
785     get += (clip -> gx_rectangle_left - xpos);
786 
787     palette = (GX_COLOR *)pixelmap -> gx_pixelmap_aux_data;
788 
789     if (!palette)
790     {
791         return;
792     }
793     /* now we are on the first visible row, copy pixels until we get
794        to the enf of the last visible row
795      */
796     putrow = (GX_COLOR *)context -> gx_draw_context_memory;
797     putrow += yval * context -> gx_draw_context_pitch;
798     putrow += xpos;
799 
800     width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
801 
802     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
803     {
804         put = putrow;
805         for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
806         {
807             r = (GX_UBYTE)REDVAL_32BPP(palette[*get]);
808             g = (GX_UBYTE)GREENVAL_32BPP(palette[*get]);
809             b = (GX_UBYTE)BLUEVAL_32BPP(palette[*get++]);
810 
811             color = (GX_COLOR)ASSEMBLECOLOR_24BPP(r, g, b);
812             *put++ = color & 0x00ffffff;
813         }
814         putrow += context -> gx_draw_context_pitch;
815         get += pixelmap -> gx_pixelmap_width - width;
816     }
817 }
818 
819 /**************************************************************************/
820 /*                                                                        */
821 /*  FUNCTION                                               RELEASE        */
822 /*                                                                        */
823 /*    _gx_display_driver_24xrgb_palette_pixelmap_transparent_write        */
824 /*                                                         PORTABLE C     */
825 /*                                                           6.1.7        */
826 /*  AUTHOR                                                                */
827 /*                                                                        */
828 /*    Kenneth Maxwell, Microsoft Corporation                              */
829 /*                                                                        */
830 /*  DESCRIPTION                                                           */
831 /*                                                                        */
832 /*    Internal helper function that handles writing of uncompressed       */
833 /*    pixlemap file with transparent of palette pixelmap.                 */
834 /*                                                                        */
835 /*  INPUT                                                                 */
836 /*                                                                        */
837 /*    context                               Drawing context               */
838 /*    xpos                                  x-coord of top-left draw point*/
839 /*    ypos                                  y-coord of top-left draw point*/
840 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
841 /*                                                                        */
842 /*  OUTPUT                                                                */
843 /*                                                                        */
844 /*    None                                                                */
845 /*                                                                        */
846 /*  CALLS                                                                 */
847 /*                                                                        */
848 /*    _gx_display_driver_32bpp_pixel_write  Basic display driver pixel    */
849 /*                                            write function for 32bpp    */
850 /*                                            color depth                 */
851 /*                                                                        */
852 /*  CALLED BY                                                             */
853 /*                                                                        */
854 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
855 /*                                                                        */
856 /*  RELEASE HISTORY                                                       */
857 /*                                                                        */
858 /*    DATE              NAME                      DESCRIPTION             */
859 /*                                                                        */
860 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
861 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
862 /*                                            resulting in version 6.1    */
863 /*  06-02-2021     Kenneth Maxwell          Modified comment(s),          */
864 /*                                            removed unused assignments, */
865 /*                                            resulting in version 6.1.7  */
866 /*                                                                        */
867 /**************************************************************************/
_gx_display_driver_24xrgb_palette_pixelmap_transparent_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)868 static VOID _gx_display_driver_24xrgb_palette_pixelmap_transparent_write(GX_DRAW_CONTEXT *context,
869                                                                          INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
870 {
871 INT           xval;
872 INT           yval;
873 GX_COLOR      color;
874 INT           width;
875 GX_UBYTE     *get;
876 GX_COLOR     *palette;
877 GX_UBYTE      r;
878 GX_UBYTE      g;
879 GX_UBYTE      b;
880 
881 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
882 
883     palette = (GX_COLOR *)pixelmap -> gx_pixelmap_aux_data;
884 
885     if (!palette)
886     {
887         return;
888     }
889 
890     get = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data + pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos));
891     get += (clip -> gx_rectangle_left - xpos);
892 
893     width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
894 
895     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
896     {
897         for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
898         {
899             if ((*get) != pixelmap -> gx_pixelmap_transparent_color)
900             {
901                 r = (GX_UBYTE)REDVAL_32BPP(palette[*get]);
902                 g = (GX_UBYTE)GREENVAL_32BPP(palette[*get]);
903                 b = (GX_UBYTE)BLUEVAL_32BPP(palette[*get]);
904                 color = (GX_COLOR)ASSEMBLECOLOR_24BPP(r, g, b);
905                 _gx_display_driver_32bpp_pixel_write(context, xval, yval, color);
906             }
907             get++;
908         }
909 
910         get += pixelmap -> gx_pixelmap_width - width;
911     }
912 }
913 
914 /**************************************************************************/
915 /*                                                                        */
916 /*  FUNCTION                                               RELEASE        */
917 /*                                                                        */
918 /*    _gx_display_driver_24xrgb_palette_pixelmap_transparent_compressed   */
919 /*    _write                                              PORTABLE C      */
920 /*                                                           6.1          */
921 /*  AUTHOR                                                                */
922 /*                                                                        */
923 /*    Kenneth Maxwell, Microsoft Corporation                              */
924 /*                                                                        */
925 /*  DESCRIPTION                                                           */
926 /*                                                                        */
927 /*    Internal helper function that handles writing of compressed         */
928 /*    pixlemap file with transparent of palette pixelmap.                 */
929 /*                                                                        */
930 /*  INPUT                                                                 */
931 /*                                                                        */
932 /*    context                               Drawing context               */
933 /*    xpos                                  x-coord of top-left draw point*/
934 /*    ypos                                  y-coord of top-left draw point*/
935 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
936 /*                                                                        */
937 /*  OUTPUT                                                                */
938 /*                                                                        */
939 /*    None                                                                */
940 /*                                                                        */
941 /*  CALLS                                                                 */
942 /*                                                                        */
943 /*    _gx_display_driver_24xrgb_pixel_blend Basic display driver pixel    */
944 /*                                            blend function for 24xrgb   */
945 /*                                            format                      */
946 /*                                                                        */
947 /*  CALLED BY                                                             */
948 /*                                                                        */
949 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
950 /*                                                                        */
951 /*  RELEASE HISTORY                                                       */
952 /*                                                                        */
953 /*    DATE              NAME                      DESCRIPTION             */
954 /*                                                                        */
955 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
956 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
957 /*                                            resulting in version 6.1    */
958 /*                                                                        */
959 /**************************************************************************/
_gx_display_driver_24xrgb_palette_pixelmap_transparent_compressed_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)960 static VOID _gx_display_driver_24xrgb_palette_pixelmap_transparent_compressed_write(GX_DRAW_CONTEXT *context,
961                                                                                     INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
962 {
963 INT             yval;
964 INT             xval;
965 GX_CONST UCHAR *get;
966 UCHAR           count;
967 GX_COLOR        pixel;
968 GX_COLOR       *palette;
969 GX_COLOR       *put;
970 GX_COLOR       *putrow;
971 GX_UBYTE        r;
972 GX_UBYTE        g;
973 GX_UBYTE        b;
974 GX_UBYTE        brush_alpha;
975 GX_RECTANGLE   *clip = context -> gx_draw_context_clip;
976 
977     get = (GX_CONST UCHAR *)pixelmap -> gx_pixelmap_data;
978     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
979 
980     /* compressed with  alpha is a one-byte count and  one-byte pixel index */
981     /* first, skip to the starting row */
982     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
983     {
984         xval = 0;
985         while (xval < pixelmap -> gx_pixelmap_width)
986         {
987             count = *get++;
988 
989             if (count & 0x80)
990             {
991                 count = (UCHAR)((count & 0x7f) + 1);
992                 get++;      /* skip repeated pixel value */
993             }
994             else
995             {
996                 count++;
997                 get += count;   /* skip raw pixel values */
998             }
999             xval += count;
1000         }
1001     }
1002 
1003     /* Now we are on the first visible row, copy pixels until we get
1004        to the end of the last visible row. */
1005 
1006     palette = (GX_COLOR *)pixelmap -> gx_pixelmap_aux_data;
1007     putrow = (GX_COLOR *)context -> gx_draw_context_memory;
1008     putrow += yval * context -> gx_draw_context_pitch;
1009     putrow += xpos;
1010 
1011     while (yval <= clip -> gx_rectangle_bottom)
1012     {
1013         xval = xpos;
1014         put = putrow;
1015 
1016         while (xval < xpos + pixelmap -> gx_pixelmap_width)
1017         {
1018             count = *get++;
1019             if (count & 0x80)
1020             {
1021                 /* repeated value */
1022                 count = (UCHAR)((count & 0x7f) + 1);
1023                 if ((*get) != pixelmap -> gx_pixelmap_transparent_color)
1024                 {
1025                     r = (GX_UBYTE)REDVAL_32BPP(palette[*get]);
1026                     g = (GX_UBYTE)GREENVAL_32BPP(palette[*get]);
1027                     b = (GX_UBYTE)BLUEVAL_32BPP(palette[*get]);
1028 
1029                     pixel = (GX_COLOR)ASSEMBLECOLOR_24BPP(r, g, b);
1030                     if (brush_alpha == 0xff)
1031                     {
1032                         while (count--)
1033                         {
1034                             if (xval >= clip -> gx_rectangle_left &&
1035                                 xval <= clip -> gx_rectangle_right)
1036                             {
1037                                 *put = pixel;
1038                             }
1039                             xval++;
1040                             put++;
1041                         }
1042                     }
1043                     else
1044                     {
1045                         while (count--)
1046                         {
1047                             if (xval >= clip -> gx_rectangle_left &&
1048                                 xval <= clip -> gx_rectangle_right)
1049                             {
1050                                 _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, brush_alpha);
1051                             }
1052                             xval++;
1053                         }
1054                     }
1055                 }
1056                 else
1057                 {
1058                     xval += count;
1059                     put += count;
1060                 }
1061 
1062                 get++;
1063             }
1064             else
1065             {
1066                 /* string of non-repeated values */
1067                 count++;
1068                 if (brush_alpha == 0xff)
1069                 {
1070                     while (count--)
1071                     {
1072                         if ((*get) != pixelmap -> gx_pixelmap_transparent_color)
1073                         {
1074                             if (xval >= clip -> gx_rectangle_left &&
1075                                 xval <= clip -> gx_rectangle_right)
1076                             {
1077                                 r = (GX_UBYTE)REDVAL_32BPP(palette[*get]);
1078                                 g = (GX_UBYTE)GREENVAL_32BPP(palette[*get]);
1079                                 b = (GX_UBYTE)BLUEVAL_32BPP(palette[*get]);
1080                                 pixel = (GX_COLOR)ASSEMBLECOLOR_24BPP(r, g, b);
1081                                 *put = pixel;
1082                             }
1083                         }
1084                         get++;
1085                         xval++;
1086                         put++;
1087                     }
1088                 }
1089                 else
1090                 {
1091                     while (count--)
1092                     {
1093                         if ((*get) != pixelmap -> gx_pixelmap_transparent_color)
1094                         {
1095                             if (xval >= clip -> gx_rectangle_left &&
1096                                 xval <= clip -> gx_rectangle_right)
1097                             {
1098                                 r = (GX_UBYTE)REDVAL_32BPP(palette[*get]);
1099                                 g = (GX_UBYTE)GREENVAL_32BPP(palette[*get]);
1100                                 b = (GX_UBYTE)BLUEVAL_32BPP(palette[*get]);
1101                                 pixel = (GX_COLOR)ASSEMBLECOLOR_24BPP(r, g, b);
1102                                 _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, brush_alpha);
1103                             }
1104                         }
1105                         get++;
1106                         xval++;
1107                     }
1108                 }
1109             }
1110         }
1111         yval++;
1112         putrow += context -> gx_draw_context_pitch;
1113     }
1114 }
1115 
1116 /**************************************************************************/
1117 /*                                                                        */
1118 /*  FUNCTION                                               RELEASE        */
1119 /*                                                                        */
1120 /*    _gx_display_driver_24xrgb_565rgb_pixelmap_write     PORTABLE C      */
1121 /*                                                           6.1          */
1122 /*  AUTHOR                                                                */
1123 /*                                                                        */
1124 /*    Kenneth Maxwell, Microsoft Corporation                              */
1125 /*                                                                        */
1126 /*  DESCRIPTION                                                           */
1127 /*                                                                        */
1128 /*    Internal helper function that handles writing of 565rgb format      */
1129 /*    uncompressed pixlemap file without alpha channel.                   */
1130 /*                                                                        */
1131 /*  INPUT                                                                 */
1132 /*                                                                        */
1133 /*    context                               Drawing context               */
1134 /*    xpos                                  x-coord of top-left draw point*/
1135 /*    ypos                                  y-coord of top-left draw point*/
1136 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
1137 /*                                                                        */
1138 /*  OUTPUT                                                                */
1139 /*                                                                        */
1140 /*    None                                                                */
1141 /*                                                                        */
1142 /*  CALLS                                                                 */
1143 /*                                                                        */
1144 /*    None                                                                */
1145 /*                                                                        */
1146 /*  CALLED BY                                                             */
1147 /*                                                                        */
1148 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
1149 /*                                                                        */
1150 /*  RELEASE HISTORY                                                       */
1151 /*                                                                        */
1152 /*    DATE              NAME                      DESCRIPTION             */
1153 /*                                                                        */
1154 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1155 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1156 /*                                            resulting in version 6.1    */
1157 /*                                                                        */
1158 /**************************************************************************/
_gx_display_driver_24xrgb_565rgb_pixelmap_raw_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1159 static VOID _gx_display_driver_24xrgb_565rgb_pixelmap_raw_write(GX_DRAW_CONTEXT *context,
1160                                                                 INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1161 {
1162 INT              xval;
1163 INT              yval;
1164 INT              width;
1165 GX_COLOR        *putrow;
1166 USHORT          *getrow;
1167 GX_COLOR        *put;
1168 GX_CONST USHORT *get;
1169 
1170 GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
1171 
1172     putrow = (GX_COLOR *)context -> gx_draw_context_memory;
1173     putrow += clip -> gx_rectangle_top * context -> gx_draw_context_pitch;
1174     putrow += clip -> gx_rectangle_left;
1175 
1176     getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
1177     getrow += pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos);
1178     getrow += (clip -> gx_rectangle_left - xpos);
1179 
1180     width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
1181 
1182     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
1183     {
1184         put = putrow;
1185         get = getrow;
1186 
1187         for (xval = 0; xval < width; xval++)
1188         {
1189             *put++ = (GX_COLOR)ASSEMBLECOLOR_32BPP(REDVAL_16BPP(*get) << 3,
1190                                                    GREENVAL_16BPP(*get) << 2,
1191                                                    BLUEVAL_16BPP(*get) << 3);
1192             get++;
1193         }
1194         putrow += context -> gx_draw_context_pitch;
1195         getrow += pixelmap -> gx_pixelmap_width;
1196     }
1197 }
1198 
1199 /**************************************************************************/
1200 /*                                                                        */
1201 /*  FUNCTION                                               RELEASE        */
1202 /*                                                                        */
1203 /*    _gx_display_driver_24xrgb_565rgb_pixelmap_compressed_write          */
1204 /*                                                        PORTABLE C      */
1205 /*                                                           6.1          */
1206 /*  AUTHOR                                                                */
1207 /*                                                                        */
1208 /*    Kenneth Maxwell, Microsoft Corporation                              */
1209 /*                                                                        */
1210 /*  DESCRIPTION                                                           */
1211 /*                                                                        */
1212 /*    Internal helper function that handles writing of compressed         */
1213 /*    pixelmap data of 565rgb format in 32bpp driver.                     */
1214 /*                                                                        */
1215 /*  INPUT                                                                 */
1216 /*                                                                        */
1217 /*    context                               Drawing context               */
1218 /*    xpos                                  x-coord of top-left draw point*/
1219 /*    ypos                                  y-coord of top-left draw point*/
1220 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
1221 /*                                                                        */
1222 /*  OUTPUT                                                                */
1223 /*                                                                        */
1224 /*    None                                                                */
1225 /*                                                                        */
1226 /*  CALLS                                                                 */
1227 /*                                                                        */
1228 /*    _gx_display_driver_24xrgb_pixel_blend Basic display driver pixel    */
1229 /*                                            blend function for 24xrgb   */
1230 /*                                            format                      */
1231 /*                                                                        */
1232 /*  CALLED BY                                                             */
1233 /*                                                                        */
1234 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
1235 /*                                                                        */
1236 /*  RELEASE HISTORY                                                       */
1237 /*                                                                        */
1238 /*    DATE              NAME                      DESCRIPTION             */
1239 /*                                                                        */
1240 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1241 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1242 /*                                            resulting in version 6.1    */
1243 /*                                                                        */
1244 /**************************************************************************/
_gx_display_driver_24xrgb_565rgb_pixelmap_compressed_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1245 static VOID _gx_display_driver_24xrgb_565rgb_pixelmap_compressed_write(GX_DRAW_CONTEXT *context,
1246                                                                        INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1247 {
1248 INT              yval;
1249 INT              xval;
1250 GX_CONST USHORT *get;
1251 USHORT           count;
1252 GX_COLOR         pixel;
1253 GX_UBYTE         r;
1254 GX_UBYTE         g;
1255 GX_UBYTE         b;
1256 GX_UBYTE         brush_alpha;
1257 GX_COLOR        *put;
1258 GX_COLOR        *putrow;
1259 GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
1260 
1261     get = (GX_CONST USHORT *)pixelmap -> gx_pixelmap_data;
1262     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
1263 
1264     /* first, skip to the starting row */
1265     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
1266     {
1267         xval = 0;
1268         while (xval < pixelmap -> gx_pixelmap_width)
1269         {
1270             count = *get++;
1271 
1272             if (count & 0x8000)
1273             {
1274                 count = (USHORT)((count & 0x7fff) + 1);
1275                 get++;      /* skip repeated pixel value */
1276             }
1277             else
1278             {
1279                 count++;
1280                 get += count;   /* skip raw pixel values */
1281             }
1282             xval += count;
1283         }
1284     }
1285 
1286     /* now we are on the first visible row, copy pixels until we get
1287        to the enf of the last visible row
1288      */
1289     putrow = (GX_COLOR *)context -> gx_draw_context_memory;
1290     putrow += yval * context -> gx_draw_context_pitch;
1291     putrow += xpos;
1292 
1293     while (yval <= clip -> gx_rectangle_bottom)
1294     {
1295         xval = xpos;
1296         put = putrow;
1297 
1298         while (xval < xpos + pixelmap -> gx_pixelmap_width)
1299         {
1300             count = *get++;
1301 
1302             if (count & 0x8000)
1303             {
1304                 /* repeated value */
1305                 count = (USHORT)((count & 0x7fff) + 1);
1306                 pixel = *get++;
1307                 r = (GX_UBYTE)(((USHORT)pixel & 0xf800) >> 8);
1308                 g = (GX_UBYTE)(((USHORT)pixel & 0x07e0) >> 3);
1309                 b = (GX_UBYTE)(((USHORT)pixel & 0x001f) << 3);
1310                 pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
1311                 if (brush_alpha == 0xff)
1312                 {
1313                     while (count--)
1314                     {
1315                         if (xval >= clip -> gx_rectangle_left &&
1316                             xval <= clip -> gx_rectangle_right)
1317                         {
1318                             *put = pixel;
1319                         }
1320                         xval++;
1321                         put++;
1322                     }
1323                 }
1324                 else
1325                 {
1326                     while (count--)
1327                     {
1328                         if (xval >= clip -> gx_rectangle_left &&
1329                             xval <= clip -> gx_rectangle_right)
1330                         {
1331                             _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, brush_alpha);
1332                         }
1333                         xval++;
1334                     }
1335                 }
1336             }
1337             else
1338             {
1339                 /* string of non-repeated values */
1340                 count++;
1341                 if (brush_alpha == 0xff)
1342                 {
1343                     while (count--)
1344                     {
1345                         if (xval >= clip -> gx_rectangle_left &&
1346                             xval <= clip -> gx_rectangle_right)
1347                         {
1348                             pixel = *get;
1349                             r = (GX_UBYTE)(((USHORT)pixel & 0xf800) >> 8);
1350                             g = (GX_UBYTE)(((USHORT)pixel & 0x07e0) >> 3);
1351                             b = (GX_UBYTE)(((USHORT)pixel & 0x001f) << 3);
1352                             pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
1353                             *put = pixel;
1354                         }
1355                         get++;
1356                         put++;
1357                         xval++;
1358                     }
1359                 }
1360                 else
1361                 {
1362                     while (count--)
1363                     {
1364                         if (xval >= clip -> gx_rectangle_left &&
1365                             xval <= clip -> gx_rectangle_right)
1366                         {
1367                             pixel = *get;
1368                             r = (GX_UBYTE)(((USHORT)pixel & 0xf800) >> 8);
1369                             g = (GX_UBYTE)(((USHORT)pixel & 0x07e0) >> 3);
1370                             b = (GX_UBYTE)(((USHORT)pixel & 0x001f) << 3);
1371                             pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
1372                             _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, brush_alpha);
1373                         }
1374                         get++;
1375                         xval++;
1376                     }
1377                 }
1378             }
1379         }
1380         yval++;
1381         putrow += context -> gx_draw_context_pitch;
1382     }
1383 }
1384 
1385 /**************************************************************************/
1386 /*                                                                        */
1387 /*  FUNCTION                                               RELEASE        */
1388 /*                                                                        */
1389 /*    _gx_display_driver_24xrgb_565rgb_pixelmap_compressed_alpha_write    */
1390 /*                                                        PORTABLE C      */
1391 /*                                                           6.1          */
1392 /*  AUTHOR                                                                */
1393 /*                                                                        */
1394 /*    Kenneth Maxwell, Microsoft Corporation                              */
1395 /*                                                                        */
1396 /*  DESCRIPTION                                                           */
1397 /*                                                                        */
1398 /*    Internal helper function that handles writing of compressed-alpha   */
1399 /*    pixelmap data of 565rgb format with 32bpp driver.                   */
1400 /*                                                                        */
1401 /*  INPUT                                                                 */
1402 /*                                                                        */
1403 /*    context                               Drawing context               */
1404 /*    xpos                                  x-coord of top-left draw point*/
1405 /*    ypos                                  y-coord of top-left draw point*/
1406 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
1407 /*                                                                        */
1408 /*  OUTPUT                                                                */
1409 /*                                                                        */
1410 /*    None                                                                */
1411 /*                                                                        */
1412 /*  CALLS                                                                 */
1413 /*                                                                        */
1414 /*    _gx_display_driver_24xrgb_pixel_blend Basic display driver pixel    */
1415 /*                                            blend function for 24xrgb   */
1416 /*                                            format                      */
1417 /*    _gx_display_driver_32bpp_pixel_write  Basic display driver pixel    */
1418 /*                                            write function for 32bpp    */
1419 /*                                            color depth                 */
1420 /*                                                                        */
1421 /*  CALLED BY                                                             */
1422 /*                                                                        */
1423 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
1424 /*                                                                        */
1425 /*  RELEASE HISTORY                                                       */
1426 /*                                                                        */
1427 /*    DATE              NAME                      DESCRIPTION             */
1428 /*                                                                        */
1429 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1430 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1431 /*                                            resulting in version 6.1    */
1432 /*                                                                        */
1433 /**************************************************************************/
_gx_display_driver_24xrgb_565rgb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1434 static VOID _gx_display_driver_24xrgb_565rgb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT *context,
1435                                                                              INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1436 {
1437 INT                yval;
1438 INT                xval;
1439 GX_CONST GX_UBYTE *get;
1440 GX_UBYTE           count;
1441 GX_COLOR           pixel;
1442 GX_UBYTE           alpha_value;
1443 GX_UBYTE           r;
1444 GX_UBYTE           g;
1445 GX_UBYTE           b;
1446 GX_UBYTE           brush_alpha;
1447 GX_UBYTE           combined_alpha;
1448 
1449 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
1450 
1451     get = (GX_CONST GX_UBYTE *)pixelmap -> gx_pixelmap_data;
1452     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
1453 
1454     /* first, skip to the starting row */
1455     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
1456     {
1457         xval = 0;
1458         while (xval < pixelmap -> gx_pixelmap_width)
1459         {
1460             count = *get;
1461 
1462             if (count & 0x80)
1463             {
1464                 count = (GX_UBYTE)((count & 0x7f) + 1);
1465                 get += 4;      /* skip repeated pixel value */
1466             }
1467             else
1468             {
1469                 count++;
1470                 get += (count * 4);   /* skip raw pixel values */
1471             }
1472             xval += count;
1473         }
1474     }
1475 
1476     /* now we are on the first visible row, copy pixels until we get
1477        to the enf of the last visible row
1478      */
1479     while (yval <= clip -> gx_rectangle_bottom)
1480     {
1481         xval = xpos;
1482 
1483         while (xval < xpos + pixelmap -> gx_pixelmap_width)
1484         {
1485             count = *get;
1486 
1487             if (count & 0x80)
1488             {
1489                 /* repeated value */
1490                 count = (GX_UBYTE)((count & 0x7f) + 1);
1491                 alpha_value = *(get + 1);
1492 
1493                 if (alpha_value)
1494                 {
1495                     if (brush_alpha == 0xff)
1496                     {
1497                         get += 2;
1498                         pixel = *(USHORT *)get;
1499                         r = (GX_UBYTE)(((USHORT)pixel & 0xf800) >> 8);
1500                         g = (GX_UBYTE)(((USHORT)pixel & 0x07e0) >> 3);
1501                         b = (GX_UBYTE)(((USHORT)pixel & 0x001f) << 3);
1502                         pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
1503                         get += 2;
1504                         while (count--)
1505                         {
1506                             if (xval >= clip -> gx_rectangle_left &&
1507                                 xval <= clip -> gx_rectangle_right)
1508                             {
1509                                 if (alpha_value == 0xff)
1510                                 {
1511                                     _gx_display_driver_32bpp_pixel_write(context, xval, yval, pixel);
1512                                 }
1513                                 else
1514                                 {
1515                                     _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, alpha_value);
1516                                 }
1517                             }
1518                             xval++;
1519                         }
1520                     }
1521                     else
1522                     {
1523                         combined_alpha = (GX_UBYTE)(alpha_value * brush_alpha / 255);
1524                         if (combined_alpha)
1525                         {
1526                             get += 2;
1527                             pixel = *(USHORT *)get;
1528                             r = (GX_UBYTE)(((USHORT)pixel & 0xf800) >> 8);
1529                             g = (GX_UBYTE)(((USHORT)pixel & 0x07e0) >> 3);
1530                             b = (GX_UBYTE)(((USHORT)pixel & 0x001f) << 3);
1531                             pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
1532                             get += 2;
1533                             while (count--)
1534                             {
1535                                 if (xval >= clip -> gx_rectangle_left &&
1536                                     xval <= clip -> gx_rectangle_right)
1537                                 {
1538                                     _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, combined_alpha);
1539                                 }
1540                                 xval++;
1541                             }
1542                         }
1543                         else
1544                         {
1545                             get += 4;
1546                             xval += count;
1547                         }
1548                     }
1549                 }
1550                 else
1551                 {
1552                     xval += count;
1553                     get += 4;
1554                 }
1555             }
1556             else
1557             {
1558                 /* string of non-repeated values */
1559                 count++;
1560                 if (brush_alpha == 0xff)
1561                 {
1562                     while (count--)
1563                     {
1564                         if (xval >= clip -> gx_rectangle_left &&
1565                             xval <= clip -> gx_rectangle_right)
1566                         {
1567                             alpha_value = *(get + 1);
1568                             get += 2;
1569                             if (alpha_value)
1570                             {
1571                                 pixel = *(USHORT *)get;
1572                                 r = (GX_UBYTE)(((USHORT)pixel & 0xf800) >> 8);
1573                                 g = (GX_UBYTE)(((USHORT)pixel & 0x07e0) >> 3);
1574                                 b = (GX_UBYTE)(((USHORT)pixel & 0x001f) << 3);
1575                                 pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
1576                                 if (alpha_value == 0xff)
1577                                 {
1578                                     _gx_display_driver_32bpp_pixel_write(context, xval, yval, pixel);
1579                                 }
1580                                 else
1581                                 {
1582                                     _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, alpha_value);
1583                                 }
1584                             }
1585                             get += 2;
1586                         }
1587                         else
1588                         {
1589                             get += 4;
1590                         }
1591                         xval++;
1592                     }
1593                 }
1594                 else
1595                 {
1596                     while (count--)
1597                     {
1598                         if (xval >= clip -> gx_rectangle_left &&
1599                             xval <= clip -> gx_rectangle_right)
1600                         {
1601                             alpha_value = *(get + 1);
1602                             get += 2;
1603                             if (alpha_value)
1604                             {
1605                                 pixel = *(USHORT *)get;
1606                                 r = (GX_UBYTE)(((USHORT)pixel & 0xf800) >> 8);
1607                                 g = (GX_UBYTE)(((USHORT)pixel & 0x07e0) >> 3);
1608                                 b = (GX_UBYTE)(((USHORT)pixel & 0x001f) << 3);
1609                                 pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
1610                                 combined_alpha = (GX_UBYTE)(brush_alpha * alpha_value / 255);
1611                                 _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, combined_alpha);
1612                             }
1613                             get += 2;
1614                         }
1615                         else
1616                         {
1617                             get += 4;
1618                         }
1619                         xval++;
1620                     }
1621                 }
1622             }
1623         }
1624         yval++;
1625     }
1626 }
1627 
1628 /**************************************************************************/
1629 /*                                                                        */
1630 /*  FUNCTION                                               RELEASE        */
1631 /*                                                                        */
1632 /*    _gx_display_driver_24xrgb_565rgb_pixelmap_alpha_write               */
1633 /*                                                        PORTABLE C      */
1634 /*                                                           6.1          */
1635 /*  AUTHOR                                                                */
1636 /*                                                                        */
1637 /*    Kenneth Maxwell, Microsoft Corporation                              */
1638 /*                                                                        */
1639 /*  DESCRIPTION                                                           */
1640 /*                                                                        */
1641 /*    Internal helper function that handles writing of non_compressed     */
1642 /*    but with alpha channel pixelmap data of 565rgb format with 32bpp    */
1643 /*    driver.                                                             */
1644 /*  INPUT                                                                 */
1645 /*                                                                        */
1646 /*    context                               Drawing context               */
1647 /*    xpos                                  x-coord of top-left draw point*/
1648 /*    ypos                                  y-coord of top-left draw point*/
1649 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
1650 /*                                                                        */
1651 /*  OUTPUT                                                                */
1652 /*                                                                        */
1653 /*    None                                                                */
1654 /*                                                                        */
1655 /*  CALLS                                                                 */
1656 /*                                                                        */
1657 /*    _gx_display_driver_24xrgb_pixel_blend Basic display driver pixel    */
1658 /*                                            blend function for 24xrgb   */
1659 /*                                            format                      */
1660 /*    _gx_display_driver_32bpp_pixel_write  Basic display driver pixel    */
1661 /*                                            write function for 32bpp    */
1662 /*                                            color depth                 */
1663 /*                                                                        */
1664 /*  CALLED BY                                                             */
1665 /*                                                                        */
1666 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
1667 /*                                                                        */
1668 /*  RELEASE HISTORY                                                       */
1669 /*                                                                        */
1670 /*    DATE              NAME                      DESCRIPTION             */
1671 /*                                                                        */
1672 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1673 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1674 /*                                            resulting in version 6.1    */
1675 /*                                                                        */
1676 /**************************************************************************/
_gx_display_driver_24xrgb_565rgb_pixelmap_alpha_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1677 static VOID _gx_display_driver_24xrgb_565rgb_pixelmap_alpha_write(GX_DRAW_CONTEXT *context,
1678                                                                   INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1679 {
1680 INT                skipcount;
1681 INT                xval;
1682 INT                yval;
1683 GX_CONST GX_UBYTE *getalpha;
1684 GX_CONST USHORT   *get;
1685 USHORT            *getrow;
1686 GX_UBYTE          *getrowalpha;
1687 GX_UBYTE           r;
1688 GX_UBYTE           g;
1689 GX_UBYTE           b;
1690 GX_COLOR           pixel;
1691 GX_UBYTE           alpha_value;
1692 
1693 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
1694 
1695     skipcount = (pixelmap -> gx_pixelmap_width) * (clip -> gx_rectangle_top - ypos);
1696     skipcount += (clip -> gx_rectangle_left - xpos);
1697     getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
1698     getrow += skipcount;
1699 
1700     getrowalpha = (GX_UBYTE *)(pixelmap -> gx_pixelmap_aux_data);
1701     getrowalpha += skipcount;
1702 
1703     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
1704     {
1705         get = getrow;
1706         getalpha = getrowalpha;
1707 
1708         for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
1709         {
1710             alpha_value = *getalpha++;
1711             pixel = *get++;
1712             if (alpha_value)
1713             {
1714                 r = (GX_UBYTE)(((USHORT)pixel & 0xf800) >> 8);
1715                 g = (GX_UBYTE)(((USHORT)pixel & 0x07e0) >> 3);
1716                 b = (GX_UBYTE)(((USHORT)pixel & 0x001f) << 3);
1717                 pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
1718                 if (alpha_value == 0xff)
1719                 {
1720                     _gx_display_driver_32bpp_pixel_write(context, xval, yval, pixel);
1721                 }
1722                 else
1723                 {
1724                     _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, alpha_value);
1725                 }
1726             }
1727         }
1728         getrow += pixelmap -> gx_pixelmap_width;
1729         getrowalpha += pixelmap -> gx_pixelmap_width;
1730     }
1731 }
1732 
1733 /**************************************************************************/
1734 /*                                                                        */
1735 /*  FUNCTION                                               RELEASE        */
1736 /*                                                                        */
1737 /*    _gx_display_driver_24xrgb_4444argb_pixelmap_alpha_write             */
1738 /*                                                        PORTABLE C      */
1739 /*                                                           6.1          */
1740 /*  AUTHOR                                                                */
1741 /*                                                                        */
1742 /*    Kenneth Maxwell, Microsoft Corporation                              */
1743 /*                                                                        */
1744 /*  DESCRIPTION                                                           */
1745 /*                                                                        */
1746 /*    Internal helper function that handles writing of uncompressed       */
1747 /*    pixlemap file with alpha channel of 4444argb format.                */
1748 /*                                                                        */
1749 /*  INPUT                                                                 */
1750 /*                                                                        */
1751 /*    context                               Drawing context               */
1752 /*    xpos                                  x-coord of top-left draw point*/
1753 /*    ypos                                  y-coord of top-left draw point*/
1754 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
1755 /*                                                                        */
1756 /*  OUTPUT                                                                */
1757 /*                                                                        */
1758 /*    None                                                                */
1759 /*                                                                        */
1760 /*  CALLS                                                                 */
1761 /*                                                                        */
1762 /*    _gx_display_driver_24xrgb_pixel_blend Basic display driver pixel    */
1763 /*                                            blend function for 24xrgb   */
1764 /*                                            format                      */
1765 /*    _gx_display_driver_32bpp_pixel_write  Basic display driver pixel    */
1766 /*                                            write function for 32bpp    */
1767 /*                                            color depth                 */
1768 /*                                                                        */
1769 /*  CALLED BY                                                             */
1770 /*                                                                        */
1771 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
1772 /*                                                                        */
1773 /*  RELEASE HISTORY                                                       */
1774 /*                                                                        */
1775 /*    DATE              NAME                      DESCRIPTION             */
1776 /*                                                                        */
1777 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1778 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1779 /*                                            resulting in version 6.1    */
1780 /*                                                                        */
1781 /**************************************************************************/
_gx_display_driver_24xrgb_4444argb_pixelmap_alpha_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1782 static VOID _gx_display_driver_24xrgb_4444argb_pixelmap_alpha_write(GX_DRAW_CONTEXT *context,
1783                                                                     INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1784 {
1785 INT              skipcount;
1786 INT              xval;
1787 INT              yval;
1788 USHORT          *getrow;
1789 GX_CONST USHORT *get;
1790 UCHAR            alpha_value;
1791 ULONG            pixel;
1792 
1793 GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
1794 
1795     /* calculate how many pixels to skip */
1796     skipcount = (pixelmap -> gx_pixelmap_width) * (clip -> gx_rectangle_top - ypos);
1797     skipcount += (clip -> gx_rectangle_left - xpos);
1798     getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
1799     getrow += skipcount;
1800 
1801     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
1802     {
1803         get = getrow;
1804 
1805         for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
1806         {
1807             /* 0x000f- -> b , 0x00f0- -> g , 0x0f00- -> r , 0xf000- -> a */
1808             /*4444bgra - ->  565rgb*/
1809             alpha_value = (UCHAR)(((*get) & 0xf000) >> 8);
1810             if (alpha_value)
1811             {
1812                 pixel = (GX_COLOR)((((*get) & 0x0f00) << 12) | (((*get) & 0x00f0) << 8) | (((*get) & 0x000f) << 4));
1813                 if (alpha_value == 0xf0)
1814                 {
1815                     _gx_display_driver_32bpp_pixel_write(context, xval, yval, pixel);
1816                 }
1817                 else
1818                 {
1819                     _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, alpha_value);
1820                 }
1821             }
1822             get++;
1823         }
1824         getrow += pixelmap -> gx_pixelmap_width;
1825     }
1826 }
1827 
1828 /**************************************************************************/
1829 /*                                                                        */
1830 /*  FUNCTION                                               RELEASE        */
1831 /*                                                                        */
1832 /*    _gx_display_driver_24xrgb_4444argb_pixelmap_compressed_alpha_write  */
1833 /*                                                        PORTABLE C      */
1834 /*                                                           6.1          */
1835 /*  AUTHOR                                                                */
1836 /*                                                                        */
1837 /*    Kenneth Maxwell, Microsoft Corporation                              */
1838 /*                                                                        */
1839 /*  DESCRIPTION                                                           */
1840 /*                                                                        */
1841 /*    Internal helper function that handles writing of compressed         */
1842 /*    pixelmap data of 4444argb format.                                   */
1843 /*                                                                        */
1844 /*  INPUT                                                                 */
1845 /*                                                                        */
1846 /*    context                               Drawing context               */
1847 /*    xpos                                  x-coord of top-left draw point*/
1848 /*    ypos                                  y-coord of top-left draw point*/
1849 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
1850 /*                                                                        */
1851 /*  OUTPUT                                                                */
1852 /*                                                                        */
1853 /*    None                                                                */
1854 /*                                                                        */
1855 /*  CALLS                                                                 */
1856 /*                                                                        */
1857 /*    _gx_display_driver_24xrgb_pixel_blend Basic display driver pixel    */
1858 /*                                            blend function for 24xrgb   */
1859 /*                                            format                      */
1860 /*                                                                        */
1861 /*  CALLED BY                                                             */
1862 /*                                                                        */
1863 /*    _gx_display_driver_24xrgb_pixelmap_draw                             */
1864 /*                                                                        */
1865 /*  RELEASE HISTORY                                                       */
1866 /*                                                                        */
1867 /*    DATE              NAME                      DESCRIPTION             */
1868 /*                                                                        */
1869 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1870 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1871 /*                                            resulting in version 6.1    */
1872 /*                                                                        */
1873 /**************************************************************************/
_gx_display_driver_24xrgb_4444argb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1874 static VOID _gx_display_driver_24xrgb_4444argb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT *context,
1875                                                                                INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1876 {
1877 INT              yval;
1878 INT              xval;
1879 GX_CONST USHORT *get;
1880 USHORT           count;
1881 GX_COLOR         pixel;
1882 GX_UBYTE         falpha;
1883 GX_UBYTE         brush_alpha;
1884 GX_UBYTE         combined_alpha;
1885 GX_UBYTE         r;
1886 GX_UBYTE         g;
1887 GX_UBYTE         b;
1888 
1889 GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
1890 
1891     get = (GX_CONST USHORT *)pixelmap -> gx_pixelmap_data;
1892     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
1893 
1894     /* first, skip to the starting row */
1895     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
1896     {
1897         xval = 0;
1898         while (xval < pixelmap -> gx_pixelmap_width)
1899         {
1900             count = *get++;
1901 
1902             if (count & 0x8000)
1903             {
1904                 count = (USHORT)((count & 0x7fff) + 1);
1905                 get++;      /* skip repeated pixel value */
1906             }
1907             else
1908             {
1909                 count++;
1910                 get += count;   /* skip raw pixel values */
1911             }
1912             xval += count;
1913         }
1914     }
1915 
1916     /* now we are on the first visible row, copy pixels until we get
1917        to the enf of the last visible row
1918      */
1919     while (yval <= clip -> gx_rectangle_bottom)
1920     {
1921         xval = xpos;
1922 
1923         while (xval < xpos + pixelmap -> gx_pixelmap_width)
1924         {
1925             count = *get++;
1926 
1927             if (count & 0x8000)
1928             {
1929                 /* repeated value */
1930                 count = (USHORT)((count & 0x7fff) + 1);
1931                 pixel = *get++;
1932                 falpha = (GX_UBYTE)(((USHORT)pixel & 0xf000) >> 8);
1933                 falpha = (falpha >> 4) | falpha;
1934                 if (falpha)
1935                 {
1936                     r = (GX_UBYTE)(((USHORT)pixel & 0x0f00) >> 4);
1937                     r = (GX_UBYTE)((r >> 4) | r);
1938                     g = (GX_UBYTE)((USHORT)pixel & 0x00f0);
1939                     g = (GX_UBYTE)((g >> 4) | g);
1940                     b = (GX_UBYTE)((USHORT)pixel & 0x000f);
1941                     b = (GX_UBYTE)((b << 4) | b);
1942                     pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
1943                     if (brush_alpha == 0xff)
1944                     {
1945                         combined_alpha = falpha;
1946                     }
1947                     else
1948                     {
1949                         combined_alpha = (GX_UBYTE)(brush_alpha * falpha / 255);
1950                     }
1951 
1952                     while (count--)
1953                     {
1954                         if (xval >= clip -> gx_rectangle_left &&
1955                             xval <= clip -> gx_rectangle_right)
1956                         {
1957                             _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, combined_alpha);
1958                         }
1959                         xval++;
1960                     }
1961                 }
1962                 else
1963                 {
1964                     xval += count;
1965                 }
1966             }
1967             else
1968             {
1969                 /* string of non-repeated values */
1970                 count++;
1971                 if (brush_alpha == 0xff)
1972                 {
1973                     while (count--)
1974                     {
1975                         if (xval >= clip -> gx_rectangle_left &&
1976                             xval <= clip -> gx_rectangle_right)
1977                         {
1978                             pixel = *get;
1979                             falpha = (GX_UBYTE)(((USHORT)pixel & 0xf000) >> 8);
1980                             falpha = (falpha >> 4) | falpha;
1981                             r = (GX_UBYTE)(((USHORT)pixel & 0x0f00) >> 4);
1982                             r = (GX_UBYTE)((r >> 4) | r);
1983                             g = (GX_UBYTE)((USHORT)pixel & 0x00f0);
1984                             g = (GX_UBYTE)((g >> 4) | g);
1985                             b = (GX_UBYTE)((USHORT)pixel & 0x000f);
1986                             b = (GX_UBYTE)((b << 4) | b);
1987                             pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
1988                             if (falpha)
1989                             {
1990                                 _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, falpha);
1991                             }
1992                         }
1993                         get++;
1994                         xval++;
1995                     }
1996                 }
1997                 else
1998                 {
1999                     while (count--)
2000                     {
2001                         if (xval >= clip -> gx_rectangle_left &&
2002                             xval <= clip -> gx_rectangle_right)
2003                         {
2004                             pixel = *get;
2005                             falpha = (GX_UBYTE)(((USHORT)pixel & 0xf000) >> 8);
2006                             falpha = (falpha >> 4) | falpha;
2007                             combined_alpha = (GX_UBYTE)(falpha * brush_alpha / 255);
2008                             r = (GX_UBYTE)(((USHORT)pixel & 0x0f00) >> 4);
2009                             r = (GX_UBYTE)((r >> 4) | r);
2010                             g = (GX_UBYTE)((USHORT)pixel & 0x00f0);
2011                             g = (GX_UBYTE)((g >> 4) | g);
2012                             b = (GX_UBYTE)((USHORT)pixel & 0x000f);
2013                             b = (GX_UBYTE)((b << 4) | b);
2014                             pixel = (GX_COLOR)ASSEMBLECOLOR_32BPP(r, g, b);
2015                             _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, pixel, combined_alpha);
2016                         }
2017                         get++;
2018                         xval++;
2019                     }
2020                 }
2021             }
2022         }
2023         yval++;
2024     }
2025 }
2026 
2027 /**************************************************************************/
2028 /*                                                                        */
2029 /*  FUNCTION                                               RELEASE        */
2030 /*                                                                        */
2031 /*    _gx_display_driver_24xrgb_pixelmap_draw             PORTABLE C      */
2032 /*                                                           6.1          */
2033 /*  AUTHOR                                                                */
2034 /*                                                                        */
2035 /*    Kenneth Maxwell, Microsoft Corporation                              */
2036 /*                                                                        */
2037 /*  DESCRIPTION                                                           */
2038 /*                                                                        */
2039 /*    32xrgb format screen driver pixelmap drawing function that handles  */
2040 /*    compressed or uncompress, with or without alpha channel.            */
2041 /*                                                                        */
2042 /*  INPUT                                                                 */
2043 /*                                                                        */
2044 /*    context                               Drawing context               */
2045 /*    xpos                                  x-coord of top-left draw point*/
2046 /*    ypos                                  y-coord of top-left draw point*/
2047 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
2048 /*                                                                        */
2049 /*  OUTPUT                                                                */
2050 /*                                                                        */
2051 /*    None                                                                */
2052 /*                                                                        */
2053 /*  CALLS                                                                 */
2054 /*                                                                        */
2055 /*    _gx_display_driver_24xrgb_palette_pixelmap_transparent_c_write      */
2056 /*                                          Real display driver pixelmap  */
2057 /*                                            draw function               */
2058 /*    _gx_display_driver_24xrgb_palette_pixelmap_transparent_write        */
2059 /*                                          Real display driver pixelmap  */
2060 /*                                            draw function               */
2061 /*    _gx_display_driver_24xrgb_palette_pixelmap_compressed_write         */
2062 /*                                          Real display driver pixelmap  */
2063 /*                                            draw function               */
2064 /*    _gx_display_driver_24xrgb_palette_pixelmap_write                    */
2065 /*                                          Real display driver pixelmap  */
2066 /*                                            draw function               */
2067 /*    _gx_display_driver_24xrgb_4444argb_pixelmap_compressed_alpha_write  */
2068 /*                                          Real display driver pixelmap  */
2069 /*                                            draw function               */
2070 /*    _gx_display_driver_24xrgb_4444argb_pixelmap_alpha_write             */
2071 /*                                          Real display driver pixelmap  */
2072 /*                                            draw function               */
2073 /*    _gx_display_driver_24xrgb_565rgb_pixelmap_compressed_alpha_write    */
2074 /*                                          Real display driver pixelmap  */
2075 /*                                            draw function               */
2076 /*    _gx_display_driver_24xrgb_565rgb_pixelmap_alpha_write               */
2077 /*                                          Real display driver pixelmap  */
2078 /*                                            draw function               */
2079 /*    _gx_display_driver_24xrgb_565rgb_pixelmap_compressed_write          */
2080 /*                                          Real display driver pixelmap  */
2081 /*                                            draw function               */
2082 /*    _gx_display_driver_24xrgb_565rgb_pixelmap_raw_write                 */
2083 /*                                          Real display driver pixelmap  */
2084 /*                                            draw function               */
2085 /*    _gx_display_driver_24xrgb_pixelmap_compressed_alpha_write           */
2086 /*                                          Real display driver pixelmap  */
2087 /*                                            draw function               */
2088 /*    _gx_display_driver_24xrgb_pixelmap_alpha_write                      */
2089 /*                                          Real display driver pixelmap  */
2090 /*                                            draw function               */
2091 /*    _gx_display_driver_24xrgb_pixelmap_compressed_write                 */
2092 /*                                          Real display driver pixelmap  */
2093 /*                                            draw function               */
2094 /*    _gx_display_driver_24xrgb_pixelmap_raw_write                        */
2095 /*                                          Real display driver pixelmap  */
2096 /*                                            draw function               */
2097 /*    _gx_display_driver_24xrgb_pixelmap_blend                            */
2098 /*                                          Basic display driver pixelmap */
2099 /*                                            blend function with alpha   */
2100 /*                                                                        */
2101 /*  CALLED BY                                                             */
2102 /*                                                                        */
2103 /*    GUIX Internal Code                                                  */
2104 /*                                                                        */
2105 /*  RELEASE HISTORY                                                       */
2106 /*                                                                        */
2107 /*    DATE              NAME                      DESCRIPTION             */
2108 /*                                                                        */
2109 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
2110 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
2111 /*                                            resulting in version 6.1    */
2112 /*                                                                        */
2113 /**************************************************************************/
_gx_display_driver_24xrgb_pixelmap_draw(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)2114 VOID _gx_display_driver_24xrgb_pixelmap_draw(GX_DRAW_CONTEXT *context,
2115                                              INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
2116 {
2117 GX_BOOL  drawn = GX_FALSE;
2118 GX_UBYTE brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
2119 
2120     if (brush_alpha == 0)
2121     {
2122         /* Draw nothing here. Just return. */
2123         return;
2124     }
2125 
2126     switch (pixelmap -> gx_pixelmap_format)
2127     {
2128     case GX_COLOR_FORMAT_8BIT_PALETTE:
2129         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT)
2130         {
2131             if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
2132             {
2133                 /* compressed with transparent */
2134                 _gx_display_driver_24xrgb_palette_pixelmap_transparent_compressed_write(context, xpos, ypos, pixelmap);
2135                 drawn = GX_TRUE;
2136             }
2137             else
2138             {
2139                 /* no compression with transparent */
2140                 if (brush_alpha == 0xff)
2141                 {
2142                     _gx_display_driver_24xrgb_palette_pixelmap_transparent_write(context, xpos, ypos, pixelmap);
2143                     drawn = GX_TRUE;
2144                 }
2145             }
2146         }
2147         else
2148         {
2149             if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
2150             {
2151                 /* compressed with no alpha */
2152                 _gx_display_driver_24xrgb_palette_pixelmap_compressed_write(context, xpos, ypos, pixelmap);
2153                 drawn = GX_TRUE;
2154             }
2155             else
2156             {
2157                 /* no compression or alpha */
2158                 if (brush_alpha == 0xff)
2159                 {
2160                     _gx_display_driver_24xrgb_palette_pixelmap_write(context, xpos, ypos, pixelmap);
2161                     drawn = GX_TRUE;
2162                 }
2163             }
2164         }
2165         break;
2166 
2167     case GX_COLOR_FORMAT_4444ARGB:
2168         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
2169         {
2170             /* compressed */
2171             _gx_display_driver_24xrgb_4444argb_pixelmap_compressed_alpha_write(context, xpos, ypos, pixelmap);
2172             drawn = GX_TRUE;
2173         }
2174         else
2175         {
2176             /* no compression  */
2177             if (brush_alpha == 0xff)
2178             {
2179                 _gx_display_driver_24xrgb_4444argb_pixelmap_alpha_write(context, xpos, ypos, pixelmap);
2180                 drawn = GX_TRUE;
2181             }
2182         }
2183         break;
2184 
2185     case GX_COLOR_FORMAT_565RGB:
2186         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
2187         {
2188             if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
2189             {
2190                 /* compressed with alpha */
2191                 _gx_display_driver_24xrgb_565rgb_pixelmap_compressed_alpha_write(context, xpos, ypos, pixelmap);
2192                 drawn = GX_TRUE;
2193             }
2194             else
2195             {
2196                 /* uncompressed with alpha */
2197                 if (brush_alpha == 0xff)
2198                 {
2199                     _gx_display_driver_24xrgb_565rgb_pixelmap_alpha_write(context, xpos, ypos, pixelmap);
2200                     drawn = GX_TRUE;
2201                 }
2202             }
2203         }
2204         else
2205         {
2206             if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
2207             {
2208                 /* compressed without alpha */
2209                 _gx_display_driver_24xrgb_565rgb_pixelmap_compressed_write(context, xpos, ypos, pixelmap);
2210                 drawn = GX_TRUE;
2211             }
2212             else
2213             {
2214                 /* uncompressed withou alpha */
2215                 if (brush_alpha == 0xff)
2216                 {
2217                     _gx_display_driver_24xrgb_565rgb_pixelmap_raw_write(context, xpos, ypos, pixelmap);
2218                     drawn = GX_TRUE;
2219                 }
2220             }
2221         }
2222         break;
2223 
2224     case GX_COLOR_FORMAT_24XRGB:
2225     case GX_COLOR_FORMAT_32ARGB:
2226         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
2227         {
2228             if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
2229             {
2230                 /* has both compression and alpha */
2231                 _gx_display_driver_24xrgb_pixelmap_compressed_alpha_write(context, xpos, ypos, pixelmap);
2232                 drawn = GX_TRUE;
2233             }
2234             else
2235             {
2236                 /* alpha, no compression */
2237                 if (brush_alpha == 0xff)
2238                 {
2239                     _gx_display_driver_24xrgb_pixelmap_alpha_write(context, xpos, ypos, pixelmap);
2240                     drawn = GX_TRUE;
2241                 }
2242             }
2243         }
2244         else
2245         {
2246             if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
2247             {
2248                 /* compressed with no alpha */
2249                 _gx_display_driver_24xrgb_pixelmap_compressed_write(context, xpos, ypos, pixelmap);
2250                 drawn = GX_TRUE;
2251             }
2252             else
2253             {
2254                 /* no compression or alpha */
2255                 if (brush_alpha == 0xff)
2256                 {
2257                     _gx_display_driver_24xrgb_pixelmap_raw_write(context, xpos, ypos, pixelmap);
2258                     drawn = GX_TRUE;
2259                 }
2260             }
2261         }
2262         break;
2263 
2264     default:
2265         break;
2266     }
2267 
2268     if ((!drawn) && (brush_alpha != 0xff))
2269     {
2270         _gx_display_driver_24xrgb_pixelmap_blend(context, xpos, ypos, pixelmap, brush_alpha);
2271     }
2272 
2273     return;
2274 }
2275 
2276