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 #if defined(GX_ARC_DRAWING_SUPPORT)
30 
31 #if defined(GX_BRUSH_ALPHA_SUPPORT)
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_alpha_blend    */
37 /*                                                        PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    Internal helper function that handles writing of uncompressed       */
46 /*    pixlemap file with alpha channel with brush alpha.                  */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    context                               Drawing context               */
51 /*    xstart                                x-coord of line left          */
52 /*    xend                                  x-coord of line right         */
53 /*    y                                     y-coord of line top           */
54 /*    info                                  GX_FILL_PIXELMAP_INFO struct  */
55 /*    alpha                                 Alpha value                   */
56 /*                                                                        */
57 /*  OUTPUT                                                                */
58 /*                                                                        */
59 /*    None                                                                */
60 /*                                                                        */
61 /*  CALLS                                                                 */
62 /*                                                                        */
63 /*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
64 /*                                            blend function              */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_draw           */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
75 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*                                                                        */
78 /**************************************************************************/
_gx_display_driver_4444argb_horizontal_pixelmap_line_alpha_blend(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT y,GX_FILL_PIXELMAP_INFO * info,GX_UBYTE alpha)79 static VOID _gx_display_driver_4444argb_horizontal_pixelmap_line_alpha_blend(GX_DRAW_CONTEXT *context,
80                                                                              INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info, GX_UBYTE alpha)
81 {
82 INT              xval;
83 INT              offset;
84 INT              pic_width;
85 USHORT           color;
86 GX_CONST USHORT *get;
87 GX_PIXELMAP     *pixelmap;
88 VOID             (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR color, GX_UBYTE alpha);
89 
90     pixelmap = info -> pixelmap;
91     blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
92 
93     if (blend_func == GX_NULL)
94     {
95         return;
96     }
97     pic_width = pixelmap -> gx_pixelmap_width;
98 
99     if ((info -> draw) && (xstart <= xend))
100     {
101         get = (GX_CONST USHORT *)info -> current_pixel_ptr;
102 
103         /*calculate the offset.*/
104         offset = (info -> x_offset % pic_width);
105 
106         for (xval = xstart; xval <= xend; xval++)
107         {
108             /*get points to the start postion of this row. So we need to calculate its position.*/
109             color = *(get + offset);
110             offset++;
111             if (color & 0xf000)
112             {
113                 /* not transparent */
114                 blend_func(context, xval, y, color, alpha);
115             }
116 
117             if (offset >= pic_width)
118             {
119                 offset -= pic_width;
120             }
121         }
122     }
123 
124     /*This line is drawn. Update the pointer position for next row.*/
125     info -> current_pixel_ptr += (UINT)pic_width * sizeof(USHORT);
126 }
127 
128 /**************************************************************************/
129 /*                                                                        */
130 /*  FUNCTION                                               RELEASE        */
131 /*                                                                        */
132 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_raw_blend      */
133 /*                                                        PORTABLE C      */
134 /*                                                           6.1          */
135 /*  AUTHOR                                                                */
136 /*                                                                        */
137 /*    Kenneth Maxwell, Microsoft Corporation                              */
138 /*                                                                        */
139 /*  DESCRIPTION                                                           */
140 /*                                                                        */
141 /*    Internal helper function that handles writing of uncompressed       */
142 /*    pixlemap file with alpha whose value is always 0xf.                 */
143 /*                                                                        */
144 /*  INPUT                                                                 */
145 /*                                                                        */
146 /*    context                               Drawing context               */
147 /*    xstart                                x-coord of line left          */
148 /*    xend                                  x-coord of line end           */
149 /*    y                                     y-coord of line top           */
150 /*    info                                  GX_FILL_PIXELMAP_INFO struct  */
151 /*    alpha                                 Alpha value                   */
152 /*                                                                        */
153 /*  OUTPUT                                                                */
154 /*                                                                        */
155 /*    None                                                                */
156 /*                                                                        */
157 /*  CALLS                                                                 */
158 /*                                                                        */
159 /*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
160 /*                                            blend function              */
161 /*                                                                        */
162 /*  CALLED BY                                                             */
163 /*                                                                        */
164 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_draw           */
165 /*                                                                        */
166 /*  RELEASE HISTORY                                                       */
167 /*                                                                        */
168 /*    DATE              NAME                      DESCRIPTION             */
169 /*                                                                        */
170 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
171 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
172 /*                                            resulting in version 6.1    */
173 /*                                                                        */
174 /**************************************************************************/
_gx_display_driver_4444argb_horizontal_pixelmap_line_raw_blend(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT y,GX_FILL_PIXELMAP_INFO * info,GX_UBYTE alpha)175 static VOID _gx_display_driver_4444argb_horizontal_pixelmap_line_raw_blend(GX_DRAW_CONTEXT *context,
176                                                                            INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info, GX_UBYTE alpha)
177 {
178 INT              xval;
179 INT              offset;
180 INT              pic_width;
181 GX_CONST USHORT *get;
182 GX_PIXELMAP     *pixelmap;
183 VOID             (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR color, GX_UBYTE alpha);
184 
185     pixelmap = info -> pixelmap;
186     blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
187 
188     if (blend_func == GX_NULL)
189     {
190         return;
191     }
192 
193     pic_width = pixelmap -> gx_pixelmap_width;
194     get = (GX_CONST USHORT *)info -> current_pixel_ptr;
195 
196     if ((info -> draw) && (xstart <= xend))
197     {
198         /* calculate the offset. */
199         offset = (info -> x_offset % pic_width);
200 
201         for (xval = xstart; xval <= xend; xval++)
202         {
203             /*get points to the start postion of this row. So we need to calculate its position.*/
204             blend_func(context, xval, y, *(get + offset), alpha);
205 
206             offset++;
207             if (offset >= pic_width)
208             {
209                 offset -= pic_width;
210             }
211         }
212     }
213 
214     /*This line is drawn. Update the pointer position for next row.*/
215     info -> current_pixel_ptr += (UINT)pic_width * sizeof(USHORT);
216 }
217 
218 /**************************************************************************/
219 /*                                                                        */
220 /*  FUNCTION                                               RELEASE        */
221 /*                                                                        */
222 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_    */
223 /*    alpha_blend                                                         */
224 /*                                                        PORTABLE C      */
225 /*                                                           6.1          */
226 /*  AUTHOR                                                                */
227 /*                                                                        */
228 /*    Kenneth Maxwell, Microsoft Corporation                              */
229 /*                                                                        */
230 /*  DESCRIPTION                                                           */
231 /*                                                                        */
232 /*    Internal helper function that handles writing of compressed         */
233 /*    pixlemap file with alpha channel.                                   */
234 /*                                                                        */
235 /*  INPUT                                                                 */
236 /*                                                                        */
237 /*    context                               Drawing context               */
238 /*    xstart                                x-coord of line left          */
239 /*    xend                                  x-coord of line end           */
240 /*    y                                     y-coord of line top           */
241 /*    info                                  GX_FILL_PIXELMAP_INFO struct  */
242 /*    alpha                                 Alpha value                   */
243 /*                                                                        */
244 /*  OUTPUT                                                                */
245 /*                                                                        */
246 /*    None                                                                */
247 /*                                                                        */
248 /*  CALLS                                                                 */
249 /*                                                                        */
250 /*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
251 /*                                            blend function              */
252 /*                                                                        */
253 /*  CALLED BY                                                             */
254 /*                                                                        */
255 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_draw           */
256 /*                                                                        */
257 /*  RELEASE HISTORY                                                       */
258 /*                                                                        */
259 /*    DATE              NAME                      DESCRIPTION             */
260 /*                                                                        */
261 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
262 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
263 /*                                            resulting in version 6.1    */
264 /*                                                                        */
265 /**************************************************************************/
_gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_alpha_blend(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT y,GX_FILL_PIXELMAP_INFO * info,GX_UBYTE alpha)266 static VOID _gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_alpha_blend(GX_DRAW_CONTEXT *context,
267                                                                                         INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info, GX_UBYTE alpha)
268 {
269 INT              start_pos;
270 INT              xval;
271 USHORT           count;
272 USHORT           pixel;
273 GX_CONST USHORT *get = GX_NULL;
274 GX_PIXELMAP     *pixelmap;
275 VOID             (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR color, GX_UBYTE alpha);
276 
277     pixelmap = info -> pixelmap;
278     blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
279 
280     if (blend_func == GX_NULL)
281     {
282         return;
283     }
284 
285     if ((info -> draw) && (xstart <= xend))
286     {
287         /* Calculate draw start position. */
288         start_pos = xstart - (info -> x_offset % pixelmap -> gx_pixelmap_width);
289 
290         /* Repeat the draw operation to fill the whole dirty area. */
291         while (start_pos <= xend)
292         {
293             xval = start_pos;
294             /*Start from where we need to repeat.*/
295             get = (GX_CONST USHORT *)info -> current_pixel_ptr;
296 
297             while (xval < start_pos + pixelmap -> gx_pixelmap_width)
298             {
299                 count = *get++;
300                 if (count & 0x8000)
301                 {
302                     count = (USHORT)((count & 0x7fff) + 1);
303                     pixel = *get++;
304                     if (pixel & 0xf000)
305                     {
306                         while (count--)
307                         {
308                             if (xval >= xstart && xval <= xend)
309                             {
310                                 blend_func(context, xval, y, pixel, alpha);
311                             }
312                             xval++;
313                         }
314                     }
315                     else
316                     {
317                         xval += count;
318                     }
319                 }
320                 else
321                 {
322                     count++;
323                     while (count--)
324                     {
325                         pixel = *get++;
326                         if (xval >= xstart && xval <= xend)
327                         {
328                             if (pixel & 0xf000)
329                             {
330                                 blend_func(context, xval, y, pixel, alpha);
331                             }
332                         }
333                         xval++;
334                     }
335                 }
336             }
337             start_pos += pixelmap -> gx_pixelmap_width;
338         }
339     }
340     else
341     {
342         xval = 0;
343         get = (GX_CONST USHORT *)info -> current_pixel_ptr;
344         while (xval < pixelmap -> gx_pixelmap_width)
345         {
346             count = *get++;
347             if (count & 0x8000)
348             {
349                 count = (USHORT)((count & 0x7fff) + 1);
350                 get++;      /* skip repeated pixel value */
351             }
352             else
353             {
354                 count++;
355                 get += count;   /* skip raw pixel values */
356             }
357             xval += count;
358         }
359     }
360 
361     /*This line is drawn. cache the pointer for next line draw.*/
362     info -> current_pixel_ptr = (GX_UBYTE *)get;
363 }
364 
365 /**************************************************************************/
366 /*                                                                        */
367 /*  FUNCTION                                               RELEASE        */
368 /*                                                                        */
369 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_c_blend        */
370 /*                                                        PORTABLE C      */
371 /*                                                           6.1          */
372 /*  AUTHOR                                                                */
373 /*                                                                        */
374 /*    Kenneth Maxwell, Microsoft Corporation                              */
375 /*                                                                        */
376 /*  DESCRIPTION                                                           */
377 /*                                                                        */
378 /*    Internal helper function that handles writing of compressed         */
379 /*    pixlemap file with alpha whose value is always 0xf.                 */
380 /*                                                                        */
381 /*  INPUT                                                                 */
382 /*                                                                        */
383 /*    context                               Drawing context               */
384 /*    xstart                                x-coord of line left          */
385 /*    xend                                  x-coord of line end           */
386 /*    y                                     y-coord of line top           */
387 /*    info                                  GX_FILL_PIXELMAP_INFO struct  */
388 /*    alpha                                 Alpha value                   */
389 /*                                                                        */
390 /*  OUTPUT                                                                */
391 /*                                                                        */
392 /*    None                                                                */
393 /*                                                                        */
394 /*  CALLS                                                                 */
395 /*                                                                        */
396 /*    None                                                                */
397 /*                                                                        */
398 /*  CALLED BY                                                             */
399 /*                                                                        */
400 /*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
401 /*                                            blend function              */
402 /*                                                                        */
403 /*  CALLED BY                                                             */
404 /*                                                                        */
405 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_draw           */
406 /*                                                                        */
407 /*  RELEASE HISTORY                                                       */
408 /*                                                                        */
409 /*    DATE              NAME                      DESCRIPTION             */
410 /*                                                                        */
411 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
412 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
413 /*                                            resulting in version 6.1    */
414 /*                                                                        */
415 /**************************************************************************/
_gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_blend(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT y,GX_FILL_PIXELMAP_INFO * info,GX_UBYTE alpha)416 static VOID _gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_blend(GX_DRAW_CONTEXT *context,
417                                                                                   INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info, GX_UBYTE alpha)
418 {
419 INT              start_pos;
420 INT              xval;
421 USHORT           count;
422 USHORT           pixel;
423 GX_CONST USHORT *get = GX_NULL;
424 GX_PIXELMAP     *pixelmap;
425 VOID             (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
426 
427     blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
428     pixelmap = info -> pixelmap;
429     if (blend_func == GX_NULL)
430     {
431         return;
432     }
433 
434     if ((info -> draw) && (xstart <= xend))
435     {
436         /* Calculate draw start position. */
437         start_pos = xstart - (info -> x_offset % pixelmap -> gx_pixelmap_width);
438 
439         /* Repeat the draw operation to fill the whole dirty area. */
440         while (start_pos <= xend)
441         {
442             xval = start_pos;
443             /*Start from where we need to repeat.*/
444             get = (GX_CONST USHORT *)info -> current_pixel_ptr;
445 
446             while (xval < start_pos + pixelmap -> gx_pixelmap_width)
447             {
448                 count = *get++;
449                 if (count & 0x8000)
450                 {
451                     count = (USHORT)((count & 0x7fff) + 1);
452                     pixel = *get++;
453                     while (count--)
454                     {
455                         if (xval >= xstart && xval <= xend)
456                         {
457                             blend_func(context, xval, y, pixel, alpha);
458                         }
459                         xval++;
460                     }
461                 }
462                 else
463                 {
464                     count++;
465                     while (count--)
466                     {
467                         pixel = *get++;
468                         if (xval >= xstart && xval <= xend)
469                         {
470                             blend_func(context, xval, y, pixel, alpha);
471                         }
472                         xval++;
473                     }
474                 }
475             }
476             start_pos += pixelmap -> gx_pixelmap_width;
477         }
478     }
479     else
480     {
481         xval = 0;
482         get = (GX_CONST USHORT *)info -> current_pixel_ptr;
483         while (xval < pixelmap -> gx_pixelmap_width)
484         {
485             count = *get++;
486             if (count & 0x8000)
487             {
488                 count = (USHORT)((count & 0x7fff) + 1);
489                 get++;      /* skip repeated pixel value */
490             }
491             else
492             {
493                 count++;
494                 get += count;   /* skip raw pixel values */
495             }
496             xval += count;
497         }
498     }
499 
500     /* This line is drawn. cache the pointer for next line draw. */
501     info -> current_pixel_ptr = (GX_UBYTE *)get;
502 }
503 
504 #endif /* GX_BRUSH_ALPHA_SUPPORT */
505 /**************************************************************************/
506 /*                                                                        */
507 /*  FUNCTION                                               RELEASE        */
508 /*                                                                        */
509 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_alpha_write    */
510 /*                                                        PORTABLE C      */
511 /*                                                           6.1          */
512 /*  AUTHOR                                                                */
513 /*                                                                        */
514 /*    Kenneth Maxwell, Microsoft Corporation                              */
515 /*                                                                        */
516 /*  DESCRIPTION                                                           */
517 /*                                                                        */
518 /*    Internal helper function that handles writing of uncompressed       */
519 /*    pixlemap file with alpha channel.                                   */
520 /*                                                                        */
521 /*  INPUT                                                                 */
522 /*                                                                        */
523 /*    context                               Drawing context               */
524 /*    xstart                                x-coord of line left          */
525 /*    xend                                  x-coord of line end           */
526 /*    y                                     y-coord of line top           */
527 /*    info                                  GX_FILL_PIXELMAP_INFO struct  */
528 /*                                                                        */
529 /*  OUTPUT                                                                */
530 /*                                                                        */
531 /*    None                                                                */
532 /*                                                                        */
533 /*  CALLS                                                                 */
534 /*                                                                        */
535 /*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
536 /*                                            blend function              */
537 /*                                                                        */
538 /*  CALLED BY                                                             */
539 /*                                                                        */
540 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_draw           */
541 /*                                                                        */
542 /*  RELEASE HISTORY                                                       */
543 /*                                                                        */
544 /*    DATE              NAME                      DESCRIPTION             */
545 /*                                                                        */
546 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
547 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
548 /*                                            resulting in version 6.1    */
549 /*                                                                        */
550 /**************************************************************************/
_gx_display_driver_4444argb_horizontal_pixelmap_line_alpha_write(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT y,GX_FILL_PIXELMAP_INFO * info)551 static VOID _gx_display_driver_4444argb_horizontal_pixelmap_line_alpha_write(GX_DRAW_CONTEXT *context,
552                                                                              INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
553 {
554 INT              xval;
555 INT              offset;
556 INT              pic_width;
557 USHORT           color;
558 GX_CONST USHORT *get;
559 GX_PIXELMAP     *pixelmap;
560 VOID             (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR color, GX_UBYTE alpha);
561 
562     pixelmap = info -> pixelmap;
563     blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
564 
565     if (blend_func == GX_NULL)
566     {
567         return;
568     }
569     pic_width = pixelmap -> gx_pixelmap_width;
570 
571     if ((info -> draw) && (xstart <= xend))
572     {
573         get = (GX_CONST USHORT *)info -> current_pixel_ptr;
574 
575         /* calculate the offset. */
576         offset = (info -> x_offset % pic_width);
577 
578         for (xval = xstart; xval <= xend; xval++)
579         {
580             /* get points to the start postion of this row. So we need to calculate its position. */
581             color = *(get + offset);
582             offset++;
583 
584             if (color & 0xf000)
585             {
586                 /* not transparent */
587                 blend_func(context, xval, y, color, 0xff);
588             }
589 
590             if (offset >= pic_width)
591             {
592                 offset -= pic_width;
593             }
594         }
595     }
596 
597     /* This line is drawn. Update the pointer position for next row. */
598     info -> current_pixel_ptr += (UINT)pic_width * sizeof(USHORT);
599 }
600 
601 /**************************************************************************/
602 /*                                                                        */
603 /*  FUNCTION                                               RELEASE        */
604 /*                                                                        */
605 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_raw_write      */
606 /*                                                        PORTABLE C      */
607 /*                                                           6.1          */
608 /*  AUTHOR                                                                */
609 /*                                                                        */
610 /*    Kenneth Maxwell, Microsoft Corporation                              */
611 /*                                                                        */
612 /*  DESCRIPTION                                                           */
613 /*                                                                        */
614 /*    Internal helper function that handles writing of uncompressed       */
615 /*    pixlemap file with alpha whose value is always 0xf.                 */
616 /*                                                                        */
617 /*  INPUT                                                                 */
618 /*                                                                        */
619 /*    context                               Drawing context               */
620 /*    xstart                                x-coord of line left          */
621 /*    xend                                  x-coord of line end           */
622 /*    y                                     y-coord of line top           */
623 /*    info                                  GX_FILL_PIXELMAP_INFO struct  */
624 /*                                                                        */
625 /*  OUTPUT                                                                */
626 /*                                                                        */
627 /*    None                                                                */
628 /*                                                                        */
629 /*  CALLS                                                                 */
630 /*                                                                        */
631 /*    None                                                                */
632 /*                                                                        */
633 /*  CALLED BY                                                             */
634 /*                                                                        */
635 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_draw           */
636 /*                                                                        */
637 /*  RELEASE HISTORY                                                       */
638 /*                                                                        */
639 /*    DATE              NAME                      DESCRIPTION             */
640 /*                                                                        */
641 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
642 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
643 /*                                            resulting in version 6.1    */
644 /*                                                                        */
645 /**************************************************************************/
_gx_display_driver_4444argb_horizontal_pixelmap_line_raw_write(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT y,GX_FILL_PIXELMAP_INFO * info)646 static VOID _gx_display_driver_4444argb_horizontal_pixelmap_line_raw_write(GX_DRAW_CONTEXT *context,
647                                                                            INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
648 {
649 INT              xval;
650 INT              offset;
651 INT              pic_width;
652 GX_CONST USHORT *get;
653 USHORT          *put;
654 GX_PIXELMAP     *pixelmap;
655 
656     pixelmap = info -> pixelmap;
657 
658     pic_width = pixelmap -> gx_pixelmap_width;
659     get = (GX_CONST USHORT *)info -> current_pixel_ptr;
660 
661     if ((info -> draw) && (xstart <= xend))
662     {
663         put = (USHORT *)context -> gx_draw_context_memory;
664         put += y * context -> gx_draw_context_pitch;
665         put += xstart;
666 
667         /* calculate the offset. */
668         offset = (info -> x_offset % pic_width);
669 
670         for (xval = xstart; xval <= xend; xval++)
671         {
672             /* get points to the start postion of this row. So we need to calculate its position. */
673             *put++ = *(get + offset);
674             offset++;
675             if (offset >= pic_width)
676             {
677                 offset -= pic_width;
678             }
679         }
680     }
681 
682     /* This line is drawn. Update the pointer position for next row. */
683     info -> current_pixel_ptr += (UINT)pic_width * sizeof(USHORT);
684 }
685 
686 /**************************************************************************/
687 /*                                                                        */
688 /*  FUNCTION                                               RELEASE        */
689 /*                                                                        */
690 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_c_a_write      */
691 /*                                                        PORTABLE C      */
692 /*                                                           6.1          */
693 /*  AUTHOR                                                                */
694 /*                                                                        */
695 /*    Kenneth Maxwell, Microsoft Corporation                              */
696 /*                                                                        */
697 /*  DESCRIPTION                                                           */
698 /*                                                                        */
699 /*    Internal helper function that handles writing of compressed         */
700 /*    pixlemap file with alpha channel.                                   */
701 /*                                                                        */
702 /*  INPUT                                                                 */
703 /*                                                                        */
704 /*    context                               Drawing context               */
705 /*    xstart                                x-coord of line left          */
706 /*    xend                                  x-coord of line end           */
707 /*    y                                     y-coord of line top           */
708 /*    info                                  GX_FILL_PIXELMAP_INFO struct  */
709 /*                                                                        */
710 /*  OUTPUT                                                                */
711 /*                                                                        */
712 /*    None                                                                */
713 /*                                                                        */
714 /*  CALLS                                                                 */
715 /*                                                                        */
716 /*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
717 /*                                            blend function              */
718 /*                                                                        */
719 /*  CALLED BY                                                             */
720 /*                                                                        */
721 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_draw           */
722 /*                                                                        */
723 /*  RELEASE HISTORY                                                       */
724 /*                                                                        */
725 /*    DATE              NAME                      DESCRIPTION             */
726 /*                                                                        */
727 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
728 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
729 /*                                            resulting in version 6.1    */
730 /*                                                                        */
731 /**************************************************************************/
_gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_alpha_write(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT y,GX_FILL_PIXELMAP_INFO * info)732 static VOID _gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_alpha_write(GX_DRAW_CONTEXT *context,
733                                                                                         INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
734 {
735 INT              start_pos;
736 INT              xval;
737 USHORT           count;
738 USHORT           pixel;
739 GX_CONST USHORT *get = GX_NULL;
740 GX_PIXELMAP     *pixelmap;
741 VOID             (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR color, GX_UBYTE alpha);
742 
743     pixelmap = info -> pixelmap;
744     blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
745 
746     if (blend_func == GX_NULL)
747     {
748         return;
749     }
750 
751     if ((info -> draw) && (xstart <= xend))
752     {
753         /* Calculate draw start position. */
754         start_pos = xstart - (info -> x_offset % pixelmap -> gx_pixelmap_width);
755 
756         /* Repeat the draw operation to fill the whole dirty area. */
757         while (start_pos <= xend)
758         {
759             xval = start_pos;
760             /*Start from where we need to repeat.*/
761             get = (GX_CONST USHORT *)info -> current_pixel_ptr;
762 
763             while (xval < start_pos + pixelmap -> gx_pixelmap_width)
764             {
765                 count = *get++;
766                 if (count & 0x8000)
767                 {
768                     count = (USHORT)((count & 0x7fff) + 1);
769                     pixel = *get++;
770                     if (pixel & 0xf000)
771                     {
772                         while (count--)
773                         {
774                             if (xval >= xstart && xval <= xend)
775                             {
776                                 blend_func(context, xval, y, pixel, 0xff);
777                             }
778                             xval++;
779                         }
780                     }
781                     else
782                     {
783                         xval += count;
784                     }
785                 }
786                 else
787                 {
788                     count++;
789                     while (count--)
790                     {
791                         pixel = *get++;
792                         if (xval >= xstart && xval <= xend)
793                         {
794                             if (pixel & 0xf000)
795                             {
796                                 blend_func(context, xval, y, pixel, 0xff);
797                             }
798                         }
799                         xval++;
800                     }
801                 }
802             }
803             start_pos += pixelmap -> gx_pixelmap_width;
804         }
805     }
806     else
807     {
808         xval = 0;
809         get = (GX_CONST USHORT *)info -> current_pixel_ptr;
810         while (xval < pixelmap -> gx_pixelmap_width)
811         {
812             count = *get++;
813             if (count & 0x8000)
814             {
815                 count = (USHORT)((count & 0x7fff) + 1);
816                 get++;      /* skip repeated pixel value */
817             }
818             else
819             {
820                 count++;
821                 get += count;   /* skip raw pixel values */
822             }
823             xval += count;
824         }
825     }
826 
827     /* This line is drawn. cache the pointer for next line draw. */
828     info -> current_pixel_ptr = (GX_UBYTE *)get;
829 }
830 
831 /**************************************************************************/
832 /*                                                                        */
833 /*  FUNCTION                                               RELEASE        */
834 /*                                                                        */
835 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_c_write        */
836 /*                                                        PORTABLE C      */
837 /*                                                           6.1          */
838 /*  AUTHOR                                                                */
839 /*                                                                        */
840 /*    Kenneth Maxwell, Microsoft Corporation                              */
841 /*                                                                        */
842 /*  DESCRIPTION                                                           */
843 /*                                                                        */
844 /*    Internal helper function that handles writing of compressed         */
845 /*    pixlemap file with alpha whose value is always 0xf.                 */
846 /*                                                                        */
847 /*  INPUT                                                                 */
848 /*                                                                        */
849 /*    context                               Drawing context               */
850 /*    xstart                                x-coord of line left          */
851 /*    xend                                  x-coord of line end           */
852 /*    y                                     y-coord of line top           */
853 /*    info                                  GX_FILL_PIXELMAP_INFO struct  */
854 /*                                                                        */
855 /*  OUTPUT                                                                */
856 /*                                                                        */
857 /*    None                                                                */
858 /*                                                                        */
859 /*  CALLS                                                                 */
860 /*                                                                        */
861 /*    None                                                                */
862 /*                                                                        */
863 /*  CALLED BY                                                             */
864 /*                                                                        */
865 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_draw           */
866 /*                                                                        */
867 /*  RELEASE HISTORY                                                       */
868 /*                                                                        */
869 /*    DATE              NAME                      DESCRIPTION             */
870 /*                                                                        */
871 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
872 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
873 /*                                            resulting in version 6.1    */
874 /*                                                                        */
875 /**************************************************************************/
_gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_write(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT y,GX_FILL_PIXELMAP_INFO * info)876 static VOID _gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_write(GX_DRAW_CONTEXT *context,
877                                                                                   INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
878 {
879 INT              start_pos;
880 INT              xval;
881 USHORT           count;
882 USHORT           pixel;
883 GX_CONST USHORT *get = GX_NULL;
884 USHORT          *put;
885 GX_PIXELMAP     *pixelmap;
886 
887     pixelmap = info -> pixelmap;
888 
889     if ((info -> draw) && (xstart <= xend))
890     {
891         /* Calculate draw start position. */
892         start_pos = xstart - (info -> x_offset % pixelmap -> gx_pixelmap_width);
893 
894         put = (USHORT *)context -> gx_draw_context_memory;
895         put += y * context -> gx_draw_context_pitch + start_pos;
896 
897         /* Repeat the draw operation to fill the whole dirty area. */
898         while (start_pos <= xend)
899         {
900             xval = start_pos;
901 
902             /* Start from where we need to repeat. */
903             get = (GX_CONST USHORT *)info -> current_pixel_ptr;
904 
905             while (xval < start_pos + pixelmap -> gx_pixelmap_width)
906             {
907                 count = *get++;
908                 if (count & 0x8000)
909                 {
910                     count = (USHORT)((count & 0x7fff) + 1);
911                     pixel = *get++;
912                     while (count--)
913                     {
914                         if (xval >= xstart && xval <= xend)
915                         {
916                             *put = pixel;
917                         }
918                         xval++;
919                         put++;
920                     }
921                 }
922                 else
923                 {
924                     count++;
925                     while (count--)
926                     {
927                         pixel = *get++;
928                         if (xval >= xstart && xval <= xend)
929                         {
930                             *put = pixel;
931                         }
932                         xval++;
933                         put++;
934                     }
935                 }
936             }
937             start_pos += pixelmap -> gx_pixelmap_width;
938         }
939     }
940     else
941     {
942         xval = 0;
943         get = (GX_CONST USHORT *)info -> current_pixel_ptr;
944         while (xval < pixelmap -> gx_pixelmap_width)
945         {
946             count = *get++;
947             if (count & 0x8000)
948             {
949                 count = (USHORT)((count & 0x7fff) + 1);
950                 get++;      /* skip repeated pixel value */
951             }
952             else
953             {
954                 count++;
955                 get += count;   /* skip raw pixel values */
956             }
957             xval += count;
958         }
959     }
960 
961     /* This line is drawn. cache the pointer for next line draw. */
962     info -> current_pixel_ptr = (GX_UBYTE *)get;
963 }
964 
965 /**************************************************************************/
966 /*                                                                        */
967 /*  FUNCTION                                               RELEASE        */
968 /*                                                                        */
969 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_draw           */
970 /*                                                        PORTABLE C      */
971 /*                                                           6.1          */
972 /*  AUTHOR                                                                */
973 /*                                                                        */
974 /*    Kenneth Maxwell, Microsoft Corporation                              */
975 /*                                                                        */
976 /*  DESCRIPTION                                                           */
977 /*                                                                        */
978 /*    565rgb screen driver pixelmap drawing function that handles         */
979 /*    compressed or uncompress, with or without alpha channel.            */
980 /*                                                                        */
981 /*  INPUT                                                                 */
982 /*                                                                        */
983 /*    context                               Drawing context               */
984 /*    xstart                                x-coord of line left          */
985 /*    xend                                  x-coord of line end           */
986 /*    y                                     y-coord of line top           */
987 /*    info                                  GX_FILL_PIXELMAP_INFO struct  */
988 /*                                                                        */
989 /*  OUTPUT                                                                */
990 /*                                                                        */
991 /*    None                                                                */
992 /*                                                                        */
993 /*  CALLS                                                                 */
994 /*                                                                        */
995 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_c_a_blend      */
996 /*                                          Real display driver pixelmap  */
997 /*                                            line draw function          */
998 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_alpha_blend    */
999 /*                                          Real display driver pixelmap  */
1000 /*                                            line draw function          */
1001 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_c_blend        */
1002 /*                                          Real display driver pixelmap  */
1003 /*                                            line draw function          */
1004 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_raw_blend      */
1005 /*                                          Real display driver pixelmap  */
1006 /*                                            line draw function          */
1007 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_c_a_write      */
1008 /*                                          Real display driver pixelmap  */
1009 /*                                            line draw function          */
1010 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_alpha_write    */
1011 /*                                          Real display driver pixelmap  */
1012 /*                                            line draw function          */
1013 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_c_write        */
1014 /*                                          Real display driver pixelmap  */
1015 /*                                            line draw function          */
1016 /*    _gx_display_driver_4444argb_horizontal_pixelmap_line_raw_write      */
1017 /*                                          Real display driver pixelmap  */
1018 /*                                            line draw function          */
1019 /*                                                                        */
1020 /*  CALLED BY                                                             */
1021 /*                                                                        */
1022 /*    GUIX Internal Code                                                  */
1023 /*                                                                        */
1024 /*  RELEASE HISTORY                                                       */
1025 /*                                                                        */
1026 /*    DATE              NAME                      DESCRIPTION             */
1027 /*                                                                        */
1028 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1029 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1030 /*                                            resulting in version 6.1    */
1031 /*                                                                        */
1032 /**************************************************************************/
_gx_display_driver_4444argb_horizontal_pixelmap_line_draw(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT y,GX_FILL_PIXELMAP_INFO * info)1033 VOID _gx_display_driver_4444argb_horizontal_pixelmap_line_draw(GX_DRAW_CONTEXT *context,
1034                                                                INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
1035 {
1036 #if defined GX_BRUSH_ALPHA_SUPPORT
1037 GX_UBYTE alpha;
1038 
1039     alpha = context -> gx_draw_context_brush.gx_brush_alpha;
1040     if ((alpha == 0) || (info -> pixelmap == GX_NULL))
1041     {
1042         /* Nothing to drawn. Just return. */
1043         return;
1044     }
1045     if (alpha != 0xff)
1046     {
1047 
1048         if (info -> pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
1049         {
1050             if (info -> pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1051             {
1052                 /* has both compression and alpha */
1053                 _gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_alpha_blend(context, xstart, xend, y, info, alpha);
1054             }
1055             else
1056             {
1057                 /* alpha, no compression */
1058                 _gx_display_driver_4444argb_horizontal_pixelmap_line_alpha_blend(context, xstart, xend, y, info, alpha);
1059             }
1060         }
1061         else
1062         {
1063             if (info -> pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1064             {
1065                 /* compressed with no alpha */
1066                 _gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_blend(context, xstart, xend, y, info, alpha);
1067             }
1068             else
1069             {
1070                 /* no compression or alpha */
1071                 _gx_display_driver_4444argb_horizontal_pixelmap_line_raw_blend(context, xstart, xend, y, info, alpha);
1072             }
1073         }
1074 
1075         /*Current pixelmap has gone over, so the offset pointer should be reset.*/
1076         if (info -> current_pixel_ptr >= info -> pixelmap -> gx_pixelmap_data + info -> pixelmap -> gx_pixelmap_data_size)
1077         {
1078             info -> current_pixel_ptr = (GX_UBYTE *)info -> pixelmap -> gx_pixelmap_data;
1079             info -> current_aux_ptr = (GX_UBYTE *)info -> pixelmap -> gx_pixelmap_aux_data;
1080         }
1081         return;
1082     }
1083 #endif
1084 
1085     if (info -> pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
1086     {
1087         if (info -> pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1088         {
1089             /* has both compression and alpha */
1090             _gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_alpha_write(context, xstart, xend, y, info);
1091         }
1092         else
1093         {
1094             /* alpha, no compression */
1095             _gx_display_driver_4444argb_horizontal_pixelmap_line_alpha_write(context, xstart, xend, y, info);
1096         }
1097     }
1098     else
1099     {
1100         if (info -> pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
1101         {
1102             /* has both compression */
1103             _gx_display_driver_4444argb_horizontal_pixelmap_line_compressed_write(context, xstart, xend, y, info);
1104         }
1105         else
1106         {
1107             /*no alpha, no compression */
1108             _gx_display_driver_4444argb_horizontal_pixelmap_line_raw_write(context, xstart, xend, y, info);
1109         }
1110     }
1111 
1112     /*Current pixelmap has gone over, so the offset pointer should be reset.*/
1113     if (info -> current_pixel_ptr >= info -> pixelmap -> gx_pixelmap_data + info -> pixelmap -> gx_pixelmap_data_size)
1114     {
1115         info -> current_pixel_ptr = (GX_UBYTE *)info -> pixelmap -> gx_pixelmap_data;
1116         info -> current_aux_ptr = (GX_UBYTE *)info -> pixelmap -> gx_pixelmap_aux_data;
1117     }
1118 }
1119 
1120 #endif /* GX_ARC_DRAWING_SUPPORT */
1121 
1122