1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Display Management (Display)                                        */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_display.h"
28 
29 /**************************************************************************/
30 /*                                                                        */
31 /*  FUNCTION                                               RELEASE        */
32 /*                                                                        */
33 /*    _gx_display_driver_1bpp_horizontal_line_draw        PORTABLE C      */
34 /*                                                           6.1          */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    Kenneth Maxwell, Microsoft Corporation                              */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*    Horizontal 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 /*    width                                 Width (height) of the line    */
50 /*    color                                 Color of line to write        */
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 /*                                                                        */
72 /**************************************************************************/
_gx_display_driver_1bpp_horizontal_line_draw(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT ypos,INT width,GX_COLOR color)73 VOID _gx_display_driver_1bpp_horizontal_line_draw(GX_DRAW_CONTEXT *context, INT xstart, INT xend, INT ypos, INT width, GX_COLOR color)
74 {
75 INT       row;
76 INT       column;
77 GX_UBYTE *put;
78 GX_UBYTE *putrow;
79 GX_UBYTE  mask;
80 INT       stride;
81 
82     /* Get row pitch in bytes.  */
83     stride = (context -> gx_draw_context_pitch + 7) >> 3;
84 
85     /* pick up start address of canvas memory */
86     putrow = (GX_UBYTE *)context -> gx_draw_context_memory;
87     putrow += ypos * stride;
88     putrow += (xstart >> 3);
89 
90     for (row = 0; row < width; row++)
91     {
92         put = putrow;
93 
94         mask = (GX_UBYTE)(0x80 >> (xstart & 0x07));
95 
96         column = xstart;
97         while (column <= xend)
98         {
99             if ((mask == 0x80) && (xend - column + 1 >= 8))
100             {
101                 while (xend - column + 1 >= 8)
102                 {
103                     if (color == 0x00)
104                     {
105                         *put++ = 0x00;
106                     }
107                     else if (color == 0x01)
108                     {
109                         *put++ = 0xff;
110                     }
111 
112                     column += 8;
113                 }
114             }
115             else
116             {
117                 if (color == 0x00)
118                 {
119                     *put = (GX_UBYTE)((*put) & (~mask));
120                 }
121                 else if (color == 0x01)
122                 {
123                     *put |= mask;
124                 }
125 
126                 mask >>= 1;
127 
128                 if (mask == 0)
129                 {
130                     put++;
131                     mask = 0x80;
132                 }
133 
134                 column++;
135             }
136         }
137 
138         putrow += stride;
139     }
140 }
141 
142