Skip to content

Commit 3597049

Browse files
committed
fix bug in jpeg decoder
1 parent 47f8005 commit 3597049

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ v4l2source_yuv
44
v4l2compress
55
v4l2uncompress_jpeg
66
*.a
7+
CMakeCache.txt
8+
CMakeFiles/
9+
*.cmake
10+

CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
3+
# set project name from current directory
4+
get_filename_component(BASENAME ${CMAKE_SOURCE_DIR} NAME)
5+
project(${BASENAME})
6+
7+
set (CMAKE_CXX_STANDARD 11)
8+
set(CMAKE_C_FLAGS "-Wall")
9+
set(CMAKE_CXX_FLAGS "-Wall")
10+
11+
# define executable to build
12+
include_directories("include")
13+
add_executable(${PROJECT_NAME} src/v4l2compress.cpp)
14+
15+
# v4l2wrapper
16+
aux_source_directory(v4l2wrapper/src LIBSRC_FILES)
17+
include_directories("v4l2wrapper/inc")
18+
add_library(v4l2wrapper STATIC ${LIBSRC_FILES})
19+
target_link_libraries (${PROJECT_NAME} v4l2wrapper)
20+
21+
#libyuv
22+
include(FindJPEG)
23+
if (JPEG_FOUND)
24+
include_directories(${JPEG_INCLUDE_DIR})
25+
target_link_libraries(${PROJECT_NAME} ${JPEG_LIBRARY})
26+
add_definitions(-DHAVE_JPEG)
27+
endif()
28+
29+
add_subdirectory(libyuv EXCLUDE_FROM_ALL)
30+
include_directories("libyuv/include")
31+
target_link_libraries (${PROJECT_NAME} yuv)

include/codecfactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CodecFactory {
2727
Codec* Create(int outformat, int informat, int width, int height, const std::map<std::string,std::string> & opt, int verbose) {
2828
Codec* convertor = NULL;
2929
auto itDecoder = m_registryDecoder.find(informat);
30-
if (itDecoder != std::end(m_registryEncoder)) {
30+
if (itDecoder != std::end(m_registryDecoder)) {
3131
convertor = itDecoder->second(outformat, informat, width, height, opt, verbose);
3232
} else {
3333
auto itEncoder = m_registryEncoder.find(outformat);

include/jpegdecoder.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ class JpegDecoder : public Codec {
3636
jpeg_mem_src(&m_cinfo, (unsigned char*)buffer, rsize);
3737
jpeg_read_header(&m_cinfo, TRUE);
3838
LOG(INFO) << "width:" << m_cinfo.image_width << " height:" << m_cinfo.image_height << " num_components:" << m_cinfo.num_components;
39+
m_cinfo.out_color_space = JCS_YCbCr;
3940

4041
jpeg_start_decompress(&m_cinfo);
41-
unsigned int image_size = m_cinfo.image_width * m_cinfo.image_height * m_cinfo.num_components;
42-
unsigned char image_buffer[image_size];
4342

4443
unsigned char bufline[m_cinfo.image_width * m_cinfo.num_components];
4544
while (m_cinfo.output_scanline < m_cinfo.output_height)
@@ -63,7 +62,7 @@ class JpegDecoder : public Codec {
6362
m_width, m_height,
6463
m_outformat);
6564

66-
int wsize = videoOutput->write((char *)image_buffer,image_size);
65+
int wsize = videoOutput->write((char *)outBuffer,videoOutput->getBufferSize());
6766
LOG(DEBUG) << "Copied size:" << wsize;
6867

6968
}

0 commit comments

Comments
 (0)