Skip to content

Commit 251abfe

Browse files
committed
chang uint8_t * to char * with base64 encode
1 parent 601f409 commit 251abfe

File tree

3 files changed

+155
-13
lines changed

3 files changed

+155
-13
lines changed

.idea/workspace.xml

Lines changed: 141 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stable-diffusion-abi.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ bool load_from_file(void* sd, const char* file_path, const char* schedule)
207207
return false;
208208
};
209209

210-
uint8_t* txt2img(void* sd, const sd_txt2img_options* opt, int64_t* output_size)
210+
const char* txt2img(void* sd, const sd_txt2img_options* opt)
211211
{
212212
const auto sm = std::string(opt->sample_method);
213213
const auto it = SampleMethodMap.find(sm);
@@ -224,16 +224,16 @@ uint8_t* txt2img(void* sd, const sd_txt2img_options* opt, int64_t* output_size)
224224
/* int sample_steps */ opt->sample_steps,
225225
/* int64_t seed */ opt->seed
226226
);
227-
*output_size = static_cast<int64_t>(result.size());
228-
const auto buffer = new uint8_t[result.size()];
229-
std::memcpy(buffer, result.data(), result.size());
227+
const auto str=code::base64_encode<std::string,std::vector<uint8_t>>(result,false);
228+
const auto buffer = new char[str.size()];
229+
std::memcpy(buffer, str.c_str(), str.size());
230230
return buffer;
231231
}
232232
delete opt;
233233
return nullptr;
234234
};
235235

236-
uint8_t* img2img(void* sd, const sd_img2img_options* opt, int64_t* output_size)
236+
const char* img2img(void* sd, const sd_img2img_options* opt)
237237
{
238238
const auto sm = std::string(opt->sample_method);
239239
const auto it = SampleMethodMap.find(sm);
@@ -253,10 +253,11 @@ uint8_t* img2img(void* sd, const sd_img2img_options* opt, int64_t* output_size)
253253
/* float strength */ opt->strength,
254254
/* int64_t seed */ opt->seed
255255
);
256-
*output_size = static_cast<int64_t>(result.size());
257-
const auto buffer = new uint8_t[result.size()];
258-
std::memcpy(buffer, result.data(), result.size());
256+
const auto str=code::base64_encode<std::string,std::vector<uint8_t>>(result,false);
257+
const auto buffer = new char[str.size()];
258+
std::memcpy(buffer, str.c_str(), str.size());
259259
return buffer;
260+
260261
}
261262
delete opt;
262263
return nullptr;
@@ -276,12 +277,12 @@ const char* get_stable_diffusion_system_info()
276277
{
277278
const std::string info = sd_get_system_info();
278279
const size_t length = info.size() + 1;
279-
char* buffer = new char[length];
280+
const auto buffer = new char[length];
280281
std::memcpy(buffer, info.c_str(), length);
281282
return buffer;
282283
};
283284

284-
void free_buffer(const uint8_t* buffer)
285+
void free_buffer(const char* buffer)
285286
{
286287
delete [] buffer;
287288
}

stable-diffusion-abi.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ STABLE_DIFFUSION_API void destroy_stable_diffusion(void* sd);
7979

8080
STABLE_DIFFUSION_API bool load_from_file(void* sd, const char* file_path, const char* schedule);
8181

82-
STABLE_DIFFUSION_API uint8_t* txt2img(void* sd, const sd_txt2img_options* opt, int64_t* output_size);
82+
STABLE_DIFFUSION_API const char * txt2img(void* sd, const sd_txt2img_options* opt);
8383

84-
STABLE_DIFFUSION_API uint8_t* img2img(void* sd, const sd_img2img_options* opt, int64_t* output_size);
84+
STABLE_DIFFUSION_API const char* img2img(void* sd, const sd_img2img_options* opt);
8585

8686
STABLE_DIFFUSION_API void set_stable_diffusion_log_level(const char* level);
8787

8888
STABLE_DIFFUSION_API const char* get_stable_diffusion_system_info();
8989

90-
STABLE_DIFFUSION_API void free_buffer(const uint8_t* buffer);
90+
STABLE_DIFFUSION_API void free_buffer(const char* buffer);
9191

9292
#ifdef __cplusplus
9393
}

0 commit comments

Comments
 (0)