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
24 /* Include necessary system files. */
25
26 #include "gx_api.h"
27 #include "gx_display.h"
28 #include "gx_system.h"
29 #include "gx_utility.h"
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _gx_display_driver_8bpp_rotated_block_move PORTABLE C */
36 /* 6.1.4 */
37 /* AUTHOR */
38 /* */
39 /* Kenneth Maxwell, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* 8-bit color format display driver rotated block moving function. */
44 /* */
45 /* INPUT */
46 /* */
47 /* context Draw context */
48 /* block The rectangle to be moved */
49 /* xshift Amount to move on X-axis */
50 /* yshift Amount to move on Y-axis */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* None */
55 /* */
56 /* CALLS */
57 /* */
58 /* memmove Move a block of data */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* GUIX Internal Code */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 02-02-2021 Kenneth Maxwell Initial Version 6.1.4 */
69 /* */
70 /**************************************************************************/
_gx_display_driver_8bpp_rotated_block_move(GX_DRAW_CONTEXT * context,GX_RECTANGLE * block,INT xshift,INT yshift)71 VOID _gx_display_driver_8bpp_rotated_block_move(GX_DRAW_CONTEXT *context,
72 GX_RECTANGLE *block, INT xshift, INT yshift)
73 {
74 GX_UBYTE *pGet;
75 GX_UBYTE *pPut;
76 int width;
77 int y;
78 int height;
79 GX_RECTANGLE rotated_block;
80
81 GX_SWAP_VALS(xshift, yshift);
82
83 if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
84 {
85 rotated_block.gx_rectangle_left = block -> gx_rectangle_top;
86 rotated_block.gx_rectangle_right = block -> gx_rectangle_bottom;
87 rotated_block.gx_rectangle_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - block -> gx_rectangle_right - 1);
88 rotated_block.gx_rectangle_bottom = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - block -> gx_rectangle_left - 1);
89
90 yshift = -yshift;
91 }
92 else
93 {
94 rotated_block.gx_rectangle_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - block -> gx_rectangle_bottom - 1);
95 rotated_block.gx_rectangle_right = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - block -> gx_rectangle_top - 1);
96 rotated_block.gx_rectangle_top = block -> gx_rectangle_left;
97 rotated_block.gx_rectangle_bottom = block -> gx_rectangle_right;
98
99 xshift = -xshift;
100 }
101
102 if (xshift)
103 {
104 if (xshift > 0)
105 {
106 pPut = (GX_UBYTE *)context -> gx_draw_context_memory;
107 pPut += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
108 pPut += rotated_block.gx_rectangle_left + xshift;
109
110 pGet = (GX_UBYTE *)context -> gx_draw_context_memory;
111 pGet += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
112 pGet += rotated_block.gx_rectangle_left;
113
114 width = rotated_block.gx_rectangle_right - rotated_block.gx_rectangle_left + 1 - xshift;
115 }
116 else
117 {
118 /* Have to copy from right to left. */
119 pPut = (GX_UBYTE *)context -> gx_draw_context_memory;
120 pPut += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
121 pPut += rotated_block.gx_rectangle_left;
122
123 pGet = (GX_UBYTE *)context -> gx_draw_context_memory;
124 pGet += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
125 pGet += rotated_block.gx_rectangle_left - xshift;
126
127 width = rotated_block.gx_rectangle_right - rotated_block.gx_rectangle_left + 1 + xshift;
128 }
129
130
131 if (width <= 0)
132 {
133 return;
134 }
135
136 for (y = rotated_block.gx_rectangle_top; y <= rotated_block.gx_rectangle_bottom; y++)
137 {
138 memmove(pPut, pGet, (size_t)width);
139
140 pPut += context -> gx_draw_context_pitch;
141 pGet += context -> gx_draw_context_pitch;
142 }
143 }
144 else
145 {
146 width = rotated_block.gx_rectangle_right - rotated_block.gx_rectangle_left + 1;
147
148 if (yshift > 0)
149 {
150 /* Have to copy from top to bottom. */
151 pPut = (GX_UBYTE *)context -> gx_draw_context_memory;
152 pPut += rotated_block.gx_rectangle_bottom * context -> gx_draw_context_pitch;
153 pPut += rotated_block.gx_rectangle_left;
154
155 pGet = (GX_UBYTE *)context -> gx_draw_context_memory;
156 pGet += (rotated_block.gx_rectangle_bottom - yshift) * context -> gx_draw_context_pitch;
157 pGet += rotated_block.gx_rectangle_left;
158
159 height = rotated_block.gx_rectangle_bottom - rotated_block.gx_rectangle_top + 1 - yshift;
160
161 for (y = 0; y < height; y++)
162 {
163 memmove(pPut, pGet, (size_t)width);
164
165 pPut -= context -> gx_draw_context_pitch;
166 pGet -= context -> gx_draw_context_pitch;
167 }
168 }
169 else
170 {
171 /* Have to copy from bottom to top. */
172 pPut = (GX_UBYTE *)context -> gx_draw_context_memory;
173 pPut += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
174 pPut += rotated_block.gx_rectangle_left;
175
176 pGet = (GX_UBYTE *)context -> gx_draw_context_memory;
177 pGet += (rotated_block.gx_rectangle_top - yshift) * context -> gx_draw_context_pitch;
178 pGet += rotated_block.gx_rectangle_left;
179
180 height = rotated_block.gx_rectangle_bottom - rotated_block.gx_rectangle_top + 1 + yshift;
181
182 for (y = 0; y < height; y++)
183 {
184 memmove(pPut, pGet, (size_t)width);
185
186 pPut += context -> gx_draw_context_pitch;
187 pGet += context -> gx_draw_context_pitch;
188 }
189 }
190 }
191 }
192
193