GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_8bpp_pixelmap_draw.c Lines: 160 160 100.0 %
Date: 2026-03-06 19:21:09 Branches: 84 84 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_8bpp_pixelmap_raw_write          PORTABLE C      */
36
/*                                                           6.1          */
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
/*    xpos                                  x-coord of top-left draw point*/
50
/*    ypos                                  y-coord of top-left draw point*/
51
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLED BY                                                             */
58
/*                                                                        */
59
/*    GUIX Internal Code                                                  */
60
/*                                                                        */
61
/**************************************************************************/
62
161
static VOID _gx_display_driver_8bpp_pixelmap_raw_write(GX_DRAW_CONTEXT *context,
63
                                                       INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
64
{
65
INT             xval;
66
INT             yval;
67
INT             width;
68
GX_UBYTE       *putrow;
69
GX_UBYTE       *getrow;
70
GX_UBYTE       *put;
71
GX_CONST GX_UBYTE *get;
72
73
161
GX_RECTANGLE   *clip = context -> gx_draw_context_clip;
74
75
161
    putrow = (GX_UBYTE *)context -> gx_draw_context_memory;
76
161
    putrow += clip -> gx_rectangle_top * context -> gx_draw_context_pitch;
77
161
    putrow += clip -> gx_rectangle_left;
78
79
161
    getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data);
80
161
    getrow += pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos);
81
161
    getrow += (clip -> gx_rectangle_left - xpos);
82
83
161
    width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
84
85
21236
    for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
86
    {
87
21075
        put = putrow;
88
21075
        get = getrow;
89
90
4322705
        for (xval = 0; xval < width; xval++)
91
        {
92
4301630
            *put++ = *get++;
93
        }
94
21075
        putrow += context -> gx_draw_context_pitch;
95
21075
        getrow += pixelmap -> gx_pixelmap_width;
96
    }
