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 /* Include necessary system files.  */
24 
25 #include "gx_api.h"
26 #include "gx_display.h"
27 
28 /**************************************************************************/
29 /*                                                                        */
30 /*  FUNCTION                                               RELEASE        */
31 /*                                                                        */
32 /*    _gx_display_driver_1bpp_horizontal_pattern_line_draw                */
33 /*                                                        PORTABLE C      */
34 /*                                                           6.1          */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    Kenneth Maxwell, Microsoft Corporation                              */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*    Horizontal pattern line draw function for 1bpp display driver.      */
42 /*                                                                        */
43 /*  INPUT                                                                 */
44 /*                                                                        */
45 /*    context                               Drawing context               */
46 /*    xstart                                x-coord of left endpoint      */
47 /*    xend                                  x-coord of right endpoint     */
48 /*    ypos                                  y-coord of line top           */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    None                                                                */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    GUIX Internal Code                                                  */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
67 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*                                                                        */
70 /**************************************************************************/
_gx_display_driver_1bpp_horizontal_pattern_line_draw(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT ypos)71 VOID _gx_display_driver_1bpp_horizontal_pattern_line_draw(GX_DRAW_CONTEXT *context, INT xstart, INT xend, INT ypos)
72 {
73 INT       column;
74 GX_UBYTE *put;
75 GX_UBYTE *rowstart;
76 ULONG     pattern;
77 ULONG     mask;
78 GX_UBYTE  on_color;
79 GX_UBYTE  off_color;
80 INT       pos;
81 INT       len = xend - xstart + 1;
82 INT       start_in_byte = 0;
83 GX_UBYTE  start_mask;
84 
85     /* pick up start address of canvas memory */
86     rowstart = (GX_UBYTE *)context -> gx_draw_context_memory;
87 
88     pos = context -> gx_draw_context_pitch * ypos + xstart;
89 
90     /* pick up the requested pattern and mask */
91     pattern = context -> gx_draw_context_brush.gx_brush_line_pattern;
92     mask = context -> gx_draw_context_brush.gx_brush_pattern_mask;
93     on_color = (GX_UBYTE)context -> gx_draw_context_brush.gx_brush_line_color & 0x01;
94     off_color = (GX_UBYTE)context -> gx_draw_context_brush.gx_brush_fill_color & 0x01;
95 
96     put = rowstart;
97     put +=  pos >> 3;
98     start_in_byte = pos & 0x07;
99     start_mask = (GX_UBYTE)(((GX_UBYTE)0x80) >> start_in_byte);
100 
101     for (column = 0; column < len; column++)
102     {
103         if (pattern & mask)
104         {
105             if (on_color == 0x00)
106             {
107                 *put = (GX_UBYTE)((*put) & (~start_mask));
108             }
109             else
110             {
111                 *put |= start_mask;
112             }
113         }
114         else
115         {
116             if (off_color == 0x00)
117             {
118                 *put &= (GX_UBYTE)((*put) & (~start_mask));
119             }
120             else
121             {
122                 *put |= start_mask;
123             }
124         }
125         start_mask >>= 1;
126         if (start_mask == 0)
127         {
128             put++;
129             start_mask = 0x80;
130         }
131 
132         mask >>= 1;
133         if (!mask)
134         {
135             mask = 0x80000000;
136         }
137     }
138 
139     /* save current masks value back to brush */
140     context -> gx_draw_context_brush.gx_brush_pattern_mask = mask;
141 }
142 
143