Skip to content

Commit 106b4a9

Browse files
committed
Adjust the structure for preparing to develop different architectures
1 parent b769cc5 commit 106b4a9

File tree

6 files changed

+522
-535
lines changed

6 files changed

+522
-535
lines changed

Makefile

+6-40
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
CFLAGS=-Wall -Werror -O2
2-
ifdef DEBUG
3-
CFLAGS=-g -Wall -Werror -O0
4-
endif
5-
6-
ifndef CUDA_PATH
7-
CUDA_PATH=/usr/local/cuda
8-
endif
9-
101
ifndef PYTHON_VERSION
112
PYTHON_VERSION=$(shell python3 -c "import sys; print('%d.%d' % (sys.version_info.major, sys.version_info.minor,))")
123
endif
@@ -15,45 +6,20 @@ ifndef PYTHON_BIN
156
PYTHON_BIN=python${PYTHON_VERSION}
167
endif
178

18-
# ifndef PYTHON_INCLUDE_PATH
19-
# PYTHON_INCLUDE_PATH=/usr/include/python${PYTHON_VERSION}
20-
# endif
21-
22-
# ifndef PYTHON_LIB_PATH
23-
# PYTHON_LIB_PATH=$(shell ldconfig -p | grep python${PYTHON_VERSION} | head -n 1 | xargs dirname | tail -n 1)
24-
# endif
25-
26-
# ifndef PYTHON_DYNLOAD_PATH
27-
# PYTHON_DYNLOAD_PATH=$(shell ${PYTHON_BIN} -c "import sys; print(list(filter(lambda x: 'lib-dynload' in x, sys.path))[0])")
28-
# endif
29-
30-
# PYTHON_LIB_NAME=$(shell ${PYTHON_BIN} -c "import sys; print('nvjpeg.cpython-%d%dm' % (sys.version_info.major, sys.version_info.minor,))")-x86_64-linux-gnu.so
31-
32-
# all: out/nvjpeg-test out/${PYTHON_LIB_NAME}
33-
all: out/nvjpeg-test python-interface
9+
all: pynvjpeg
3410
out:
3511
mkdir out
3612

37-
out/nvjpeg-test.o: out nvjpeg-python.c
38-
gcc -o out/nvjpeg-test.o -c nvjpeg-python.c -I${CUDA_PATH}/include -D BUILD_TEST ${CFLAGS}
39-
40-
out/nvjpeg-test: out/nvjpeg-test.o
41-
gcc -o out/nvjpeg-test out/nvjpeg-test.o -L${CUDA_PATH}/lib64 -lnvjpeg -lcudart ${CFLAGS}
13+
test:
14+
${PYTHON_BIN} tests/test.py
15+
${PYTHON_BIN} tests/test-with-multiprocessing.py
4216

43-
# out/nvjpeg-python.o: out nvjpeg-python.c
44-
# gcc -fPIC -o out/nvjpeg-python.o -c nvjpeg-python.c -I${CUDA_PATH}/include -I${PYTHON_INCLUDE_PATH} ${CFLAGS}
45-
46-
# out/${PYTHON_LIB_NAME}: out/nvjpeg-python.o
47-
# 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}
48-
python-interface:
17+
pynvjpeg:
4918
${PYTHON_BIN} setup.py build
5019

5120
clean:
5221
rm -Rf out build dist pynvjpeg.egg-info
5322

54-
release: clean python-interface
23+
release: clean pynvjpeg
5524
${PYTHON_BIN} setup.py sdist
5625
${PYTHON_BIN} -m twine upload dist/*
57-
58-
# install: out/${PYTHON_LIB_NAME}
59-
# cp -f out/${PYTHON_LIB_NAME} ${PYTHON_DYNLOAD_PATH}

include/JpegCoder.hpp

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#pragma once
2+
3+
#include <sys/types.h>
4+
#include <malloc.h>
5+
#include <memory.h>
6+
#include <iostream>
7+
#include <exception>
8+
9+
class JpegCoderError: std::runtime_error{
10+
protected:
11+
int _code;
12+
public:
13+
JpegCoderError(int code, const std::string& str):std::runtime_error(str){
14+
this->_code = code;
15+
}
16+
JpegCoderError(int code, const char* str):std::runtime_error(str){
17+
this->_code = code;
18+
}
19+
int code(){
20+
return this->_code;
21+
}
22+
};
23+
24+
typedef enum
25+
{
26+
JPEGCODER_CSS_444 = 0,
27+
JPEGCODER_CSS_422 = 1,
28+
JPEGCODER_CSS_420 = 2,
29+
JPEGCODER_CSS_440 = 3,
30+
JPEGCODER_CSS_411 = 4,
31+
JPEGCODER_CSS_410 = 5,
32+
JPEGCODER_CSS_GRAY = 6,
33+
JPEGCODER_CSS_UNKNOWN = -1
34+
} JpegCoderChromaSubsampling;
35+
36+
typedef enum{
37+
JPEGCODER_PIXFMT_RGB = 3,
38+
JPEGCODER_PIXFMT_BGR = 4,
39+
JPEGCODER_PIXFMT_RGBI = 5,
40+
JPEGCODER_PIXFMT_BGRI = 6,
41+
}JpegCoderColorFormat;
42+
43+
class JpegCoderImage{
44+
public:
45+
void* img;
46+
JpegCoderChromaSubsampling subsampling;
47+
size_t height;
48+
size_t width;
49+
short nChannel;
50+
51+
JpegCoderImage(size_t width, size_t height, short nChannel, JpegCoderChromaSubsampling subsampling);
52+
~JpegCoderImage();
53+
void fill(const unsigned char* data);
54+
unsigned char* buffer();
55+
};
56+
57+
class JpegCoderBytes{
58+
public:
59+
size_t size;
60+
unsigned char* data;
61+
JpegCoderBytes(size_t size){
62+
this->data = (unsigned char*)malloc(size);
63+
this->size = size;
64+
}
65+
66+
~JpegCoderBytes(){
67+
if(this->data!=nullptr){
68+
free(this->data);
69+
}
70+
}
71+
};
72+
73+
class JpegCoder{
74+
protected:
75+
static void* _global_context;
76+
public:
77+
JpegCoder();
78+
~JpegCoder();
79+
JpegCoderImage* decode(const unsigned char* jpegData, size_t length);
80+
JpegCoderBytes* encode(JpegCoderImage* img, int quality);
81+
static void cleanUpEnv();
82+
};

0 commit comments

Comments
 (0)