MCPcopy Create free account
hub / github.com/DiscordMessenger/dm / DecodeWithStbImage

Function DecodeWithStbImage

src/windows/ImageLoader.cpp:90–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88#include <stb/stb_image_write.h>
89
90static Image DecodeWithStbImage(const uint8_t* pData, size_t size)
91{
92 if (size > INT_MAX)
93 return Image();
94
95 // note: doing some work with raw STBI contexts here. don't mind it.
96 /*
97 stbi__context s;
98 stbi__start_mem(&s, pData, (int) size); // why do you have to be an INT here...
99
100 if (stbi__gif_test(&s)) {
101
102 }
103 */
104
105 int x = 0, w = 0, h = 0;
106 stbi_uc* dataStbi = stbi_load_from_memory(pData, int(size), &w, &h, &x, 4);
107 if (!dataStbi)
108 return Image();
109
110 // byte swap because stbi is annoying
111 for (int i = 0; i < w * h; i++)
112 {
113 stbi_uc* pd = &dataStbi[i * 4];
114 stbi_uc tmp = pd[0];
115 pd[0] = pd[2];
116 pd[2] = tmp;
117 }
118
119 return Image(ImageFrame(dataStbi, stbi_image_free, 0), w, h);
120}
121
122#else
123

Callers 1

ConvertToBitmapMethod · 0.85

Calls 2

ImageClass · 0.85
ImageFrameClass · 0.85

Tested by

no test coverage detected