forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request IntelRealSense#39 from IntelRealSense/mchanan_colo…
…r_jpeg_compress Mchanan color jpeg compress
- Loading branch information
Showing
19 changed files
with
174 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
typedef enum zipMethod { | ||
gzip, | ||
rvl, | ||
Jpeg, | ||
} zipMethod; | ||
|
||
class decompressFrameFactory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
|
||
#include <iomanip> | ||
#include <cstdint> | ||
#include <cstring> | ||
#include "decompressFrameJpeg.h" | ||
#include <stdio.h> | ||
#include "jpeglib.h" | ||
|
||
//TODO: add this code for RGB format | ||
// (void) jpeg_read_scanlines(&cinfo, destBuffer, 1); | ||
// for (int i = 0; i < cinfo.output_width h; i ++) { | ||
// ptr[i] = destBuffer[0][i]; | ||
// ptr[i+ 1] = destBuffer[0][i +1]; | ||
// ptr[i+ 2] = destBuffer[0][i +2]; | ||
// } | ||
// ptr += cinfo.output_width * cinfo.output_component; | ||
//(void) jpeg_read_scanlines(&cinfo, destBuffer, 1); | ||
//memcpy(ptr,destBuffer[0], 640*3); | ||
//ptr+= 640*3; | ||
|
||
void decompressFrameJpeg::decompressColorFrame(unsigned char* buffer, int size, unsigned char* uncompressedBuf) | ||
{ | ||
struct jpeg_error_mgr jerr; | ||
struct jpeg_decompress_struct cinfo; | ||
unsigned char * ptr = uncompressedBuf; | ||
uint64_t compressedSize = 0; | ||
|
||
cinfo.err = jpeg_std_error(&jerr); | ||
jpeg_create_decompress(&cinfo); | ||
memcpy(&compressedSize, buffer, sizeof(unsigned int)); | ||
unsigned char* data = buffer + sizeof(unsigned int); | ||
jpeg_mem_src(&cinfo, data , compressedSize); | ||
(void) jpeg_read_header(&cinfo, TRUE); | ||
cinfo.out_color_space = JCS_YCbCr; | ||
(void) jpeg_start_decompress(&cinfo); | ||
|
||
uint64_t row_stride = cinfo.output_width * cinfo.output_components; | ||
JSAMPARRAY destBuffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); | ||
while (cinfo.output_scanline < cinfo.output_height) { | ||
(void) jpeg_read_scanlines(&cinfo, destBuffer, 1); | ||
for (int i = 0; i < cinfo.output_width ; i += 2) { //input strides by 4 bytes, output strides by 6 (2 pixels) | ||
ptr[i*2] = destBuffer[0][i*3]; // Y (unique to this pixel) | ||
ptr[i*2 + 1] = destBuffer[0][i*3 + 1]; // U (shared between pixels) | ||
ptr[i*2 + 2] = destBuffer[0][i*3 + 3]; // Y (unique to this pixel) | ||
ptr[i*2 + 3] = destBuffer[0][i*3 + 2]; // V (shared between pixels) | ||
} | ||
ptr+= cinfo.output_width *2; | ||
} | ||
|
||
(void) jpeg_finish_decompress(&cinfo); | ||
jpeg_destroy_decompress(&cinfo); | ||
printf("finish color decompression with jpeg, full size: %lu , compressed size %u \n", size, compressedSize); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <map> | ||
#include <string> | ||
#include <sstream> | ||
#include <functional> | ||
#include <list> | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <cassert> | ||
#include "IdecompressFrame.h" | ||
|
||
class decompressFrameJpeg :public IdecompressFrame | ||
{ | ||
public: | ||
void decompressColorFrame(unsigned char* buffer, int size, unsigned char* uncompressedBuf); | ||
void decompressDepthFrame(unsigned char* buffer, int size, unsigned char* uncompressedBuf){}; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
typedef enum zipMethod { | ||
gzip, | ||
rvl, | ||
Jpeg, | ||
} zipMethod; | ||
|
||
class compressFrameFactory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <cstdint> | ||
#include <cstring> | ||
#include "compressFrameJpeg.h" | ||
#include <stdio.h> | ||
#include "jpeglib.h" | ||
|
||
int compressFrameJpeg::compressColorFrame(unsigned char* buffer, int size, unsigned char* compressedBuf, int width, int height) | ||
{ | ||
struct jpeg_error_mgr jerr; | ||
struct jpeg_compress_struct cinfo; | ||
JSAMPROW row_pointer[1]; | ||
int row_stride; | ||
cinfo.err = jpeg_std_error(&jerr); | ||
uint64_t compressedSize = 0; | ||
unsigned char * data; | ||
int bpp = size/(width*height); | ||
|
||
jpeg_create_compress(&cinfo); | ||
jpeg_mem_dest(&cinfo, &data, &compressedSize); | ||
cinfo.image_width = width; | ||
cinfo.image_height = height; | ||
cinfo.input_components = 3; | ||
cinfo.in_color_space = JCS_YCbCr; | ||
jpeg_set_defaults(&cinfo); | ||
jpeg_start_compress(&cinfo, TRUE); | ||
row_stride = cinfo.image_width * cinfo.input_components; | ||
|
||
unsigned char *tmprowbuf = new unsigned char[cinfo.image_width * cinfo.input_components]; | ||
row_pointer[0] = tmprowbuf; | ||
while (cinfo.next_scanline < cinfo.image_height) { | ||
//row_pointer[0] = & buffer[cinfo.next_scanline * row_stride]; | ||
//(void) jpeg_write_scanlines(&cinfo, row_pointer, 1); | ||
for (int i = 0; i < cinfo.image_width; i += 2) { //input strides by 4 bytes, output strides by 6 (2 pixels) | ||
tmprowbuf[i*3] = buffer[i*2 + 0]; // Y (unique to this pixel) | ||
tmprowbuf[i*3 + 1] = buffer[i*2 + 1]; // U (shared between pixels) | ||
tmprowbuf[i*3 + 2] = buffer[i*2 + 3]; // V (shared between pixels) | ||
tmprowbuf[i*3 + 3] = buffer[i*2 + 2]; // Y (unique to this pixel) | ||
tmprowbuf[i*3 + 4] = buffer[i*2 + 1]; // U (shared between pixels) | ||
tmprowbuf[i*3 + 5] = buffer[i*2 + 3]; // V (shared between pixels) | ||
} | ||
row_pointer[0] = tmprowbuf; | ||
buffer += cinfo.image_width * 2; | ||
jpeg_write_scanlines(&cinfo, row_pointer, 1); | ||
} | ||
jpeg_finish_compress(&cinfo); | ||
jpeg_destroy_compress(&cinfo); | ||
printf("finish color compression with jpeg, full size: %lu , compressed size %u \n", size, compressedSize); | ||
|
||
memcpy(compressedBuf + 4, data, compressedSize); | ||
memcpy(compressedBuf, &compressedSize, sizeof(unsigned int)); | ||
return compressedSize; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include "IcompressFrame.h" | ||
#include <zlib.h> | ||
|
||
class compressFrameJpeg :public IcompressFrame | ||
{ | ||
public: | ||
int compressColorFrame(unsigned char* buffer, int size, unsigned char* compressedBuf, int width, int height); | ||
int compressDepthFrame(unsigned char* buffer, int size, unsigned char* compressedBuf){}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters