Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitccae95a

Browse files
dellduleejet
andauthored
feat: support RGBA image input of flexible size (leejet#212)
* Support png image and resize image with 64 pixels in img2img mode* update the error information---------Co-authored-by: leejet <leejet714@gmail.com>
1 parent90e9178 commitccae95a

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

‎examples/cli/main.cpp‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#defineSTB_IMAGE_WRITE_STATIC
1818
#include"stb_image_write.h"
1919

20+
#include"stb_image_resize.h"
21+
2022
constchar* rng_type_to_str[] = {
2123
"std_default",
2224
"cuda",
@@ -663,21 +665,47 @@ int main(int argc, const char* argv[]) {
663665
fprintf(stderr,"load image from '%s' failed\n", params.input_path.c_str());
664666
return1;
665667
}
666-
if (c!=3) {
667-
fprintf(stderr,"input image must bea 3 channels RGB image, but got %d channels\n", c);
668+
if (c<3) {
669+
fprintf(stderr,"the number of channels for theinput image must be>= 3, but got %d channels\n", c);
668670
free(input_image_buffer);
669671
return1;
670672
}
671-
if (params.width <=0 || params.width %64 !=0) {
672-
fprintf(stderr,"error: the width of image must bea multiple of 64\n");
673+
if (params.width <=0) {
674+
fprintf(stderr,"error: the width of image must begreater than 0\n");
673675
free(input_image_buffer);
674676
return1;
675677
}
676-
if (params.height <=0 || params.height %64 !=0) {
677-
fprintf(stderr,"error: the height of image must bea multiple of 64\n");
678+
if (params.height <=0) {
679+
fprintf(stderr,"error: the height of image must begreater than 0\n");
678680
free(input_image_buffer);
679681
return1;
680682
}
683+
684+
// Resize input image ...
685+
if (params.height %64 !=0 || params.width %64 !=0) {
686+
int resized_height = params.height + (64 - params.height %64);
687+
int resized_width = params.width + (64 - params.width %64);
688+
689+
uint8_t *resized_image_buffer = (uint8_t *)malloc(resized_height * resized_width *3);
690+
if (resized_image_buffer ==NULL) {
691+
fprintf(stderr,"error: allocate memory for resize input image\n");
692+
free(input_image_buffer);
693+
return1;
694+
}
695+
stbir_resize(input_image_buffer, params.width, params.height,0,
696+
resized_image_buffer, resized_width, resized_height,0, STBIR_TYPE_UINT8,
697+
3/*RGB channel*/, STBIR_ALPHA_CHANNEL_NONE,0,
698+
STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP,
699+
STBIR_FILTER_BOX, STBIR_FILTER_BOX,
700+
STBIR_COLORSPACE_SRGB,nullptr
701+
);
702+
703+
// Save resized result
704+
free(input_image_buffer);
705+
input_image_buffer = resized_image_buffer;
706+
params.height = resized_height;
707+
params.width = resized_width;
708+
}
681709
}
682710

683711
sd_ctx_t* sd_ctx =new_sd_ctx(params.model_path.c_str(),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp