|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "brightnessandcontrastpopup.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Tnz6 includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tapp.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "menubarcommandids.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "cellselection.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "filmstripselection.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzQt includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/intfield.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/planeviewer.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/menubarcommand.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/tselectionhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/icongenerator.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshcell.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheethandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tframehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tcolumnhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevelhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshleveltypes.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "timagecache.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelgr.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trasterimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tundo.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qsplitter></qsplitter>
|
|
Toshihiro Shimizu |
890ddd |
#include <qscrollarea></qscrollarea>
|
|
Toshihiro Shimizu |
890ddd |
#include <qgridlayout></qgridlayout>
|
|
Toshihiro Shimizu |
890ddd |
#include <qpushbutton></qpushbutton>
|
|
Toshihiro Shimizu |
890ddd |
#include <qlabel></qlabel>
|
|
Toshihiro Shimizu |
890ddd |
#include <qmainwindow></qmainwindow>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Local namespace stuff
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void my_compute_lut(double contrast, double brightness, std::vector<int> &lut) {</int>
|
|
Shinya Kitaoka |
120a6e |
const int maxChannelValue = lut.size() - 1;
|
|
Shinya Kitaoka |
120a6e |
const double half_maxChannelValueD = 0.5 * maxChannelValue;
|
|
Shinya Kitaoka |
120a6e |
const double maxChannelValueD = maxChannelValue;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
double value, nvalue, power;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int lutSize = lut.size();
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < lutSize; i++) {
|
|
Shinya Kitaoka |
120a6e |
value = i / maxChannelValueD;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// brightness
|
|
Shinya Kitaoka |
120a6e |
if (brightness < 0.0)
|
|
Shinya Kitaoka |
120a6e |
value = value * (1.0 + brightness);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
value = value + ((1.0 - value) * brightness);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// contrast
|
|
Shinya Kitaoka |
120a6e |
if (contrast < 0.0) {
|
|
Shinya Kitaoka |
120a6e |
if (value > 0.5)
|
|
Shinya Kitaoka |
120a6e |
nvalue = 1.0 - value;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
nvalue = value;
|
|
Shinya Kitaoka |
120a6e |
if (nvalue < 0.0) nvalue = 0.0;
|
|
Shinya Kitaoka |
120a6e |
nvalue = 0.5 * pow(nvalue * 2.0, (double)(1.0 + contrast));
|
|
Shinya Kitaoka |
120a6e |
if (value > 0.5)
|
|
Shinya Kitaoka |
120a6e |
value = 1.0 - nvalue;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
value = nvalue;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (value > 0.5)
|
|
Shinya Kitaoka |
120a6e |
nvalue = 1.0 - value;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
nvalue = value;
|
|
Shinya Kitaoka |
120a6e |
if (nvalue < 0.0) nvalue = 0.0;
|
|
Shinya Kitaoka |
120a6e |
power =
|
|
Shinya Kitaoka |
120a6e |
(contrast == 1.0) ? half_maxChannelValueD : 1.0 / (1.0 - contrast);
|
|
Shinya Kitaoka |
120a6e |
nvalue = 0.5 * pow(2.0 * nvalue, power);
|
|
Shinya Kitaoka |
120a6e |
if (value > 0.5)
|
|
Shinya Kitaoka |
120a6e |
value = 1.0 - nvalue;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
value = nvalue;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
lut[i] = value * maxChannelValueD;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline void doPix(PIX *outPix, const PIX *inPix, const std::vector<int> &lut) {</int>
|
|
Shinya Kitaoka |
120a6e |
if (inPix->m) {
|
|
Shinya Kitaoka |
120a6e |
*outPix = depremultiply(*inPix);
|
|
Shinya Kitaoka |
120a6e |
outPix->r = lut[outPix->r];
|
|
Shinya Kitaoka |
120a6e |
outPix->g = lut[outPix->g];
|
|
Shinya Kitaoka |
120a6e |
outPix->b = lut[outPix->b];
|
|
Shinya Kitaoka |
120a6e |
outPix->m = outPix->m;
|
|
Shinya Kitaoka |
120a6e |
*outPix = premultiply(*outPix);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
inline void doPix<tpixelgr8>(TPixelGR8 *outPix, const TPixelGR8 *inPix,</tpixelgr8>
|
|
Shinya Kitaoka |
120a6e |
const std::vector<int> &lut) {</int>
|
|
Shinya Kitaoka |
120a6e |
outPix->value = lut[inPix->value];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
inline void doPix<tpixelgr16>(TPixelGR16 *outPix, const TPixelGR16 *inPix,</tpixelgr16>
|
|
Shinya Kitaoka |
120a6e |
const std::vector<int> &lut) {</int>
|
|
Shinya Kitaoka |
120a6e |
outPix->value = lut[inPix->value];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Shinya Kitaoka |
120a6e |
void onChange(const TRasterPT<pix> &in, const TRasterPT<pix> &out, int contrast,</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
int brightness) {
|
|
Shinya Kitaoka |
120a6e |
assert(in->getSize() == out->getSize());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double b = brightness / 127.0;
|
|
Shinya Kitaoka |
120a6e |
double c = contrast / 127.0;
|
|
Shinya Kitaoka |
120a6e |
if (c > 1) c = 1;
|
|
Shinya Kitaoka |
120a6e |
if (c < -1) c = -1;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::vector<int> lut(PIX::maxChannelValue + 1);</int>
|
|
Shinya Kitaoka |
120a6e |
my_compute_lut(c, b, lut);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
in->lock();
|
|
Shinya Kitaoka |
120a6e |
out->lock();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int lx = in->getLx(), y, ly = in->getLy();
|
|
Shinya Kitaoka |
120a6e |
for (y = 0; y < ly; ++y) {
|
|
Shinya Kitaoka |
120a6e |
const PIX *inPix = in->pixels(y), *endInPix = inPix + lx;
|
|
Shinya Kitaoka |
120a6e |
PIX *outPix = out->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (inPix < endInPix) {
|
|
Shinya Kitaoka |
120a6e |
doPix(outPix, inPix, lut);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
++inPix;
|
|
Shinya Kitaoka |
120a6e |
++outPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
in->unlock();
|
|
Shinya Kitaoka |
120a6e |
out->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void onChange(const TRasterP &in, const TRasterP &out, int contrast,
|
|
Shinya Kitaoka |
120a6e |
int brightness) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P in32(in);
|
|
Shinya Kitaoka |
120a6e |
if (in32) {
|
|
Shinya Kitaoka |
120a6e |
onChange<tpixel32>(in32, out, contrast, brightness);</tpixel32>
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRaster64P in64(in);
|
|
Shinya Kitaoka |
120a6e |
if (in64) {
|
|
Shinya Kitaoka |
120a6e |
onChange<tpixel64>(in64, out, contrast, brightness);</tpixel64>
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P inGR8(in);
|
|
Shinya Kitaoka |
120a6e |
if (inGR8) {
|
|
Shinya Kitaoka |
120a6e |
onChange<tpixelgr8>(inGR8, out, contrast, brightness);</tpixelgr8>
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterGR16P inGR16(in);
|
|
Shinya Kitaoka |
120a6e |
if (inGR16) onChange<tpixelgr16>(inGR16, out, contrast, brightness);</tpixelgr16>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename ras=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline void onChange(const RAS &ras, int contrast, int brightness) {
|
|
Shinya Kitaoka |
120a6e |
onChange(ras, ras, contrast, brightness);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// BrightnessAndContrastPopup Swatch
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class BrightnessAndContrastPopup::Swatch : public PlaneViewer {
|
|
Shinya Kitaoka |
120a6e |
TRasterP m_ras;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
Swatch(QWidget *parent = 0) : PlaneViewer(parent) {
|
|
Shinya Kitaoka |
120a6e |
setBgColor(TPixel32::White, TPixel32::White);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterP raster() const { return m_ras; }
|
|
Shinya Kitaoka |
120a6e |
TRasterP &raster() { return m_ras; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void paintGL() override {
|
|
Shinya Kitaoka |
120a6e |
drawBackground();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_ras) {
|
|
Shinya Kitaoka |
120a6e |
glEnable(GL_BLEND);
|
|
Shinya Kitaoka |
120a6e |
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Note GL_ONE instead of GL_SRC_ALPHA: it's needed since the input
|
|
Shinya Kitaoka |
120a6e |
// image is supposedly premultiplied - and it works because the
|
|
Shinya Kitaoka |
120a6e |
// viewer's background is opaque.
|
|
Shinya Kitaoka |
120a6e |
// See tpixelutils.h's overPixT function for comparison.
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
pushGLWorldCoordinates();
|
|
Shinya Kitaoka |
120a6e |
draw(m_ras);
|
|
Shinya Kitaoka |
120a6e |
popGLCoordinates();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
glDisable(GL_BLEND);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// BrightnessAndContrastPopup implementation
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
BrightnessAndContrastPopup::BrightnessAndContrastPopup()
|
|
Shinya Kitaoka |
120a6e |
: Dialog(TApp::instance()->getMainWindow(), true, false,
|
|
Shinya Kitaoka |
120a6e |
"BrightnessAndContrast")
|
|
Shinya Kitaoka |
120a6e |
, m_startRas(0) {
|
|
Shinya Kitaoka |
120a6e |
setWindowTitle(tr("Brightness and Contrast"));
|
|
Shinya Kitaoka |
120a6e |
setLabelWidth(0);
|
|
Shinya Kitaoka |
120a6e |
setModal(false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setTopMargin(0);
|
|
Shinya Kitaoka |
120a6e |
setTopSpacing(0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
beginVLayout();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QSplitter *splitter = new QSplitter(Qt::Vertical);
|
|
Shinya Kitaoka |
120a6e |
splitter->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,
|
|
Shinya Kitaoka |
120a6e |
QSizePolicy::MinimumExpanding));
|
|
Shinya Kitaoka |
120a6e |
addWidget(splitter);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
endVLayout();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//------------------------- Top Layout --------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *scrollArea = new QScrollArea(splitter);
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setWidgetResizable(true);
|
|
Shinya Kitaoka |
120a6e |
splitter->addWidget(scrollArea);
|
|
Shinya Kitaoka |
120a6e |
splitter->setStretchFactor(0, 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QFrame *topWidget = new QFrame(scrollArea);
|
|
Shinya Kitaoka |
120a6e |
topWidget->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,
|
|
Shinya Kitaoka |
120a6e |
QSizePolicy::MinimumExpanding));
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setWidget(topWidget);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QGridLayout *topLayout = new QGridLayout(this);
|
|
Shinya Kitaoka |
120a6e |
topWidget->setLayout(topLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//------------------------- Parameters --------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Brightness
|
|
Shinya Kitaoka |
120a6e |
QLabel *brightnessLabel = new QLabel(tr("Brightness:"));
|
|
Shinya Kitaoka |
120a6e |
topLayout->addWidget(brightnessLabel, 0, 0,
|
|
Shinya Kitaoka |
120a6e |
Qt::AlignRight | Qt::AlignVCenter);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_brightnessField = new DVGui::IntField(topWidget);
|
|
Shinya Kitaoka |
120a6e |
m_brightnessField->setRange(-127, 127);
|
|
Shinya Kitaoka |
120a6e |
m_brightnessField->setValue(0);
|
|
Shinya Kitaoka |
120a6e |
topLayout->addWidget(m_brightnessField, 0, 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Contrast
|
|
Shinya Kitaoka |
120a6e |
QLabel *contrastLabel = new QLabel(tr("Contrast:"));
|
|
Shinya Kitaoka |
120a6e |
topLayout->addWidget(contrastLabel, 1, 0, Qt::AlignRight | Qt::AlignVCenter);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_contrastField = new DVGui::IntField(topWidget);
|
|
Shinya Kitaoka |
120a6e |
m_contrastField->setRange(-127, 127);
|
|
Shinya Kitaoka |
120a6e |
m_contrastField->setValue(0);
|
|
Shinya Kitaoka |
120a6e |
topLayout->addWidget(m_contrastField, 1, 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
topLayout->setRowStretch(2, 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------- Swatch ----------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_viewer = new Swatch(splitter);
|
|
Shinya Kitaoka |
120a6e |
m_viewer->setMinimumHeight(150);
|
|
Shinya Kitaoka |
120a6e |
m_viewer->setFocusPolicy(Qt::WheelFocus);
|
|
Shinya Kitaoka |
120a6e |
splitter->addWidget(m_viewer);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------- Button ----------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_okBtn = new QPushButton(QString("Apply"), this);
|
|
Shinya Kitaoka |
120a6e |
connect(m_okBtn, SIGNAL(clicked()), this, SLOT(apply()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
addButtonBarWidget(m_okBtn);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//------------------------ Connections --------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TApp *app = TApp::instance();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_brightnessField, SIGNAL(valueChanged(bool)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onValuesChanged(bool)));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_contrastField, SIGNAL(valueChanged(bool)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onValuesChanged(bool)));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_viewer->resize(0, 350);
|
|
Shinya Kitaoka |
120a6e |
resize(600, 500);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void BrightnessAndContrastPopup::setCurrentSampleRaster() {
|
|
Shinya Kitaoka |
120a6e |
TRasterP sampleRas;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_startRas = TRasterP();
|
|
Shinya Kitaoka |
120a6e |
TSelection *selection =
|
|
Shinya Kitaoka |
120a6e |
TApp::instance()->getCurrentSelection()->getSelection();
|
|
Shinya Kitaoka |
120a6e |
TCellSelection *cellSelection = dynamic_cast<tcellselection *="">(selection);</tcellselection>
|
|
Shinya Kitaoka |
120a6e |
TFilmstripSelection *filmstripSelection =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<tfilmstripselection *="">(selection);</tfilmstripselection>
|
|
Shinya Kitaoka |
120a6e |
if (cellSelection) {
|
|
Shinya Kitaoka |
120a6e |
TApp *app = TApp::instance();
|
|
Shinya Kitaoka |
120a6e |
TXsheet *xsh = app->getCurrentXsheet()->getXsheet();
|
|
Shinya Kitaoka |
120a6e |
TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrameIndex(),
|
|
Shinya Kitaoka |
120a6e |
app->getCurrentColumn()->getColumnIndex());
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP rasImage = cell.getImage(true);
|
|
Shinya Kitaoka |
120a6e |
if (rasImage && rasImage->getRaster())
|
|
Shinya Kitaoka |
120a6e |
sampleRas = rasImage->getRaster()->clone();
|
|
Shinya Kitaoka |
120a6e |
} else if (filmstripSelection) {
|
|
Shinya Kitaoka |
120a6e |
TApp *app = TApp::instance();
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *simpleLevel = app->getCurrentLevel()->getSimpleLevel();
|
|
Shinya Kitaoka |
120a6e |
if (simpleLevel) {
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(
|
|
Shinya Kitaoka |
120a6e |
app->getCurrentFrame()->getFid(), true);
|
|
Shinya Kitaoka |
120a6e |
if (rasImage && rasImage->getRaster())
|
|
Shinya Kitaoka |
120a6e |
sampleRas = rasImage->getRaster()->clone();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (!sampleRas) {
|
|
Shinya Kitaoka |
120a6e |
m_viewer->raster() = TRasterP();
|
|
Shinya Kitaoka |
120a6e |
m_viewer->update();
|
|
Shinya Kitaoka |
120a6e |
m_okBtn->setEnabled(false);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_okBtn->setEnabled(true);
|
|
Shinya Kitaoka |
120a6e |
m_startRas = sampleRas->clone();
|
|
Shinya Kitaoka |
120a6e |
onChange(m_startRas, sampleRas, m_contrastField->getValue(),
|
|
Shinya Kitaoka |
120a6e |
m_brightnessField->getValue());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_viewer->raster() = sampleRas;
|
|
Shinya Kitaoka |
120a6e |
m_viewer->update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void BrightnessAndContrastPopup::showEvent(QShowEvent *se) {
|
|
Shinya Kitaoka |
120a6e |
TApp *app = TApp::instance();
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(app->getCurrentFrame(), SIGNAL(frameTypeChanged()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setCurrentSampleRaster()));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(app->getCurrentFrame(), SIGNAL(frameSwitched()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setCurrentSampleRaster()));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(app->getCurrentColumn(), SIGNAL(columnIndexSwitched()),
|
|
Shinya Kitaoka |
120a6e |
this, SLOT(setCurrentSampleRaster()));
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Shinya Kitaoka |
120a6e |
setCurrentSampleRaster();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void BrightnessAndContrastPopup::hideEvent(QHideEvent *he) {
|
|
Shinya Kitaoka |
120a6e |
TApp *app = TApp::instance();
|
|
Shinya Kitaoka |
120a6e |
disconnect(app->getCurrentFrame(), SIGNAL(frameTypeChanged()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setCurrentSampleRaster()));
|
|
Shinya Kitaoka |
120a6e |
disconnect(app->getCurrentFrame(), SIGNAL(frameSwitched()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setCurrentSampleRaster()));
|
|
Shinya Kitaoka |
120a6e |
disconnect(app->getCurrentColumn(), SIGNAL(columnIndexSwitched()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setCurrentSampleRaster()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Dialog::hideEvent(he);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_viewer->raster() = TRasterP();
|
|
Shinya Kitaoka |
120a6e |
m_startRas = TRasterP();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class TRasterBrightnessUndo : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
int m_r, m_c, m_brightness, m_contrast;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QString m_rasId;
|
|
Shinya Kitaoka |
120a6e |
int m_rasSize;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TRasterBrightnessUndo(int brightness, int contrast, int r, int c,
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras)
|
|
Shinya Kitaoka |
120a6e |
: m_r(r)
|
|
Shinya Kitaoka |
120a6e |
, m_c(c)
|
|
Shinya Kitaoka |
120a6e |
, m_rasId()
|
|
Shinya Kitaoka |
120a6e |
, m_brightness(brightness)
|
|
Shinya Kitaoka |
120a6e |
, m_contrast(contrast)
|
|
Shinya Kitaoka |
120a6e |
, m_rasSize(ras->getLx() * ras->getLy() * ras->getPixelSize()) {
|
|
Shinya Kitaoka |
120a6e |
m_rasId = QString("BrightnessUndo") + QString::number((uintptr_t)this);
|
|
Shinya Kitaoka |
120a6e |
TImageCache::instance()->add(m_rasId, TRasterImageP(ras));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~TRasterBrightnessUndo() { TImageCache::instance()->remove(m_rasId); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void undo() const {
|
|
Shinya Kitaoka |
120a6e |
TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
|
|
Shinya Kitaoka |
120a6e |
TXshCell cell = xsheet->getCell(m_r, m_c);
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP rasImage = (TRasterImageP)cell.getImage(true);
|
|
Shinya Kitaoka |
120a6e |
if (!rasImage) return;
|
|
Shinya Kitaoka |
120a6e |
rasImage->setRaster(
|
|
Shinya Kitaoka |
120a6e |
((TRasterImageP)TImageCache::instance()->get(m_rasId, true))
|
|
Shinya Kitaoka |
120a6e |
->getRaster()
|
|
Shinya Kitaoka |
120a6e |
->clone());
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
|
|
Shinya Kitaoka |
120a6e |
assert(simpleLevel);
|
|
Shinya Kitaoka |
120a6e |
simpleLevel->touchFrame(cell.getFrameId());
|
|
Shinya Kitaoka |
120a6e |
simpleLevel->setDirtyFlag(false);
|
|
Shinya Kitaoka |
120a6e |
IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_isLastInBlock) {
|
|
Shinya Kitaoka |
120a6e |
TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void redo() const {
|
|
Shinya Kitaoka |
120a6e |
TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
|
|
Shinya Kitaoka |
120a6e |
TXshCell cell = xsheet->getCell(m_r, m_c);
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP rasImage = (TRasterImageP)cell.getImage(true);
|
|
Shinya Kitaoka |
120a6e |
if (!rasImage) return;
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = rasImage->getRaster();
|
|
Shinya Kitaoka |
120a6e |
if (!ras) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
onChange(ras, m_contrast, m_brightness);
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
|
|
Shinya Kitaoka |
120a6e |
assert(simpleLevel);
|
|
Shinya Kitaoka |
120a6e |
simpleLevel->touchFrame(cell.getFrameId());
|
|
Shinya Kitaoka |
120a6e |
simpleLevel->setDirtyFlag(false);
|
|
Shinya Kitaoka |
120a6e |
IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());
|
|
Shinya Kitaoka |
120a6e |
if (m_isLastInBlock) {
|
|
Shinya Kitaoka |
120a6e |
TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int getSize() const { return sizeof(*this) + m_rasSize; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void BrightnessAndContrastPopup::apply() {
|
|
Shinya Kitaoka |
120a6e |
TCellSelection *cellSelection =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<tcellselection *="">(TSelection::getCurrent());</tcellselection>
|
|
Shinya Kitaoka |
120a6e |
int brightness = m_brightnessField->getValue();
|
|
Shinya Kitaoka |
120a6e |
int contrast = m_contrastField->getValue();
|
|
Shinya Kitaoka |
120a6e |
if (cellSelection) {
|
|
Shinya Kitaoka |
120a6e |
std::set<trasterimage *=""> images;</trasterimage>
|
|
Shinya Kitaoka |
120a6e |
int r0, c0, r1, c1;
|
|
Shinya Kitaoka |
120a6e |
cellSelection->getSelectedCells(r0, c0, r1, c1);
|
|
Shinya Kitaoka |
120a6e |
TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
|
|
Shinya Kitaoka |
120a6e |
bool oneImageChanged = false;
|
|
Shinya Kitaoka |
120a6e |
int c, r;
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->beginBlock();
|
|
Shinya Kitaoka |
120a6e |
for (c = c0; c <= c1; c++)
|
|
Shinya Kitaoka |
120a6e |
for (r = r0; r <= r1; r++) {
|
|
Shinya Kitaoka |
120a6e |
TXshCell cell = xsheet->getCell(r, c);
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP rasImage = (TRasterImageP)cell.getImage(true);
|
|
Shinya Kitaoka |
120a6e |
if (!rasImage) continue;
|
|
Shinya Kitaoka |
120a6e |
if (images.find(rasImage.getPointer()) != images.end()) continue;
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = rasImage->getRaster();
|
|
Shinya Kitaoka |
120a6e |
if (!ras) continue;
|
|
Shinya Kitaoka |
120a6e |
images.insert(rasImage.getPointer());
|
|
Shinya Kitaoka |
120a6e |
oneImageChanged = true;
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new TRasterBrightnessUndo(
|
|
Shinya Kitaoka |
120a6e |
brightness, contrast, r, c, ras->clone()));
|
|
Shinya Kitaoka |
120a6e |
onChange(ras, contrast, brightness);
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
|
|
Shinya Kitaoka |
120a6e |
assert(simpleLevel);
|
|
Shinya Kitaoka |
120a6e |
simpleLevel->touchFrame(cell.getFrameId());
|
|
Shinya Kitaoka |
120a6e |
simpleLevel->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->endBlock();
|
|
Shinya Kitaoka |
120a6e |
if (oneImageChanged) {
|
|
Shinya Kitaoka |
120a6e |
close();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TFilmstripSelection *filmstripSelection =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<tfilmstripselection *="">(TSelection::getCurrent());</tfilmstripselection>
|
|
Shinya Kitaoka |
120a6e |
if (filmstripSelection) {
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *simpleLevel =
|
|
Shinya Kitaoka |
120a6e |
TApp::instance()->getCurrentLevel()->getSimpleLevel();
|
|
Shinya Kitaoka |
120a6e |
if (simpleLevel) {
|
|
Shinya Kitaoka |
120a6e |
std::set<tframeid> fids = filmstripSelection->getSelectedFids();</tframeid>
|
|
Shinya Kitaoka |
120a6e |
std::set<tframeid>::iterator it = fids.begin();</tframeid>
|
|
Shinya Kitaoka |
120a6e |
bool oneImageChanged = false;
|
|
Shinya Kitaoka |
120a6e |
for (auto const &fid : fids) {
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP rasImage =
|
|
Shinya Kitaoka |
120a6e |
(TRasterImageP)simpleLevel->getFrame(fid, true);
|
|
Shinya Kitaoka |
120a6e |
;
|
|
Shinya Kitaoka |
120a6e |
if (!rasImage) continue;
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = rasImage->getRaster();
|
|
Shinya Kitaoka |
120a6e |
if (!ras) continue;
|
|
Shinya Kitaoka |
120a6e |
oneImageChanged = true;
|
|
Shinya Kitaoka |
120a6e |
onChange(ras, contrast, brightness);
|
|
Shinya Kitaoka |
120a6e |
simpleLevel->touchFrame(fid);
|
|
Shinya Kitaoka |
120a6e |
simpleLevel->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
IconGenerator::instance()->invalidate(simpleLevel, fid);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (oneImageChanged) {
|
|
Shinya Kitaoka |
120a6e |
close();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
DVGui::error(QObject::tr("The current selection is invalid."));
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void BrightnessAndContrastPopup::onValuesChanged(bool dragging) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_startRas || !m_viewer->raster()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
onChange(m_startRas, m_viewer->raster(), m_contrastField->getValue(),
|
|
Shinya Kitaoka |
120a6e |
m_brightnessField->getValue());
|
|
Shinya Kitaoka |
120a6e |
m_viewer->update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
OpenPopupCommandHandler<brightnessandcontrastpopup></brightnessandcontrastpopup>
|
|
Shinya Kitaoka |
120a6e |
openBrightnessAndContrastPopup(MI_BrightnessAndContrast);
|