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_4bpp_horizontal_line_draw        PORTABLE C      */
33 /*                                                           6.1          */
34 /*  AUTHOR                                                                */
35 /*                                                                        */
36 /*    Kenneth Maxwell, Microsoft Corporation                              */
37 /*                                                                        */
38 /*  DESCRIPTION                                                           */
39 /*                                                                        */
40 /*    Horizontal line draw function for 4bpp display driver.              */
41 /*                                                                        */
42 /*  INPUT                                                                 */
43 /*                                                                        */
44 /*    context                               Drawing context               */
45 /*    xstart                                x-coord of left endpoint      */
46 /*    xend                                  x-coord of right endpoint     */
47 /*    ypos                                  y-coord of line top           */
48 /*    width                                 Width (height) of the line    */
49 /*    color                                 Color of line to write        */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    None                                                                */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    GUIX Internal Code                                                  */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
68 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
_gx_display_driver_4bpp_horizontal_line_draw(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT ypos,INT width,GX_COLOR color)72 VOID _gx_display_driver_4bpp_horizontal_line_draw(GX_DRAW_CONTEXT *context, INT xstart, INT xend, INT ypos, INT width, GX_COLOR color)
73 {
74 INT       row;
75 INT       column;
76 GX_UBYTE *put;
77 GX_UBYTE *putrow;
78 GX_UBYTE  mask;
79 GX_UBYTE  pixel;
80 INT       stride;
81 
82     /* Get row pitch in bytes.  */
83     stride = (context -> gx_draw_context_pitch + 1) >> 1;
84     pixel = (GX_UBYTE)(color & 0x0f);
85     pixel |= (GX_UBYTE)(pixel << 4);
86 
87     /* pick up start address of canvas memory */
88     putrow = (GX_UBYTE *)context -> gx_draw_context_memory;
89     putrow += ypos * stride;
90     putrow += (xstart >> 1);
91 
92     for (row = 0; row < width; row++)
93     {
94         put = putrow;
95 
96         if (xstart & 0x01)
97         {
98             mask = 0x0f;
99         }
100         else
101         {
102             mask = 0xf0;
103         }
104 
105         column = xstart;
106         while (column <= xend)
107         {
108             if ((mask == 0xf0) && (xend - column) > 2)
109             {
110                 while ((xend - column) > 2)
111                 {
112                     *put++ = pixel;
113                     column += 2;
114                 }
115             }
116             else
117             {
118                 /*Set bits first.*/
119                 *put &= (GX_UBYTE)(~mask);
120                 *put |= (GX_UBYTE)(pixel & mask);
121                 mask >>= 4;
122 
123                 if (mask == 0)
124                 {
125                     mask = 0xf0;
126                     put++;
127                 }
128                 column++;
129             }
130         }
131         putrow += stride;
132     }
133 }
134 
135