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 /*  FUNCTION                                               RELEASE        */
30 /*                                                                        */
31 /*    _gx_display_driver_4bpp_vertical_line_draw          PORTABLE C      */
32 /*                                                           6.1          */
33 /*  AUTHOR                                                                */
34 /*                                                                        */
35 /*    Kenneth Maxwell, Microsoft Corporation                              */
36 /*                                                                        */
37 /*  DESCRIPTION                                                           */
38 /*                                                                        */
39 /*    Vertical line draw function for 4bpp display driver.                */
40 /*                                                                        */
41 /*  INPUT                                                                 */
42 /*                                                                        */
43 /*    context                               Drawing context               */
44 /*    ystart                                y-coord of top endpoint       */
45 /*    yend                                  y-coord of bottom endpoint    */
46 /*    xpos                                  x-coord of left edge          */
47 /*    width                                 width of the line             */
48 /*    color                                 Color of line to write        */
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_4bpp_vertical_line_draw(GX_DRAW_CONTEXT * context,INT ystart,INT yend,INT xpos,INT width,GX_COLOR color)71 VOID _gx_display_driver_4bpp_vertical_line_draw(GX_DRAW_CONTEXT *context, INT ystart, INT yend, INT xpos, INT width, GX_COLOR color)
72 {
73 INT       row;
74 INT       column;
75 GX_UBYTE *put;
76 GX_UBYTE *putrow;
77 GX_UBYTE  mask;
78 GX_UBYTE  pixel;
79 INT       stride;
80 
81     /* Get row pitch in bytes.  */
82     stride = (context -> gx_draw_context_pitch + 1) >> 1;
83     pixel = (GX_UBYTE)(color & 0x0f);
84     pixel |= (GX_UBYTE)(pixel << 4);
85 
86     /* pick up starting address of canvas memory */
87     putrow =  (GX_UBYTE *)context -> gx_draw_context_memory;
88     putrow += ystart * stride;
89     putrow += (xpos >> 1);
90 
91     /* draw line from top to bottom */
92     for (row = ystart; row <= yend; row++)
93     {
94         put = putrow;
95 
96         if (xpos & 0x01)
97         {
98             mask = 0x0f;
99         }
100         else
101         {
102             mask = 0xf0;
103         }
104 
105         /* draw line width from left to right */
106         for (column = 0; column < width;)
107         {
108             if ((mask == 0xf0) && (width - column >= 2))
109             {
110                 *put++ = pixel;
111                 column += 2;
112             }
113             else
114             {
115                 /* Set bits first */
116                 *put &= (GX_UBYTE)(~mask);
117                 *put |= (pixel & mask);
118                 mask >>= 4;
119 
120                 if (mask == 0)
121                 {
122                     put++;
123                     mask = 0xf0;
124                 }
125                 column++;
126             }
127         }
128 
129         /* advance to the next scaneline */
130         putrow +=  stride;
131     }
132 }
133 
134