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_4bpp_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 4bpp 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_4bpp_horizontal_line_draw(GX_DRAW_CONTEXT * context,INT xstart,INT xend,INT ypos,INT width,GX_COLOR color)73 VOID _gx_display_driver_4bpp_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 GX_UBYTE  pixel;
81 INT       stride;
82 
83     /* Get row pitch in bytes.  */
84     stride = (context -> gx_draw_context_pitch + 1) >> 1;
85     pixel = (GX_UBYTE)(color & 0x0f);
86     pixel |= (GX_UBYTE)(pixel << 4);
87 
88     /* pick up start address of canvas memory */
89     putrow = (GX_UBYTE *)context -> gx_draw_context_memory;
90     putrow += ypos * stride;
91     putrow += (xstart >> 1);
92 
93     for (row = 0; row < width; row++)
94     {
95         put = putrow;
96 
97         if (xstart & 0x01)
98         {
99             mask = 0x0f;
100         }
101         else
102         {
103             mask = 0xf0;
104         }
105 
106         column = xstart;
107         while (column <= xend)
108         {
109             if ((mask == 0xf0) && (xend - column) > 2)
110             {
111                 while ((xend - column) > 2)
112                 {
113                     *put++ = pixel;
114                     column += 2;
115                 }
116             }
117             else
118             {
119                 /*Set bits first.*/
120                 *put &= (GX_UBYTE)(~mask);
121                 *put |= (GX_UBYTE)(pixel & mask);
122                 mask >>= 4;
123 
124                 if (mask == 0)
125                 {
126                     mask = 0xf0;
127                     put++;
128                 }
129                 column++;
130             }
131         }
132         putrow += stride;
133     }
134 }
135 
136