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

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