Skip to content

Commit

Permalink
fixed decoder color space management.
Browse files Browse the repository at this point in the history
  • Loading branch information
ponchio committed Nov 20, 2022
1 parent d63e92a commit ecc7140
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/deepzoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void TileRow::nextRow() {
tile.width = end - start;
tile.encoder = new JpegEncoder();
tile.encoder->setQuality(quality);
tile.encoder->setColorSpace(JCS_RGB, 3);
QString filepath = QString("%1/%2_%3.jpg").arg(path).arg(col).arg(current_row); //path + "/" + QString::number(col) + "_" + QString::numberto_string(current_row) + ".jpg");
tile.encoder->init(filepath.toStdString().c_str(), tile.width, h);
push_back(tile);
Expand Down
15 changes: 8 additions & 7 deletions src/jpeg_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ JpegDecoder::~JpegDecoder() {
}

void JpegDecoder::setColorSpace(J_COLOR_SPACE colorSpace) {
this->colorSpace = colorSpace;
decInfo.out_color_space = colorSpace;
}

void JpegDecoder::setJpegColorSpace(J_COLOR_SPACE colorSpace) {
this->jpegColorSpace = colorSpace;
}

J_COLOR_SPACE JpegDecoder::getColorSpace() const {
return colorSpace;
return decInfo.out_color_space;
}

J_COLOR_SPACE JpegDecoder::getJpegColorSpace() const {
return decInfo.jpeg_color_space;
}

bool JpegDecoder::decode(uint8_t* buffer, size_t len, uint8_t*& img, int& width, int& height) {
Expand Down Expand Up @@ -77,8 +78,8 @@ bool JpegDecoder::init(const char* path, int &width, int &height) {

bool JpegDecoder::init(int &width, int &height) {
jpeg_read_header(&decInfo, (boolean)true);
decInfo.out_color_space = colorSpace;
decInfo.jpeg_color_space = jpegColorSpace;
//decInfo.out_color_space = colorSpace;
//decInfo.jpeg_color_space = jpegColorSpace;
decInfo.raw_data_out = (boolean)false;

if(decInfo.num_components > 1)
Expand Down
8 changes: 3 additions & 5 deletions src/jpeg_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class JpegDecoder {

//JCS_GRAYSCALE, JCS_RGB, JCS_YCbCr, or JCS_CMYK.

void setColorSpace(J_COLOR_SPACE space);
void setJpegColorSpace(J_COLOR_SPACE colorSpace);
J_COLOR_SPACE getColorSpace() const;
void setColorSpace(J_COLOR_SPACE space);
J_COLOR_SPACE getJpegColorSpace() const;

bool decode(uint8_t* buffer, size_t len, uint8_t*& img, int& width, int& height);
bool decode(const char* path, uint8_t*& img, int& width, int& height);
bool decode(FILE* file, uint8_t*& img, int& width, int& height);
Expand All @@ -43,9 +44,6 @@ class JpegDecoder {
jpeg_decompress_struct decInfo;
jpeg_error_mgr errMgr;

J_COLOR_SPACE colorSpace = JCS_RGB;
J_COLOR_SPACE jpegColorSpace = JCS_YCbCr;

bool subsampled = false;
};

Expand Down
1 change: 0 additions & 1 deletion src/legacy_rti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,6 @@ bool LRti::decodeJPEG(size_t size, unsigned char *buffer, unsigned int plane) {
int w, h;
JpegDecoder dec;
dec.setColorSpace(JCS_GRAYSCALE);
dec.setJpegColorSpace(JCS_GRAYSCALE);

if(!dec.decode(buffer, size, img, w, h) || w != width || h != height) {
cerr << "Failed decoding jpeg or different size." << endl;
Expand Down
1 change: 0 additions & 1 deletion src/rti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ bool Rti::loadData(const char *folder) {
for(int i = 0; i < njpegs; i++) {
planedecs[i] = new JpegDecoder;
planedecs[i]->setColorSpace(JCS_RGB);
planedecs[i]->setJpegColorSpace(JCS_YCbCr);

int w, h;
planedecs[i]->init(dir.filePath(QString("plane_%1.jpg").arg(i)).toStdString().c_str(), w, h);
Expand Down

0 comments on commit ecc7140

Please sign in to comment.