Skip to content

Commit c18fcd5

Browse files
committed
1.9.4 fix de-nearest
1 parent 571f9c9 commit c18fcd5

File tree

4 files changed

+35
-38
lines changed

4 files changed

+35
-38
lines changed

RealSR-NCNN-Android-CLI/Resize/src/main/jni/main.cpp

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -548,22 +548,21 @@ int main(int argc, char **argv)
548548
} else {
549549
not_use_ncnn = false;
550550
if (abs(scale_y - scale_x) < 1)
551-
scale_d = round((scale_x + scale_y) / 2);
551+
scale = round((scale_x + scale_y) / 2);
552552
else if (scale_x > scale_y)
553-
scale_d = round(scale_y);
553+
scale = round(scale_y);
554554
else
555-
scale_d = round(scale_x);
555+
scale = round(scale_x);
556556

557-
fprintf(stderr, "image might be interpolated by nearest x%.0f\n", scale_d);
558557
scale_d = 1 / scale_d;
558+
fprintf(stderr, "image might be interpolated by nearest x%d\n", scale);
559559
}
560560
}
561561
}
562562

563563

564564
int out_w, out_h;
565-
if (scale != scale_d || !not_use_ncnn) {
566-
// fprintf(stderr, "reset scale\n");
565+
if ( scale_d<1 ) {
567566
out_w = (int) (w * scale_d);
568567
out_h = (int) (h * scale_d);
569568
} else {
@@ -629,13 +628,12 @@ int main(int argc, char **argv)
629628
}
630629
}
631630
} else {
632-
631+
if(scale_d>=1)
633632
{
634633
int p = 0;
635634
int q = 0;
636635
//row
637636
for (int i = 0; i < h; i++) {
638-
639637
//line
640638
void *l = buf + q;
641639
for (int j = 0; j < w; j++) {
@@ -645,36 +643,25 @@ int main(int argc, char **argv)
645643
memcpy(buf + q, pixeldata + p, sizeof(unsigned char) * c);
646644
q += c;
647645
}
648-
649-
if (verbose) {
650-
fprintf(stderr, "i:%d j:%d :", i, j);
651-
for (int i = 0; i < 32; i++) {
652-
fprintf(stderr, " %02X", buf[i]
653-
);
654-
}
655-
fprintf(stderr, " ,m=%d %d\n", p, q);
656-
}
657-
658646
p += c;
659647
}
660-
661-
662-
663648
// mult-line
664649
for (int k = 1; k < scale; k++) {
665650
memcpy(buf + q, l, sizeof(unsigned char) * out_line_size);
666651
q += out_line_size;
667652
}
668-
669-
670-
/*
671-
* print
672-
w++;
673-
if(w==100){
674-
w=0;
675-
fprintf(stderr, "%.2f%%\n", (i+1)*1e2/h);
676-
}
677-
*/
653+
}
654+
}else{
655+
// de-nearest
656+
int p=(scale-1)/2, q=0;
657+
double step = 1/scale_d;
658+
// row
659+
for(int i=0;i<out_h;i++){
660+
for(int j=0;j<out_w;j++){
661+
memcpy(buf + q, pixeldata + p+j*scale, sizeof(unsigned char) * c);
662+
q+=c;
663+
}
664+
p+=w*c;
678665
}
679666
}
680667
}
@@ -861,7 +848,7 @@ int main(int argc, char **argv)
861848
success = false;
862849
} else {
863850
success = imwrite(outputpath.c_str(), image);
864-
fprintf(stderr, "opencv save image success, c=%d, w=%d, h=%d\n", c, w, h);
851+
fprintf(stderr, "opencv save image success, c=%d, w=%d, h=%d\n", c, out_w, out_h);
865852
}
866853
}else
867854
#endif

RealSR-NCNN-Android-GUI/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
applicationId "com.tumuyan.ncnn.realsr"
1010
minSdk 24
1111
targetSdk 28
12-
versionCode 38
13-
versionName '1.9.3'
12+
versionCode 39
13+
versionName '1.9.4'
1414

1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
}

RealSR-NCNN-Android-GUI/app/src/main/res/values-zh/strings.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@
4545
\n算法包含但不限于不限于Box Cubic Hamming Jinc Lanczos Lagrange Mitchell Sinc,可以通过命令./magick -list filter查看支持的全部算法。也可以参阅说明 https://legacy.imagemagick.org/Usage/filter
4646
\nImageMagick的功能非常强大,示例命令仅仅是缩放图片的调用。
4747

48-
\n\n四、显示指定信息
48+
\n\n四、Anime4K
49+
\n本应用内置了Anime4KCPP https://github.com/TianZerL/Anime4KCPP
50+
\n这个项目包含了Anime4K 0.9 算法(也就是说并非最新版)以及 ACNet (一个基于卷积神经网络的超分辨率算法)
51+
\n它所支持的参数详见说明 https://github.com/TianZerL/Anime4KCPP/wiki/CLI
52+
53+
\n\n五、显示指定信息
4954
\n in 显示输入的图像
5055
\n out 显示输出的图像
5156
\n show (跟随图像的路径作为参数)显示指定路径的图像
5257
\n help 显示帮助信息
53-
\n\n五、调用shell命令
58+
59+
\n\n六、调用shell命令
5460
\n 如ls head cp rm等等
5561
</string>
5662
<string name="input_command">输入shell命令,如 ./realsr-ncnn -i input.png -o output.png</string>

RealSR-NCNN-Android-GUI/app/src/main/res/values/strings.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
\n./magick input.png -filter filter -resize n% output.png
2727
\nfilter could be Box Cubic Hamming Jinc Lanczos Lagrange Mitchell Sinc, etc,intpu ./magick -list filter and see more filter, or visit https://legacy.imagemagick.org/Usage/filter
2828

29+
\n\n4、Anime4K https://github.com/TianZerL/Anime4KCPP
30+
\nIt contains Anime4K 0.9 (not the latest) and ACNet.
31+
\nPlease visit the wiki to get more information. https://github.com/TianZerL/Anime4KCPP/wiki/CLI
2932

30-
\n\n4.Show image/info
33+
\n\n5.Show image/info
3134
\n in
3235
\n out
3336
\n show
3437
\n help
35-
\n\n5.Shell command
38+
39+
\n\n6.Shell command
3640
\nls head cp rm etc.
3741
\n\n
3842
Tips.

0 commit comments

Comments
 (0)