Skip to content

Commit

Permalink
chang uint8_t * to char * with base64 encode
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberhan123 committed Nov 26, 2023
1 parent 601f409 commit 251abfe
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 13 deletions.
141 changes: 141 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions stable-diffusion-abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool load_from_file(void* sd, const char* file_path, const char* schedule)
return false;
};

uint8_t* txt2img(void* sd, const sd_txt2img_options* opt, int64_t* output_size)
const char* txt2img(void* sd, const sd_txt2img_options* opt)
{
const auto sm = std::string(opt->sample_method);
const auto it = SampleMethodMap.find(sm);
Expand All @@ -224,16 +224,16 @@ uint8_t* txt2img(void* sd, const sd_txt2img_options* opt, int64_t* output_size)
/* int sample_steps */ opt->sample_steps,
/* int64_t seed */ opt->seed
);
*output_size = static_cast<int64_t>(result.size());
const auto buffer = new uint8_t[result.size()];
std::memcpy(buffer, result.data(), result.size());
const auto str=code::base64_encode<std::string,std::vector<uint8_t>>(result,false);
const auto buffer = new char[str.size()];
std::memcpy(buffer, str.c_str(), str.size());
return buffer;
}
delete opt;
return nullptr;
};

uint8_t* img2img(void* sd, const sd_img2img_options* opt, int64_t* output_size)
const char* img2img(void* sd, const sd_img2img_options* opt)
{
const auto sm = std::string(opt->sample_method);
const auto it = SampleMethodMap.find(sm);
Expand All @@ -253,10 +253,11 @@ uint8_t* img2img(void* sd, const sd_img2img_options* opt, int64_t* output_size)
/* float strength */ opt->strength,
/* int64_t seed */ opt->seed
);
*output_size = static_cast<int64_t>(result.size());
const auto buffer = new uint8_t[result.size()];
std::memcpy(buffer, result.data(), result.size());
const auto str=code::base64_encode<std::string,std::vector<uint8_t>>(result,false);
const auto buffer = new char[str.size()];
std::memcpy(buffer, str.c_str(), str.size());
return buffer;

}
delete opt;
return nullptr;
Expand All @@ -276,12 +277,12 @@ const char* get_stable_diffusion_system_info()
{
const std::string info = sd_get_system_info();
const size_t length = info.size() + 1;
char* buffer = new char[length];
const auto buffer = new char[length];
std::memcpy(buffer, info.c_str(), length);
return buffer;
};

void free_buffer(const uint8_t* buffer)
void free_buffer(const char* buffer)
{
delete [] buffer;
}
6 changes: 3 additions & 3 deletions stable-diffusion-abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ STABLE_DIFFUSION_API void destroy_stable_diffusion(void* sd);

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

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

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

STABLE_DIFFUSION_API void set_stable_diffusion_log_level(const char* level);

STABLE_DIFFUSION_API const char* get_stable_diffusion_system_info();

STABLE_DIFFUSION_API void free_buffer(const uint8_t* buffer);
STABLE_DIFFUSION_API void free_buffer(const char* buffer);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 251abfe

Please sign in to comment.