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