GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_draw.c Lines: 141 141 100.0 %
Date: 2024-12-05 08:52:37 Branches: 88 88 100.0 %

Line Branch Exec Source
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_context.h"
29
30
/**************************************************************************/
31
/*                                                                        */
32
/*  FUNCTION                                               RELEASE        */
33
/*                                                                        */
34
/*    _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_raw_write  */
35
/*                                                        PORTABLE C      */
36
/*                                                           6.1.4        */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    Internal helper function that handles writing of uncompressed       */
44
/*    pixlemap file without alpha channel.                                */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    context                               Drawing context               */
49
/*    xstart                                x-coord of line left          */
50
/*    xend                                  x-coord of line right         */
51
/*    y                                     y-coord of line top           */
52
/*    info                                  GX_FILL_PIXELMAP_INFO struct  */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLED BY                                                             */
59
/*                                                                        */
60
/*    _gx_display_driver_8bpp_horizontal_pixelmap_line_draw               */
61
/*                                                                        */
62
/*  RELEASE HISTORY                                                       */
63
/*                                                                        */
64
/*    DATE              NAME                      DESCRIPTION             */
65
/*                                                                        */
66
/*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
67
/*                                                                        */
68
/**************************************************************************/
69
8687
static VOID _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_raw_write(GX_DRAW_CONTEXT *context,
70
                                                                               INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
71
{
72
INT                xval;
73
INT                offset;
74
INT                pic_width;
75
GX_CONST GX_UBYTE *get;
76
GX_UBYTE          *put;
77
GX_PIXELMAP       *pixelmap;
78
79
8687
    pixelmap = info -> pixelmap;
80
81
8687
    pic_width = pixelmap -> gx_pixelmap_height;
82
83

8687
    if ((info -> draw) && (xstart <= xend))
84
    {
85
5962
        get = info -> current_pixel_ptr;
86
5962
        put = (GX_UBYTE *)context -> gx_draw_context_memory;
87
5962
        put += y * context -> gx_draw_context_pitch + xstart;
88
89
        /* Calculate the map offset in x-axis. */
90
5962
        offset = (info -> x_offset % pic_width);
91
92
619366
        for (xval = xstart; xval <= xend; xval++)
93
        {
94
            /* get points to the start postion of this row. So we need to calculate its position. */
95
613404
            *put++ = *(get + offset);
96
613404
            offset++;
97
613404
            if (offset >= pic_width)
98
            {
99
3882
                offset -= pic_width;
100
            }
101
        }
102
    }
103
104
    /* This line is drawn. Update the pointer position for next row. */
105
8687
    info -> current_pixel_ptr += (UINT)pic_width * sizeof(GX_UBYTE);
106
8687
}
107
108
/**************************************************************************/
109
/*                                                                        */
110
/*  FUNCTION                                               RELEASE        */
111
/*                                                                        */
112
/*    _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_           */
113
/*                                                       compressed_write */
114
/*                                                                        */
115
/*                                                        PORTABLE C      */
116
/*                                                           6.1.4        */
117
/*  AUTHOR                                                                */
118
/*                                                                        */
119
/*    Kenneth Maxwell, Microsoft Corporation                              */
120
/*                                                                        */
121
/*  DESCRIPTION                                                           */
122
/*                                                                        */
123
/*    Internal helper function that handles writing of compressed         */
124
/*    pixlemap file.                                                      */
125
/*                                                                        */
126
/*  INPUT                                                                 */
127
/*                                                                        */
128
/*    context                               Drawing context               */
129
/*    xstart                                x-coord of line left          */
130
/*    xend                                  x-coord of line right         */
131
/*    y                                     y-coord of line top           */
132
/*    info                                  GX_FILL_PIXELMAP_INFO struct  */
133
/*                                                                        */
134
/*  OUTPUT                                                                */
135
/*                                                                        */
136
/*    None                                                                */
137
/*                                                                        */
138
/*  CALLS                                                                 */
139
/*                                                                        */
140
/*    None                                                                */
141
/*                                                                        */
142
/*  CALLED BY                                                             */
143
/*                                                                        */
144
/*    _gx_display_driver_8bpp_horizontal_pixelmap_line_draw               */
145
/*                                                                        */
146
/*  RELEASE HISTORY                                                       */
147
/*                                                                        */
148
/*    DATE              NAME                      DESCRIPTION             */
149
/*                                                                        */
150
/*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
151
/*                                                                        */
152
/**************************************************************************/
153
6905
static VOID _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_compressed_write(GX_DRAW_CONTEXT *context,
154
                                                                                      INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
155
{
156
INT                start_pos;
157
INT                xval;
158
GX_UBYTE           count;
159
6905
GX_CONST GX_UBYTE *get = GX_NULL;
160
GX_UBYTE           pixel;
161
GX_UBYTE          *put;
162
GX_PIXELMAP       *pixelmap;
163
164
6905
    pixelmap = info -> pixelmap;
165
166

6905
    if ((info -> draw) && (xstart <= xend))
167
    {
168
        /* Calculate draw start position. */
169
5962
        start_pos = xstart - (info -> x_offset % pixelmap -> gx_pixelmap_height);
170
171
5962
        put = (GX_UBYTE *)context -> gx_draw_context_memory;
172
5962
        put += y * context -> gx_draw_context_pitch + start_pos;
173
174
        /*Repeat the draw operation to fill the whole dirty area.*/
175
44963
        while (start_pos <= xend)
176
        {
177
39001
            xval = start_pos;
178
179
            /*Start from where we need to repeat.*/
180
39001
            get = (GX_CONST GX_UBYTE *)info -> current_pixel_ptr;
181
182
158406
            while (xval < start_pos + pixelmap -> gx_pixelmap_width)
183
            {
184
119405
                count = *get++;
185
119405
                if (count & 0x80)
186
                {
187
62908
                    count = (GX_UBYTE)((count & 0x7f) + 1);
188
62908
                    pixel = *get++;
189
447402
                    while (count--)
190
                    {
191

384494
                        if (xval >= xstart && xval <= xend)
192
                        {
193
337172
                            *put = pixel;
194
                        }
195
384494
                        xval++;
196
384494
                        put++;
197
                    }
198
                }
199
                else
200
                {
201
56497
                    count++;
202
374021
                    while (count--)
203
                    {
204
317524
                        pixel = *get++;
205

317524
                        if (xval >= xstart && xval <= xend)
206
                        {
207
276232
                            *put = pixel;
208
                        }
209
317524
                        xval++;
210
317524
                        put++;
211
                    }
212
                }
213
            }
214
39001
            start_pos += pixelmap -> gx_pixelmap_height;
215
        }
216
    }
217
    else
218
    {
219
943
        xval = 0;
220
943
        get = (GX_CONST GX_UBYTE *)info -> current_pixel_ptr;
221
3776
        while (xval < pixelmap -> gx_pixelmap_height)
222
        {
223
2833
            count = *get++;
224
2833
            if (count & 0x80)
225
            {
226
1511
                count = (GX_UBYTE)((count & 0x7f) + 1);
227
1511
                get++;
228
            }
229
            else
230
            {
231
1322
                count++;
232
1322
                get += count;
233
            }
234
2833
            xval += count;
235
        }
236
    }
237
238
    /*This line is drawn. cache the pointer for next line draw.*/
239
6905
    info -> current_pixel_ptr = (GX_UBYTE *)get;
240
6905
}
241
242
/**************************************************************************/
243
/*                                                                        */
244
/*  FUNCTION                                               RELEASE        */
245
/*                                                                        */
246
/*    _gx_display_driver_8bpp_rotated_horizontal_line_pixelmap_           */
247
/*                                                      transparent_write */
248
/*                                                                        */
249
/*                                                        PORTABLE C      */
250
/*                                                           6.1.4        */
251
/*  AUTHOR                                                                */
252
/*                                                                        */
253
/*    Kenneth Maxwell, Microsoft Corporation                              */
254
/*                                                                        */
255
/*  DESCRIPTION                                                           */
256
/*                                                                        */
257
/*    Internal helper function that handles writing of uncompressed       */
258
/*    pixlemap file with alpha channel.                                   */
259
/*                                                                        */
260
/*  INPUT                                                                 */
261
/*                                                                        */
262
/*    context                               Drawing context               */
263
/*    xstart                                x-coord of line left          */
264
/*    xend                                  x-coord of line right         */
265
/*    y                                     y-coord of line top           */
266
/*    info                                  GX_FILL_PIXELMAP_INFO struct  */
267
/*                                                                        */
268
/*  OUTPUT                                                                */
269
/*                                                                        */
270
/*    None                                                                */
271
/*                                                                        */
272
/*  CALLS                                                                 */
273
/*                                                                        */
274
/*    None                                                                */
275
/*                                                                        */
276
/*  CALLED BY                                                             */
277
/*                                                                        */
278
/*    _gx_display_driver_8bpp_horizontal_pixelmap_line_draw               */
279
/*                                                                        */
280
/*  RELEASE HISTORY                                                       */
281
/*                                                                        */
282
/*    DATE              NAME                      DESCRIPTION             */
283
/*                                                                        */
284
/*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
285
/*                                                                        */
286
/**************************************************************************/
287
7107
static VOID _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_transparent_write(GX_DRAW_CONTEXT *context,
288
                                                                                       INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
289
{
290
INT                xval;
291
INT                offset;
292
INT                pic_width;
293
GX_CONST GX_UBYTE *get;
294
GX_UBYTE          *put;
295
GX_PIXELMAP       *pixelmap;
296
GX_UBYTE           pixel;
297
298
7107
    pixelmap = info -> pixelmap;
299
7107
    pic_width = pixelmap -> gx_pixelmap_height;
300
301

7107
    if ((info -> draw) && (xstart <= xend))
302
    {
303
5962
        get = info -> current_pixel_ptr;
304
5962
        put = (GX_UBYTE *)context -> gx_draw_context_memory;
305
5962
        put += y * context -> gx_draw_context_pitch + xstart;
306
307
        /* Calculate the map offset in x-axis. */
308
5962
        offset = (info -> x_offset % pic_width);
309
310
619366
        for (xval = xstart; xval <= xend; xval++)
311
        {
312
            /* get points to the start postion of this row. So we need to calculate its position. */
313
613404
            pixel = *(get + offset);
314
613404
            offset++;
315
613404
            if (offset >= pic_width)
316
            {
317
15859
                offset -= pic_width;
318
            }
319
320
613404
            if (pixel != pixelmap -> gx_pixelmap_transparent_color)
321
            {
322
203632
                *put = pixel;
323
            }
324
613404
            put++;
325
        }
326
    }
327
328
    /* This line is drawn. Update the pointer position for next row. */
329
7107
    info -> current_pixel_ptr += (UINT)pic_width * sizeof(GX_UBYTE);
330
7107
}
331
332
/**************************************************************************/
333
/*                                                                        */
334
/*  FUNCTION                                               RELEASE        */
335
/*                                                                        */
336
/*    _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_           */
337
/*                                           compressed_transparent_write */
338
/*                                                                        */
339
/*                                                        PORTABLE C      */
340
/*                                                           6.1.4        */
341
/*  AUTHOR                                                                */
342
/*                                                                        */
343
/*    Kenneth Maxwell, Microsoft Corporation                              */
344
/*                                                                        */
345
/*  DESCRIPTION                                                           */
346
/*                                                                        */
347
/*    Internal helper function that handles writing of compressed         */
348
/*    pixlemap file with alpha channel.                                   */
349
/*                                                                        */
350
/*  INPUT                                                                 */
351
/*                                                                        */
352
/*    context                               Drawing context               */
353
/*    xstart                                x-coord of line left          */
354
/*    xend                                  x-coord of line right         */
355
/*    y                                     y-coord of line top           */
356
/*    info                                  GX_FILL_PIXELMAP_INFO struct  */
357
/*                                                                        */
358
/*  OUTPUT                                                                */
359
/*                                                                        */
360
/*    None                                                                */
361
/*                                                                        */
362
/*  CALLS                                                                 */
363
/*                                                                        */
364
/*    None                                                                */
365
/*                                                                        */
366
/*  CALLED BY                                                             */
367
/*                                                                        */
368
/*    _gx_display_driver_8bpp_horizontal_pixelmap_line_draw               */
369
/*                                                                        */
370
/*  RELEASE HISTORY                                                       */
371
/*                                                                        */
372
/*    DATE              NAME                      DESCRIPTION             */
373
/*                                                                        */
374
/*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
375
/*                                                                        */
376
/**************************************************************************/
377
8147
static VOID _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_compressed_transparent_write(GX_DRAW_CONTEXT *context,
378
                                                                                                  INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
379
{
380
INT                start_pos;
381
INT                xval;
382
GX_UBYTE           count;
383
8147
GX_CONST GX_UBYTE *get = GX_NULL;
384
GX_UBYTE           pixel;
385
GX_UBYTE          *put;
386
GX_PIXELMAP       *pixelmap;
387
388
8147
    pixelmap = info -> pixelmap;
389
390

8147
    if ((info -> draw) && (xstart <= xend))
391
    {
392
        /* Calcualte draw start position. */
393
5962
        start_pos = xstart - (info -> x_offset % pixelmap -> gx_pixelmap_height);
394
395
5962
        put = (GX_UBYTE *)context -> gx_draw_context_memory;
396
5962
        put += y * context -> gx_draw_context_pitch + start_pos;
397
398
399
        /*Repeat the draw operation to fill the whole dirty area.*/
400
14925
        while (start_pos <= xend)
401
        {
402
8963
            xval = start_pos;
403
404
            /*Start from where we need to repeat.*/
405
8963
            get = (GX_CONST GX_UBYTE *)info -> current_pixel_ptr;
406
407
39694
            while (xval < start_pos + pixelmap -> gx_pixelmap_height)
408
            {
409
30731
                count = *get++;
410
30731
                if (count & 0x80)
411
                {
412
29545
                    count = (GX_UBYTE)((count & 0x7f) + 1);
413
29545
                    pixel = *get++;
414
29545
                    if (pixel != pixelmap -> gx_pixelmap_transparent_color)
415
                    {
416
534367
                        while (count--)
417
                        {
418

523106
                            if (xval >= xstart && xval <= xend)
419
                            {
420
221461
                                *put = pixel;
421
                            }
422
523106
                            xval++;
423
523106
                            put++;
424
                        }
425
                    }
426
                    else
427
                    {
428
18284
                        xval += count;
429
18284
                        put += count;
430
                    }
431
                }
432
                else
433
                {
434
1186
                    count++;
435
2877
                    while (count--)
436
                    {
437
1691
                        pixel = *get++;
438
439

1691
                        if (xval >= xstart && xval <= xend)
440
                        {
441
649
                            if (pixel != pixelmap -> gx_pixelmap_transparent_color)
442
                            {
443
30
                                *put = pixel;
444
                            }
445
                        }
446
1691
                        xval++;
447
1691
                        put++;
448
                    }
449
                }
450
            }
451
8963
            start_pos += pixelmap -> gx_pixelmap_height;
452
        }
453
    }
454
    else
455
    {
456
2185
        xval = 0;
457
2185
        get = (GX_CONST GX_UBYTE *)info -> current_pixel_ptr;
458
11726
        while (xval < pixelmap -> gx_pixelmap_height)
459
        {
460
9541
            count = *get++;
461
9541
            if (count & 0x80)
462
            {
463
9199
                count = (GX_UBYTE)((count & 0x7f) + 1);
464
9199
                get++;
465
            }
466
            else
467
            {
468
342
                count++;
469
342
                get += count;
470
            }
471
9541
            xval += count;
472
        }
473
    }
474
475
    /* This line is drawn. cache the pointer for next line draw.*/
476
8147
    info -> current_pixel_ptr = (GX_UBYTE *)get;
477
8147
}
478
479
/**************************************************************************/
480
/*                                                                        */
481
/*  FUNCTION                                               RELEASE        */
482
/*                                                                        */
483
/*    _gx_display_driver_8bpp_rotated_pixelmap_draw       PORTABLE C      */
484
/*                                                           6.1.5        */
485
/*  AUTHOR                                                                */
486
/*                                                                        */
487
/*    Kenneth Maxwell, Microsoft Corporation                              */
488
/*                                                                        */
489
/*  DESCRIPTION                                                           */
490
/*                                                                        */
491
/*    8bit screen driver pixelmap drawing function that handles           */
492
/*    compressed or uncompress, with or without alpha channel.            */
493
/*                                                                        */
494
/*  INPUT                                                                 */
495
/*                                                                        */
496
/*    context                               Drawing context               */
497
/*    xstart                                x-coord of line left          */
498
/*    xend                                  x-coord of line end           */
499
/*    y                                     y-coord of line top           */
500
/*    info                                  GX_FILL_PIXELMAP_INFO struct  */
501
/*                                                                        */
502
/*  OUTPUT                                                                */
503
/*                                                                        */
504
/*    None                                                                */
505
/*                                                                        */
506
/*  CALLS                                                                 */
507
/*                                                                        */
508
/*     _gx_display_driver_8bit_rotated_horizontal_pixelmap_line_raw_write */
509
/*     _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_          */
510
/*                                                       compressed_write */
511
/*     _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_          */
512
/*                                                      transparent_write */
513
/*     _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_          */
514
/*                                           compressed_transparent_write */
515
/*                                                                        */
516
/*  CALLED BY                                                             */
517
/*                                                                        */
518
/*    GUIX Internal Code                                                  */
519
/*                                                                        */
520
/*  RELEASE HISTORY                                                       */
521
/*                                                                        */
522
/*    DATE              NAME                      DESCRIPTION             */
523
/*                                                                        */
524
/*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
525
/*  03-02-2021     Ting Zhu                 Modified comment(s),          */
526
/*                                            removed redundant code,     */
527
/*                                            resulting in version 6.1.5  */
528
/*                                                                        */
529
/**************************************************************************/
530
30848
VOID _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_draw(GX_DRAW_CONTEXT *context,
531
                                                                   INT ystart, INT yend, INT x, GX_FILL_PIXELMAP_INFO *info)
532
{
533
INT xstart;
534
INT xend;
535
INT y;
536
537
30848
    if (info -> pixelmap == GX_NULL)
538
    {
539
        /* Nothing to drawn. Just return. */
540
2
        return;
541
    }
542
543
30846
    if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
544
    {
545
17194
        xstart = ystart;
546
17194
        xend = yend;
547
17194
        y = context -> gx_draw_context_canvas -> gx_canvas_x_resolution - x - 1;
548
    }
549
    else
550
    {
551
13652
        xstart = context -> gx_draw_context_canvas -> gx_canvas_y_resolution - yend - 1;
552
13652
        xend = context -> gx_draw_context_canvas -> gx_canvas_y_resolution - ystart - 1;
553
13652
        y = x;
554
13652
        info -> x_offset = (yend - ystart + 1 + info -> x_offset) % info -> pixelmap -> gx_pixelmap_height;
555
556
13652
        if (info -> x_offset)
557
        {
558
12765
            info -> x_offset = info -> pixelmap -> gx_pixelmap_height - info -> x_offset;
559
        }
560
    }
561
562
30846
    if (info -> pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT)
563
    {
564
15254
        if (info -> pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
565
        {
566
            /* has both compression and transparent */
567
8147
            _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_compressed_transparent_write(context, xstart, xend, y, info);
568
        }
569
        else
570
        {
571
            /* transparent, no compression */
572
7107
            _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_transparent_write(context, xstart, xend, y, info);
573
        }
574
    }
575
    else
576
    {
577
15592
        if (info -> pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
578
        {
579
            /* compressed with no transparency */
580
6905
            _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_compressed_write(context, xstart, xend, y, info);
581
        }
582
        else
583
        {
584
            /* no compression or transaprency */
585
8687
            _gx_display_driver_8bpp_rotated_horizontal_pixelmap_line_raw_write(context, xstart, xend, y, info);
586
        }
587
    }
588
589
590
    /*Current pixelmap has gone over, so the offset pointer should be reset.*/
591
30846
    if (info -> current_pixel_ptr >= info -> pixelmap -> gx_pixelmap_data + info -> pixelmap -> gx_pixelmap_data_size)
592
    {
593
607
        info -> current_pixel_ptr = (GX_UBYTE *)info -> pixelmap -> gx_pixelmap_data;
594
607
        info -> current_aux_ptr = (GX_UBYTE *)info -> pixelmap -> gx_pixelmap_aux_data;
595
    }
596
597
30846
    return;
598
}
599