Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOMERGE] some hacks, to get jpeg encoding up and running, using turbojpeg #130

Open
wants to merge 2 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions projects/samples/contests/robocup/controllers/player/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ else
GOAL := $(MAKECMDGOALS)
endif

LIBRARIES += -lturbojpeg

defaut: release

release debug profile: clients
Expand Down
30 changes: 19 additions & 11 deletions projects/samples/contests/robocup/controllers/player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ void usleep(__int64 usec) {
#define ByteSizeLong ByteSize
#endif

// #define JPEG_COMPRESSION 1 // uncomment this to test JPEG compression
#define JPEG_COMPRESSION 1 // uncomment this to test JPEG compression

// #define TURBOJPEG 1
#define TURBOJPEG 1
// It turns out that the libjpeg interface to turbojpeg runs faster than the native turbojpeg interface
// Alternatives to be considered: NVIDIA CUDA nvJPEG Encoder, Intel IPP JPEG encoder
#ifdef TURBOJPEG
#include <turbojpeg.h>
#define TRUE true
#define FALSE false
#else
#include <jpeglib.h>
#endif
Expand Down Expand Up @@ -200,7 +202,7 @@ static void encode_jpeg(const unsigned char *image, int width, int height, int q
unsigned char **buffer) {
#ifdef TURBOJPEG
tjhandle compressor = tjInitCompress();
tjCompress2(compressor, image, width, 0, height, TJPF_RGB, buffer, size, TJSAMP_444, quality, TJFLAG_FASTDCT);
tjCompress2(compressor, image, width, 0, height, TJPF_RGB, buffer, size, TJSAMP_422, quality, TJFLAG_FASTDCT);
tjDestroy(compressor);
#else
struct jpeg_compress_struct cinfo;
Expand Down Expand Up @@ -557,26 +559,32 @@ class PlayerServer {
measurement->set_name(camera->getName());
measurement->set_width(width);
measurement->set_height(height);
measurement->set_quality(-1); // raw image (JPEG compression not yet supported)
const unsigned char *rgba_image = camera->getImage();
// measurement->set_quality(-1); // raw image (JPEG compression not yet supported)
const unsigned char *bgra_image = camera->getImage();
const int rgb_image_size = width * height * 3;
unsigned char *rgb_image = new unsigned char[rgb_image_size];
for (int i = 0; i < width * height; i++) {
rgb_image[3 * i] = rgba_image[4 * i];
rgb_image[3 * i + 1] = rgba_image[4 * i + 1];
rgb_image[3 * i + 2] = rgba_image[4 * i + 2];
rgb_image[3 * i] = bgra_image[4 * i + 2];
rgb_image[3 * i + 1] = bgra_image[4 * i + 1];
rgb_image[3 * i + 2] = bgra_image[4 * i + 0];
}
measurement->set_image(rgb_image, rgb_image_size);
delete[] rgb_image;

#ifdef JPEG_COMPRESSION
// testing JPEG compression (impacts the performance)
unsigned char *buffer = NULL;
long unsigned int bufferSize = 0;
encode_jpeg(rgba_image, width, height, 95, &bufferSize, &buffer);
encode_jpeg(rgb_image, width, height, 95, &bufferSize, &buffer);

measurement->set_quality(95);
measurement->set_image(buffer, bufferSize);
free_jpeg(buffer);
buffer = NULL;
#else
measurement->set_image(rgb_image, rgb_image_size);
#endif
delete[] rgb_image;



continue;
}
Expand Down