cogl/bitmap-conversion: Don't break strict-aliasing for flt_pack/unpack
Simply reinterpreting the bytes differently is a strict-aliasing
violation if the type of the object isn't char or the target type of the
reinterpretation. None of that is the case here, so we have to resort to
a memcpy.
Fixes: 60c082caa
("cogl/bitmap-conversion: Support packing fp16 formats")
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3499>
This commit is contained in:
parent
0cd85e4adf
commit
a0a1d102a0
@ -45,16 +45,22 @@ typedef enum
|
||||
MEDIUM_TYPE_FLOAT,
|
||||
} MediumType;
|
||||
|
||||
G_STATIC_ASSERT (sizeof (uint32_t) == sizeof (GLfloat));
|
||||
|
||||
inline static uint32_t
|
||||
pack_flt (GLfloat b)
|
||||
{
|
||||
return *(uint32_t *) &b;
|
||||
uint32_t ret;
|
||||
memcpy (&ret, &b, sizeof (uint32_t));
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline static GLfloat
|
||||
unpack_flt (uint32_t b)
|
||||
{
|
||||
return *(GLfloat *) &b;
|
||||
GLfloat ret;
|
||||
memcpy (&ret, &b, sizeof (GLfloat));
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define CLAMP_NORM(b) (MAX (MIN ((b), 1.0), 0.0))
|
||||
|
Loading…
Reference in New Issue
Block a user