gdk: Make gdk_memory_depth_merge() use a table

This makes it clearer how depths are merged.

Also use the actual desired merge modes, the previous code had some
weird behaviors.
This commit is contained in:
Benjamin Otte 2024-06-29 02:31:56 +02:00
parent 8d5325b816
commit 9abc83fdad

View File

@ -1536,35 +1536,19 @@ GdkMemoryDepth
gdk_memory_depth_merge (GdkMemoryDepth depth1, gdk_memory_depth_merge (GdkMemoryDepth depth1,
GdkMemoryDepth depth2) GdkMemoryDepth depth2)
{ {
switch (depth1) static const GdkMemoryDepth merged_depths[GDK_N_DEPTHS][GDK_N_DEPTHS] = {
{ /* U8 U8_SRGB U16 FLOAT16 FLOAT32 */
case GDK_MEMORY_U8: [GDK_MEMORY_U8] = { GDK_MEMORY_U8, GDK_MEMORY_FLOAT16, GDK_MEMORY_U16, GDK_MEMORY_FLOAT16, GDK_MEMORY_FLOAT32 },
if (depth2 == GDK_MEMORY_U8_SRGB) [GDK_MEMORY_U8_SRGB] = { GDK_MEMORY_FLOAT16, GDK_MEMORY_U8_SRGB, GDK_MEMORY_FLOAT32, GDK_MEMORY_FLOAT16, GDK_MEMORY_FLOAT32 },
return GDK_MEMORY_FLOAT16; [GDK_MEMORY_U16] = { GDK_MEMORY_U16, GDK_MEMORY_FLOAT32, GDK_MEMORY_U16, GDK_MEMORY_FLOAT32, GDK_MEMORY_FLOAT32 },
else [GDK_MEMORY_FLOAT16] = { GDK_MEMORY_FLOAT16, GDK_MEMORY_FLOAT16, GDK_MEMORY_FLOAT32, GDK_MEMORY_FLOAT16, GDK_MEMORY_FLOAT32 },
return depth2; [GDK_MEMORY_FLOAT32] = { GDK_MEMORY_FLOAT32, GDK_MEMORY_FLOAT32, GDK_MEMORY_FLOAT32, GDK_MEMORY_FLOAT32, GDK_MEMORY_FLOAT32 },
};
case GDK_MEMORY_U8_SRGB: g_assert (depth1 < GDK_N_DEPTHS);
if (depth2 == GDK_MEMORY_U8) g_assert (depth2 < GDK_N_DEPTHS);
return GDK_MEMORY_FLOAT16;
else
return depth2;
case GDK_MEMORY_FLOAT32: return merged_depths[depth1][depth2];
return GDK_MEMORY_FLOAT32;
case GDK_MEMORY_U16:
case GDK_MEMORY_FLOAT16:
if (depth2 == depth1 || depth2 == GDK_MEMORY_U8)
return depth1;
else
return GDK_MEMORY_FLOAT32;
case GDK_N_DEPTHS:
default:
g_assert_not_reached ();
return GDK_MEMORY_U8;
}
} }
/* /*