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 #include "gx_context.h"
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_display_driver_565rgb_pixelmap_raw_write        PORTABLE C      */
35 /*                                                           6.X          */
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 /*    GUIX Internal Code                                                  */
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 /*  10-31-2023     Ting Zhu                 Modified comment(s),          */
72 /*                                            added partial canvas buffer */
73 /*                                            support,                    */
74 /*                                            resulting in version 6.3.0  */
75 /*                                                                        */
76 /**************************************************************************/
_gx_display_driver_565rgb_pixelmap_raw_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)77 static VOID _gx_display_driver_565rgb_pixelmap_raw_write(GX_DRAW_CONTEXT *context,
78                                                          INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
79 {
80 INT              xval;
81 INT              yval;
82 INT              width;
83 USHORT          *putrow;
84 USHORT          *getrow;
85 USHORT          *put;
86 GX_CONST USHORT *get;
87 
88 GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
89 
90     putrow = (USHORT *)context -> gx_draw_context_memory;
91 
92     GX_CALCULATE_PUTROW(putrow, clip->gx_rectangle_left, clip->gx_rectangle_top, context);
93 
94     getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
95     getrow += pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos);
96     getrow += (clip -> gx_rectangle_left - xpos);
97 
98     width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
99 
100     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
101     {
102         put = putrow;
103         get = getrow;
104 
105         for (xval = 0; xval < width; xval++)
106         {
107             *put++ = *get++;
108         }
109         putrow += context -> gx_draw_context_pitch;
110         getrow += pixelmap -> gx_pixelmap_width;
111     }
112 }
113 
114 /**************************************************************************/
115 /*                                                                        */
116 /*  FUNCTION                                               RELEASE        */
117 /*                                                                        */
118 /*    _gx_display_driver_565rgb_pixelmap_alpha_write      PORTABLE C      */
119 /*                                                           6.1          */
120 /*  AUTHOR                                                                */
121 /*                                                                        */
122 /*    Kenneth Maxwell, Microsoft Corporation                              */
123 /*                                                                        */
124 /*  DESCRIPTION                                                           */
125 /*                                                                        */
126 /*    Internal helper function that handles writing of uncompressed       */
127 /*    pixlemap file with alpha channel.                                   */
128 /*                                                                        */
129 /*  INPUT                                                                 */
130 /*                                                                        */
131 /*    context                               Drawing context               */
132 /*    xpos                                  x-coord of top-left draw point*/
133 /*    ypos                                  y-coord of top-left draw point*/
134 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
135 /*                                                                        */
136 /*  OUTPUT                                                                */
137 /*                                                                        */
138 /*    None                                                                */
139 /*                                                                        */
140 /*  CALLS                                                                 */
141 /*                                                                        */
142 /*    _gx_display_driver_565rgb_pixel_blend  Display driver basic pixel   */
143 /*                                             blend function             */
144 /*                                                                        */
145 /*  CALLED BY                                                             */
146 /*                                                                        */
147 /*    GUIX Internal Code                                                  */
148 /*                                                                        */
149 /*  RELEASE HISTORY                                                       */
150 /*                                                                        */
151 /*    DATE              NAME                      DESCRIPTION             */
152 /*                                                                        */
153 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
154 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
155 /*                                            resulting in version 6.1    */
156 /*                                                                        */
157 /**************************************************************************/
_gx_display_driver_565rgb_pixelmap_alpha_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)158 static VOID _gx_display_driver_565rgb_pixelmap_alpha_write(GX_DRAW_CONTEXT *context,
159                                                            INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
160 {
161 INT                skipcount;
162 INT                xval;
163 INT                yval;
164 USHORT            *getrow;
165 GX_UBYTE          *getrowalpha;
166 GX_CONST USHORT   *get;
167 GX_CONST GX_UBYTE *getalpha;
168 
169 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
170 void               (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
171 
172     blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
173     if (blend_func == GX_NULL)
174     {
175         return;
176     }
177 
178     /* calculate how many pixels to skip */
179     skipcount = (pixelmap -> gx_pixelmap_width) * (clip -> gx_rectangle_top - ypos);
180     skipcount += (clip -> gx_rectangle_left - xpos);
181     getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
182     getrow += skipcount;
183 
184     getrowalpha = (GX_UBYTE *)(pixelmap -> gx_pixelmap_aux_data);
185     getrowalpha += skipcount;
186 
187     for (yval  = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
188     {
189         get = getrow;
190         getalpha = getrowalpha;
191 
192         for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
193         {
194             blend_func(context, xval, yval, *get++, *getalpha++);
195         }
196         getrow += pixelmap -> gx_pixelmap_width;
197         getrowalpha += pixelmap -> gx_pixelmap_width;
198     }
199 }
200 
201 /**************************************************************************/
202 /*                                                                        */
203 /*  FUNCTION                                               RELEASE        */
204 /*                                                                        */
205 /*    _gx_display_driver_565rgb_pixelmap_compressed_write                 */
206 /*                                                        PORTABLE C      */
207 /*                                                           6.X          */
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 /*    None                                                                */
231 /*                                                                        */
232 /*  CALLED BY                                                             */
233 /*                                                                        */
234 /*    GUIX Internal Code                                                  */
235 /*                                                                        */
236 /*  RELEASE HISTORY                                                       */
237 /*                                                                        */
238 /*    DATE              NAME                      DESCRIPTION             */
239 /*                                                                        */
240 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
241 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
242 /*                                            resulting in version 6.1    */
243 /*  10-31-2023     Ting Zhu                 Modified comment(s),          */
244 /*                                            added partial canvas buffer */
245 /*                                            support,                    */
246 /*                                            resulting in version 6.3.0  */
247 /*                                                                        */
248 /**************************************************************************/
_gx_display_driver_565rgb_pixelmap_compressed_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)249 static VOID _gx_display_driver_565rgb_pixelmap_compressed_write(GX_DRAW_CONTEXT *context,
250                                                                 INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
251 {
252 INT              yval;
253 INT              xval;
254 GX_CONST USHORT *get;
255 USHORT          *put;
256 USHORT          *putrow;
257 USHORT           count;
258 USHORT           pixel;
259 
260 GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
261 
262     get = (GX_CONST USHORT *)pixelmap -> gx_pixelmap_data;
263     /* compressed with no alpha is a two-byte count and two-byte pixel value */
264 
265     /* first, skip to the starting row */
266     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
267     {
268         xval = 0;
269         while (xval < pixelmap -> gx_pixelmap_width)
270         {
271             count = *get++;
272 
273             if (count & 0x8000)
274             {
275                 count = (USHORT)((count & 0x7fff) + 1u);
276                 get++;      /* skip repeated pixel value */
277             }
278             else
279             {
280                 count++;
281                 get += count;   /* skip raw pixel values */
282             }
283             xval += count;
284         }
285     }
286 
287     /* now we are on the first visible row, copy pixels until we get
288        to the enf of the last visible row
289      */
290     putrow = (USHORT *)context -> gx_draw_context_memory;
291 
292     GX_CALCULATE_PUTROW(putrow, xpos, yval, context);
293 
294     while (yval <= clip -> gx_rectangle_bottom)
295     {
296         put = putrow;
297         xval = xpos;
298 
299         while (xval < xpos + pixelmap -> gx_pixelmap_width)
300         {
301             count = *get++;
302 
303             if (count & 0x8000)
304             {
305                 /* repeated value */
306                 count = (USHORT)((count & 0x7fff) + 1u);
307                 pixel = *get++;
308                 while (count--)
309                 {
310                     if (xval >= clip -> gx_rectangle_left &&
311                         xval <= clip -> gx_rectangle_right)
312                     {
313                         *put = pixel;
314                     }
315                     put++;
316                     xval++;
317                 }
318             }
319             else
320             {
321                 /* string of non-repeated values */
322                 count++;
323 
324                 while (count--)
325                 {
326                     if (xval >= clip -> gx_rectangle_left &&
327                         xval <= clip -> gx_rectangle_right)
328                     {
329                         *put = *get;
330                     }
331                     put++;
332                     get++;
333                     xval++;
334                 }
335             }
336         }
337         putrow +=  context -> gx_draw_context_pitch;
338         yval++;
339     }
340 }
341 
342 /**************************************************************************/
343 /*                                                                        */
344 /*  FUNCTION                                               RELEASE        */
345 /*                                                                        */
346 /*    _gx_display_driver_565rgb_pixelmap_compressed_alpha_write           */
347 /*                                                        PORTABLE C      */
348 /*                                                           6.1          */
349 /*  AUTHOR                                                                */
350 /*                                                                        */
351 /*    Kenneth Maxwell, Microsoft Corporation                              */
352 /*                                                                        */
353 /*  DESCRIPTION                                                           */
354 /*                                                                        */
355 /*    Internal helper function that handles writing of compressed         */
356 /*    pixlemap file with alpha channel.                                   */
357 /*                                                                        */
358 /*  INPUT                                                                 */
359 /*                                                                        */
360 /*    context                               Drawing context               */
361 /*    xpos                                  x-coord of top-left draw point*/
362 /*    ypos                                  y-coord of top-left draw point*/
363 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
364 /*                                                                        */
365 /*  OUTPUT                                                                */
366 /*                                                                        */
367 /*    None                                                                */
368 /*                                                                        */
369 /*  CALLS                                                                 */
370 /*                                                                        */
371 /*    _gx_display_driver_565rgb_pixel_blend  Display driver basic pixel   */
372 /*                                             blend function             */
373 /*                                                                        */
374 /*  CALLED BY                                                             */
375 /*                                                                        */
376 /*    GUIX Internal Code                                                  */
377 /*                                                                        */
378 /*  RELEASE HISTORY                                                       */
379 /*                                                                        */
380 /*    DATE              NAME                      DESCRIPTION             */
381 /*                                                                        */
382 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
383 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
384 /*                                            resulting in version 6.1    */
385 /*                                                                        */
386 /**************************************************************************/
_gx_display_driver_565rgb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)387 static VOID _gx_display_driver_565rgb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT *context,
388                                                                       INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
389 {
390 INT                yval;
391 INT                xval;
392 GX_CONST GX_UBYTE *get;
393 GX_CONST USHORT   *getpixel;
394 USHORT             count;
395 USHORT             pixel;
396 GX_UBYTE           falpha;
397 GX_UBYTE           brush_alpha;
398 GX_UBYTE           combined_alpha;
399 
400 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
401 void               (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
402 
403     blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
404     if (blend_func == GX_NULL)
405     {
406         return;
407     }
408 
409     get = pixelmap -> gx_pixelmap_data;
410     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
411 
412     /* compressed with alpha is byte count, byte alpha, and and two-byte pixel value */
413 
414     /* first, skip to the starting row */
415     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
416     {
417         xval = 0;
418         while (xval < pixelmap -> gx_pixelmap_width)
419         {
420             count = *get;
421 
422             if (count & 0x80)
423             {
424                 count = (USHORT)((count & 0x7f) + 1u);
425                 get +=  4;      /* skip repeated pixel value */
426             }
427             else
428             {
429                 count++;
430                 get += (count * 4);      /* skip string of non-repeated pixels */
431             }
432             xval += count;
433         }
434     }
435 
436     /* now we are on the first visible row, copy pixels until we get
437        to the enf of the last visible row
438      */
439     while (yval <= clip -> gx_rectangle_bottom)
440     {
441         xval = xpos;
442         while (xval < xpos + pixelmap -> gx_pixelmap_width)
443         {
444             count = *get;
445 
446             if (count & 0x80)
447             {
448                 /* repeated value */
449                 count = (USHORT)((count & 0x7f) + 1u);
450                 falpha = *(get + 1);
451 
452                 if (falpha)
453                 {
454                     get += 2;
455 
456                     getpixel = (USHORT *)get;
457                     pixel = *getpixel;
458                     get += 2;
459 
460                     if (brush_alpha == 0xff)
461                     {
462                         combined_alpha = falpha;
463                     }
464                     else
465                     {
466                         combined_alpha = (GX_UBYTE)(falpha * brush_alpha / 255);
467                     }
468 
469                     while (count--)
470                     {
471                         if (xval >= clip -> gx_rectangle_left &&
472                             xval <= clip -> gx_rectangle_right)
473                         {
474                             blend_func(context, xval, yval, pixel, combined_alpha);
475                         }
476                         xval++;
477                     }
478                 }
479                 else
480                 {
481                     get += 4;
482                     xval += count;
483                 }
484             }
485             else
486             {
487                 /* string of non-repeated values */
488                 count++;
489                 if (brush_alpha == 0xff)
490                 {
491                     while (count--)
492                     {
493                         if (xval >= clip -> gx_rectangle_left &&
494                             xval <= clip -> gx_rectangle_right)
495                         {
496                             falpha = *(get + 1);
497                             get += 2;
498                             getpixel = (USHORT *)get;
499                             pixel = *getpixel;
500                             get += 2;
501                             blend_func(context, xval, yval, pixel, falpha);
502                         }
503                         else
504                         {
505                             get += 4;
506                         }
507                         xval++;
508                     }
509                 }
510                 else
511                 {
512                     while (count--)
513                     {
514                         if (xval >= clip -> gx_rectangle_left &&
515                             xval <= clip -> gx_rectangle_right)
516                         {
517                             falpha = *(get + 1);
518                             get += 2;
519                             getpixel = (USHORT *)get;
520                             pixel = *getpixel;
521                             get += 2;
522                             combined_alpha = (GX_UBYTE)(falpha * brush_alpha / 255);
523                             blend_func(context, xval, yval, pixel, combined_alpha);
524                         }
525                         else
526                         {
527                             get += 4;
528                         }
529                         xval++;
530                     }
531                 }
532             }
533         }
534         yval++;
535     }
536 }
537 
538 
539 /**************************************************************************/
540 /*                                                                        */
541 /*  FUNCTION                                               RELEASE        */
542 /*                                                                        */
543 /*    _gx_display_driver_565rgb_palette_pixelmap_raw_write  PORTABLE C    */
544 /*                                                           6.3.0        */
545 /*  AUTHOR                                                                */
546 /*                                                                        */
547 /*    Kenneth Maxwell, Microsoft Corporation                              */
548 /*                                                                        */
549 /*  DESCRIPTION                                                           */
550 /*                                                                        */
551 /*    Internal helper function that handles writing of raw pixlemap       */
552 /*    file without transparent for palette pixelmap                       */
553 /*                                                                        */
554 /*  INPUT                                                                 */
555 /*                                                                        */
556 /*    context                               Drawing context               */
557 /*    xpos                                  x-coord of top-left draw point*/
558 /*    ypos                                  y-coord of top-left draw point*/
559 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
560 /*                                                                        */
561 /*  OUTPUT                                                                */
562 /*                                                                        */
563 /*    None                                                                */
564 /*                                                                        */
565 /*  CALLS                                                                 */
566 /*                                                                        */
567 /*    None                                                                */
568 /*                                                                        */
569 /*  CALLED BY                                                             */
570 /*                                                                        */
571 /*    GUIX Internal Code                                                  */
572 /*                                                                        */
573 /*  RELEASE HISTORY                                                       */
574 /*                                                                        */
575 /*    DATE              NAME                      DESCRIPTION             */
576 /*                                                                        */
577 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
578 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
579 /*                                            resulting in version 6.1    */
580 /*  10-31-2023     Ting Zhu                 Modified comment(s),          */
581 /*                                            added partial canvas buffer */
582 /*                                            support,                    */
583 /*                                            resulting in version 6.3.0  */
584 /*                                                                        */
585 /**************************************************************************/
_gx_display_driver_565rgb_palette_pixelmap_raw_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)586 static VOID _gx_display_driver_565rgb_palette_pixelmap_raw_write(GX_DRAW_CONTEXT *context,
587                                                                  INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
588 {
589 INT                xval;
590 INT                yval;
591 INT                width;
592 USHORT            *putrow;
593 GX_UBYTE          *getrow;
594 USHORT            *put;
595 GX_CONST GX_UBYTE *get;
596 GX_COLOR          *palette;
597 GX_UBYTE           r;
598 GX_UBYTE           g;
599 GX_UBYTE           b;
600 
601 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
602 
603     putrow = (USHORT *)context -> gx_draw_context_memory;
604 
605     GX_CALCULATE_PUTROW(putrow, clip->gx_rectangle_left, clip->gx_rectangle_top, context);
606 
607     getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data);
608     getrow += pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos);
609     getrow += (clip -> gx_rectangle_left - xpos);
610 
611     palette = (GX_COLOR *)pixelmap -> gx_pixelmap_aux_data;
612 
613     width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
614 
615     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
616     {
617         put = putrow;
618         get = getrow;
619 
620         for (xval = 0; xval < width; xval++)
621         {
622             r = (GX_UBYTE)(REDVAL_32BPP(palette[*get]) >> 3);
623             g = (GX_UBYTE)(GREENVAL_32BPP(palette[*get]) >> 2);
624             b = (GX_UBYTE)(BLUEVAL_32BPP(palette[*get++]) >> 3);
625             *put++ = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
626         }
627         putrow += context -> gx_draw_context_pitch;
628         getrow += pixelmap -> gx_pixelmap_width;
629     }
630 }
631 
632 /**************************************************************************/
633 /*                                                                        */
634 /*  FUNCTION                                               RELEASE        */
635 /*                                                                        */
636 /*    _gx_display_driver_565rgb_palette_pixelmap_transparent_raw_write    */
637 /*                                                           PORTABLE C   */
638 /*                                                           6.X          */
639 /*  AUTHOR                                                                */
640 /*                                                                        */
641 /*    Kenneth Maxwell, Microsoft Corporation                              */
642 /*                                                                        */
643 /*  DESCRIPTION                                                           */
644 /*                                                                        */
645 /*    Internal helper function that handles writing of raw pixlemap       */
646 /*    file with transparent for palette pixelmap.                         */
647 /*                                                                        */
648 /*  INPUT                                                                 */
649 /*                                                                        */
650 /*    context                               Drawing context               */
651 /*    xpos                                  x-coord of top-left draw point*/
652 /*    ypos                                  y-coord of top-left draw point*/
653 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
654 /*                                                                        */
655 /*  OUTPUT                                                                */
656 /*                                                                        */
657 /*    None                                                                */
658 /*                                                                        */
659 /*  CALLS                                                                 */
660 /*                                                                        */
661 /*    None                                                                */
662 /*                                                                        */
663 /*  CALLED BY                                                             */
664 /*                                                                        */
665 /*    GUIX Internal Code                                                  */
666 /*                                                                        */
667 /*  RELEASE HISTORY                                                       */
668 /*                                                                        */
669 /*    DATE              NAME                      DESCRIPTION             */
670 /*                                                                        */
671 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
672 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
673 /*                                            resulting in version 6.1    */
674 /*  10-31-2023     Ting Zhu                 Modified comment(s),          */
675 /*                                            added partial canvas buffer */
676 /*                                            support,                    */
677 /*                                            resulting in version 6.3.0  */
678 /*                                                                        */
679 /**************************************************************************/
_gx_display_driver_565rgb_palette_pixelmap_transparent_raw_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)680 static VOID _gx_display_driver_565rgb_palette_pixelmap_transparent_raw_write(GX_DRAW_CONTEXT *context,
681                                                                              INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
682 {
683 INT                xval;
684 INT                yval;
685 INT                width;
686 USHORT            *putrow;
687 GX_UBYTE          *getrow;
688 USHORT            *put;
689 GX_CONST GX_UBYTE *get;
690 GX_COLOR          *palette;
691 GX_UBYTE           r;
692 GX_UBYTE           g;
693 GX_UBYTE           b;
694 
695 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
696 
697     putrow = (USHORT *)context->gx_draw_context_memory;
698     GX_CALCULATE_PUTROW(putrow, clip->gx_rectangle_left, clip->gx_rectangle_top, context);
699 
700     getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data);
701     getrow += pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos);
702     getrow += (clip -> gx_rectangle_left - xpos);
703 
704     palette = (GX_COLOR *)pixelmap -> gx_pixelmap_aux_data;
705 
706     width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
707 
708     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
709     {
710         put = putrow;
711         get = getrow;
712 
713         for (xval = 0; xval < width; xval++)
714         {
715             if ((*get) != pixelmap -> gx_pixelmap_transparent_color)
716             {
717                 r = (GX_UBYTE)(REDVAL_32BPP(palette[*get]) >> 3);
718                 g = (GX_UBYTE)(GREENVAL_32BPP(palette[*get]) >> 2);
719                 b = (GX_UBYTE)(BLUEVAL_32BPP(palette[*get]) >> 3);
720                 *put = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
721             }
722             get++;
723             put++;
724         }
725         putrow += context -> gx_draw_context_pitch;
726         getrow += pixelmap -> gx_pixelmap_width;
727     }
728 }
729 
730 /**************************************************************************/
731 /*                                                                        */
732 /*  FUNCTION                                               RELEASE        */
733 /*                                                                        */
734 /*    _gx_display_driver_565rgb_palette_pixelmap_transparent_compressed   */
735 /*      _write                                                            */
736 /*                                                        PORTABLE C      */
737 /*                                                           6.3.0        */
738 /*  AUTHOR                                                                */
739 /*                                                                        */
740 /*    Kenneth Maxwell, Microsoft Corporation                              */
741 /*                                                                        */
742 /*  DESCRIPTION                                                           */
743 /*                                                                        */
744 /*    Internal helper function that handles writing of compressed         */
745 /*    pixlemap file with transparent for palette pixelmap                 */
746 /*                                                                        */
747 /*  INPUT                                                                 */
748 /*                                                                        */
749 /*    context                               Drawing context               */
750 /*    xpos                                  x-coord of top-left draw point*/
751 /*    ypos                                  y-coord of top-left draw point*/
752 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
753 /*                                                                        */
754 /*  OUTPUT                                                                */
755 /*                                                                        */
756 /*    None                                                                */
757 /*                                                                        */
758 /*  CALLS                                                                 */
759 /*                                                                        */
760 /*    _gx_display_driver_565rgb_pixel_blend  Display driver basic pixel   */
761 /*                                             blend function             */
762 /*                                                                        */
763 /*  CALLED BY                                                             */
764 /*                                                                        */
765 /*    GUIX Internal Code                                                  */
766 /*                                                                        */
767 /*  RELEASE HISTORY                                                       */
768 /*                                                                        */
769 /*    DATE              NAME                      DESCRIPTION             */
770 /*                                                                        */
771 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
772 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
773 /*                                            resulting in version 6.1    */
774 /*  10-31-2023     Ting Zhu                 Modified comment(s),          */
775 /*                                            added partial canvas buffer */
776 /*                                            support,                    */
777 /*                                            resulting in version 6.3.0  */
778 /*                                                                        */
779 /**************************************************************************/
_gx_display_driver_565rgb_palette_pixelmap_transparent_compressed_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)780 static VOID _gx_display_driver_565rgb_palette_pixelmap_transparent_compressed_write(GX_DRAW_CONTEXT *context,
781                                                                                     INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
782 {
783 INT                yval;
784 INT                xval;
785 GX_CONST GX_UBYTE *get;
786 USHORT            *put;
787 USHORT            *putrow;
788 GX_COLOR          *palette;
789 GX_UBYTE           brush_alpha;
790 USHORT             count;
791 USHORT             pixel;
792 GX_UBYTE           r;
793 GX_UBYTE           g;
794 GX_UBYTE           b;
795 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
796 
797     get = (GX_CONST GX_UBYTE *)pixelmap -> gx_pixelmap_data;
798     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
799 
800     /* compressed with no alpha is a one-byte count and one-byte index value */
801     /* first, skip to the starting row */
802     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
803     {
804         xval = 0;
805         while (xval < pixelmap -> gx_pixelmap_width)
806         {
807             count = *get++;
808 
809             if (count & 0x80)
810             {
811                 count = (USHORT)((count & 0x7f) + 1u);
812                 get++;      /* skip repeated pixel value */
813             }
814             else
815             {
816                 count++;
817                 get += count;   /* skip raw pixel values */
818             }
819             xval += count;
820         }
821     }
822 
823     /* Now we are on the first visible row, copy pixels until we get
824        to the end of the last visible row. */
825     putrow = (USHORT *)context -> gx_draw_context_memory;
826     GX_CALCULATE_PUTROW(putrow, xpos, yval, context);
827 
828     palette = (GX_COLOR *)pixelmap -> gx_pixelmap_aux_data;
829 
830     while (yval <= clip -> gx_rectangle_bottom)
831     {
832         put = putrow;
833         xval = xpos;
834 
835         while (xval < xpos + pixelmap -> gx_pixelmap_width)
836         {
837             count = *get++;
838 
839             if (count & 0x80)
840             {
841                 /* repeated value */
842                 count = (USHORT)((count & 0x7f) + 1u);
843 
844                 if ((*get) != pixelmap -> gx_pixelmap_transparent_color)
845                 {
846                     r = (GX_UBYTE)(REDVAL_32BPP(palette[*get]) >> 3);
847                     g = (GX_UBYTE)(GREENVAL_32BPP(palette[*get]) >> 2);
848                     b = (GX_UBYTE)(BLUEVAL_32BPP(palette[*get]) >> 3);
849 
850                     if (brush_alpha == 0xff)
851                     {
852                         while (count--)
853                         {
854                             if (xval >= clip -> gx_rectangle_left &&
855                                 xval <= clip -> gx_rectangle_right)
856                             {
857                                 *put = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
858                             }
859                             put++;
860                             xval++;
861                         }
862                     }
863                     else
864                     {
865                         pixel = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
866                         while (count--)
867                         {
868                             if (xval >= clip -> gx_rectangle_left &&
869                                 xval <= clip -> gx_rectangle_right)
870                             {
871                                 _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, brush_alpha);
872                             }
873                             xval++;
874                         }
875                     }
876                 }
877                 else
878                 {
879                     put += count;
880                     xval += count;
881                 }
882                 get++;
883             }
884             else
885             {
886                 /* string of non-repeated values */
887                 count++;
888 
889                 if (brush_alpha == 0xff)
890                 {
891                     while (count--)
892                     {
893                         if ((*get) != pixelmap -> gx_pixelmap_transparent_color)
894                         {
895                             if (xval >= clip -> gx_rectangle_left &&
896                                 xval <= clip -> gx_rectangle_right)
897                             {
898                                 r = (GX_UBYTE)(REDVAL_32BPP(palette[*get]) >> 3);
899                                 g = (GX_UBYTE)(GREENVAL_32BPP(palette[*get]) >> 2);
900                                 b = (GX_UBYTE)(BLUEVAL_32BPP(palette[*get]) >> 3);
901                                 *put = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
902                             }
903                         }
904                         put++;
905                         get++;
906                         xval++;
907                     }
908                 }
909                 else
910                 {
911                     while (count--)
912                     {
913                         if ((*get) != pixelmap -> gx_pixelmap_transparent_color)
914                         {
915                             if (xval >= clip -> gx_rectangle_left &&
916                                 xval <= clip -> gx_rectangle_right)
917                             {
918                                 r = (GX_UBYTE)(REDVAL_32BPP(palette[*get]) >> 3);
919                                 g = (GX_UBYTE)(GREENVAL_32BPP(palette[*get]) >> 2);
920                                 b = (GX_UBYTE)(BLUEVAL_32BPP(palette[*get]) >> 3);
921                                 pixel = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
922                                 _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, brush_alpha);
923                             }
924                         }
925                         get++;
926                         xval++;
927                     }
928                 }
929             }
930         }
931         putrow += context -> gx_draw_context_pitch;
932         yval++;
933     }
934 }
935 
936 
937 /**************************************************************************/
938 /*                                                                        */
939 /*  FUNCTION                                               RELEASE        */
940 /*                                                                        */
941 /*    _gx_display_driver_565rgb_palette_pixelmap_compressed_write         */
942 /*                                                        PORTABLE C      */
943 /*                                                           6.3.0        */
944 /*  AUTHOR                                                                */
945 /*                                                                        */
946 /*    Kenneth Maxwell, Microsoft Corporation                              */
947 /*                                                                        */
948 /*  DESCRIPTION                                                           */
949 /*                                                                        */
950 /*    Internal helper function that handles writing of compressed         */
951 /*    pixlemap file without alpha channel for palette pixelmap.           */
952 /*                                                                        */
953 /*  INPUT                                                                 */
954 /*                                                                        */
955 /*    context                               Drawing context               */
956 /*    xpos                                  x-coord of top-left draw point*/
957 /*    ypos                                  y-coord of top-left draw point*/
958 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
959 /*                                                                        */
960 /*  OUTPUT                                                                */
961 /*                                                                        */
962 /*    None                                                                */
963 /*                                                                        */
964 /*  CALLS                                                                 */
965 /*                                                                        */
966 /*    None                                                                */
967 /*                                                                        */
968 /*  CALLED BY                                                             */
969 /*                                                                        */
970 /*    GUIX Internal Code                                                  */
971 /*                                                                        */
972 /*  RELEASE HISTORY                                                       */
973 /*                                                                        */
974 /*    DATE              NAME                      DESCRIPTION             */
975 /*                                                                        */
976 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
977 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
978 /*                                            resulting in version 6.1    */
979 /*  10-31-2023     Ting Zhu                 Modified comment(s),          */
980 /*                                            added partial canvas buffer */
981 /*                                            support,                    */
982 /*                                            resulting in version 6.3.0  */
983 /*                                                                        */
984 /**************************************************************************/
_gx_display_driver_565rgb_palette_pixelmap_compressed_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)985 static VOID _gx_display_driver_565rgb_palette_pixelmap_compressed_write(GX_DRAW_CONTEXT *context,
986                                                                         INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
987 {
988 INT                yval;
989 INT                xval;
990 GX_CONST GX_UBYTE *get;
991 USHORT            *put;
992 USHORT            *putrow;
993 GX_COLOR          *palette;
994 USHORT             count;
995 GX_UBYTE           r;
996 GX_UBYTE           g;
997 GX_UBYTE           b;
998 GX_UBYTE           brush_alpha;
999 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
1000 
1001     get = (GX_CONST GX_UBYTE *)pixelmap -> gx_pixelmap_data;
1002     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
1003 
1004     /* compressed with no alpha is a one-byte count and one-byte index value */
1005     /* first, skip to the starting row */
1006     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
1007     {
1008         xval = 0;
1009         while (xval < pixelmap -> gx_pixelmap_width)
1010         {
1011             count = *get++;
1012 
1013             if (count & 0x80)
1014             {
1015                 count = (USHORT)((count & 0x7f) + 1u);
1016                 get++;      /* skip repeated pixel value */
1017             }
1018             else
1019             {
1020                 count++;
1021                 get += count;   /* skip raw pixel values */
1022             }
1023             xval += count;
1024         }
1025     }
1026 
1027     /* Now we are on the first visible row, copy pixels until we get
1028        to the end of the last visible row. */
1029     putrow = (USHORT *)context -> gx_draw_context_memory;
1030     GX_CALCULATE_PUTROW(putrow, xpos, yval, context);
1031 
1032     palette = (GX_COLOR *)pixelmap -> gx_pixelmap_aux_data;
1033 
1034     while (yval <= clip -> gx_rectangle_bottom)
1035     {
1036         put = putrow;
1037         xval = xpos;
1038 
1039         while (xval < xpos + pixelmap -> gx_pixelmap_width)
1040         {
1041             count = *get++;
1042 
1043             if (count & 0x80)
1044             {
1045                 /* repeated value */
1046                 count = (USHORT)((count & 0x7f) + 1u);
1047 
1048                 r = (GX_UBYTE)(REDVAL_32BPP(palette[*get]) >> 3);
1049                 g = (GX_UBYTE)(GREENVAL_32BPP(palette[*get]) >> 2);
1050                 b = (GX_UBYTE)(BLUEVAL_32BPP(palette[*get++]) >> 3);
1051 
1052                 if (brush_alpha == 0xff)
1053                 {
1054                     while (count--)
1055                     {
1056                         if (xval >= clip -> gx_rectangle_left &&
1057                             xval <= clip -> gx_rectangle_right)
1058                         {
1059                             *put = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
1060                         }
1061                         put++;
1062                         xval++;
1063                     }
1064                 }
1065                 else
1066                 {
1067                     while (count--)
1068                     {
1069                         if (xval >= clip -> gx_rectangle_left &&
1070                             xval <= clip -> gx_rectangle_right)
1071                         {
1072                             _gx_display_driver_565rgb_pixel_blend(context, xval, yval, (USHORT)ASSEMBLECOLOR_16BPP(r, g, b), brush_alpha);
1073                         }
1074                         xval++;
1075                     }
1076                 }
1077             }
1078             else
1079             {
1080                 /* string of non-repeated values */
1081                 count++;
1082                 if (brush_alpha == 0xff)
1083                 {
1084                     while (count--)
1085                     {
1086                         if (xval >= clip -> gx_rectangle_left &&
1087                             xval <= clip -> gx_rectangle_right)
1088                         {
1089                             r = (GX_UBYTE)(REDVAL_32BPP(palette[*get]) >> 3);
1090                             g = (GX_UBYTE)(GREENVAL_32BPP(palette[*get]) >> 2);
1091                             b = (GX_UBYTE)(BLUEVAL_32BPP(palette[*get]) >> 3);
1092                             *put = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
1093                         }
1094 
1095                         put++;
1096                         get++;
1097                         xval++;
1098                     }
1099                 }
1100                 else
1101                 {
1102                     while (count--)
1103                     {
1104                         if (xval >= clip -> gx_rectangle_left &&
1105                             xval <= clip -> gx_rectangle_right)
1106                         {
1107                             r = (GX_UBYTE)(REDVAL_32BPP(palette[*get]) >> 3);
1108                             g = (GX_UBYTE)(GREENVAL_32BPP(palette[*get]) >> 2);
1109                             b = (GX_UBYTE)(BLUEVAL_32BPP(palette[*get]) >> 3);
1110                             _gx_display_driver_565rgb_pixel_blend(context, xval, yval, (USHORT)ASSEMBLECOLOR_16BPP(r, g, b), brush_alpha);
1111                         }
1112 
1113                         get++;
1114                         xval++;
1115                     }
1116                 }
1117             }
1118         }
1119         putrow += context -> gx_draw_context_pitch;
1120         yval++;
1121     }
1122 }
1123 
1124 /**************************************************************************/
1125 /*                                                                        */
1126 /*  FUNCTION                                               RELEASE        */
1127 /*                                                                        */
1128 /*    _gx_display_driver_16bpp_4444argb_pixelmap_raw_write                */
1129 /*                                                         PORTABLE C     */
1130 /*                                                           6.1          */
1131 /*  AUTHOR                                                                */
1132 /*                                                                        */
1133 /*    Kenneth Maxwell, Microsoft Corporation                              */
1134 /*                                                                        */
1135 /*  DESCRIPTION                                                           */
1136 /*                                                                        */
1137 /*    Internal helper function that handles writing of uncompressed       */
1138 /*    pixlemap file with alpha channel of 4444argb format.                */
1139 /*                                                                        */
1140 /*  INPUT                                                                 */
1141 /*                                                                        */
1142 /*    context                               Drawing context               */
1143 /*    xpos                                  x-coord of top-left draw point*/
1144 /*    ypos                                  y-coord of top-left draw point*/
1145 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
1146 /*                                                                        */
1147 /*  OUTPUT                                                                */
1148 /*                                                                        */
1149 /*    None                                                                */
1150 /*                                                                        */
1151 /*  CALLS                                                                 */
1152 /*                                                                        */
1153 /*    _gx_display_driver_565rgb_pixel_blend  Display driver basic pixel   */
1154 /*                                             blend function             */
1155 /*    _gx_display_driver_16bpp_pixel_write   Display driver basic pixel   */
1156 /*                                             write function             */
1157 /*                                                                        */
1158 /*  CALLED BY                                                             */
1159 /*                                                                        */
1160 /*    GUIX Internal Code                                                  */
1161 /*                                                                        */
1162 /*  RELEASE HISTORY                                                       */
1163 /*                                                                        */
1164 /*    DATE              NAME                      DESCRIPTION             */
1165 /*                                                                        */
1166 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1167 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1168 /*                                            resulting in version 6.1    */
1169 /*                                                                        */
1170 /**************************************************************************/
_gx_display_driver_16bpp_4444argb_pixelmap_raw_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1171 static VOID _gx_display_driver_16bpp_4444argb_pixelmap_raw_write(GX_DRAW_CONTEXT *context,
1172                                                                  INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1173 {
1174 INT              skipcount;
1175 INT              xval;
1176 INT              yval;
1177 USHORT          *getrow;
1178 GX_CONST USHORT *get;
1179 UCHAR            alpha_value;
1180 USHORT           pixel;
1181 
1182 GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
1183 
1184     /* calculate how many pixels to skip */
1185     skipcount = (pixelmap -> gx_pixelmap_width) * (clip -> gx_rectangle_top - ypos);
1186     skipcount += (clip -> gx_rectangle_left - xpos);
1187     getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
1188     getrow += skipcount;
1189 
1190     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
1191     {
1192         get = getrow;
1193 
1194         for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
1195         {
1196             /* 0x000f- -> b , 0x00f0- -> g , 0x0f00- -> r , 0xf000- -> a */
1197             /*4444bgra - ->  565rgb*/
1198             alpha_value = (UCHAR)(((*get) & 0xf000) >> 8);
1199             alpha_value = alpha_value | (alpha_value >> 4);
1200             if (alpha_value)
1201             {
1202                 pixel = (USHORT)((((*get) & 0x0f00) << 4) | (((*get) & 0x00f0) << 3) | (((*get) & 0x000f) << 1));
1203                 if (alpha_value == 0xff)
1204                 {
1205                     _gx_display_driver_16bpp_pixel_write(context, xval, yval, pixel);
1206                 }
1207                 else
1208                 {
1209                     _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha_value);
1210                 }
1211             }
1212             get++;
1213         }
1214         getrow += pixelmap -> gx_pixelmap_width;
1215     }
1216 }
1217 /**************************************************************************/
1218 /*                                                                        */
1219 /*  FUNCTION                                               RELEASE        */
1220 /*                                                                        */
1221 /*    _gx_display_driver_16bpp_4444argb_pixelmap_compressed_write         */
1222 /*                                                        PORTABLE C      */
1223 /*                                                           6.1          */
1224 /*  AUTHOR                                                                */
1225 /*                                                                        */
1226 /*    Kenneth Maxwell, Microsoft Corporation                              */
1227 /*                                                                        */
1228 /*  DESCRIPTION                                                           */
1229 /*                                                                        */
1230 /*    Internal helper function that handles writing of compressed         */
1231 /*    pixelmap data of format 4444argb in 16bpp drivers.                  */
1232 /*                                                                        */
1233 /*  INPUT                                                                 */
1234 /*                                                                        */
1235 /*    context                               Drawing context               */
1236 /*    xpos                                  x-coord of top-left draw point*/
1237 /*    ypos                                  y-coord of top-left draw point*/
1238 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
1239 /*                                                                        */
1240 /*  OUTPUT                                                                */
1241 /*                                                                        */
1242 /*    None                                                                */
1243 /*                                                                        */
1244 /*  CALLS                                                                 */
1245 /*                                                                        */
1246 /*    _gx_display_driver_565rgb_pixel_blend  Display driver basic pixel   */
1247 /*                                             blend function             */
1248 /*    _gx_display_driver_16bpp_pixel_write   Display driver basic pixel   */
1249 /*                                             write function             */
1250 /*                                                                        */
1251 /*  CALLED BY                                                             */
1252 /*                                                                        */
1253 /*    GUIX Internal Code                                                  */
1254 /*                                                                        */
1255 /*  RELEASE HISTORY                                                       */
1256 /*                                                                        */
1257 /*    DATE              NAME                      DESCRIPTION             */
1258 /*                                                                        */
1259 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1260 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1261 /*                                            resulting in version 6.1    */
1262 /*                                                                        */
1263 /**************************************************************************/
_gx_display_driver_16bpp_4444argb_pixelmap_compressed_write(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1264 static VOID _gx_display_driver_16bpp_4444argb_pixelmap_compressed_write(GX_DRAW_CONTEXT *context,
1265                                                                         INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1266 {
1267 INT              yval;
1268 INT              xval;
1269 GX_CONST USHORT *get;
1270 USHORT           count;
1271 USHORT           pixel;
1272 GX_UBYTE         alpha_value;
1273 GX_UBYTE         combined_alpha;
1274 GX_UBYTE         brush_alpha;
1275 GX_UBYTE         r;
1276 GX_UBYTE         g;
1277 GX_UBYTE         b;
1278 
1279 GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
1280 
1281     get = (GX_CONST USHORT *)pixelmap -> gx_pixelmap_data;
1282     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
1283 
1284     /* first, skip to the starting row */
1285     for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
1286     {
1287         xval = 0;
1288         while (xval < pixelmap -> gx_pixelmap_width)
1289         {
1290             count = *get++;
1291 
1292             if (count & 0x8000)
1293             {
1294                 count = (USHORT)((count & 0x7fff) + 1u);
1295                 get++;      /* skip repeated pixel value */
1296             }
1297             else
1298             {
1299                 count++;
1300                 get += count;   /* skip raw pixel values */
1301             }
1302             xval += count;
1303         }
1304     }
1305 
1306     /* now we are on the first visible row, copy pixels until we get
1307        to the enf of the last visible row
1308      */
1309     while (yval <= clip -> gx_rectangle_bottom)
1310     {
1311         xval = xpos;
1312 
1313         while (xval < xpos + pixelmap -> gx_pixelmap_width)
1314         {
1315             count = *get++;
1316 
1317             if (count & 0x8000)
1318             {
1319                 /* repeated value */
1320                 count = (USHORT)((count & 0x7fff) + 1u);
1321                 pixel = *get++;
1322                 alpha_value = (GX_UBYTE)((pixel & 0xf000) >> 8);
1323                 alpha_value = (alpha_value >> 4) | alpha_value;
1324                 if (alpha_value)
1325                 {
1326                     r = (GX_UBYTE)((pixel & 0x0f00) >> 7);
1327                     g = (GX_UBYTE)((pixel & 0x00f0) >> 2);
1328                     b = (GX_UBYTE)((pixel & 0x000f) << 1);
1329                     pixel = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
1330 
1331                     if (brush_alpha == 0xff)
1332                     {
1333                         while (count--)
1334                         {
1335                             if (xval >= clip -> gx_rectangle_left &&
1336                                 xval <= clip -> gx_rectangle_right)
1337                             {
1338                                 if (alpha_value == 0xff)
1339                                 {
1340                                     _gx_display_driver_16bpp_pixel_write(context, xval, yval, pixel);
1341                                 }
1342                                 else
1343                                 {
1344                                     _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha_value);
1345                                 }
1346                             }
1347                             xval++;
1348                         }
1349                     }
1350                     else
1351                     {
1352                         while (count--)
1353                         {
1354                             if (xval >= clip -> gx_rectangle_left &&
1355                                 xval <= clip -> gx_rectangle_right)
1356                             {
1357                                 combined_alpha = (GX_UBYTE)(brush_alpha * alpha_value / 255);
1358                                 _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, combined_alpha);
1359                             }
1360                             xval++;
1361                         }
1362                     }
1363                 }
1364                 else
1365                 {
1366                     while (count--)
1367                     {
1368                         xval++;
1369                     }
1370                 }
1371             }
1372             else
1373             {
1374                 /* string of non-repeated values */
1375                 count++;
1376 
1377                 if (brush_alpha == 0xff)
1378                 {
1379                     while (count--)
1380                     {
1381                         if (xval >= clip -> gx_rectangle_left &&
1382                             xval <= clip -> gx_rectangle_right)
1383                         {
1384                             pixel = *get;
1385                             alpha_value = (GX_UBYTE)((pixel & 0xf000) >> 8);
1386                             alpha_value = (alpha_value >> 4) | alpha_value;
1387                             r = (GX_UBYTE)((pixel & 0x0f00) >> 7);
1388                             g = (GX_UBYTE)((pixel & 0x00f0) >> 2);
1389                             b = (GX_UBYTE)((pixel & 0x000f) << 1);
1390                             pixel = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
1391                             if (alpha_value)
1392                             {
1393                                 if (alpha_value == 0xff)
1394                                 {
1395                                     _gx_display_driver_16bpp_pixel_write(context, xval, yval, pixel);
1396                                 }
1397                                 else
1398                                 {
1399                                     _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, alpha_value);
1400                                 }
1401                             }
1402                         }
1403                         get++;
1404                         xval++;
1405                     }
1406                 }
1407                 else
1408                 {
1409                     while (count--)
1410                     {
1411                         if (xval >= clip -> gx_rectangle_left &&
1412                             xval <= clip -> gx_rectangle_right)
1413                         {
1414                             pixel = *get;
1415                             alpha_value = (GX_UBYTE)((pixel & 0xf000) >> 8);
1416                             alpha_value = (alpha_value >> 4) | alpha_value;
1417                             r = (GX_UBYTE)((pixel & 0x0f00) >> 7);
1418                             g = (GX_UBYTE)((pixel & 0x00f0) >> 2);
1419                             b = (GX_UBYTE)((pixel & 0x000f) << 1);
1420                             pixel = (USHORT)ASSEMBLECOLOR_16BPP(r, g, b);
1421                             combined_alpha = (GX_UBYTE)(brush_alpha * alpha_value / 255);
1422                             _gx_display_driver_565rgb_pixel_blend(context, xval, yval, pixel, combined_alpha);
1423                         }
1424                         get++;
1425                         xval++;
1426                     }
1427                 }
1428             }
1429         }
1430         yval++;
1431     }
1432 }
1433 
1434 /**************************************************************************/
1435 /*                                                                        */
1436 /*  FUNCTION                                               RELEASE        */
1437 /*                                                                        */
1438 /*    _gx_display_driver_565rgb_pixelmap_draw             PORTABLE C      */
1439 /*                                                           6.1          */
1440 /*  AUTHOR                                                                */
1441 /*                                                                        */
1442 /*    Kenneth Maxwell, Microsoft Corporation                              */
1443 /*                                                                        */
1444 /*  DESCRIPTION                                                           */
1445 /*                                                                        */
1446 /*    565rgb screen driver pixelmap drawing function that handles         */
1447 /*    compressed or uncompress, with or without alpha channel.            */
1448 /*                                                                        */
1449 /*  INPUT                                                                 */
1450 /*                                                                        */
1451 /*    context                               Drawing context               */
1452 /*    xpos                                  x-coord of top-left draw point*/
1453 /*    ypos                                  y-coord of top-left draw point*/
1454 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
1455 /*                                                                        */
1456 /*  OUTPUT                                                                */
1457 /*                                                                        */
1458 /*    None                                                                */
1459 /*                                                                        */
1460 /*  CALLS                                                                 */
1461 /*                                                                        */
1462 /*     _gx_display_driver_565rgb_pixelmap_compressed_alpha_write          */
1463 /*     _gx_display_driver_565rgb_pixelmap_alpha_write                     */
1464 /*     _gx_display_driver_565rgb_pixelmap_compressed_write                */
1465 /*     _gx_display_driver_565rgb_pixelmap_raw_write                       */
1466 /*     _gx_display_driver_565rgb_palette_pixelmap_compressed_write        */
1467 /*     _gx_display_driver_565rgb_palette_pixelmap_raw_write               */
1468 /*     _gx_display_driver_16bpp_4444argb_pixelmap_raw_write               */
1469 /*     _gx_display_driver_565rgb_palette_pixelmap_transparent_compressed  */
1470 /*       _write                                                           */
1471 /*     _gx_display_driver_565rgb_palette_pixelmap_transparent_raw_write   */
1472 /*     _gx_display_driver_16bpp_4444argb_pixelmap_compressed_write        */
1473 /*     _gx_display_driver_565rgb_pixelmap_blend                           */
1474 /*                                                                        */
1475 /*  CALLED BY                                                             */
1476 /*                                                                        */
1477 /*    GUIX Internal Code                                                  */
1478 /*                                                                        */
1479 /*  RELEASE HISTORY                                                       */
1480 /*                                                                        */
1481 /*    DATE              NAME                      DESCRIPTION             */
1482 /*                                                                        */
1483 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1484 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1485 /*                                            resulting in version 6.1    */
1486 /*                                                                        */
1487 /**************************************************************************/
_gx_display_driver_565rgb_pixelmap_draw(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1488 VOID _gx_display_driver_565rgb_pixelmap_draw(GX_DRAW_CONTEXT *context,
1489                                              INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1490 {
1491 GX_BOOL  drawn = GX_FALSE;
1492 GX_UBYTE brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
1493 
1494     if (brush_alpha == 0)
1495     {
1496         /* Draw nothing here. Just return. */
1497         return;
1498     }
1499 
1500     switch (pixelmap -> gx_pixelmap_format)
1501     {
1502     case GX_COLOR_FORMAT_8BIT_PALETTE:
1503         if (pixelmap -> gx_pixelmap_aux_data == GX_NULL)
1504         {
1505             break;
1506         }
1507 
1508         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT)
1509         {
1510             if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1511             {
1512                 /* compressed with */
1513                 _gx_display_driver_565rgb_palette_pixelmap_transparent_compressed_write(context, xpos, ypos, pixelmap);
1514                 drawn = GX_TRUE;
1515             }
1516             else
1517             {
1518                 /* no compression */
1519                 if (brush_alpha == 0xff)
1520                 {
1521                     _gx_display_driver_565rgb_palette_pixelmap_transparent_raw_write(context, xpos, ypos, pixelmap);
1522                     drawn = GX_TRUE;
1523                 }
1524             }
1525         }
1526         else
1527         {
1528             if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1529             {
1530                 /* compressed with */
1531 
1532                 _gx_display_driver_565rgb_palette_pixelmap_compressed_write(context, xpos, ypos, pixelmap);
1533                 drawn = GX_TRUE;
1534             }
1535             else
1536             {
1537                 /* no compression */
1538                 if (brush_alpha == 0xff)
1539                 {
1540                     _gx_display_driver_565rgb_palette_pixelmap_raw_write(context, xpos, ypos, pixelmap);
1541                     drawn = GX_TRUE;
1542                 }
1543             }
1544         }
1545         break;
1546 
1547     case GX_COLOR_FORMAT_565BGR:
1548     case GX_COLOR_FORMAT_565RGB:
1549         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
1550         {
1551             if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1552             {
1553                 /* has both compression and alpha */
1554                 _gx_display_driver_565rgb_pixelmap_compressed_alpha_write(context,
1555                                                                           xpos, ypos, pixelmap);
1556                 drawn = GX_TRUE;
1557             }
1558             else
1559             {
1560                 /* alpha, no compression */
1561                 if (brush_alpha == 0xff)
1562                 {
1563                     _gx_display_driver_565rgb_pixelmap_alpha_write(context, xpos, ypos, pixelmap);
1564                     drawn = GX_TRUE;
1565                 }
1566             }
1567         }
1568         else
1569         {
1570             if (brush_alpha == 0xff)
1571             {
1572                 if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1573                 {
1574                     /* compressed with no alpha */
1575                     _gx_display_driver_565rgb_pixelmap_compressed_write(context,
1576                                                                         xpos, ypos, pixelmap);
1577                 }
1578                 else
1579                 {
1580                     /* no compression or alpha */
1581                     _gx_display_driver_565rgb_pixelmap_raw_write(context,
1582                                                                  xpos, ypos, pixelmap);
1583                 }
1584                 drawn = GX_TRUE;
1585             }
1586         }
1587         break;
1588 
1589     case GX_COLOR_FORMAT_4444ARGB:
1590         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1591         {
1592             /*not write yet*/
1593             _gx_display_driver_16bpp_4444argb_pixelmap_compressed_write(context, xpos, ypos, pixelmap);
1594             drawn = GX_TRUE;
1595         }
1596         else
1597         {
1598             if (brush_alpha == 0xff)
1599             {
1600                 _gx_display_driver_16bpp_4444argb_pixelmap_raw_write(context, xpos, ypos, pixelmap);
1601                 drawn = GX_TRUE;
1602             }
1603         }
1604         break;
1605 
1606     default:
1607         drawn = GX_TRUE;
1608         break;
1609     }
1610 
1611     if ((!drawn) && (brush_alpha != 0xff))
1612     {
1613         _gx_display_driver_565rgb_pixelmap_blend(context, xpos, ypos, pixelmap, brush_alpha);
1614     }
1615 
1616     return;
1617 }
1618 
1619 
1620 /**************************************************************************/
1621 /*                                                                        */
1622 /*  FUNCTION                                               RELEASE        */
1623 /*                                                                        */
1624 /*    _gx_display_driver_1555xrgb_pixelmap_draw           PORTABLE C      */
1625 /*                                                           6.1          */
1626 /*  AUTHOR                                                                */
1627 /*                                                                        */
1628 /*    Kenneth Maxwell, Microsoft Corporation                              */
1629 /*                                                                        */
1630 /*  DESCRIPTION                                                           */
1631 /*                                                                        */
1632 /*    1555xrgb screen driver pixelmap drawing function that handles       */
1633 /*    compressed or uncompress, with or without alpha channel.            */
1634 /*                                                                        */
1635 /*  INPUT                                                                 */
1636 /*                                                                        */
1637 /*    context                               Drawing context               */
1638 /*    xpos                                  x-coord of top-left draw point*/
1639 /*    ypos                                  y-coord of top-left draw point*/
1640 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
1641 /*                                                                        */
1642 /*  OUTPUT                                                                */
1643 /*                                                                        */
1644 /*    None                                                                */
1645 /*                                                                        */
1646 /*  CALLS                                                                 */
1647 /*                                                                        */
1648 /*     _gx_display_driver_565rgb_pixelmap_compressed_alpha_write          */
1649 /*     _gx_display_driver_565rgb_pixelmap_alpha_write                     */
1650 /*     _gx_display_driver_565rgb_pixelmap_compressed_write                */
1651 /*     _gx_display_driver_565rgb_pixelmap_raw_write                       */
1652 /*     _gx_display_driver_15555xrgb_pixelmap_blend                        */
1653 /*                                                                        */
1654 /*  CALLED BY                                                             */
1655 /*                                                                        */
1656 /*    GUIX Internal Code                                                  */
1657 /*                                                                        */
1658 /*  RELEASE HISTORY                                                       */
1659 /*                                                                        */
1660 /*    DATE              NAME                      DESCRIPTION             */
1661 /*                                                                        */
1662 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1663 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1664 /*                                            resulting in version 6.1    */
1665 /*                                                                        */
1666 /**************************************************************************/
_gx_display_driver_1555xrgb_pixelmap_draw(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap)1667 VOID _gx_display_driver_1555xrgb_pixelmap_draw(GX_DRAW_CONTEXT *context,
1668                                                INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
1669 {
1670 GX_BOOL  drawn = GX_FALSE;
1671 GX_UBYTE brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
1672 
1673     if (brush_alpha == 0)
1674     {
1675         /* Draw nothing here. Just return. */
1676         return;
1677     }
1678 
1679     switch (pixelmap -> gx_pixelmap_format)
1680     {
1681     case GX_COLOR_FORMAT_1555XRGB:
1682         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
1683         {
1684             if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1685             {
1686                 /* has both compression and alpha */
1687                 _gx_display_driver_565rgb_pixelmap_compressed_alpha_write(context,
1688                                                                           xpos, ypos, pixelmap);
1689                 drawn = GX_TRUE;
1690             }
1691             else
1692             {
1693                 /* alpha, no compression */
1694                 if (brush_alpha == 0xff)
1695                 {
1696                     _gx_display_driver_565rgb_pixelmap_alpha_write(context, xpos, ypos, pixelmap);
1697                     drawn = GX_TRUE;
1698                 }
1699             }
1700         }
1701         else
1702         {
1703             if (brush_alpha == 0xff)
1704             {
1705                 if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1706                 {
1707                     /* compressed with no alpha */
1708                     _gx_display_driver_565rgb_pixelmap_compressed_write(context,
1709                                                                         xpos, ypos, pixelmap);
1710                 }
1711                 else
1712                 {
1713                     /* no compression or alpha */
1714                     _gx_display_driver_565rgb_pixelmap_raw_write(context,
1715                                                                  xpos, ypos, pixelmap);
1716                 }
1717                 drawn = GX_TRUE;
1718             }
1719         }
1720         break;
1721 
1722     default:
1723         return;
1724     }
1725 
1726     if (!drawn)
1727     {
1728         _gx_display_driver_1555xrgb_pixelmap_blend(context, xpos, ypos, pixelmap, brush_alpha);
1729     }
1730 
1731     return;
1732 }
1733 
1734