initial commit
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
#include "cdcp.h"
|
||||
|
||||
|
||||
cDCP::cDCP(QObject* parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void cDCPList::load(const QString& fileName)
|
||||
{
|
||||
m_fileName = fileName;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
#ifndef CDCP_H
|
||||
#define CDCP_H
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaObject>
|
||||
#include <QList>
|
||||
|
||||
|
||||
class cDCP : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit cDCP(QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(cDCP*)
|
||||
|
||||
class cDCPList : public QList<cDCP*>
|
||||
{
|
||||
public:
|
||||
void load(const QString& fileName);
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
};
|
||||
|
||||
#endif // CDCP_H
|
||||
+96
-172
@@ -5,8 +5,6 @@
|
||||
|
||||
#include "cimage.h"
|
||||
|
||||
#include "libraw/libraw.h"
|
||||
|
||||
#include <QTransform>
|
||||
#include <QFileInfo>
|
||||
|
||||
@@ -14,54 +12,73 @@
|
||||
|
||||
|
||||
cImage::cImage() :
|
||||
QImage()
|
||||
QImage(),
|
||||
m_isChromatic(true),
|
||||
m_camType(camera_unknown)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cImage::cImage(const QSize &size, QImage::Format format) :
|
||||
QImage(size, format)
|
||||
QImage(size, format),
|
||||
m_isChromatic(true),
|
||||
m_camType(camera_unknown)
|
||||
{
|
||||
}
|
||||
|
||||
cImage::cImage(int width, int height, QImage::Format format) :
|
||||
QImage(width, height, format)
|
||||
QImage(width, height, format),
|
||||
m_isChromatic(true),
|
||||
m_camType(camera_unknown)
|
||||
{
|
||||
}
|
||||
|
||||
cImage::cImage(uchar *data, int width, int height, QImage::Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) :
|
||||
QImage(data, width, height, format, cleanupFunction, cleanupInfo)
|
||||
QImage(data, width, height, format, cleanupFunction, cleanupInfo),
|
||||
m_isChromatic(true),
|
||||
m_camType(camera_unknown)
|
||||
{
|
||||
}
|
||||
|
||||
cImage::cImage(const uchar *data, int width, int height, QImage::Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) :
|
||||
QImage(data, width, height, format, cleanupFunction, cleanupInfo)
|
||||
QImage(data, width, height, format, cleanupFunction, cleanupInfo),
|
||||
m_isChromatic(true),
|
||||
m_camType(camera_unknown)
|
||||
{
|
||||
}
|
||||
|
||||
cImage::cImage(uchar *data, int width, int height, int bytesPerLine, QImage::Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) :
|
||||
QImage(data, width, height, bytesPerLine, format, cleanupFunction, cleanupInfo)
|
||||
QImage(data, width, height, bytesPerLine, format, cleanupFunction, cleanupInfo),
|
||||
m_isChromatic(true),
|
||||
m_camType(camera_unknown)
|
||||
{
|
||||
}
|
||||
|
||||
cImage::cImage(const uchar *data, int width, int height, int bytesPerLine, QImage::Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) :
|
||||
QImage(data, width, height, bytesPerLine, format, cleanupFunction, cleanupInfo)
|
||||
QImage(data, width, height, bytesPerLine, format, cleanupFunction, cleanupInfo),
|
||||
m_isChromatic(true),
|
||||
m_camType(camera_unknown)
|
||||
{
|
||||
}
|
||||
|
||||
cImage::cImage(const QString &fileName, const char *format) :
|
||||
QImage()
|
||||
QImage(),
|
||||
m_isChromatic(true),
|
||||
m_camType(camera_unknown)
|
||||
{
|
||||
load(fileName, format);
|
||||
}
|
||||
|
||||
cImage::cImage(const QImage &image) :
|
||||
QImage(image)
|
||||
QImage(image),
|
||||
m_isChromatic(true),
|
||||
m_camType(camera_unknown)
|
||||
{
|
||||
}
|
||||
|
||||
cImage::cImage(QImage &&other) :
|
||||
QImage(other)
|
||||
QImage(other),
|
||||
m_isChromatic(true),
|
||||
m_camType(camera_unknown)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -78,181 +95,88 @@ bool cImage::load(const QString &fileName, const char *format)
|
||||
return(loadRAW(fileName));
|
||||
}
|
||||
|
||||
#include <math.h>
|
||||
|
||||
QImage LibRawImageToQImage(const uchar *data, const int width, const int height, const int nCols, const int colorBits)
|
||||
bool cImage::openBuffer(const QString &fileName, const QSharedPointer<QByteArray>& ba, LibRaw& iProcessor)
|
||||
{
|
||||
int colorSize = (colorBits % 8) == 0 ? colorBits / 8 : static_cast<int>(ceil(static_cast<double>(colorBits) / 8.0));
|
||||
int numPixels = width * height;
|
||||
int pixelSize = nCols * colorSize;
|
||||
uchar* pixels = new uchar[numPixels * 3];
|
||||
int error = LIBRAW_DATA_ERROR;
|
||||
QFileInfo fi(fileName);
|
||||
|
||||
for(int i = 0; i < numPixels; i++, data += pixelSize)
|
||||
if(fi.suffix().contains("iiq", Qt::CaseInsensitive) || !ba || ba->isEmpty())
|
||||
error = iProcessor.open_file(fileName.toStdString().c_str());
|
||||
else
|
||||
{
|
||||
if(nCols == 3)
|
||||
{
|
||||
// this ordering produces correct RGB results - don't ask why
|
||||
// tested with .CR2 (Canon)
|
||||
pixels[i * 3] = data[3*colorSize];
|
||||
pixels[i * 3 + 1] = data[colorSize];
|
||||
pixels[i * 3 + 2] = data[2*colorSize];
|
||||
}
|
||||
else
|
||||
{
|
||||
pixels[i * 3] = data[0];
|
||||
pixels[i * 3 + 1] = data[0];
|
||||
pixels[i * 3 + 2] = data[0];
|
||||
}
|
||||
if(ba->isEmpty() || ba->size() < 100)
|
||||
return(false);
|
||||
|
||||
error = iProcessor.open_buffer((void*)ba->constData(), static_cast<size_t>(ba->size()));
|
||||
}
|
||||
// immediately create a copy since otherwise we'd have to
|
||||
// 'delete[] pixels' somewhere else, ourselves
|
||||
// see http://doc.qt.io/qt-5.5/qimage.html#QImage-6
|
||||
QImage out = QImage(pixels, width, height, width * 3, QImage::Format_RGB888).copy();
|
||||
// QImage out = QImage(pixels, width, height, width * 3, QImage::Format_RGB32).copy();
|
||||
delete[] pixels;
|
||||
return out;
|
||||
|
||||
return (error == LIBRAW_SUCCESS);
|
||||
}
|
||||
|
||||
void LibRawImagePerformFlip(const int flip, QImage& image)
|
||||
void cImage::detectSpecialCamera(const LibRaw & iProcessor)
|
||||
{
|
||||
if(flip != 0)
|
||||
{
|
||||
QTransform rotation;
|
||||
int angle = 0;
|
||||
if(QString(iProcessor.imgdata.idata.model) == "IQ260 Achromatic")
|
||||
m_isChromatic = false;
|
||||
|
||||
if(flip == 3)
|
||||
angle = 180;
|
||||
else if(flip == 5)
|
||||
angle = -90;
|
||||
else if(flip == 6)
|
||||
angle = 90;
|
||||
|
||||
if (angle != 0)
|
||||
{
|
||||
rotation.rotate(angle);
|
||||
image = image.transformed(rotation);
|
||||
}
|
||||
}
|
||||
if (QString(iProcessor.imgdata.idata.model).contains("IQ260"))
|
||||
m_camType = camera_iiq;
|
||||
else if (QString(iProcessor.imgdata.idata.make).compare("Canon", Qt::CaseInsensitive))
|
||||
m_camType = camera_canon;
|
||||
}
|
||||
|
||||
|
||||
bool cImage::loadRAW(const QString &fileName)
|
||||
{
|
||||
LibRaw RawProcessor;
|
||||
QImage image;
|
||||
QSharedPointer<QByteArray> ba;
|
||||
LibRaw iProcessor;
|
||||
|
||||
// RawProcessor.imgdata.params.gamm[0] = 1.00;
|
||||
// RawProcessor.imgdata.params.gamm[1] = 0.00;
|
||||
// RawProcessor.imgdata.params.gamm[0] = 0.45;
|
||||
// RawProcessor.imgdata.params.gamm[1] = 4.50;
|
||||
RawProcessor.imgdata.params.gamm[0] = 1/2.4;
|
||||
RawProcessor.imgdata.params.gamm[1] = 12.92;
|
||||
// RawProcessor.imgdata.params.user_qual = 0; // fastest interpolation (linear)
|
||||
RawProcessor.imgdata.params.use_camera_wb = 1;
|
||||
|
||||
if(LIBRAW_SUCCESS == RawProcessor.open_file(fileName.toUtf8()))
|
||||
if(!openBuffer(fileName, ba, iProcessor))
|
||||
{
|
||||
if(LIBRAW_SUCCESS == RawProcessor.unpack())
|
||||
{
|
||||
if(LIBRAW_SUCCESS == RawProcessor.dcraw_process())
|
||||
{
|
||||
libraw_processed_image_t* output = RawProcessor.dcraw_make_mem_image();
|
||||
|
||||
if(LIBRAW_IMAGE_JPEG == output->type)
|
||||
{
|
||||
image.loadFromData(static_cast<uchar*>(output->data), static_cast<int>(output->data_size), "JPEG");
|
||||
LibRawImagePerformFlip(RawProcessor.imgdata.sizes.flip, image);
|
||||
}
|
||||
else if(LIBRAW_IMAGE_BITMAP == output->type)
|
||||
{
|
||||
image = LibRawImageToQImage(static_cast<uchar*>(output->data), output->width, output->height, output->colors, output->bits);
|
||||
} // else: could not read
|
||||
LibRaw::dcraw_clear_mem(output);
|
||||
}
|
||||
RawProcessor.recycle();
|
||||
}
|
||||
qDebug() << "could not open buffer";
|
||||
return(false);
|
||||
}
|
||||
*this = image;
|
||||
|
||||
detectSpecialCamera(iProcessor);
|
||||
|
||||
int error = iProcessor.unpack();
|
||||
if(strcmp(iProcessor.version(), "0.13.5") != 0) // fixes a bug specific to libraw 13 - version call is UNTESTED
|
||||
iProcessor.raw2image();
|
||||
|
||||
if(error != LIBRAW_SUCCESS)
|
||||
return(false);
|
||||
|
||||
// cv::Mat rawMat;
|
||||
|
||||
// LibRaw RawProcessor;
|
||||
// QImage image;
|
||||
|
||||
// RawProcessor.imgdata.params.gamm[0] = 1/2.4;
|
||||
// RawProcessor.imgdata.params.gamm[1] = 12.92;
|
||||
// RawProcessor.imgdata.params.use_camera_wb = 1;
|
||||
|
||||
// if(LIBRAW_SUCCESS == RawProcessor.open_file(fileName.toUtf8()))
|
||||
// {
|
||||
// if(LIBRAW_SUCCESS == RawProcessor.unpack())
|
||||
// {
|
||||
// if(LIBRAW_SUCCESS == RawProcessor.dcraw_process())
|
||||
// {
|
||||
// libraw_processed_image_t* output = RawProcessor.dcraw_make_mem_image();
|
||||
|
||||
// if(LIBRAW_IMAGE_JPEG == output->type)
|
||||
// {
|
||||
// image.loadFromData(static_cast<uchar*>(output->data), static_cast<int>(output->data_size), "JPEG");
|
||||
// LibRawImagePerformFlip(RawProcessor.imgdata.sizes.flip, image);
|
||||
// }
|
||||
// else if(LIBRAW_IMAGE_BITMAP == output->type)
|
||||
// {
|
||||
// image = LibRawImageToQImage(static_cast<uchar*>(output->data), output->width, output->height, output->colors, output->bits);
|
||||
// } // else: could not read
|
||||
// LibRaw::dcraw_clear_mem(output);
|
||||
// }
|
||||
// RawProcessor.recycle();
|
||||
// }
|
||||
// }
|
||||
// *this = image;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
//bool cImage::loadRAW(const QString &fileName)
|
||||
//{
|
||||
// LibRaw rawProcessor;
|
||||
// libraw_processed_image_t* lpOutput;
|
||||
|
||||
// rawProcessor.imgdata.params.use_camera_wb = 1;
|
||||
// rawProcessor.imgdata.params.use_auto_wb = 1;
|
||||
// rawProcessor.imgdata.params.use_camera_matrix = 0;
|
||||
//// rawProcessor.imgdata.params.gamm[0] = 1/2.22;
|
||||
//// rawProcessor.imgdata.params.gamm[1] = 4.50;
|
||||
// rawProcessor.imgdata.params.gamm[0] = 1/2.40;
|
||||
// rawProcessor.imgdata.params.gamm[1] = 12.92;
|
||||
|
||||
// if(rawProcessor.open_file(fileName.toUtf8()) != LIBRAW_SUCCESS)
|
||||
// return(false);
|
||||
|
||||
// if(rawProcessor.unpack() != LIBRAW_SUCCESS)
|
||||
// return(false);
|
||||
|
||||
// rawProcessor.raw2image();
|
||||
|
||||
// rawProcessor.dcraw_process();
|
||||
// lpOutput = rawProcessor.dcraw_make_mem_image();
|
||||
|
||||
// const libraw_data_t& imgdata = rawProcessor.imgdata;
|
||||
// uchar* pixels = nullptr;
|
||||
|
||||
// if(lpOutput->type == LIBRAW_IMAGE_JPEG)
|
||||
// {
|
||||
// loadFromData(lpOutput->data, static_cast<int>(lpOutput->data_size), "JPEG");
|
||||
|
||||
// if(imgdata.sizes.flip != 0)
|
||||
// {
|
||||
// QTransform rotation;
|
||||
// int angle = 0;
|
||||
|
||||
// if(imgdata.sizes.flip == 3)
|
||||
// angle = 180;
|
||||
// else if(imgdata.sizes.flip == 5)
|
||||
// angle = -90;
|
||||
// else if(imgdata.sizes.flip == 6)
|
||||
// angle = 90;
|
||||
// if(angle != 0)
|
||||
// {
|
||||
// rotation.rotate(angle);
|
||||
// *this = transformed(rotation);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// int numPixels = lpOutput->width * lpOutput->height;
|
||||
// int colorSize = lpOutput->bits / 8;
|
||||
// int pixelSize = lpOutput->colors * colorSize;
|
||||
// pixels = new uchar[numPixels * 4];
|
||||
// uchar* data = lpOutput->data;
|
||||
|
||||
// for(int i = 0; i < numPixels; i++, data += pixelSize)
|
||||
// {
|
||||
// if(lpOutput->colors == 3)
|
||||
// {
|
||||
// pixels[i * 4] = data[2 * colorSize];
|
||||
// pixels[i * 4 + 1] = data[1 * colorSize];
|
||||
// pixels[i * 4 + 2] = data[0];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// pixels[i * 4] = data[0];
|
||||
// pixels[i * 4 + 1] = data[0];
|
||||
// pixels[i * 4 + 2] = data[0];
|
||||
// }
|
||||
// }
|
||||
// *this = QImage(pixels, lpOutput->width, lpOutput->height, QImage::Format_RGB32);
|
||||
// }
|
||||
|
||||
// rawProcessor.recycle();
|
||||
|
||||
// return(true);
|
||||
//}
|
||||
|
||||
@@ -7,127 +7,44 @@
|
||||
#define CIMAGE_H
|
||||
|
||||
|
||||
#include "libraw/libraw.h"
|
||||
|
||||
#include <QImage>
|
||||
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\class cImage cimage.h "cimage.h"
|
||||
*/
|
||||
class cImage : public QImage
|
||||
{
|
||||
public:
|
||||
cImage();
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn cImage
|
||||
\param size
|
||||
\param format
|
||||
*/
|
||||
cImage(const QSize &size, QImage::Format format);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn cImage
|
||||
\param width
|
||||
\param height
|
||||
\param format
|
||||
*/
|
||||
cImage(int width, int height, QImage::Format format);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn cImage
|
||||
\param data
|
||||
\param width
|
||||
\param height
|
||||
\param format
|
||||
\param cleanupFunction
|
||||
\param cleanupInfo
|
||||
*/
|
||||
cImage(uchar *data, int width, int height, QImage::Format format, QImageCleanupFunction cleanupFunction = nullptr, void *cleanupInfo = nullptr);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn cImage
|
||||
\param data
|
||||
\param width
|
||||
\param height
|
||||
\param format
|
||||
\param cleanupFunction
|
||||
\param cleanupInfo
|
||||
*/
|
||||
cImage(const uchar *data, int width, int height, QImage::Format format, QImageCleanupFunction cleanupFunction = nullptr, void *cleanupInfo = nullptr);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn cImage
|
||||
\param data
|
||||
\param width
|
||||
\param height
|
||||
\param bytesPerLine
|
||||
\param format
|
||||
\param cleanupFunction
|
||||
\param cleanupInfo
|
||||
*/
|
||||
cImage(uchar *data, int width, int height, int bytesPerLine, QImage::Format format, QImageCleanupFunction cleanupFunction = nullptr, void *cleanupInfo = nullptr);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn cImage
|
||||
\param data
|
||||
\param width
|
||||
\param height
|
||||
\param bytesPerLine
|
||||
\param format
|
||||
\param cleanupFunction
|
||||
\param cleanupInfo
|
||||
*/
|
||||
cImage(const uchar *data, int width, int height, int bytesPerLine, QImage::Format format, QImageCleanupFunction cleanupFunction = nullptr, void *cleanupInfo = nullptr);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn cImage
|
||||
\param fileName
|
||||
\param format
|
||||
*/
|
||||
cImage(const QString &fileName, const char *format = nullptr);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn cImage
|
||||
\param image
|
||||
*/
|
||||
cImage(const QImage &image);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn cImage
|
||||
\param other
|
||||
*/
|
||||
cImage(QImage &&other);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn load
|
||||
\param fileName
|
||||
\param format
|
||||
\return bool
|
||||
*/
|
||||
bool load(const QString &fileName, const char *format = nullptr);
|
||||
|
||||
private:
|
||||
/*!
|
||||
\brief
|
||||
protected:
|
||||
enum Cam
|
||||
{
|
||||
camera_unknown = 0,
|
||||
camera_iiq,
|
||||
camera_canon,
|
||||
camera_end
|
||||
};
|
||||
|
||||
private:
|
||||
bool m_isChromatic;
|
||||
Cam m_camType;
|
||||
|
||||
\fn loadRAW
|
||||
\param fileName
|
||||
\return bool
|
||||
*/
|
||||
bool loadRAW(const QString &fileName);
|
||||
|
||||
bool openBuffer(const QString &fileName, const QSharedPointer<QByteArray>& ba, LibRaw& iProcessor);
|
||||
void detectSpecialCamera(const LibRaw & iProcessor);
|
||||
};
|
||||
|
||||
#endif // CIMAGE_H
|
||||
|
||||
@@ -44,7 +44,6 @@ DEFINES += APP_VERSION=\\\"$$VERSION\\\"
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
cdcp.cpp \
|
||||
cexif.cpp \
|
||||
cexportdialog.cpp \
|
||||
cimage.cpp \
|
||||
@@ -54,7 +53,6 @@ SOURCES += \
|
||||
cmainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
cdcp.h \
|
||||
cexif.h \
|
||||
cexportdialog.h \
|
||||
cimage.h \
|
||||
|
||||
Reference in New Issue
Block a user