97
161
}
98
99
100
101
/**************************************************************************/
102
/*                                                                        */
103
/*  FUNCTION                                               RELEASE        */
104
/*                                                                        */
105
/*    _gx_display_driver_8bpp_pixelmap_compressed_write   PORTABLE C      */
106
/*                                                           6.1.7        */
107
/*  AUTHOR                                                                */
108
/*                                                                        */
109
/*    Kenneth Maxwell, Microsoft Corporation                              */
110
/*                                                                        */
111
/*  DESCRIPTION                                                           */
112
/*                                                                        */
113
/*    Internal helper function that handles writing of compressed         */
114
/*    pixlemap file.                                                      */
115
/*                                                                        */
116
/*  INPUT                                                                 */
117
/*                                                                        */
118
/*    context                               Drawing context               */
119
/*    xpos                                  x-coord of top-left draw point*/
120
/*    ypos                                  y-coord of top-left draw point*/
121
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
122
/*                                                                        */
123
/*  OUTPUT                                                                */
124
/*                                                                        */
125
/*    None                                                                */
126
/*                                                                        */
127
/*  CALLS                                                                 */
128
/*                                                                        */
129
/*    None                                                                */
130
/*                                                                        */
131
/*  CALLED BY                                                             */
132
/*                                                                        */
133
/*    GUIX Internal Code                                                  */
134
/*                                                                        */
135
/**************************************************************************/
136
11815
static VOID _gx_display_driver_8bpp_pixelmap_compressed_write(GX_DRAW_CONTEXT *context,
137
                                                              INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
138
{
139
INT             yval;
140
INT             xval;
141
GX_CONST GX_UBYTE *get;
142
GX_UBYTE       *put;
143
GX_UBYTE       *putrow;
144
GX_UBYTE        count;
145
INT             length;
146
INT             repeat;
147
INT             width;
148
11815
GX_UBYTE        pixel = 0;
149
11815
GX_RECTANGLE   *clip = context -> gx_draw_context_clip;
150
151
11815
    get = (GX_CONST GX_UBYTE *)pixelmap -> gx_pixelmap_data;
152
153
    /* first, skip to the starting row */
154
71539
    for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
155
    {
156
59724
        xval = 0;
157
9453263
        while (xval < pixelmap -> gx_pixelmap_width)
158
        {
159
9393539
            count = *get++;
160
161
9393539
            if (count & 0x80)
162
            {
163
5441139
                count = (GX_UBYTE)((count & 0x7f) + 1);
164
5441139
                get++;      /* skip repeated pixel value */
165
            }
166
            else
167
            {
168
3952400
                count++;
169
3952400
                get += count;   /* skip raw pixel values */
170
            }
171
9393539
            xval += count;
172
        }
173
    }
174
175
    /* now we are on the first visible row, copy pixels until we get
176
       to the enf of the last visible row
177
     */
178
11815
    putrow = (GX_UBYTE *)context -> gx_draw_context_memory;
179
11815
    putrow += yval * context -> gx_draw_context_pitch;
180
11815
    putrow += xpos;
181
182
247813
    while (yval <= clip -> gx_rectangle_bottom)
183
    {
184
235998
        put = putrow;
185
235998
        xval = xpos;
186
235998
        width = pixelmap -> gx_pixelmap_width;
187
188
8241654
        while (xval < (xpos + pixelmap -> gx_pixelmap_width))
189
        {
190
8005656
            count = *get++;
191
8005656
            if (count & 0x80)
192
            {
193
                /* repeated value */
194
4633570
                count = (GX_UBYTE)((count & 0x7f) + 1);
195
4633570
                pixel = *get++;
196
4633570
                repeat = GX_TRUE;
197
            }
198
            else
199
            {
200
                /* string of non-repeated values */
201
3372086
                count++;
202
3372086
                repeat = GX_FALSE;
203
            }
204
205
8005656
            if (repeat == GX_TRUE)
206
            {
207
208
4633570
                if (count < width)
209
                {
210
4592582
                    length = count;
211
                }
212
                else
213
                {
214
40988
                    length = width;
215
                }
216
4633570
                width -= length;
217
32205303
                while (length--)
218
                {
219
27571733
                    if (xval >= clip -> gx_rectangle_left &&
220
23782121
                        xval <= clip -> gx_rectangle_right)
221
                    {
222
4706990
                        *put = pixel;
223
                    }
224
27571733
                    put++;
225
27571733
                    xval++;
226
                }
227
            }
228
            else
229
            {
230
3372086
                if (count < pixelmap -> gx_pixelmap_width)
231
                {
232
3306989
                    length = count;
233
                }
234
                else
235
                {
236
65097
                    length = pixelmap -> gx_pixelmap_width;
237
                }
238
3372086
                width -= length;
239
24063863
                while (length--)
240
                {
241
20691777
                    if (xval >= clip -> gx_rectangle_left &&
242
17838830
                        xval <= clip -> gx_rectangle_right)
243
                    {
244
5038391
                        *put = *get;
245
                    }
246
20691777
                    put++;
247
20691777
                    get++;
248
20691777
                    xval++;
249
                }
250
            }
251
        }
252
235998
        putrow +=  context -> gx_draw_context_pitch;
253
235998
        yval++;
254
    }
255
11815
}
256
257
/**************************************************************************/
258
/*                                                                        */
259
/*  FUNCTION                                               RELEASE        */
260
/*                                                                        */
261
/*    _gx_display_driver_8bpp_pixelmap_transparent_write  PORTABLE C      */
262
/*                                                           6.1          */
263
/*  AUTHOR                                                                */
264
/*                                                                        */
265
/*    Kenneth Maxwell, Microsoft Corporation                              */
266
/*                                                                        */
267
/*  DESCRIPTION                                                           */
268
/*                                                                        */
269
/*    Internal helper function that handles writing of uncompressed       */
270
/*    pixlemap file with alpha channel.                                   */
271
/*                                                                        */
272
/*  INPUT                                                                 */
273
/*                                                                        */
274
/*    context                               Drawing context               */
275
/*    xpos                                  x-coord of top-left draw point*/
276
/*    ypos                                  y-coord of top-left draw point*/
277
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
278
/*                                                                        */
279
/*  OUTPUT                                                                */
280
/*                                                                        */
281
/*    None                                                                */
282
/*                                                                        */
283
/*  CALLS                                                                 */
284
/*                                                                        */
285
/*    None                                                                */
286
/*                                                                        */
287
/*  CALLED BY                                                             */
288
/*                                                                        */
289
/*    GUIX Internal Code                                                  */
290
/*                                                                        */
291
/**************************************************************************/
292
1077
static VOID _gx_display_driver_8bpp_pixelmap_transparent_write(GX_DRAW_CONTEXT *context,
293
                                                               INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
294
{
295
INT             xval;
296
INT             yval;
297
INT             width;
298
GX_UBYTE       *putrow;
299
GX_UBYTE       *getrow;
300
GX_UBYTE       *put;
301
GX_UBYTE        inval;
302
GX_CONST GX_UBYTE *get;
303
304
1077
GX_RECTANGLE   *clip = context -> gx_draw_context_clip;
305
306
1077
    putrow = (GX_UBYTE *)context -> gx_draw_context_memory;
307
1077
    putrow += clip -> gx_rectangle_top * context -> gx_draw_context_pitch;
308
1077
    putrow += clip -> gx_rectangle_left;
309
310
1077
    getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data);
311
1077
    getrow += pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos);
312
1077
    getrow += (clip -> gx_rectangle_left - xpos);
313
314
1077
    width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
315
316
209673
    for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
317
    {
318
208596
        put = putrow;
319
208596
        get = getrow;
320
321
53640091
        for (xval = 0; xval < width; xval++)
322
        {
323
53431495
            inval = *get++;
324
53431495
            if (inval == pixelmap -> gx_pixelmap_transparent_color)
325
            {
326
28221681
                put++;
327
            }
328
            else
329
            {
330
25209814
                *put++ = inval;
331
            }
332
        }
333
208596
        putrow += context -> gx_draw_context_pitch;
334
208596
        getrow += pixelmap -> gx_pixelmap_width;
335
    }
336
1077
}
337
338
/**************************************************************************/
339
/*                                                                        */
340
/*  FUNCTION                                               RELEASE        */
341
/*                                                                        */
342
/*    _gx_display_driver_8bpp_pixelmap_compressed_transparent_write       */
343
/*                                                        PORTABLE C      */
344
/*                                                           6.1.7        */
345
/*  AUTHOR                                                                */
346
/*                                                                        */
347
/*    Kenneth Maxwell, Microsoft Corporation                              */
348
/*                                                                        */
349
/*  DESCRIPTION                                                           */
350
/*                                                                        */
351
/*    Internal helper function that handles writing of compressed         */
352
/*    pixlemap file with alpha channel.                                   */
353
/*                                                                        */
354
/*  INPUT                                                                 */
355
/*                                                                        */
356
/*    context                               Drawing context               */
357
/*    xpos                                  x-coord of top-left draw point*/
358
/*    ypos                                  y-coord of top-left draw point*/
359
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
360
/*                                                                        */
361
/*  OUTPUT                                                                */
362
/*                                                                        */
363
/*    None                                                                */
364
/*                                                                        */
365
/*  CALLS                                                                 */
366
/*                                                                        */
367
/*    None                                                                */
368
/*                                                                        */
369
/*  CALLED BY                                                             */
370
/*                                                                        */
371
/*    GUIX Internal Code                                                  */
372
/*                                                                        */
373
/**************************************************************************/
374
16626
static VOID _gx_display_driver_8bpp_pixelmap_compressed_transparent_write(GX_DRAW_CONTEXT *context,
375
                                                                          INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
376
{
377
INT             yval;
378
INT             xval;
379
GX_CONST GX_UBYTE *get;
380
GX_UBYTE       *put;
381
GX_UBYTE       *putrow;
382
GX_UBYTE        count;
383
INT             length;
384
INT             repeat;
385
INT             width;
386
16626
GX_UBYTE        pixel = 0;
387
16626
GX_RECTANGLE   *clip = context -> gx_draw_context_clip;
388
389
16626
    get = (GX_CONST GX_UBYTE *)pixelmap -> gx_pixelmap_data;
390
391
    /* first, skip to the starting row */
392
16735
    for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
393
    {
394
109
        xval = 0;
395
499
        while (xval < pixelmap -> gx_pixelmap_width)
396
        {
397
390
            count = *get++;
398
399
390
            if (count & 0x80)
400
            {
401
320
                count = (GX_UBYTE)((count & 0x7f) + 1);
402
320
                get++;      /* skip repeated pixel value */
403
            }
404
            else
405
            {
406
70
                count++;
407
70
                get += count;   /* skip raw pixel values */
408
            }
409
390
            xval += count;
410
        }
411
    }
412
413
    /* now we are on the first visible row, copy pixels until we get
414
       to the enf of the last visible row
415
     */
416
16626
    putrow = (GX_UBYTE *)context -> gx_draw_context_memory;
417
16626
    putrow += yval * context -> gx_draw_context_pitch;
418
16626
    putrow += xpos;
419
420
318727
    while (yval <= clip -> gx_rectangle_bottom)
421
    {
422
302101
        put = putrow;
423
302101
        xval = xpos;
424
302101
        width = pixelmap -> gx_pixelmap_width;
425
426
1432242
        while (xval < (xpos + pixelmap -> gx_pixelmap_width))
427
        {
428
1130141
            count = *get++;
429
1130141
            if (count & 0x80)
430
            {
431
                /* repeated value */
432
565603
                count = (GX_UBYTE)((count & 0x7f) + 1);
433
565603
                pixel = *get++;
434
565603
                repeat = GX_TRUE;
435
            }
436
            else
437
            {
438
                /* string of non-repeated values */
439
564538
                count++;
440
564538
                repeat = GX_FALSE;
441
            }
442
443
1130141
            if (repeat == GX_TRUE)
444
            {
445
565603
                if (count < width)
446
                {
447
451273
                    length = count;
448
                }
449
                else
450
                {
451
114330
                    length = width;
452
                }
453
565603
                width -= length;
454
455
565603
                if (pixel == pixelmap -> gx_pixelmap_transparent_color)
456
                {
457
225074
                    put += length;
458
225074
                    xval += length;
459
                }
460
                else
461
                {
462
3068409
                    while (length--)
463
                    {
464
2727880
                        if (xval >= clip -> gx_rectangle_left &&
465
2725804
                            xval <= clip -> gx_rectangle_right)
466
                        {
467
2717505
                            *put = pixel;
468
                        }
469
2727880
                        put++;
470
2727880
                        xval++;
471
                    }
472
                }
473
            }
474
            else
475
            {
476
564538
                if (count < pixelmap -> gx_pixelmap_width)
477
                {
478
533828
                    length = count;
479
                }
480
                else
481
                {
482
30710
                    length = pixelmap -> gx_pixelmap_width;
483
                }
484
485
564538
                width -= length;
486
487
3310566
                while (length--)
488
                {
489
2746028
                    pixel = *get++;
490
491
2746028
                    if (xval >= clip -> gx_rectangle_left &&
492
2745573
                        xval <= clip -> gx_rectangle_right &&
493
2742094
                        pixel != pixelmap -> gx_pixelmap_transparent_color)
494
                    {
495
2468112
                        *put = pixel;
496
                    }
497
2746028
                    put++;
498
2746028
                    xval++;
499
                }
500
            }
501
        }
502
302101
        putrow +=  context -> gx_draw_context_pitch;
503
302101
        yval++;
504
    }
505
16626
}
506
507
/**************************************************************************/
508
/*                                                                        */
509
/*  FUNCTION                                               RELEASE        */
510
/*                                                                        */
511
/*    _gx_display_driver_8bpp_pixelmap_draw               PORTABLE C      */
512
/*                                                           6.1          */
513
/*  AUTHOR                                                                */
514
/*                                                                        */
515
/*    Kenneth Maxwell, Microsoft Corporation                              */
516
/*                                                                        */
517
/*  DESCRIPTION                                                           */
518
/*                                                                        */
519
/*    8bit screen driver pixelmap drawing function that handles           */
520
/*    compressed or uncompress, with or without alpha channel.            */
521
/*                                                                        */
522
/*  INPUT                                                                 */
523
/*                                                                        */
524
/*    context                               Drawing context               */
525
/*    xpos                                  x-coord of top-left draw point*/
526
/*    ypos                                  y-coord of top-left draw point*/
527
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
528
/*                                                                        */
529
/*  OUTPUT                                                                */
530
/*                                                                        */
531
/*    None                                                                */
532
/*                                                                        */
533
/*  CALLS                                                                 */
534
/*                                                                        */
535
/*     _gx_display_driver_8bit_pixelmap_compressed_write                  */
536
/*     _gx_display_driver_8bit_pixelmap_compressed_transparent_write      */
537
/*     _gx_display_driver_8bit_pixelmap_transparent_write                 */
538
/*     _gx_display_driver_8bit_pixelmap_raw_write                         */
539
/*                                                                        */
540
/*  CALLED BY                                                             */
541
/*                                                                        */
542
/*    GUIX Internal Code                                                  */
543
/*                                                                        */
544
/**************************************************************************/
545
29681
VOID _gx_display_driver_8bpp_pixelmap_draw(GX_DRAW_CONTEXT *context,
546
                                           INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
547
{
548
549
29681
    if (pixelmap -> gx_pixelmap_format != GX_COLOR_FORMAT_8BIT_PALETTE ||
550
29680
        (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA))
551
    {
552
        /* wrong color format for this driver */
553
2
        return;
554
    }
555
556
29679
    if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT)
557
    {
558
17703
        if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
559
        {
560
            /* has both compression and transparent */
561
16626
            _gx_display_driver_8bpp_pixelmap_compressed_transparent_write(context, xpos, ypos, pixelmap);
562
        }
563
        else
564
        {
565
            /* transparent, no compression */
566
1077
            _gx_display_driver_8bpp_pixelmap_transparent_write(context, xpos, ypos, pixelmap);
567
        }
568
    }
569
    else
570
    {
571
11976
        if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
572
        {
573
            /* compressed with no transparency */
574
11815
            _gx_display_driver_8bpp_pixelmap_compressed_write(context, xpos, ypos, pixelmap);
575
        }
576
        else
577
        {
578
            /* no compression or transaprency */
579
161
            _gx_display_driver_8bpp_pixelmap_raw_write(context, xpos, ypos, pixelmap);
580
        }
581
    }
582
}
583