From ecc71409eb3d2c453a65c404def787054b1daa1f Mon Sep 17 00:00:00 2001 From: ponchio Date: Sun, 20 Nov 2022 04:08:42 +0100 Subject: [PATCH] fixed decoder color space management. --- src/deepzoom.cpp | 1 + src/jpeg_decoder.cpp | 15 ++++++++------- src/jpeg_decoder.h | 8 +++----- src/legacy_rti.cpp | 1 - src/rti.cpp | 1 - 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/deepzoom.cpp b/src/deepzoom.cpp index c330b4c8..9b9f32b9 100644 --- a/src/deepzoom.cpp +++ b/src/deepzoom.cpp @@ -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); diff --git a/src/jpeg_decoder.cpp b/src/jpeg_decoder.cpp index c5b1695f..6de2b5d1 100644 --- a/src/jpeg_decoder.cpp +++ b/src/jpeg_decoder.cpp @@ -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) { @@ -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) diff --git a/src/jpeg_decoder.h b/src/jpeg_decoder.h index ea64908d..2c9ed270 100644 --- a/src/jpeg_decoder.h +++ b/src/jpeg_decoder.h @@ -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); @@ -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; }; diff --git a/src/legacy_rti.cpp b/src/legacy_rti.cpp index 13eafc18..99c1a5a1 100644 --- a/src/legacy_rti.cpp +++ b/src/legacy_rti.cpp @@ -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; diff --git a/src/rti.cpp b/src/rti.cpp index a765241c..d7b35761 100644 --- a/src/rti.cpp +++ b/src/rti.cpp @@ -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);