mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-07-23 11:20:53 -05:00
chore: add .clang-tidy configuration and apply modernize checks (#902)
This commit is contained in:
@@ -808,7 +808,7 @@ void parse_args(int argc, const char** argv, SDParams& params) {
|
||||
return -1;
|
||||
}
|
||||
const char* mode = argv[index];
|
||||
if (mode != NULL) {
|
||||
if (mode != nullptr) {
|
||||
int mode_found = -1;
|
||||
for (int i = 0; i < MODE_COUNT; i++) {
|
||||
if (!strcmp(mode, modes_str[i])) {
|
||||
@@ -1199,7 +1199,7 @@ void parse_args(int argc, const char** argv, SDParams& params) {
|
||||
}
|
||||
|
||||
if (params.seed < 0) {
|
||||
srand((int)time(NULL));
|
||||
srand((int)time(nullptr));
|
||||
params.seed = rand();
|
||||
}
|
||||
|
||||
@@ -1314,9 +1314,9 @@ void sd_log_cb(enum sd_log_level_t level, const char* log, void* data) {
|
||||
uint8_t* load_image(const char* image_path, int& width, int& height, int expected_width = 0, int expected_height = 0, int expected_channel = 3) {
|
||||
int c = 0;
|
||||
uint8_t* image_buffer = (uint8_t*)stbi_load(image_path, &width, &height, &c, expected_channel);
|
||||
if (image_buffer == NULL) {
|
||||
if (image_buffer == nullptr) {
|
||||
fprintf(stderr, "load image from '%s' failed\n", image_path);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
if (c < expected_channel) {
|
||||
fprintf(stderr,
|
||||
@@ -1326,17 +1326,17 @@ uint8_t* load_image(const char* image_path, int& width, int& height, int expecte
|
||||
c,
|
||||
image_path);
|
||||
free(image_buffer);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
if (width <= 0) {
|
||||
fprintf(stderr, "error: the width of image must be greater than 0, image_path = %s\n", image_path);
|
||||
free(image_buffer);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
if (height <= 0) {
|
||||
fprintf(stderr, "error: the height of image must be greater than 0, image_path = %s\n", image_path);
|
||||
free(image_buffer);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Resize input image ...
|
||||
@@ -1358,10 +1358,10 @@ uint8_t* load_image(const char* image_path, int& width, int& height, int expecte
|
||||
if (crop_x != 0 || crop_y != 0) {
|
||||
printf("crop input image from %dx%d to %dx%d, image_path = %s\n", width, height, crop_w, crop_h, image_path);
|
||||
uint8_t* cropped_image_buffer = (uint8_t*)malloc(crop_w * crop_h * expected_channel);
|
||||
if (cropped_image_buffer == NULL) {
|
||||
if (cropped_image_buffer == nullptr) {
|
||||
fprintf(stderr, "error: allocate memory for crop\n");
|
||||
free(image_buffer);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
for (int row = 0; row < crop_h; row++) {
|
||||
uint8_t* src = image_buffer + ((crop_y + row) * width + crop_x) * expected_channel;
|
||||
@@ -1380,10 +1380,10 @@ uint8_t* load_image(const char* image_path, int& width, int& height, int expecte
|
||||
int resized_width = expected_width;
|
||||
|
||||
uint8_t* resized_image_buffer = (uint8_t*)malloc(resized_height * resized_width * expected_channel);
|
||||
if (resized_image_buffer == NULL) {
|
||||
if (resized_image_buffer == nullptr) {
|
||||
fprintf(stderr, "error: allocate memory for resize input image\n");
|
||||
free(image_buffer);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
stbir_resize(image_buffer, width, height, 0,
|
||||
resized_image_buffer, resized_width, resized_height, 0, STBIR_TYPE_UINT8,
|
||||
@@ -1434,7 +1434,7 @@ bool load_images_from_dir(const std::string dir,
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
uint8_t* image_buffer = load_image(path.c_str(), width, height, expected_width, expected_height);
|
||||
if (image_buffer == NULL) {
|
||||
if (image_buffer == nullptr) {
|
||||
fprintf(stderr, "load image from '%s' failed\n", path.c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -1486,10 +1486,10 @@ int main(int argc, const char* argv[]) {
|
||||
}
|
||||
|
||||
bool vae_decode_only = true;
|
||||
sd_image_t init_image = {(uint32_t)params.width, (uint32_t)params.height, 3, NULL};
|
||||
sd_image_t end_image = {(uint32_t)params.width, (uint32_t)params.height, 3, NULL};
|
||||
sd_image_t control_image = {(uint32_t)params.width, (uint32_t)params.height, 3, NULL};
|
||||
sd_image_t mask_image = {(uint32_t)params.width, (uint32_t)params.height, 1, NULL};
|
||||
sd_image_t init_image = {(uint32_t)params.width, (uint32_t)params.height, 3, nullptr};
|
||||
sd_image_t end_image = {(uint32_t)params.width, (uint32_t)params.height, 3, nullptr};
|
||||
sd_image_t control_image = {(uint32_t)params.width, (uint32_t)params.height, 3, nullptr};
|
||||
sd_image_t mask_image = {(uint32_t)params.width, (uint32_t)params.height, 1, nullptr};
|
||||
std::vector<sd_image_t> ref_images;
|
||||
std::vector<sd_image_t> pmid_images;
|
||||
std::vector<sd_image_t> control_frames;
|
||||
@@ -1501,17 +1501,17 @@ int main(int argc, const char* argv[]) {
|
||||
free(mask_image.data);
|
||||
for (auto image : ref_images) {
|
||||
free(image.data);
|
||||
image.data = NULL;
|
||||
image.data = nullptr;
|
||||
}
|
||||
ref_images.clear();
|
||||
for (auto image : pmid_images) {
|
||||
free(image.data);
|
||||
image.data = NULL;
|
||||
image.data = nullptr;
|
||||
}
|
||||
pmid_images.clear();
|
||||
for (auto image : control_frames) {
|
||||
free(image.data);
|
||||
image.data = NULL;
|
||||
image.data = nullptr;
|
||||
}
|
||||
control_frames.clear();
|
||||
};
|
||||
@@ -1522,7 +1522,7 @@ int main(int argc, const char* argv[]) {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
init_image.data = load_image(params.init_image_path.c_str(), width, height, params.width, params.height);
|
||||
if (init_image.data == NULL) {
|
||||
if (init_image.data == nullptr) {
|
||||
fprintf(stderr, "load image from '%s' failed\n", params.init_image_path.c_str());
|
||||
release_all_resources();
|
||||
return 1;
|
||||
@@ -1535,7 +1535,7 @@ int main(int argc, const char* argv[]) {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
end_image.data = load_image(params.end_image_path.c_str(), width, height, params.width, params.height);
|
||||
if (end_image.data == NULL) {
|
||||
if (end_image.data == nullptr) {
|
||||
fprintf(stderr, "load image from '%s' failed\n", params.end_image_path.c_str());
|
||||
release_all_resources();
|
||||
return 1;
|
||||
@@ -1547,7 +1547,7 @@ int main(int argc, const char* argv[]) {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
mask_image.data = load_image(params.mask_image_path.c_str(), width, height, params.width, params.height, 1);
|
||||
if (mask_image.data == NULL) {
|
||||
if (mask_image.data == nullptr) {
|
||||
fprintf(stderr, "load image from '%s' failed\n", params.mask_image_path.c_str());
|
||||
release_all_resources();
|
||||
return 1;
|
||||
@@ -1555,7 +1555,7 @@ int main(int argc, const char* argv[]) {
|
||||
} else {
|
||||
mask_image.data = (uint8_t*)malloc(params.width * params.height);
|
||||
memset(mask_image.data, 255, params.width * params.height);
|
||||
if (mask_image.data == NULL) {
|
||||
if (mask_image.data == nullptr) {
|
||||
fprintf(stderr, "malloc mask image failed\n");
|
||||
release_all_resources();
|
||||
return 1;
|
||||
@@ -1566,7 +1566,7 @@ int main(int argc, const char* argv[]) {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
control_image.data = load_image(params.control_image_path.c_str(), width, height, params.width, params.height);
|
||||
if (control_image.data == NULL) {
|
||||
if (control_image.data == nullptr) {
|
||||
fprintf(stderr, "load image from '%s' failed\n", params.control_image_path.c_str());
|
||||
release_all_resources();
|
||||
return 1;
|
||||
@@ -1587,7 +1587,7 @@ int main(int argc, const char* argv[]) {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
uint8_t* image_buffer = load_image(path.c_str(), width, height);
|
||||
if (image_buffer == NULL) {
|
||||
if (image_buffer == nullptr) {
|
||||
fprintf(stderr, "load image from '%s' failed\n", path.c_str());
|
||||
release_all_resources();
|
||||
return 1;
|
||||
@@ -1669,18 +1669,18 @@ int main(int argc, const char* argv[]) {
|
||||
if (params.mode == UPSCALE) {
|
||||
num_results = 1;
|
||||
results = (sd_image_t*)calloc(num_results, sizeof(sd_image_t));
|
||||
if (results == NULL) {
|
||||
if (results == nullptr) {
|
||||
printf("failed to allocate results array\n");
|
||||
release_all_resources();
|
||||
return 1;
|
||||
}
|
||||
|
||||
results[0] = init_image;
|
||||
init_image.data = NULL;
|
||||
init_image.data = nullptr;
|
||||
} else {
|
||||
sd_ctx_t* sd_ctx = new_sd_ctx(&sd_ctx_params);
|
||||
|
||||
if (sd_ctx == NULL) {
|
||||
if (sd_ctx == nullptr) {
|
||||
printf("new_sd_ctx_t failed\n");
|
||||
release_all_resources();
|
||||
return 1;
|
||||
@@ -1743,7 +1743,7 @@ int main(int argc, const char* argv[]) {
|
||||
results = generate_video(sd_ctx, &vid_gen_params, &num_results);
|
||||
}
|
||||
|
||||
if (results == NULL) {
|
||||
if (results == nullptr) {
|
||||
printf("generate failed\n");
|
||||
free_sd_ctx(sd_ctx);
|
||||
return 1;
|
||||
@@ -1759,17 +1759,17 @@ int main(int argc, const char* argv[]) {
|
||||
params.diffusion_conv_direct,
|
||||
params.n_threads);
|
||||
|
||||
if (upscaler_ctx == NULL) {
|
||||
if (upscaler_ctx == nullptr) {
|
||||
printf("new_upscaler_ctx failed\n");
|
||||
} else {
|
||||
for (int i = 0; i < num_results; i++) {
|
||||
if (results[i].data == NULL) {
|
||||
if (results[i].data == nullptr) {
|
||||
continue;
|
||||
}
|
||||
sd_image_t current_image = results[i];
|
||||
for (int u = 0; u < params.upscale_repeats; ++u) {
|
||||
sd_image_t upscaled_image = upscale(upscaler_ctx, current_image, upscale_factor);
|
||||
if (upscaled_image.data == NULL) {
|
||||
if (upscaled_image.data == nullptr) {
|
||||
printf("upscale failed\n");
|
||||
break;
|
||||
}
|
||||
@@ -1827,7 +1827,7 @@ int main(int argc, const char* argv[]) {
|
||||
file_ext = ".png";
|
||||
}
|
||||
for (int i = 0; i < num_results; i++) {
|
||||
if (results[i].data == NULL) {
|
||||
if (results[i].data == nullptr) {
|
||||
continue;
|
||||
}
|
||||
std::string final_image_path = i > 0 ? base_path + "_" + std::to_string(i + 1) + file_ext : base_path + file_ext;
|
||||
@@ -1845,7 +1845,7 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
for (int i = 0; i < num_results; i++) {
|
||||
free(results[i].data);
|
||||
results[i].data = NULL;
|
||||
results[i].data = nullptr;
|
||||
}
|
||||
free(results);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user