Skip to content

Commit 9e9b5bb

Browse files
committed
add raise ValueError
1 parent 5dbcd44 commit 9e9b5bb

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

nvjpeg-python.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,8 @@ static PyObject* NvJpeg_decode(NvJpeg* Self, PyObject* Argvs)
286286
unsigned char* jpegData;
287287
int len;
288288
if(!PyArg_ParseTuple(Argvs, "y#", &jpegData, &len)){
289-
printf("Parse the argument FAILED! You should jpegData byte string!\n");
290-
Py_INCREF(Py_None);
291-
return Py_None;
289+
PyErr_SetString(PyExc_ValueError, "Parse the argument FAILED! You should jpegData byte string!");
290+
return NULL;
292291
}
293292
NvJpegPythonImage* img = NvJpegPython_decode(m_handle, (const unsigned char*)jpegData, len);
294293

@@ -319,24 +318,22 @@ static PyObject* NvJpeg_encode(NvJpeg* Self, PyObject* Argvs)
319318
PyArrayObject *vecin;
320319
unsigned int quality = 70;
321320
if (!PyArg_ParseTuple(Argvs, "O!|I", &PyArray_Type, &vecin, &quality)){
322-
printf("Parse the argument FAILED! You should pass BGR image numpy array!\n");
323-
Py_INCREF(Py_None);
324-
return Py_None;
321+
PyErr_SetString(PyExc_ValueError, "Parse the argument FAILED! You should pass BGR image numpy array!");
322+
return NULL;
325323
}
326324

327325
if (NULL == vecin){
328326
Py_INCREF(Py_None);
329327
return Py_None;
330328
}
331329

332-
if(quality>100){
333-
quality = 100;
330+
if (PyArray_NDIM(vecin) != 3){
331+
PyErr_SetString(PyExc_ValueError, "Parse the argument FAILED! You should pass BGR image numpy array by height*width*channel!");
332+
return NULL;
334333
}
335334

336-
if (PyArray_NDIM(vecin) != 3){
337-
printf("Parse the argument FAILED! You should pass BGR image numpy array by height*width*channel !\n");
338-
Py_INCREF(Py_None);
339-
return Py_None;
335+
if(quality>100){
336+
quality = 100;
340337
}
341338

342339
NvJpegPythonHandle* m_handle = (NvJpegPythonHandle*)Self->m_handle;

0 commit comments

Comments
 (0)