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

Function upscalerModel

plugins/wasmedge_stablediffusion/sd_func.cpp:130–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130void upscalerModel(const char *UpscaleModelPath, uint32_t UpscaleRepeats,
131 int32_t NThreads, uint32_t BatchCount, sd_image_t *Results) {
132 // unused for RealESRGAN_x4plus_anime_6B.pth
133 int UpscaleFactor = 4;
134 upscaler_ctx_t *UpscalerCtx = new_upscaler_ctx(UpscaleModelPath, NThreads);
135 if (UpscalerCtx == nullptr) {
136 spdlog::error("[WasmEdge-StableDiffusion] Create upscaler ctx failed."sv);
137 } else {
138 for (uint32_t I = 0; I < BatchCount; I++) {
139 if (Results[I].data == nullptr) {
140 continue;
141 }
142 sd_image_t CurrentImage = Results[I];
143 for (uint32_t U = 0; U < UpscaleRepeats; ++U) {
144 sd_image_t UpscaledImage =
145 upscale(UpscalerCtx, CurrentImage, UpscaleFactor);
146 if (UpscaledImage.data == nullptr) {
147 spdlog::error("[WasmEdge-StableDiffusion] Upscale failed."sv);
148 break;
149 }
150 free(CurrentImage.data);
151 CurrentImage = UpscaledImage;
152 }
153 // Set the final upscaled image as the result.
154 Results[I] = CurrentImage;
155 }
156 }
157 free(UpscalerCtx);
158}
159
160bool saveResults(sd_image_t *Results, uint32_t BatchCount,
161 std::string OutputPath, uint32_t OutputPathLen,

Callers 1

bodyMethod · 0.85

Calls 1

errorFunction · 0.50

Tested by

no test coverage detected