GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_1bpp_horizontal_pixelmap_line_draw.c Lines: 174 174 100.0 %
Date: 2026-03-06 19:21:09 Branches: 108 108 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   Display Management (Display)                                        */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_display.h"
29
#include "gx_context.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_display_driver_1bpp_horizontal_pixelmap_line_raw_write          */
36
/*                                                        PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    Internal helper function that handles writing of uncompressed       */
45
/*    pixlemap file without transparency.                                 */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    context                               Drawing context               */
50
/*    xstart                                x-coord of line left          */
51
/*    xend                                  x-coord of line right         */
52
/*    y                                     y-coord of line top           */
53
/*    info                                  GX_FILL_PIXELMAP_INFO struct  */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    None                                                                */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    None                                                                */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    GUIX Internal Code                                                  */
66
/*                                                                        */
67
/**************************************************************************/
68
8315
static VOID _gx_display_driver_1bpp_horizontal_pixelmap_line_raw_write(GX_DRAW_CONTEXT *context,
69
                                                                       INT xstart, INT xend, INT y,
70
                                                                       GX_FILL_PIXELMAP_INFO *info)
71
{
72
INT             xval;
73
const GX_UBYTE *get;
74
GX_UBYTE       *put;
75
GX_UBYTE        getmask;
76
GX_UBYTE        putmask;
77
INT             getstride;
78
INT             putstride;
79
INT             pic_width;
80
INT             offset;
81
GX_UBYTE        pixel;
82
GX_PIXELMAP    *pixelmap;
83
84
8315
    pixelmap = info -> pixelmap;
85
86
8315
    pic_width = pixelmap -> gx_pixelmap_width;
87
8315
    get = info -> current_pixel_ptr;
88
8315
    getstride = (pic_width + 7) >> 3;
89
90

8315
    if ((info -> draw) && (xstart <= xend))
91
    {
92
8053
        putstride = (context -> gx_draw_context_pitch + 7) >> 3;
93
8053
        put = (GX_UBYTE *)context -> gx_draw_context_memory;
94
8053
        put += y * putstride;
95
8053
        put += xstart >> 3;
96
97
8053
        putmask = (GX_UBYTE)(0x80 >> (xstart & 0x07));
98
99
        /*calculate the offset.*/
100
8053
        offset = (info -> x_offset % pic_width);
101
102
462389
        for (xval = xstart; xval <= xend; xval++)
103
        {
104
454336
            pixel = *(get + (offset >> 3));
105
454336
            getmask = (GX_UBYTE)(0x80 >> (offset & 0x07));
106
454336
            if (pixel & getmask)
107
            {
108
209618
                *put |= putmask;
109
            }
110
            else
111
            {
112
244718
                *put &= (GX_UBYTE)(~putmask);
113
            }
114
454336
            offset++;
115
116
454336
            if (offset >= pic_width)
117
            {
118
8978
                offset -= pic_width;
119
            }
120
121
454336
            putmask >>= 1;
122
454336
            if (putmask == 0)
123
            {
124
56291
                put++;
125
56291
                putmask = 0x80;
126
            }
127
        }
128
    }
129
130
    /*This line is drawn. Update the pointer position for next row.*/
131
8315
    info -> current_pixel_ptr += (UINT)getstride * sizeof(GX_UBYTE);
132
8315
}
133
134
/**************************************************************************/
135
/*                                                                        */
136
/*  FUNCTION                                               RELEASE        */
137
/*                                                                        */
138
/*    _gx_display_driver_1bpp_horizontal_pixelmap_line_t_write            */
139
/*                                                        PORTABLE C      */
140
/*                                                           6.1          */
141
/*  AUTHOR                                                                */
142
/*                                                                        */
143
/*    Kenneth Maxwell, Microsoft Corporation                              */
144
/*                                                                        */
145
/*  DESCRIPTION                                                           */
146
/*                                                                        */
147
/*    Internal helper function that handles writing of uncompressed       */
148
/*    pixlemap file with transparent.                                     */
149
/*                                                                        */
150
/*  INPUT                                                                 */
151
/*                                                                        */
152
/*    context                               Drawing context               */
153
/*    xstart                                x-coord of line left          */
154
/*    xend                                  x-coord of line right         */
155
/*    y                                     y-coord of line top           */
156
/*    info                                  GX_FILL_PIXELMAP_INFO struct  */
157
/*                                                                        */
158
/*  OUTPUT                                                                */
159
/*                                                                        */
160
/*    None                                                                */
161
/*                                                                        */
162
/*  CALLS                                                                 */
163
/*                                                                        */
164
/*    None                                                                */
165
/*                                                                        */
166
/*  CALLED BY                                                             */
167
/*                                                                        */
168
/*    GUIX Internal Code                                                  */
169
/*                                                                        */
170
/**************************************************************************/
171
7662
static VOID _gx_display_driver_1bpp_horizontal_pixelmap_line_transparent_write(GX_DRAW_CONTEXT *context,
172
                                                                               INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
173
{
174
INT             xval;
175
const GX_UBYTE *get;
176
GX_UBYTE       *put;
177
GX_UBYTE        putmask;
178
GX_UBYTE        getmask;
179
GX_UBYTE        pixel;
180
INT             getstride;
181
INT             putstride;
182
INT             offset;
183
INT             pic_width;
184
7662
GX_PIXELMAP    *pixelmap = info -> pixelmap;
185
186
7662
    pixelmap = info -> pixelmap;
187
188
7662
    pic_width = pixelmap -> gx_pixelmap_width;
189
7662
    get = info -> current_pixel_ptr;
190
7662
    getstride = (pic_width + 3) >> 2;
191
192

7662
    if ((info -> draw) && (xstart <= xend))
193
    {
194
7415
        putstride = (context -> gx_draw_context_pitch + 7) >> 3;
195
7415
        put = (GX_UBYTE *)context -> gx_draw_context_memory;
196
7415
        put += y * putstride;
197
7415
        put += xstart >> 3;
198
199
7415
        putmask = (GX_UBYTE)(0x80 >> (xstart & 0x07));
200
201
        /* Calculate the map offset in x-axis. */
202
7415
        offset = (info -> x_offset % pic_width);
203
204
301013
        for (xval = xstart; xval <= xend; xval++)
205
        {
206
293598
            getmask = (GX_UBYTE)(0x40 >> ((offset & 0x03) << 1));
207
293598
            pixel = *(get + (offset >> 2));
208
293598
            if (getmask & pixel)
209
            {
210
                /* If not transparent, draw it. */
211
82380
                if ((getmask << 1) & pixel)
212
                {
213
40656
                    *put |= putmask;
214
                }
215
                else
216
                {
217
41724
                    *put &= (GX_UBYTE)(~putmask);
218
                }
219
            }
220
221
293598
            offset++;
222
293598
            if (offset >= pic_width)
223
            {
224
299
                offset = 0;
225
            }
226
227
293598
            putmask >>= 1;
228
293598
            if (putmask == 0)
229
            {
230
36183
                putmask = 0x80;
231
36183
                put++;
232
            }
233
        }
234
    }
235
236
    /* This line is drawn. Update the pointer position for next row. */
237
7662
    info -> current_pixel_ptr += (UINT)getstride * sizeof(GX_UBYTE);
238
7662
}
239
240
/**************************************************************************/
241
/*                                                                        */
242
/*  FUNCTION                                               RELEASE        */
243
/*                                                                        */
244
/*    _gx_display_driver_1bpp_horizontal_pixelmap_line_compressed_write   */
245
/*                                                        PORTABLE C      */
246
/*                                                           6.1          */
247
/*  AUTHOR                                                                */
248
/*                                                                        */
249
/*    Kenneth Maxwell, Microsoft Corporation                              */
250
/*                                                                        */
251
/*  DESCRIPTION                                                           */
252
/*                                                                        */
253
/*    Internal helper function that handles writing of compressed         */
254
/*    pixlemap file without transparent.                                  */
255
/*                                                                        */
256
/*  INPUT                                                                 */
257
/*                                                                        */
258
/*    context                               Drawing context               */
259
/*    xstart                                x-coord of line left          */
260
/*    xend                                  x-coord of line right         */
261
/*    y                                     y-coord of line top           */
262
/*    info                                  GX_FILL_PIXELMAP_INFO struct  */
263
/*                                                                        */
264
/*  OUTPUT                                                                */
265
/*                                                                        */
266
/*    None                                                                */
267
/*                                                                        */
268
/*  CALLS                                                                 */
269
/*                                                                        */
270
/*    None                                                                */
271
/*                                                                        */
272
/*  CALLED BY                                                             */
273
/*                                                                        */
274
/*    GUIX Internal Code                                                  */
275
/*                                                                        */
276
/**************************************************************************/
277
8248
static VOID _gx_display_driver_1bpp_horizontal_pixelmap_line_compressed_write(GX_DRAW_CONTEXT *context,
278
                                                                              INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
279
{
280
INT                start_pos;
281
INT                xval;
282
GX_UBYTE           count;
283
8248
GX_CONST GX_UBYTE *get = GX_NULL;
284
GX_UBYTE           pixel;
285
GX_UBYTE           putmask;
286
GX_UBYTE          *put;
287
GX_PIXELMAP       *pixelmap;
288
289
8248
    pixelmap = info -> pixelmap;
290
291

8248
    if ((info -> draw) && (xstart <= xend))
292
    {
293
        /* Calcualte draw start position. */
294
7734
        start_pos = xstart - (info -> x_offset % pixelmap -> gx_pixelmap_width);
295
296
7734
        put = (GX_UBYTE *)context -> gx_draw_context_memory;
297
7734
        put += y * ((context -> gx_draw_context_pitch + 7) >> 3) + (xstart >> 3);
298
299
7734
        putmask = (GX_UBYTE)(0x80 >> (xstart & 0x07));
300
301
        /* Repeat the draw operation to fill the whole dirty area.*/
302
19407
        while (start_pos <= xend)
303
        {
304
11673
            xval = start_pos;
305
306
            /* Start from where we need to repeat. */
307
11673
            get = (GX_CONST GX_UBYTE *)info -> current_pixel_ptr;
308
309
521522
            while (xval < start_pos + pixelmap -> gx_pixelmap_width)
310
            {
311
509849
                count = *get;
312
509849
                if (count & 0x80)
313
                {
314
363779
                    count = (GX_UBYTE)(((count & 0x7f) >> 1) + 1);
315
363779
                    pixel = *get++;
316
6690726
                    while (count--)
317
                    {
318

6326947
                        if (xval >= xstart && xval <= xend)
319
                        {
320
361038
                            if (pixel & 0x01)
321
                            {
322
75278
                                *put |= putmask;
323
                            }
324
                            else
325
                            {
326
285760
                                *put &= (GX_UBYTE)(~putmask);
327
                            }
328
329
361038
                            putmask >>= 1;
330
361038
                            if (putmask == 0)
331
                            {
332
44455
                                put++;
333
44455
                                putmask = 0x80;
334
                            }
335
                        }
336
6326947
                        xval++;
337
                    }
338
                }
339
                else
340
                {
341
146070
                    count = (GX_UBYTE)((count >> 1) + 1);
342
451728
                    while (count--)
343
                    {
344
305658
                        pixel = *get++;
345

305658
                        if (xval >= xstart && xval <= xend)
346
                        {
347
12929
                            if (pixel & 0x01)
348
                            {
349
7866
                                *put |= putmask;
350
                            }
351
                            else
352
                            {
353
5063
                                *put &= (GX_UBYTE)(~putmask);
354
                            }
355
356
12929
                            putmask >>= 1;
357
12929
                            if (putmask == 0)
358
                            {
359
1782
                                put++;
360
1782
                                putmask = 0x80;
361
                            }
362
                        }
363
305658
                        xval++;
364
                    }
365
                }
366
            }
367
11673
            start_pos += pixelmap -> gx_pixelmap_width;
368
        }
369
    }
370
    else
371
    {
372
514
        xval = 0;
373
514
        get = (GX_CONST GX_UBYTE *)info -> current_pixel_ptr;
374
32381
        while (xval < pixelmap -> gx_pixelmap_width)
375
        {
376
31867
            count = *get;
377
31867
            if (count & 0x80)
378
            {
379
23339
                count = (GX_UBYTE)(((count & 0x7f) >> 1) + 1);
380
23339
                get++;
381
            }
382
            else
383
            {
384
8528
                count = (GX_UBYTE)((count >> 1) + 1);
385
8528
                get += count;
386
            }
387
31867
            xval += count;
388
        }
389
    }
390
391
    /* This line is drawn. cache the pointer for next line draw. */
392
8248
    info -> current_pixel_ptr = (GX_UBYTE *)get;
393
8248
}
394
395
/**************************************************************************/
396
/*                                                                        */
397
/*  FUNCTION                                               RELEASE        */
398
/*                                                                        */
399
/*  _gx_display_driver_1bpp_horizontal_pixelmap_line_c_t_write            */
400
/*                                                        PORTABLE C      */
401
/*                                                           6.1          */
402
/*  AUTHOR                                                                */
403
/*                                                                        */
404
/*    Kenneth Maxwell, Microsoft Corporation                              */
405
/*                                                                        */
406
/*  DESCRIPTION                                                           */
407
/*                                                                        */
408
/*    Internal helper function that handles writing of compressed         */
409
/*    pixlemap file with alpha channel.                                   */
410
/*                                                                        */
411
/*  INPUT                                                                 */
412
/*                                                                        */
413
/*    context                               Drawing context               */
414
/*    xstart                                x-coord of line left          */
415
/*    xend                                  x-coord of line right         */
416
/*    y                                     y-coord of line top           */
417
/*    info                                  GX_FILL_PIXELMAP_INFO struct  */
418
/*                                                                        */
419
/*  OUTPUT                                                                */
420
/*                                                                        */
421
/*    None                                                                */
422
/*                                                                        */
423
/*  CALLS                                                                 */
424
/*                                                                        */
425
/*    None                                                                */
426
/*                                                                        */
427
/*  CALLED BY                                                             */
428
/*                                                                        */
429
/*    GUIX Internal Code                                                  */
430
/*                                                                        */
431
/**************************************************************************/
432
7609
static VOID _gx_display_driver_1bpp_horizontal_pixelmap_line_compressed_transparent_write(GX_DRAW_CONTEXT *context,
433
                                                                                          INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
434
{
435
INT                start_pos;
436
INT                xval;
437
GX_UBYTE           count;
438
7609
GX_CONST GX_UBYTE *get = GX_NULL;
439
GX_UBYTE           pixel;
440
GX_UBYTE           putmask;
441
GX_UBYTE          *put;
442
GX_PIXELMAP       *pixelmap;
443
444
7609
    pixelmap = info -> pixelmap;
445
446

7609
    if ((info -> draw) && (xstart <= xend))
447
    {
448
        /* Calculate draw start position. */
449
7415
        start_pos = xstart - (info -> x_offset % pixelmap -> gx_pixelmap_width);
450
451
7415
        put = (GX_UBYTE *)context -> gx_draw_context_memory;
452
7415
        put += y * ((context -> gx_draw_context_pitch + 7) >> 3) + (xstart >> 3);
453
454
7415
        putmask = (GX_UBYTE)(0x80 >> (xstart & 0x07));
455
456
        /*Repeat the draw operation to fill the whole dirty area.*/
457
15603
        while (start_pos <= xend)
458
        {
459
8188
            xval = start_pos;
460
            /*Start from where we need to repeat.*/
461
8188
            get = (GX_CONST GX_UBYTE *)info -> current_pixel_ptr;
462
463
59545
            while (xval < start_pos + pixelmap -> gx_pixelmap_width)
464
            {
465
51357
                count = *get;
466
51357
                if (count & 0x80)
467
                {
468
40540
                    count = (GX_UBYTE)(((count & 0x7f) >> 2) + 1);
469
40540
                    pixel = *get++;
470
840693
                    while (count--)
471
                    {
472

800153
                        if (xval >= xstart && xval <= xend)
473
                        {
474
285199
                            if (pixel & 0x01)
475
                            {
476
58713
                                if (pixel & 0x02)
477
                                {
478
19848
                                    *put |= putmask;
479
                                }
480
                                else
481
                                {
482
38865
                                    *put &= (GX_UBYTE)(~putmask);
483
                                }
484
                            }
485
486
285199
                            putmask >>= 1;
487
285199
                            if (putmask == 0)
488
                            {
489
35319
                                put++;
490
35319
                                putmask = 0x80;
491
                            }
492
                        }
493
800153
                        xval++;
494
                    }
495
                }
496
                else
497
                {
498
10817
                    count = (GX_UBYTE)((count >> 2) + 1);
499
29464
                    while (count--)
500
                    {
501
18647
                        pixel = *get++;
502

18647
                        if (xval >= xstart && xval <= xend)
503
                        {
504
8399
                            if (pixel & 0x01)
505
                            {
506
7753
                                if (pixel & 0x02)
507
                                {
508
6543
                                    *put |= putmask;
509
                                }
510
                                else
511
                                {
512
1210
                                    *put &= (GX_UBYTE)(~putmask);
513
                                }
514
                            }
515
8399
                            putmask >>= 1;
516
8399
                            if (putmask == 0)
517
                            {
518
864
                                put++;
519
864
                                putmask = 0x80;
520
                            }
521
                        }
522
18647
                        xval++;
523
                    }
524
                }
525
            }
526
8188
            start_pos += pixelmap -> gx_pixelmap_width;
527
        }
528
    }
529
    else
530
    {
531
194
        xval = 0;
532
194
        get = (GX_CONST GX_UBYTE *)info -> current_pixel_ptr;
533
1483
        while (xval < pixelmap -> gx_pixelmap_width)
534
        {
535
1289
            count = *get;
536
1289
            if (count & 0x80)
537
            {
538
997
                count = (GX_UBYTE)(((count & 0x7f) >> 2) + 1);
539
997
                get++;
540
            }
541
            else
542
            {
543
292
                count = (GX_UBYTE)((count >> 2) + 1);
544
292
                get += count;
545
            }
546
1289
            xval += count;
547
        }
548
    }
549
550
    /* This line is drawn. cache the pointer for next line draw. */
551
7609
    info -> current_pixel_ptr = (GX_UBYTE *)get;
552
7609
}
553
554
/**************************************************************************/
555
/*                                                                        */
556
/*  FUNCTION                                               RELEASE        */
557
/*                                                                        */
558
/*    _gx_display_driver_1bpp_horizontal_pixelmap_line_draw               */
559
/*                                                        PORTABLE C      */
560
/*                                                           6.1          */
561
/*  AUTHOR                                                                */
562
/*                                                                        */
563
/*    Kenneth Maxwell, Microsoft Corporation                              */
564
/*                                                                        */
565
/*  DESCRIPTION                                                           */
566
/*                                                                        */
567
/*    1bpp screen driver horizontal pixelmap line drawing function that   */
568
/*    handles compressed or uncompress, with or without alpha channel.    */
569
/*                                                                        */
570
/*  INPUT                                                                 */
571
/*                                                                        */
572
/*    context                               Drawing context               */
573
/*    xstart                                x-coord of line left          */
574
/*    xend                                  x-coord of line right         */
575
/*    y                                     y-coord of line top           */
576
/*    info                                  GX_FILL_PIXELMAP_INFO struct  */
577
/*                                                                        */
578
/*  OUTPUT                                                                */
579
/*                                                                        */
580
/*    None                                                                */
581
/*                                                                        */
582
/*  CALLS                                                                 */
583
/*                                                                        */
584
/*     _gx_display_driver_1bpp_horizontal_pixelmap_line_c_t_write         */
585
/*                                          Real pixelmap line draw       */
586
/*                                            function                    */
587
/*     _gx_display_driver_1bpp_horizontal_pixelmap_line_t_write           */
588
/*                                          Real pixelmap line draw       */
589
/*                                            function                    */
590
/*     _gx_display_driver_1bpp_horizontal_pixelmap_line_compressed_write  */
591
/*                                          Real pixelmap line draw       */
592
/*                                            function                    */
593
/*     _gx_display_driver_1bpp_horizontal_pixelmap_line_raw_write         */
594
/*                                          Real pixelmap line draw       */
595
/*                                            function                    */
596
/*                                                                        */
597
/*  CALLED BY                                                             */
598
/*                                                                        */
599
/*    GUIX Internal Code                                                  */
600
/*                                                                        */
601
/**************************************************************************/
602
31835
VOID _gx_display_driver_1bpp_horizontal_pixelmap_line_draw(GX_DRAW_CONTEXT *context, INT xstart, INT xend, INT y, GX_FILL_PIXELMAP_INFO *info)
603
{
604
31835
GX_PIXELMAP *pixelmap = info -> pixelmap;
605
606
31835
    if (pixelmap == GX_NULL)
607
    {
608
1
        return;
609
    }
610
611
31834
    if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT)
612
    {
613
15271
        if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
614
        {
615
            /* has both compression and alpha */
616
7609
            _gx_display_driver_1bpp_horizontal_pixelmap_line_compressed_transparent_write(context, xstart, xend, y, info);
617
        }
618
        else
619
        {
620
            /* alpha, no compression */
621
7662
            _gx_display_driver_1bpp_horizontal_pixelmap_line_transparent_write(context, xstart, xend, y, info);
622
        }
623
    }
624
    else
625
    {
626
16563
        if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
627
        {
628
            /* compressed with no alpha */
629
8248
            _gx_display_driver_1bpp_horizontal_pixelmap_line_compressed_write(context, xstart, xend, y, info);
630
        }
631
        else
632
        {
633
            /* no compression or alpha */
634
8315
            _gx_display_driver_1bpp_horizontal_pixelmap_line_raw_write(context, xstart, xend, y, info);
635
        }
636
    }
637
638
    /* Current pixelmap has gone over, so the offset pointer should be reset. */
639
31834
    if (info -> current_pixel_ptr >= info -> pixelmap -> gx_pixelmap_data + info -> pixelmap -> gx_pixelmap_data_size)
640
    {
641
131
        info -> current_pixel_ptr = (GX_UBYTE *)info ->  pixelmap -> gx_pixelmap_data;
642
131
        info -> current_aux_ptr = (GX_UBYTE *)info ->  pixelmap -> gx_pixelmap_aux_data;
643
    }
644
}
645