| 88 | #include <stb/stb_image_write.h> |
| 89 | |
| 90 | static 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 |
no test coverage detected