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

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