MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / ImFontAtlasTextureBlockConvert

Function ImFontAtlasTextureBlockConvert

imgui_tiny_app/imgui/imgui_draw.cpp:2859–2892  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2857}
2858
2859void ImFontAtlasTextureBlockConvert(const unsigned char* src_pixels, ImTextureFormat src_fmt, int src_pitch, unsigned char* dst_pixels, ImTextureFormat dst_fmt, int dst_pitch, int w, int h)
2860{
2861 IM_ASSERT(src_pixels != NULL && dst_pixels != NULL);
2862 if (src_fmt == dst_fmt)
2863 {
2864 int line_sz = w * ImTextureDataGetFormatBytesPerPixel(src_fmt);
2865 for (int ny = h; ny > 0; ny--, src_pixels += src_pitch, dst_pixels += dst_pitch)
2866 memcpy(dst_pixels, src_pixels, line_sz);
2867 }
2868 else if (src_fmt == ImTextureFormat_Alpha8 && dst_fmt == ImTextureFormat_RGBA32)
2869 {
2870 for (int ny = h; ny > 0; ny--, src_pixels += src_pitch, dst_pixels += dst_pitch)
2871 {
2872 const ImU8* src_p = (const ImU8*)src_pixels;
2873 ImU32* dst_p = (ImU32*)(void*)dst_pixels;
2874 for (int nx = w; nx > 0; nx--)
2875 *dst_p++ = IM_COL32(255, 255, 255, (unsigned int)(*src_p++));
2876 }
2877 }
2878 else if (src_fmt == ImTextureFormat_RGBA32 && dst_fmt == ImTextureFormat_Alpha8)
2879 {
2880 for (int ny = h; ny > 0; ny--, src_pixels += src_pitch, dst_pixels += dst_pitch)
2881 {
2882 const ImU32* src_p = (const ImU32*)(void*)src_pixels;
2883 ImU8* dst_p = (ImU8*)dst_pixels;
2884 for (int nx = w; nx > 0; nx--)
2885 *dst_p++ = ((*src_p++) >> IM_COL32_A_SHIFT) & 0xFF;
2886 }
2887 }
2888 else
2889 {
2890 IM_ASSERT(0);
2891 }
2892}
2893
2894// Source buffer may be written to (used for in-place mods).
2895// Post-process hooks may eventually be added here.

Callers 1

Tested by

no test coverage detected