Skip to content

Commit 885e6ce

Browse files
committed
setup
1 parent 9e9b5bb commit 885e6ce

15 files changed

+172
-31
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
out
2-
.vscode
2+
.vscode
3+
*.pyc
4+
dist
5+
build
6+
nvjpeg.egg-info

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020-2021 Jason Dsouza
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CUDA_PATH=/usr/local/cuda
88
endif
99

1010
ifndef PYTHON_VERSION
11-
PYTHON_VERSION=3.6
11+
PYTHON_VERSION=$(shell python3 -c "import sys; print('%d.%d' % (sys.version_info.major, sys.version_info.minor,))")
1212
endif
1313

1414
ifndef PYTHON_BIN
@@ -39,11 +39,13 @@ out/nvjpeg-test.o: out nvjpeg-python.c
3939
out/nvjpeg-test: out/nvjpeg-test.o
4040
gcc -o out/nvjpeg-test out/nvjpeg-test.o -L${CUDA_PATH}/lib64 -lnvjpeg -lcudart -L${PYTHON_LIB_PATH} -lpython${PYTHON_VERSION}m ${CFLAGS}
4141

42-
out/nvjpeg.o: out nvjpeg-python.c
43-
gcc -fPIC -o out/nvjpeg.o -c nvjpeg-python.c -I${CUDA_PATH}/include -I${PYTHON_INCLUDE_PATH} ${CFLAGS}
42+
out/nvjpeg-python.o: out nvjpeg-python.c
43+
gcc -fPIC -o out/nvjpeg-python.o -c nvjpeg-python.c -I${CUDA_PATH}/include -I${PYTHON_INCLUDE_PATH} ${CFLAGS}
4444

45-
out/${PYTHON_LIB_NAME}: out/nvjpeg.o
46-
gcc --shared -fPIC -o out/${PYTHON_LIB_NAME} out/nvjpeg.o -L${CUDA_PATH}/lib64 -lnvjpeg -lcudart -L${PYTHON_LIB_PATH} -lpython${PYTHON_VERSION}m ${CFLAGS}
45+
out/${PYTHON_LIB_NAME}: out/nvjpeg-python.o
46+
gcc --shared -fPIC -o out/${PYTHON_LIB_NAME} out/nvjpeg-python.o -L${CUDA_PATH}/lib64 -lnvjpeg -lcudart -L${PYTHON_LIB_PATH} -lpython${PYTHON_VERSION}m ${CFLAGS}
47+
mkdir -p nvjpeg/lib
48+
cp -f out/${PYTHON_LIB_NAME} nvjpeg/lib/${PYTHON_LIB_NAME}
4749

4850
clean:
4951
rm -Rf out

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
NvJpeg - Python
2+
---------------------------
3+
4+
## Require
5+
* nvjpeg
6+
* cuda >= 10.2
7+
* numpy >= 1.7
8+
* python >= 3.6
9+
* gcc >= 7.5
10+
11+
## Build
12+
```shell
13+
make
14+
```
15+
16+
## Install
17+
```shell
18+
make install
19+
```
20+
21+
## Usage
22+
```python
23+
#!/usr/bin/env python3
24+
25+
from nvjpeg import NvJpeg
26+
27+
# read file
28+
fp = open("input-image.jpg", "rb")
29+
jpegData = fp.read()
30+
fp.close()
31+
32+
# decode
33+
nj = NvJpeg()
34+
img_np = nj.decode(jpegData)
35+
36+
# use opencv show numpy image data
37+
cv2.imshow("Demo", img_np)
38+
cv2.waitKey(0)
39+
40+
# encode numpy image data
41+
jpg = nj.encode(img_np)
42+
43+
# write file
44+
fp = open("output-image.jpg", "wb")
45+
fp.write(jpg)
46+
fp.close()
47+
```

nvjpeg-python.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ int NvJpegPython_test(char* inputJpegFilePath, char* outputRawPath, char* output
234234

235235
int main(int args, char** argv){
236236
NvJpegPython_test(
237-
"./test/test.jpg",
238-
"./test/out/c-test.bgr",
239-
"./test/out/c-test.jpg"
237+
"./tests/test.jpg",
238+
"./tests/out/c-test.bgr",
239+
"./tests/out/c-test.jpg"
240240
);
241241
return 0;
242242
}

nvjpeg/__init__.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
import os
3+
import numpy as np
4+
import cv2
5+
6+
sys.path.append(os.path.join(os.path.dirname(__file__), "lib"))
7+
8+
from nvjpeg import NvJpeg as _NvJpeg
9+
10+
class NvJpeg:
11+
def __init__():
12+
self._handle = _NvJpeg()
13+
14+
def encode(self, numpy_array, quality=70):
15+
return self._handle.encode(numpy_array, quality)
16+
17+
def decode(self, jpegData):
18+
return self._handle.decode(jpegData)

nvjpeg/lib/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*
File renamed without changes.

scripts/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
cd `cd $(dirname $0) && pwd | xargs dirname`
3+
make

setup.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import setuptools
2+
import sys
3+
import os
4+
5+
with open("README.md", "r", encoding="utf-8") as fh:
6+
long_description = fh.read()
7+
8+
setuptools.setup(
9+
name="nvjpeg",
10+
version="0.0.1",
11+
author="Usingnet",
12+
author_email="zengqinghui@usingnet.com",
13+
license="MIT",
14+
description="nvjpeg for python",
15+
long_description=long_description,
16+
long_description_content_type="text/markdown",
17+
url="https://github.com/UsingNet/nvjpeg-python",
18+
packages=setuptools.find_packages(),
19+
classifiers=[
20+
"Development Status :: 4 - Beta"
21+
"Programming Language :: Python :: 3 :: Only",
22+
"License :: OSI Approved :: MIT License",
23+
"Operating System :: POSIX :: Linux",
24+
"Environment :: GPU :: NVIDIA CUDA :: 10.2",
25+
"Environment :: GPU :: NVIDIA CUDA :: 11.0",
26+
],
27+
keywords="nvjpeg jpeg encode decode",
28+
python_requires=">=3.6",
29+
project_urls={
30+
'Source': 'https://github.com/UsingNet/nvjpeg-python',
31+
'Tracker': 'https://github.com/UsingNet/nvjpeg-python/issues',
32+
},
33+
data_files=[
34+
('src', ['nvjpeg-python.c', 'Makefile'])
35+
],
36+
scripts=[
37+
'scripts/build.sh'
38+
],
39+
install_requires=['make', 'gcc']
40+
)
41+

test/test.py

-22
This file was deleted.

tests/out/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

tests/out/.gitkeep

Whitespace-only changes.
File renamed without changes.

tests/test.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
import os
5+
import numpy as np
6+
import cv2
7+
8+
sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
9+
10+
from nvjpeg import NvJpeg
11+
12+
fp = open(os.path.join(os.path.dirname(__file__), "test.jpg"), "rb")
13+
img = fp.read()
14+
fp.close()
15+
16+
nj = NvJpeg()
17+
img_np = nj.decode(img)
18+
19+
cv2.imshow("Demo", img_np)
20+
cv2.waitKey(0)
21+
22+
jpg = nj.encode(img_np)
23+
fp = open(os.path.join(os.path.dirname(__file__), "out", "python-test.jpg"), "wb")
24+
fp.write(jpg)
25+
fp.close()

0 commit comments

Comments
 (0)