MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / readControlImage

Function readControlImage

plugins/wasmedge_stablediffusion/sd_func.cpp:80–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80sd_image_t *readControlImage(Span<uint8_t> ControlImage, int Width, int Height,
81 bool CannyPreprocess) {
82 uint8_t *ControlImageBuffer = nullptr;
83 sd_image_t *ControlImg = nullptr;
84 int Channel = 0;
85 std::string ControlImagePath(ControlImage.begin(), ControlImage.end());
86
87 if (ControlImagePath.substr(0, 5) == "path:"sv) {
88 ControlImageBuffer = stbi_load(ControlImagePath.substr(5).data(), &Width,
89 &Height, &Channel, 3);
90 } else {
91 ControlImageBuffer = stbi_load_from_memory(
92 ControlImage.data(), ControlImage.size(), &Width, &Height, &Channel, 3);
93 }
94
95 if (ControlImageBuffer == nullptr) {
96 spdlog::error(
97 "[WasmEdge-StableDiffusion] Load image from control image failed."sv);
98 return nullptr;
99 }
100 ControlImg =
101 new sd_image_t{static_cast<uint32_t>(Width),
102 static_cast<uint32_t>(Height), 3, ControlImageBuffer};
103 if (CannyPreprocess) { // apply preprocessor
104 ControlImg->data =
105 preprocess_canny(ControlImg->data, ControlImg->width,
106 ControlImg->height, 0.08f, 0.08f, 0.8f, 1.0f, false);
107 }
108 free(ControlImageBuffer);
109 return ControlImg;
110}
111
112sd_image_t readMaskImage(Span<uint8_t> MaskImage, int Width, int Height) {
113 uint8_t *MaskImageBuffer = NULL;

Callers 1

bodyMethod · 0.85

Calls 6

substrMethod · 0.80
errorFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected