Skip to content

Commit b97fe9e

Browse files
committed
support windows
1 parent b3aafcb commit b97fe9e

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

nvjpeg-python.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <structmember.h>
99
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
1010
#include <numpy/arrayobject.h>
11-
#include <JpegCoder.hpp>
11+
#include "JpegCoder.hpp"
1212

1313
typedef struct
1414
{
@@ -128,8 +128,13 @@ static PyObject* NvJpeg_read(NvJpeg* Self, PyObject* Argvs)
128128
PyErr_SetString(PyExc_ValueError, "Parse the argument FAILED! You should pass jpeg file path string!");
129129
return NULL;
130130
}
131-
131+
#ifdef _MSC_VER
132+
FILE* fp;
133+
fopen_s(&fp, (const char*)jpegFile, "rb");
134+
#else
132135
FILE* fp = fopen((const char*)jpegFile, "rb");
136+
#endif
137+
133138
if (fp == NULL){
134139
PyErr_Format(PyExc_IOError, "Cannot open file \"%s\"", jpegFile);
135140
return NULL;
@@ -178,7 +183,13 @@ static PyObject* NvJpeg_write(NvJpeg* Self, PyObject* Argvs)
178183
return NULL;
179184
}
180185

186+
#ifdef _MSC_VER
187+
FILE* fp;
188+
fopen_s(&fp, (const char*)jpegFile, "wb");
189+
#else
181190
FILE* fp = fopen((const char*)jpegFile, "wb");
191+
#endif
192+
182193
if(fp == NULL){
183194
PyErr_Format(PyExc_IOError, "Cannot open file \"%s\"", jpegFile);
184195
return NULL;
@@ -217,12 +228,12 @@ static PyMethodDef NvJpeg_MethodMembers[] =
217228

218229
static PyTypeObject NvJpeg_ClassInfo =
219230
{
220-
PyVarObject_HEAD_INIT(NULL, 0)
231+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
221232
.tp_name = "nvjpeg.NvJpeg",
222233
.tp_basicsize = sizeof(NvJpeg),
223234
.tp_itemsize = 0,
224235
.tp_dealloc = NvJpeg_Destruct,
225-
.tp_print = NULL,
236+
// .tp_print = NULL,
226237
.tp_getattr = NULL,
227238
.tp_setattr = NULL,
228239
.tp_as_async = NULL,

setup.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,21 @@
3333
extension_nvjpeg = Extension('nvjpeg',
3434
['nvjpeg-python.cpp', 'src/x86/JpegCoder.cpp'],
3535
['include', numpy.get_include()],
36-
[('JPEGCODER_ARCH', 'x86')]
36+
[('JPEGCODER_ARCH', 'x86')],
3737
)
38+
elif platform.system() == 'Windows':
39+
cuda_include = '%s\\include' % (os.environ['CUDA_PATH'],)
40+
if platform.machine().endswith('64'):
41+
cuda_lib = '%s\\lib\\x64' % (os.environ['CUDA_PATH'],)
42+
else:
43+
cuda_lib = '%s\\lib\\Win32' % (os.environ['CUDA_PATH'],)
44+
extension_nvjpeg = Extension('nvjpeg',
45+
['nvjpeg-python.cpp', 'src\\x86\\JpegCoder.cpp'],
46+
['include', numpy.get_include(), cuda_include],
47+
[('JPEGCODER_ARCH', 'x86')],
48+
extra_compile_args=['/std:c++latest'],
49+
library_dirs=[cuda_lib],
50+
)
3851

3952

4053
setup(name='pynvjpeg',
@@ -75,5 +88,5 @@
7588
'Source': 'https://github.com/UsingNet/nvjpeg-python',
7689
'Tracker': 'https://github.com/UsingNet/nvjpeg-python/issues',
7790
},
78-
install_requires=['numpy>=1.17', 'wheel>=0.36.2']
91+
install_requires=['numpy>=1.17']
7992
)

src/x86/JpegCoder.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ JpegCoderImage::JpegCoderImage(size_t width, size_t height, short nChannel, Jpeg
2525
nvjpegImage_t *img = (nvjpegImage_t*)malloc(sizeof(nvjpegImage_t));
2626
for(int i = 0;i<NVJPEG_MAX_COMPONENT;i++){
2727
img->channel[i] = pBuffer + (width*height*i);
28-
img->pitch[i] = width;
28+
img->pitch[i] = (unsigned int)width;
2929
}
30-
img->pitch[0] = width*3;
30+
img->pitch[0] = (unsigned int)width*3;
3131

3232
this->img = img;
3333
this->height = height;
@@ -116,7 +116,7 @@ JpegCoderBytes* JpegCoder::encode(JpegCoderImage* img, int quality){
116116
nvjpegEncoderParamsSetOptimizedHuffman(nv_enc_params, 1, NULL);
117117
nvjpegEncoderParamsSetSamplingFactors(nv_enc_params, ChromaSubsampling_Covert_JpegCoderToNvJpeg(img->subsampling), NULL);
118118

119-
int nReturnCode = nvjpegEncodeImage(nv_handle, nv_enc_state, nv_enc_params, (nvjpegImage_t*)(img->img), NVJPEG_INPUT_BGRI, img->width, img->height, NULL);
119+
int nReturnCode = nvjpegEncodeImage(nv_handle, nv_enc_state, nv_enc_params, (nvjpegImage_t*)(img->img), NVJPEG_INPUT_BGRI, (int)img->width, (int)img->height, NULL);
120120
if (NVJPEG_STATUS_SUCCESS != nReturnCode){
121121
throw JpegCoderError(nReturnCode, "NvJpeg Encoder Error");
122122
}

tests/test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
import cv2
77
import glob
88

9-
for lib in glob.glob(os.path.join(os.path.dirname(__file__), "../build/lib.*")):
9+
for lib in glob.glob(os.path.abspath(os.path.join(os.path.dirname(__file__), "../build/lib.*"))):
1010
sys.path.append(lib)
1111

1212
from nvjpeg import NvJpeg
1313

14-
1514
nj = NvJpeg()
1615
image_file = os.path.join(os.path.dirname(__file__), "test-image", "test.jpg")
1716

0 commit comments

Comments
 (0)