GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_utility_alphamap_create.c Lines: 24 24 100.0 %
Date: 2026-03-06 19:21:09 Branches: 10 10 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
/**   Canvas Management (Canvas)                                          */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_utility.h"
29
#include "gx_canvas.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_utility_alphamap_create                         PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function creates an 8bpp alpha-map pixelmap.                   */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    width                                 width of desired alphamap     */
48
/*    height                                height of desired alphamap    */
49
/*    map                                   pointer to pixlmap structure  */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    status                                Completion status             */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    _gx_system_memory_allocator           Dynamically allocate memory   */
58
/*                                                                        */
59
/*  CALLED BY                                                             */
60
/*                                                                        */
61
/*    _gx_utility_string_to_alphamap                                      */
62
/*    application software                                                */
63
/*                                                                        */
64
/**************************************************************************/
65
4393
UINT _gx_utility_alphamap_create(INT width, INT height, GX_PIXELMAP *map)
66
{
67
/* try to allocate memory for alphamap */
68
GX_UBYTE *memptr;
69
4393
ULONG     memsize = (ULONG)(width * height);
70
71
4393
    if (width > GX_MAX_PIXELMAP_RESOLUTION)
72
    {
73
1
        return GX_INVALID_WIDTH;
74
    }
75
76
4392
    if (height > GX_MAX_PIXELMAP_RESOLUTION)
77
    {
78
1
        return GX_INVALID_HEIGHT;
79
    }
80
81

4391
    if (!memsize || _gx_system_memory_allocator == GX_NULL)
82
    {
83
11
        return GX_FAILURE;
84
    }
85
86
4380
    memptr = (GX_UBYTE *)(_gx_system_memory_allocator(memsize));
87
88
4380
    if (memptr == GX_NULL)
89
    {
90
13
        map -> gx_pixelmap_data = GX_NULL;
91
13
        return GX_FAILURE;
92
    }
93
94
4367
    map -> gx_pixelmap_aux_data = GX_NULL;
95
4367
    map -> gx_pixelmap_aux_data_size = 0;
96
4367
    map -> gx_pixelmap_data = memptr;
97
4367
    map -> gx_pixelmap_data_size = memsize;
98
4367
    map -> gx_pixelmap_flags = GX_PIXELMAP_TRANSPARENT;
99
4367
    map -> gx_pixelmap_transparent_color = 0;
100
4367
    map -> gx_pixelmap_format = GX_COLOR_FORMAT_8BIT_ALPHAMAP;
101
4367
    map -> gx_pixelmap_height = (GX_VALUE)height;
102
4367
    map -> gx_pixelmap_width = (GX_VALUE)width;
103
4367
    map -> gx_pixelmap_version_major = map -> gx_pixelmap_version_minor = 0;
104
4367
    memset(memptr, 0, (size_t)memsize);
105
4367
    return GX_SUCCESS;
106
}
107