Skip to content

Commit 2e54e03

Browse files
committed
update 1.1.5
1 parent e156f2f commit 2e54e03

File tree

11 files changed

+58
-22
lines changed

11 files changed

+58
-22
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
```
4949
5050
"""
51-
Version = "1.1.4"
51+
Version = "1.1.5"
5252

5353
Plat = sys.platform
5454

setup2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
```
4848
4949
"""
50-
Version = "1.1.4"
50+
Version = "1.1.5"
5151

5252
Plat = sys.platform
5353

src/apng_image.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ bool load_apng(Task& v)
351351
free(p_image);
352352
}
353353
ok = true;
354-
if (v.file.length() == 0) v.file = "apng";
354+
if (v.save_format.length() == 0) v.save_format = "apng";
355+
v.load_format = "apng";
355356
End:
356357

357358
if (png_ptr)

src/other_image.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,26 @@ bool jpg_save(Task& v)
9999

100100
bool to_save(Task &v)
101101
{
102-
if (!v.file.compare("bmp"))
102+
if (!v.save_format.compare("bmp"))
103103
{
104104
return bmp_save(v);
105105
}
106-
else if (!v.file.compare("png"))
106+
else if (!v.save_format.compare("png"))
107107
{
108108
return png_save(v);
109109
}
110-
else if (!v.file.compare("jpg") || !v.file.compare("jpeg"))
110+
else if (!v.save_format.compare("jpg") || !v.save_format.compare("jpeg"))
111111
{
112112
return jpg_save(v);
113113
}
114-
else if (!v.file.compare("webp") || !v.file.compare("gif"))
114+
else if (!v.save_format.compare("webp"))
115115
{
116116
if (v.outImage.size() <= 1)
117117
return webp_save(v);
118118
else
119119
return webp_save_ani(v);
120120
}
121-
else if (!v.file.compare("apng"))
121+
else if (!v.save_format.compare("apng"))
122122
{
123123
return save_apng(v);
124124
}
@@ -197,7 +197,10 @@ bool stbi_xload(Task &v)
197197
v.inFrame.push_back(100);
198198
}
199199
End:
200-
if (v.file.length() == 0) v.file = format;
200+
if (v.save_format.length() == 0) v.save_format = format;
201+
if (!v.save_format.compare("gif")) v.save_format = "webp";
202+
v.load_format = format;
203+
201204
if (pixeldata) stbi_image_free(pixeldata);
202205
if (delays) stbi_image_free(delays);
203206
return ok;

src/stb_image.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6819,7 +6819,7 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y,
68196819
}
68206820
memcpy( out + ((layers - 1) * stride), u, stride );
68216821
if (layers >= 2) {
6822-
two_back = out - 2 * stride;
6822+
two_back = out + ((layers - 2) * stride);
68236823
}
68246824

68256825
if (delays) {

src/waifu2x_main.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static int GpuId;
1515
static int TotalJobsProc = 0;
1616
static int NumThreads = 1;
1717
static int TaskId = 1;
18+
static int WebpQuality = 90;
1819

1920
bool IsDebug = false;
2021

@@ -49,7 +50,7 @@ int waifu2x_getData(void*& out, unsigned long& outSize, double& tick, int& callB
4950
outSize = v.outSize;
5051

5152
v.out = NULL;
52-
strcpy(format, v.file.c_str());
53+
strcpy(format, v.save_format.c_str());
5354
tick = v.allTick;
5455
return v.id;
5556
}
@@ -141,7 +142,7 @@ void* waifu2x_proc(void* args)
141142
name = "cpu";
142143

143144
waifu2x_printf(stdout, "[waifu2x] start encode imageId :%d, gpu:%s, format:%s, model:%s, noise:%d, scale:%d, tta:%d, tileSize:%d\n",
144-
v.callBack, name, v.file.c_str(), waifu2x->mode_name.c_str(), waifu2x->noise, waifu2x->scale, waifu2x->tta_mode, v.tileSize);
145+
v.callBack, name, v.save_format.c_str(), waifu2x->mode_name.c_str(), waifu2x->noise, waifu2x->scale, waifu2x->tta_mode, v.tileSize);
145146
int scale_run_count = 1;
146147
int frame = 0;
147148
for (std::list<ncnn::Mat *>::iterator in = v.inImage.begin(); in != v.inImage.end(); in++)
@@ -590,6 +591,7 @@ int waifu2x_addData(const unsigned char* data, unsigned int size, int callBack,
590591
v.toW = toW;
591592
v.scale = scale;
592593
v.tileSize = tileSize;
594+
v.webp_quality = WebpQuality;
593595
if ((toH <= 0 || toW <= 0) && scale <= 0)
594596
{
595597
waifu2x_set_error("invalid scale params");
@@ -601,10 +603,10 @@ int waifu2x_addData(const unsigned char* data, unsigned int size, int callBack,
601603
waifu2x_set_error("invalid model index");
602604
return sts;
603605
}
604-
if (format) v.file = format;
606+
if (format) v.save_format = format;
605607

606-
transform(v.file.begin(), v.file.end(), v.file.begin(), ::tolower);
607-
if (v.file.length() == 0 || !v.file.compare("jpg") || !v.file.compare("jpeg") || !v.file.compare("png") || !v.file.compare("webp") || !v.file.compare("jpg") || !v.file.compare("bmp") || !v.file.compare("apng"))
608+
transform(v.save_format.begin(), v.save_format.end(), v.save_format.begin(), ::tolower);
609+
if (v.save_format.length() == 0 || !v.save_format.compare("jpg") || !v.save_format.compare("jpeg") || !v.save_format.compare("png") || !v.save_format.compare("webp") || !v.save_format.compare("jpg") || !v.save_format.compare("bmp") || !v.save_format.compare("apng"))
608610
{
609611
Todecode.put(v);
610612
return TaskId;
@@ -650,6 +652,12 @@ int waifu2x_set_debug(bool isdebug)
650652
return 0;
651653
}
652654

655+
int waifu2x_set_webp_quality(int webp_quality)
656+
{
657+
WebpQuality = webp_quality;
658+
return 0;
659+
}
660+
653661
int waifu2x_remove_wait(std::set<int>& taskIds)
654662
{
655663
Todecode.remove(taskIds);

src/waifu2x_main.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class Task
3737
void* fileDate;
3838
int fileSize;
3939
int allFileSize=0;
40-
std::string file;
40+
std::string load_format;
41+
std::string save_format;
4142
std::string err;
4243
bool isSuc = true;
4344

@@ -47,6 +48,7 @@ class Task
4748
unsigned long toH;
4849
float scale = 2;
4950
int tileSize = 0;
51+
int webp_quality = 90;
5052

5153
struct timeb startTick;
5254
struct timeb decodeTick;
@@ -192,6 +194,7 @@ int waifu2x_get_path_size();
192194
int waifu2x_stop();
193195
int waifu2x_clear();
194196
int waifu2x_set_debug(bool);
197+
int waifu2x_set_webp_quality(int);
195198
int waifu2x_printf(void* p, const char* fmt, ...);
196199
int waifu2x_printf(void* p, const wchar_t* fmt, ...);
197200
int waifu2x_remove_wait(std::set<int>&);

src/waifu2x_py.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ waifu2x_py_init_set(PyObject* self, PyObject* args, PyObject* kwargs)
103103
return PyLong_FromLong(sts);
104104
}
105105

106+
static PyObject*
107+
waifu2x_py_set_webp_quality(PyObject* self, PyObject* args)
108+
{
109+
int quality=0;
110+
if (!PyArg_ParseTuple(args, "i", &quality))
111+
PyLong_FromLong(-1);
112+
if (quality <= 0 || quality > 100)
113+
{
114+
return PyLong_FromLong(-1);
115+
}
116+
waifu2x_set_webp_quality(quality);
117+
return PyLong_FromLong(0);
118+
}
106119

107120
static PyObject*
108121
waifu2x_py_clear(PyObject* self, PyObject* args)

src/waifu2x_py.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ waifu2x_py_set_debug(PyObject* self, PyObject* args);
1414
static PyObject*
1515
waifu2x_py_init_set(PyObject* self, PyObject* args, PyObject* kwargs);
1616

17+
static PyObject*
18+
waifu2x_py_set_webp_quality(PyObject* self, PyObject* args);
19+
1720
static PyObject*
1821
waifu2x_py_clear (PyObject* self, PyObject* args);
1922

@@ -58,6 +61,8 @@ static PyMethodDef SpamMethods[] = {
5861
"Init ncnn\n"},
5962
{"initSet", (PyCFunction)waifu2x_py_init_set, METH_VARARGS | METH_KEYWORDS,
6063
"Init setting\ngpuId: getGpuInfo get index \ncpuNum(Option): CPU model use CPU num, default cpu num / 2 \n"},
64+
{"setWebpQuality", (PyCFunction)waifu2x_py_set_webp_quality, METH_VARARGS,
65+
"set webp quality \ncan go from 0 (smaller output, lower quality) to 100 (best quality,larger output) \n"},
6166
{"add", (PyCFunction)waifu2x_py_add, METH_VARARGS | METH_KEYWORDS,
6267
"Add task, \ndata: img bytes \nmodelIndex: Model enum \nbackId: call back id \nformat(Option): export fmt, default import fmt \nimport support bmp png jpg gif webp \nexport support bmp png jpg webp \nwidth(Option): export set width \nhigh(Option): export set high \nscale(Option): export set width and high \ntileSize(Option): default Auto\n"},
6368
{"getGpuInfo", (PyCFunction)waifu2x_py_get_info, METH_VARARGS,
@@ -98,5 +103,5 @@ static struct PyModuleDef spammodule = {
98103

99104
static bool IsInit = false;
100105
static bool IsInitSet = false;
101-
static const char* Version = "1.1.4";
106+
static const char* Version = "1.1.5";
102107
#endif

src/webp_image.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ bool webp_load(Task &v)
4949
}
5050
v.inImage.push_back(inimage);
5151
v.inFrame.push_back(100);
52-
if (v.file.length() == 0) v.file = "webp";
52+
if (v.save_format.length() == 0) v.save_format = "webp";
53+
v.load_format = "webp";
5354
return true;
5455
}
5556

@@ -112,7 +113,8 @@ bool webp_load_ani(Task& v)
112113
++frame_index;
113114
prev_frame_timestamp = timestamp;
114115
}
115-
if (v.file.length() == 0) v.file = "webp";
116+
if (v.save_format.length() == 0) v.save_format = "webp";
117+
v.load_format = "webp";
116118
ok = true;
117119
End:
118120
WebPAnimDecoderDelete(dec);
@@ -169,7 +171,7 @@ bool webp_save_ani(Task &v)
169171
ncnn::Mat & inimage = **i;
170172
int duration= *j;
171173

172-
size = WebPEncodeLosslessRGBA((unsigned char*)inimage.data, inimage.w, inimage.h, inimage.w * (int)inimage.elemsize, &outb);
174+
size = WebPEncodeRGBA((unsigned char*)inimage.data, inimage.w, inimage.h, inimage.w * (int)inimage.elemsize, v.webp_quality, &outb);
173175

174176
const WebPData webp_data = { outb, size };
175177
frame.duration = duration;
@@ -209,11 +211,11 @@ bool webp_save(Task &v)
209211

210212
if (outimage.elemsize == 3)
211213
{
212-
length = WebPEncodeLosslessRGB((unsigned char*)outimage.data, outimage.w, outimage.h, outimage.w * (int)outimage.elemsize, &output);
214+
length = WebPEncodeRGB((unsigned char*)outimage.data, outimage.w, outimage.h, outimage.w * (int)outimage.elemsize, v.webp_quality, &output);
213215
}
214216
else if (outimage.elemsize == 4)
215217
{
216-
length = WebPEncodeLosslessRGBA((unsigned char*)outimage.data, outimage.w, outimage.h, outimage.w * (int)outimage.elemsize, &output);
218+
length = WebPEncodeRGBA((unsigned char*)outimage.data, outimage.w, outimage.h, outimage.w * (int)outimage.elemsize, v.webp_quality, &output);
217219
}
218220
else
219221
{

0 commit comments

Comments
 (0)