GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_4444argb_pixelmap_draw.c Lines: 143 143 100.0 %
Date: 2026-03-06 19:21:09 Branches: 80 80 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
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_display_driver_4444argb_pixelmap_alpha_write    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 with alpha channel.                                   */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    context                               Drawing context               */
50
/*    xpos                                  x-coord of top-left draw point*/
51
/*    ypos                                  y-coord of top-left draw point*/
52
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
61
/*                                            blend function              */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    _gx_display_driver_4444argb_pixelmap_draw                           */
66
/*                                                                        */
67
/**************************************************************************/
68
844
static VOID _gx_display_driver_4444argb_pixelmap_alpha_write(GX_DRAW_CONTEXT *context,
69
                                                           INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
70
{
71
INT              skipcount;
72
INT              xval;
73
INT              yval;
74
USHORT          *getrow;
75
GX_CONST USHORT *get;
76
USHORT           pixel;
77
GX_UBYTE         alpha;
78
GX_UBYTE         brush_alpha;
79
VOID           (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR color, GX_UBYTE alpha);
80
844
GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
81
82
844
    brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
83
844
    blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
84
844
    if (!blend_func)
85
    {
86
1
        return;
87
    }
88
89
    /* calculate how many pixels to skip */
90
843
    skipcount = (pixelmap -> gx_pixelmap_width) * (clip -> gx_rectangle_top - ypos);
91
843
    skipcount += (clip -> gx_rectangle_left - xpos);
92
843
    getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
93
843
    getrow += skipcount;
94
95
211723
    for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
96
    {
97
210880
        get = getrow;
98
99
55451888
        for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
100
        {
101
55241008
            pixel = *get++;
102
55241008
            alpha = (GX_UBYTE)(pixel >> 12);
103
55241008
            if (alpha)
104
            {
105
26043286
                blend_func(context, xval, yval, pixel, brush_alpha);
106
            }
107
        }
108
210880
        getrow += pixelmap -> gx_pixelmap_width;
109
    }
110
}
111
112
/**************************************************************************/
113
/*                                                                        */
114
/*  FUNCTION                                               RELEASE        */
115
/*                                                                        */
116
/*    _gx_display_driver_4444argb_pixelmap_raw_write      PORTABLE C      */
117
/*                                                           6.1          */
118
/*  AUTHOR                                                                */
119
/*                                                                        */
120
/*    Kenneth Maxwell, Microsoft Corporation                              */
121
/*                                                                        */
122
/*  DESCRIPTION                                                           */
123
/*                                                                        */
124
/*    Internal helper function that handles writing of uncompressed       */
125
/*    pixlemap file with 0xf alpha channel value.                         */
126
/*                                                                        */
127
/*  INPUT                                                                 */
128
/*                                                                        */
129
/*    context                               Drawing context               */
130
/*    xpos                                  x-coord of top-left draw point*/
131
/*    ypos                                  y-coord of top-left draw point*/
132
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
133
/*                                                                        */
134
/*  OUTPUT                                                                */
135
/*                                                                        */
136
/*    None                                                                */
137
/*                                                                        */
138
/*  CALLS                                                                 */
139
/*                                                                        */
140
/*    None                                                                */
141
/*                                                                        */
142
/*  CALLED BY                                                             */
143
/*                                                                        */
144
/*    _gx_display_driver_4444argb_pixelmap_draw                           */
145
/*                                                                        */
146
/**************************************************************************/
147
120
static VOID _gx_display_driver_4444argb_pixelmap_raw_write(GX_DRAW_CONTEXT *context,
148
                                                           INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
149
{
150
INT           skipcount;
151
INT           xval;
152
INT           yval;
153
USHORT       *getrow;
154
GX_CONST USHORT *get;
155
USHORT        pixel;
156
USHORT       *put;
157
USHORT       *putrow;
158
120
GX_RECTANGLE *clip = context -> gx_draw_context_clip;
159
160
    /* calculate how many pixels to skip */
161
120
    skipcount = (pixelmap -> gx_pixelmap_width) * (clip -> gx_rectangle_top - ypos);
162
120
    skipcount += (clip -> gx_rectangle_left - xpos);
163
120
    getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
164
120
    getrow += skipcount;
165
166
120
    putrow = (USHORT *)context -> gx_draw_context_memory;
167
120
    putrow += (clip -> gx_rectangle_top) * context -> gx_draw_context_pitch;
168
120
    putrow += clip -> gx_rectangle_left;
169
170
15686
    for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
171
    {
172
15566
        get = getrow;
173
15566
        put = putrow;
174
175
3355741
        for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
176
        {
177
            /*Or with 0xf000 to make sure it has no alpha.*/
178
3340175
            pixel = (*get++) | 0xf000;
179
3340175
            *put++ = pixel;
180
        }
181
15566
        getrow += pixelmap -> gx_pixelmap_width;
182
15566
        putrow += context -> gx_draw_context_pitch;
183
    }
184
120
}
185
186
/**************************************************************************/
187
/*                                                                        */
188
/*  FUNCTION                                               RELEASE        */
189
/*                                                                        */
190
/*    _gx_display_driver_4444argb_pixelmap_c_a_write     PORTABLE C       */
191
/*                                                           6.1          */
192
/*  AUTHOR                                                                */
193
/*                                                                        */
194
/*    Kenneth Maxwell, Microsoft Corporation                              */
195
/*                                                                        */
196
/*  DESCRIPTION                                                           */
197
/*                                                                        */
198
/*    Internal helper function that handles writing of compressed         */
199
/*    pixlemap file with alpha channel.                                   */
200
/*                                                                        */
201
/*  INPUT                                                                 */
202
/*                                                                        */
203
/*    context                               Drawing context               */
204
/*    xpos                                  x-coord of top-left draw point*/
205
/*    ypos                                  y-coord of top-left draw point*/
206
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
207
/*                                                                        */
208
/*  OUTPUT                                                                */
209
/*                                                                        */
210
/*    None                                                                */
211
/*                                                                        */
212
/*  CALLS                                                                 */
213
/*                                                                        */
214
/*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
215
/*                                            blend function              */
216
/*                                                                        */
217
/*  CALLED BY                                                             */
218
/*                                                                        */
219
/*    _gx_display_driver_4444argb_pixelmap_draw                           */
220
/*                                                                        */
221
/**************************************************************************/
222
9734
static VOID _gx_display_driver_4444argb_pixelmap_compressed_alpha_write(GX_DRAW_CONTEXT *context,
223
                                                                        INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
224
{
225
INT           yval;
226
INT           xval;
227
GX_CONST USHORT *get;
228
USHORT        count;
229
USHORT        pixel;
230
GX_UBYTE      alpha;
231
GX_UBYTE      brush_alpha;
232
VOID        (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
233
9734
GX_RECTANGLE *clip = context -> gx_draw_context_clip;
234
235
9734
    get = (GX_CONST USHORT *)pixelmap -> gx_pixelmap_data;
236
9734
    brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
237
9734
    blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
238
239
9734
    if (blend_func == GX_NULL)
240
    {
241
106
        return;
242
    }
243
244
    /* first, skip to the starting row */
245
9748
    for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
246
    {
247
120
        xval = 0;
248
895
        while (xval < pixelmap -> gx_pixelmap_width)
249
        {
250
775
            count = *get++;
251
252
775
            if (count & 0x8000)
253
            {
254
543
                count = (USHORT)((count & 0x7fff) + 1);
255
543
                get++;      /* skip repeated pixel value */
256
            }
257
            else
258
            {
259
232
                count++;
260
232
                get += count;   /* skip raw pixel values */
261
            }
262
775
            xval += count;
263
        }
264
    }
265
266
    /* now we are on the first visible row, copy pixels until we get
267
       to the enf of the last visible row
268
     */
269
193955
    while (yval <= clip -> gx_rectangle_bottom)
270
    {
271
184327
        xval = xpos;
272
273
886640
        while (xval < xpos + pixelmap -> gx_pixelmap_width)
274
        {
275
702313
            count = *get++;
276
277
702313
            if (count & 0x8000)
278
            {
279
                /* repeated value */
280
343686
                count = (USHORT)((count & 0x7fff) + 1);
281
343686
                pixel = *get++;
282
343686
                alpha = (GX_UBYTE)(pixel >> 12);
283
284
343686
                if (alpha)
285
                {
286
1473067
                    while (count--)
287
                    {
288
1311558
                        if (xval >= clip -> gx_rectangle_left &&
289
1302360
                            xval <= clip -> gx_rectangle_right)
290
                        {
291
1300411
                            blend_func(context, xval, yval, pixel, brush_alpha);
292
                        }
293
1311558
                        xval++;
294
                    }
295
                }
296
                else
297
                {
298
182177
                    xval += count;
299
                }
300
            }
301
            else
302
            {
303
                /* string of non-repeated values */
304
358627
                count++;
305
2175032
                while (count--)
306
                {
307
1816405
                    if (xval >= clip -> gx_rectangle_left &&
308
1815566
                        xval <= clip -> gx_rectangle_right)
309
                    {
310
1815167
                        blend_func(context, xval, yval, *get, brush_alpha);
311
                    }
312
1816405
                    get++;
313
1816405
                    xval++;
314
                }
315
            }
316
        }
317
184327
        yval++;
318
    }
319
}
320
321
/**************************************************************************/
322
/*                                                                        */
323
/*  FUNCTION                                               RELEASE        */
324
/*                                                                        */
325
/*    _gx_display_driver_4444argb_pixelmap_compressed_write               */
326
/*                                                        PORTABLE C      */
327
/*                                                           6.1          */
328
/*  AUTHOR                                                                */
329
/*                                                                        */
330
/*    Kenneth Maxwell, Microsoft Corporation                              */
331
/*                                                                        */
332
/*  DESCRIPTION                                                           */
333
/*                                                                        */
334
/*    Internal helper function that handles writing of compressed         */
335
/*    pixlemap file without alpha channel.                                */
336
/*                                                                        */
337
/*  INPUT                                                                 */
338
/*                                                                        */
339
/*    context                               Drawing context               */
340
/*    xpos                                  x-coord of top-left draw point*/
341
/*    ypos                                  y-coord of top-left draw point*/
342
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
343
/*                                                                        */
344
/*  OUTPUT                                                                */
345
/*                                                                        */
346
/*    None                                                                */
347
/*                                                                        */
348
/*  CALLS                                                                 */
349
/*                                                                        */
350
/*    None                                                                */
351
/*                                                                        */
352
/*  CALLED BY                                                             */
353
/*                                                                        */
354
/*    _gx_display_driver_4444argb_pixelmap_draw                           */
355
/*                                                                        */
356
/**************************************************************************/
357
3793
static VOID _gx_display_driver_4444argb_pixelmap_compressed_write(GX_DRAW_CONTEXT *context,
358
                                                                  INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
359
{
360
INT               yval;
361
INT               xval;
362
GX_CONST USHORT  *get;
363
USHORT            count;
364
USHORT            pixel;
365
USHORT           *put;
366
USHORT           *putrow;
367
3793
GX_RECTANGLE     *clip = context -> gx_draw_context_clip;
368
369
3793
    get = (GX_CONST USHORT *)pixelmap -> gx_pixelmap_data;
370
371
    /* first, skip to the starting row */
372
3813
    for (yval = ypos; yval < clip -> gx_rectangle_top; yval++)
373
    {
374
20
        xval = 0;
375
2659
        while (xval < pixelmap -> gx_pixelmap_width)
376
        {
377
2639
            count = *get++;
378
379
2639
            if (count & 0x8000)
380
            {
381
1463
                count = (USHORT)((count & 0x7fff) + 1);
382
1463
                get++;      /* skip repeated pixel value */
383
            }
384
            else
385
            {
386
1176
                count++;
387
1176
                get += count;   /* skip raw pixel values */
388
            }
389
2639
            xval += count;
390
        }
391
    }
392
393
    /* now we are on the first visible row, copy pixels until we get
394
    to the enf of the last visible row
395
    */
396
3793
    putrow = (USHORT *)context -> gx_draw_context_memory;
397
3793
    putrow += clip -> gx_rectangle_top * context -> gx_draw_context_pitch;
398
3793
    putrow += clip -> gx_rectangle_left;
399
400
91077
    while (yval <= clip -> gx_rectangle_bottom)
401
    {
402
87284
        xval = xpos;
403
87284
        put = putrow;
404
405
4069790
        while (xval < xpos + pixelmap -> gx_pixelmap_width)
406
        {
407
3982506
            count = *get++;
408
409
3982506
            if (count & 0x8000)
410
            {
411
                /* repeated value */
412
2154355
                count = (USHORT)((count & 0x7fff) + 1);
413
                /*Or with 0xf000 to make sure it has no alpha.*/
414
2154355
                pixel = (*get++) | 0xf000 ;
415
11785551
                while (count--)
416
                {
417
9631196
                    if (xval >= clip -> gx_rectangle_left &&
418
9625775
                        xval <= clip -> gx_rectangle_right)
419
                    {
420
2629834
                        *put++ = pixel;
421
                    }
422
9631196
                    xval++;
423
                }
424
            }
425
            else
426
            {
427
                /* string of non-repeated values */
428
1828151
                count++;
429
19541931
                while (count--)
430
                {
431
17713780
                    if (xval >= clip -> gx_rectangle_left &&
432
17707441
                        xval <= clip -> gx_rectangle_right)
433
                    {
434
                        /*Or with 0xf000 to make sure it has no alpha.*/
435
4152698
                        pixel = (*get) | 0xf000;
436
4152698
                        *put++ = pixel;
437
                    }
438
17713780
                    get++;
439
17713780
                    xval++;
440
                }
441
            }
442
        }
443
87284
        putrow += context -> gx_draw_context_pitch;
444
87284
        yval++;
445
    }
446
3793
}
447
/**************************************************************************/
448
/*                                                                        */
449
/*  FUNCTION                                               RELEASE        */
450
/*                                                                        */
451
/*    _gx_display_driver_4444argb_pixelmap_draw           PORTABLE C      */
452
/*                                                           6.1          */
453
/*  AUTHOR                                                                */
454
/*                                                                        */
455
/*    Kenneth Maxwell, Microsoft Corporation                              */
456
/*                                                                        */
457
/*  DESCRIPTION                                                           */
458
/*                                                                        */
459
/*    565rgb screen driver pixelmap drawing function that handles         */
460
/*    compressed or uncompress, with or without alpha channel.            */
461
/*                                                                        */
462
/*  INPUT                                                                 */
463
/*                                                                        */
464
/*    context                               Drawing context               */
465
/*    xpos                                  x-coord of top-left draw point*/
466
/*    ypos                                  y-coord of top-left draw point*/
467
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
468
/*                                                                        */
469
/*  OUTPUT                                                                */
470
/*                                                                        */
471
/*    None                                                                */
472
/*                                                                        */
473
/*  CALLS                                                                 */
474
/*                                                                        */
475
/*    _gx_display_driver_4444argb_pixelmap_compressed_alpha_write         */
476
/*                                          Real display driver pixelmap  */
477
/*                                            draw function               */
478
/*    _gx_display_driver_4444argb_pixelmap_compressed_write               */
479
/*                                          Real display driver pixelmap  */
480
/*                                            draw function               */
481
/*    _gx_display_driver_4444argb_pixelmap_alpha_write                    */
482
/*                                          Real display driver pixelmap  */
483
/*                                            draw function               */
484
/*    _gx_display_driver_4444argb_pixelmap_raw_write                      */
485
/*                                          Real display driver pixelmap  */
486
/*                                            draw function               */
487
/*    _gx_display_driver_4444argb_pixelmap_blend                          */
488
/*                                          Basic display driver pixelmap */
489
/*                                            blend function              */
490
/*                                                                        */
491
/*  CALLED BY                                                             */
492
/*                                                                        */
493
/*    GUIX Internal Code                                                  */
494
/*                                                                        */
495
/**************************************************************************/
496
14502
VOID _gx_display_driver_4444argb_pixelmap_draw(GX_DRAW_CONTEXT *context,
497
                                               INT xpos, INT ypos, GX_PIXELMAP *pixelmap)
498
{
499
14502
GX_BOOL   drawn = GX_FALSE;
500
14502
GX_UBYTE  brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
501
502
14502
    if (brush_alpha == 0)
503
    {
504
        /* Draw nothing here. Just return. */
505
4
        return;
506
    }
507
508
14498
    switch (pixelmap -> gx_pixelmap_format)
509
    {
510
14497
    case GX_COLOR_FORMAT_4444ARGB:
511
14497
        if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
512
        {
513
13530
            if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
514
            {
515
9734
                _gx_display_driver_4444argb_pixelmap_compressed_alpha_write(context, xpos, ypos, pixelmap);
516
9734
                drawn = GX_TRUE;
517
            }
518
            else
519
            {
520
3796
                if (brush_alpha == 0xff)
521
                {
522
3793
                    _gx_display_driver_4444argb_pixelmap_compressed_write(context, xpos, ypos, pixelmap);
523
3793
                    drawn = GX_TRUE;
524
                }
525
            }
526
        }
527
        else
528
        {
529
967
            if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
530
            {
531
844
                _gx_display_driver_4444argb_pixelmap_alpha_write(context, xpos, ypos, pixelmap);
532
844
                drawn = GX_TRUE;
533
            }
534
            else
535
            {
536
123
                if (brush_alpha == 0xff)
537
                {
538
120
                    _gx_display_driver_4444argb_pixelmap_raw_write(context, xpos, ypos, pixelmap);
539
120
                    drawn = GX_TRUE;
540
                }
541
            }
542
        }
543
14497
        break;
544
545
1
    default:
546
1
        drawn = GX_TRUE;
547
1
        break;
548
    }
549
550
14498
    if (!drawn)
551
    {
552
6
        _gx_display_driver_4444argb_pixelmap_blend(context, xpos, ypos, pixelmap, brush_alpha);
553
    }
554
555
14498
    return;
556
}
557