Toshihiro Shimizu 890ddd
#include "toonzqt/combohistogram.h"
Toshihiro Shimizu 890ddd
#include "tcolorstyles.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qvboxlayout></qvboxlayout>
Toshihiro Shimizu 890ddd
#include <qgridlayout></qgridlayout>
Toshihiro Shimizu 890ddd
#include <qcombobox></qcombobox>
Toshihiro Shimizu 890ddd
#include <qstackedwidget></qstackedwidget>
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Toshihiro Shimizu 890ddd
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Shinya Kitaoka 120a6e
// iwsw commented out temporarily
Toshihiro Shimizu 890ddd
//#include "toonzqt/ghibli_3dlut_converter.h"
Toshihiro Shimizu 890ddd
#include <qpushbutton></qpushbutton>
Toshihiro Shimizu 890ddd
#include <qdialog></qdialog>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// ChannelHistoGraph
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ChannelHistoGraph::ChannelHistoGraph(QWidget *parent, int *channelValue)
Shinya Kitaoka 120a6e
    : QWidget(parent), m_channelValuePtr(channelValue), m_pickedValue(-1) {
Shinya Kitaoka 120a6e
  // width 256+2 pixels, height 100+2 pixels (with margin)
Shinya Kitaoka 120a6e
  setFixedSize(COMBOHIST_RESOLUTION_W + 2, COMBOHIST_RESOLUTION_H + 2);
Shinya Kitaoka 120a6e
  m_values.reserve(COMBOHIST_RESOLUTION_W);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ChannelHistoGraph::~ChannelHistoGraph() { m_values.clear(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ChannelHistoGraph::setValues() {
Shinya Kitaoka 120a6e
  m_values.clear();
Shinya Kitaoka 120a6e
  m_values.resize(COMBOHIST_RESOLUTION_W);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // normalize with the maximum value
Shinya Kitaoka 120a6e
  int maxValue = 1;
Shinya Kitaoka 120a6e
  for (i = 0; i < COMBOHIST_RESOLUTION_W; i++) {
Shinya Kitaoka 120a6e
    int count                      = m_channelValuePtr[i];
Shinya Kitaoka 120a6e
    if (maxValue < count) maxValue = count;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < COMBOHIST_RESOLUTION_W; i++) {
Shinya Kitaoka 120a6e
    int v = m_channelValuePtr[i];
Shinya Kitaoka 120a6e
    m_values[i] =
Shinya Kitaoka 120a6e
        tround((double)(v * COMBOHIST_RESOLUTION_H) / (double)maxValue);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ChannelHistoGraph::paintEvent(QPaintEvent *event) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  p.setPen(QColor(144, 144, 144));
Shinya Kitaoka 120a6e
  p.setBrush(QColor(214, 214, 214));
Shinya Kitaoka 120a6e
  p.drawRect(rect().x(), rect().y(), rect().width() - 1, rect().height() - 1);
Shinya Kitaoka 120a6e
  p.setBrush(Qt::NoBrush);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // draw scale marks
Shinya Kitaoka 120a6e
  p.setPen(QColor(144, 144, 144));
Shinya Kitaoka 120a6e
  for (i = 1; i < 10; i++) {
Shinya Kitaoka 120a6e
    int posx = rect().width() * i / 10;
Shinya Kitaoka 120a6e
    p.drawLine(posx, 1, posx, COMBOHIST_RESOLUTION_H);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_values.size() == 0) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  p.setPen(Qt::black);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // draw each histogram
Shinya Kitaoka 120a6e
  for (i = 0; i < COMBOHIST_RESOLUTION_W; i++) {
Shinya Kitaoka 120a6e
    int v = m_values[i];
Shinya Kitaoka 120a6e
    if (v <= 0) continue;
Shinya Kitaoka 120a6e
    int x = 1 + i;
Shinya Kitaoka 120a6e
    p.drawLine(x, COMBOHIST_RESOLUTION_H + 1 - v, x, COMBOHIST_RESOLUTION_H);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // draw picked color's channel value
Shinya Kitaoka 120a6e
  if (m_pickedValue > -1) {
Shinya Kitaoka 120a6e
    p.setPen(Qt::white);
Shinya Kitaoka 120a6e
    int x = 1 + m_pickedValue;
Shinya Kitaoka 120a6e
    p.drawLine(x, 1, x, COMBOHIST_RESOLUTION_H);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ChannelHistoGraph::showCurrentChannelValue(int val) {
Shinya Kitaoka 120a6e
  m_pickedValue = val;
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// ChannelHistoGraph
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
RGBHistoGraph::RGBHistoGraph(QWidget *parent, int *channelValue)
Shinya Kitaoka 120a6e
    : ChannelHistoGraph(parent, channelValue) {
Shinya Kitaoka 120a6e
  m_histoImg = QImage(COMBOHIST_RESOLUTION_W, COMBOHIST_RESOLUTION_H,
Shinya Kitaoka 120a6e
                      QImage::Format_ARGB32_Premultiplied);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
RGBHistoGraph::~RGBHistoGraph() {
Shinya Kitaoka 120a6e
  for (int i = 0; i < 3; i++) m_rgbValues[i].clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RGBHistoGraph::setValues() {
Shinya Kitaoka 120a6e
  for (int chan = 0; chan < 3; chan++) {
Shinya Kitaoka 120a6e
    m_rgbValues[chan].clear();
Shinya Kitaoka 120a6e
    m_rgbValues[chan].resize(COMBOHIST_RESOLUTION_W);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // normalize with the maximum value
Shinya Kitaoka 120a6e
    int maxValue = 1;
Shinya Kitaoka 120a6e
    for (i = 0; i < COMBOHIST_RESOLUTION_W; i++) {
Shinya Kitaoka 120a6e
      int count = m_channelValuePtr[COMBOHIST_RESOLUTION_W * chan + i];
Shinya Kitaoka 120a6e
      if (maxValue < count) maxValue = count;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (i = 0; i < COMBOHIST_RESOLUTION_W; i++) {
Shinya Kitaoka 120a6e
      int v = m_channelValuePtr[COMBOHIST_RESOLUTION_W * chan + i];
Shinya Kitaoka 120a6e
      m_rgbValues[chan][i] =
Shinya Kitaoka 120a6e
          tround((double)(v * COMBOHIST_RESOLUTION_H) / (double)maxValue);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPainter imgPainter(&m_histoImg);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  imgPainter.fillRect(m_histoImg.rect(), Qt::black);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_rgbValues[0].size() == 0 || m_rgbValues[1].size() == 0 ||
Shinya Kitaoka 120a6e
      m_rgbValues[2].size() == 0) {
Shinya Kitaoka 120a6e
    imgPainter.end();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  imgPainter.setCompositionMode(QPainter::CompositionMode_Plus);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int chan = 0; chan < 3; chan++) {
Shinya Kitaoka 120a6e
    imgPainter.setPen((chan == 0) ? Qt::red
Shinya Kitaoka 120a6e
                                  : (chan == 1) ? Qt::green : Qt::blue);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (int i = 0; i < COMBOHIST_RESOLUTION_W; i++) {
Shinya Kitaoka 120a6e
      int v = m_rgbValues[chan][i];
Shinya Kitaoka 120a6e
      if (v <= 0) continue;
Shinya Kitaoka 120a6e
      int x = 1 + i;
Shinya Kitaoka 120a6e
      imgPainter.drawLine(x, COMBOHIST_RESOLUTION_H + 1 - v, x,
Shinya Kitaoka 120a6e
                          COMBOHIST_RESOLUTION_H);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  imgPainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
Shinya Kitaoka 120a6e
  imgPainter.end();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RGBHistoGraph::paintEvent(QPaintEvent *event) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  p.setCompositionMode(QPainter::CompositionMode_SourceOver);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  p.setPen(QColor(144, 144, 144));
Shinya Kitaoka 120a6e
  p.setBrush(QColor(64, 64, 64));
Shinya Kitaoka 120a6e
  p.drawRect(rect().x(), rect().y(), rect().width() - 1, rect().height() - 1);
Shinya Kitaoka 120a6e
  p.setBrush(Qt::NoBrush);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  p.drawImage(1, 1, m_histoImg);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// ChannelColorBar
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
ChannelColorBar::ChannelColorBar(QWidget *parent, QColor color)
Shinya Kitaoka 120a6e
    : QWidget(parent), m_color(color) {
Shinya Kitaoka 120a6e
  // 2 pixels margin for width
Shinya Kitaoka 120a6e
  setFixedSize(COMBOHIST_RESOLUTION_W + 2, 6);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ChannelColorBar::paintEvent(QPaintEvent *event) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QLinearGradient linearGrad(QPoint(1, 0), QPoint(COMBOHIST_RESOLUTION_W, 0));
Shinya Kitaoka 120a6e
  if (m_color == QColor(0, 0, 0, 0)) {
Shinya Kitaoka 120a6e
    linearGrad.setColorAt(0, m_color);
Shinya Kitaoka 120a6e
    linearGrad.setColorAt(1, Qt::white);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    linearGrad.setColorAt(0, Qt::black);
Shinya Kitaoka 120a6e
    linearGrad.setColorAt(1, m_color);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  p.setBrush(QBrush(linearGrad));
Shinya Kitaoka 120a6e
  p.setPen(Qt::NoPen);
Shinya Kitaoka 120a6e
  p.drawRect(rect());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// ChannelHisto
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
ChannelHisto::ChannelHisto(int channelIndex, int *channelValue,
Shinya Kitaoka 120a6e
                           QWidget *parent) {
Shinya Kitaoka 120a6e
  QString label;
Shinya Kitaoka 120a6e
  QColor color;
Shinya Kitaoka 120a6e
  switch (channelIndex) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    label = tr("Red");
Shinya Kitaoka 120a6e
    color = Qt::red;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    label = tr("Green");
Shinya Kitaoka 120a6e
    color = Qt::green;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    label = tr("Blue");
Shinya Kitaoka 120a6e
    color = Qt::blue;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    label = tr("Alpha");
Shinya Kitaoka 120a6e
    color = QColor(0, 0, 0, 0);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    label = tr("RGBA");
Shinya Kitaoka 120a6e
    color = Qt::white;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (channelIndex != 4)
Shinya Kitaoka 120a6e
    m_histogramGraph = new ChannelHistoGraph(this, channelValue);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_histogramGraph = new RGBHistoGraph(this, channelValue);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_colorBar = new ChannelColorBar(this, color);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // show/hide the alpha channel
Shinya Kitaoka 120a6e
  QPushButton *showAlphaChannelButton = 0;
Shinya Kitaoka 120a6e
  if (channelIndex == 3) {
Shinya Kitaoka 120a6e
    showAlphaChannelButton = new QPushButton("", this);
Shinya Kitaoka 120a6e
    showAlphaChannelButton->setObjectName("FxSettingsPreviewShowButton");
Shinya Kitaoka 120a6e
    showAlphaChannelButton->setFixedSize(15, 15);
Shinya Kitaoka 120a6e
    showAlphaChannelButton->setCheckable(true);
Shinya Kitaoka 120a6e
    showAlphaChannelButton->setChecked(false);
Shinya Kitaoka 120a6e
    showAlphaChannelButton->setFocusPolicy(Qt::NoFocus);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // layout
Shinya Kitaoka 120a6e
  QVBoxLayout *mainLayout = new QVBoxLayout(this);
Shinya Kitaoka 120a6e
  mainLayout->setMargin(0);
Shinya Kitaoka 120a6e
  mainLayout->setSpacing(2);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    QHBoxLayout *titleLay = new QHBoxLayout();
Shinya Kitaoka 120a6e
    titleLay->setMargin(0);
Shinya Kitaoka 120a6e
    titleLay->setSpacing(2);
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      titleLay->addWidget(new QLabel(label, this), 0);
Shinya Kitaoka 120a6e
      if (channelIndex == 3) titleLay->addWidget(showAlphaChannelButton, 0);
Shinya Kitaoka 120a6e
      titleLay->addStretch(1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    mainLayout->addLayout(titleLay);
Shinya Kitaoka 120a6e
    mainLayout->addSpacing(3);
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_histogramGraph);
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_colorBar);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  setLayout(mainLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (channelIndex == 3) {
Shinya Kitaoka 120a6e
    connect(showAlphaChannelButton, SIGNAL(toggled(bool)), this,
Shinya Kitaoka 120a6e
            SLOT(onShowAlphaButtonToggled(bool)));
Shinya Kitaoka 120a6e
    onShowAlphaButtonToggled(false);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! update the picked color's channel value
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void ChannelHisto::showCurrentChannelValue(int val) {
Shinya Kitaoka 120a6e
  m_histogramGraph->showCurrentChannelValue(val);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ChannelHisto::onShowAlphaButtonToggled(bool visible) {
Shinya Kitaoka 120a6e
  m_histogramGraph->setVisible(visible);
Shinya Kitaoka 120a6e
  m_colorBar->setVisible(visible);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// ComboHistoRGBLabel
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
ComboHistoRGBLabel::ComboHistoRGBLabel(QColor color, QWidget *parent)
Shinya Kitaoka 120a6e
    : QWidget(parent), m_color(color) {
Shinya Kitaoka 120a6e
  setFixedSize(COMBOHIST_RESOLUTION_W, 30);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ComboHistoRGBLabel::setColorAndUpdate(QColor color) {
Shinya Kitaoka 120a6e
  if (m_color == color) return;
Shinya Kitaoka 120a6e
  m_color = color;
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ComboHistoRGBLabel::paintEvent(QPaintEvent *pe) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Shinya Kitaoka 120a6e
  p.setPen(Qt::black);
Shinya Kitaoka 120a6e
  QRect bgRect = QRect(rect().left(), rect().top(), rect().width() - 1,
Shinya Kitaoka 120a6e
                       rect().height() - 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_color.alpha() == 0) {
Shinya Kitaoka 120a6e
    p.setBrush(Qt::gray);
Shinya Kitaoka 120a6e
    p.drawRect(bgRect);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // iwsw commented out temporarily
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
  if(Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled())
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
          QColor convertedColor(m_color);
Shinya Kitaoka 120a6e
          Ghibli3DLutConverter::instance()->convert(convertedColor);
Shinya Kitaoka 120a6e
          p.setBrush(convertedColor);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  p.setBrush(m_color);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  p.drawRect(bgRect);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // white text for dark color, black text for light color
Shinya Kitaoka 120a6e
  int val = m_color.red() * 30 + m_color.green() * 59 + m_color.blue() * 11;
Shinya Kitaoka 120a6e
  if (val < 12800)
Shinya Kitaoka 120a6e
    p.setPen(Qt::white);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    p.setPen(Qt::black);
Shinya Kitaoka 120a6e
  p.setBrush(Qt::NoBrush);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  p.drawText(rect(), Qt::AlignCenter, QString("R:%1 G:%2 B:%3")
Shinya Kitaoka 120a6e
                                          .arg(m_color.red())
Shinya Kitaoka 120a6e
                                          .arg(m_color.green())
Shinya Kitaoka 120a6e
                                          .arg(m_color.blue()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// ComboHistogram
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ComboHistogram::ComboHistogram(QWidget *parent)
Shinya Kitaoka 120a6e
    : QWidget(parent), m_raster(0), m_palette(0) {
Shinya Kitaoka 120a6e
  for (int chan        = 0; chan < 4; chan++)
Shinya Kitaoka 120a6e
    m_histograms[chan] = new ChannelHisto(chan, &m_channelValue[chan][0], this);
Shinya Kitaoka 120a6e
  m_histograms[4]      = new ChannelHisto(4, &m_channelValue[0][0], this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // RGB label
Shinya Kitaoka 120a6e
  m_rgbLabel = new ComboHistoRGBLabel(QColor(128, 128, 128), this);
Shinya Kitaoka 120a6e
  m_rgbLabel->setStyleSheet("font-size: 18px;");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_rectAverageRgbLabel = new ComboHistoRGBLabel(QColor(128, 128, 128), this);
Shinya Kitaoka 120a6e
  m_rectAverageRgbLabel->setStyleSheet("font-size: 18px;");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_xPosLabel = new QLabel("", this);
Shinya Kitaoka 120a6e
  m_yPosLabel = new QLabel("", this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // layout
Shinya Kitaoka 120a6e
  QVBoxLayout *mainLayout = new QVBoxLayout();
Shinya Kitaoka 120a6e
  mainLayout->setMargin(5);
Shinya Kitaoka 120a6e
  mainLayout->setSpacing(5);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_histograms[4]);  // RGB
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    mainLayout->addWidget(new QLabel("Picked Color", this), 0,
Shinya Kitaoka 120a6e
                          Qt::AlignLeft | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_rgbLabel, 0, Qt::AlignCenter);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    mainLayout->addWidget(new QLabel("Average Color (Ctrl + Drag)", this), 0,
Shinya Kitaoka 120a6e
                          Qt::AlignLeft | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_rectAverageRgbLabel, 0, Qt::AlignCenter);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QGridLayout *infoParamLay = new QGridLayout();
Shinya Kitaoka 120a6e
    infoParamLay->setHorizontalSpacing(3);
Shinya Kitaoka 120a6e
    infoParamLay->setVerticalSpacing(5);
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      infoParamLay->addWidget(new QLabel("X:", this), 0, 0,
Shinya Kitaoka 120a6e
                              Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      infoParamLay->addWidget(m_xPosLabel, 0, 1,
Shinya Kitaoka 120a6e
                              Qt::AlignLeft | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      infoParamLay->addWidget(new QLabel("Y:", this), 1, 0,
Shinya Kitaoka 120a6e
                              Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      infoParamLay->addWidget(m_yPosLabel, 1, 1,
Shinya Kitaoka 120a6e
                              Qt::AlignLeft | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    mainLayout->addLayout(infoParamLay, 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_histograms[0]);  // R
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_histograms[1]);  // G
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_histograms[2]);  // B
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_histograms[3]);  // A
Shinya Kitaoka 120a6e
    mainLayout->addStretch(1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  setLayout(mainLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_rectAverageRgbLabel->setColorAndUpdate(Qt::transparent);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ComboHistogram::~ComboHistogram() {
Shinya Kitaoka 120a6e
  memset(m_channelValue, 0, sizeof m_channelValue);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ComboHistogram::setRaster(const TRasterP &raster,
Shinya Kitaoka 120a6e
                               const TPaletteP &palette) {
Shinya Kitaoka 120a6e
  if (palette.getPointer()) m_palette = palette;
Shinya Kitaoka 120a6e
  m_raster                            = raster;
Shinya Kitaoka 120a6e
  computeChannelsValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int i = 0; i < 5; i++) m_histograms[i]->refleshValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ComboHistogram::computeChannelsValue() {
Shinya Kitaoka 120a6e
  memset(m_channelValue, 0, sizeof m_channelValue);
Shinya Kitaoka 120a6e
  if (!m_raster.getPointer()) return;
Shinya Kitaoka 120a6e
  TRasterCM32P cmRaster = m_raster;
Shinya Kitaoka 120a6e
  bool isCmRaster       = !!cmRaster;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRaster64P raster64 = m_raster;
Shinya Kitaoka 120a6e
  bool is64bit        = !!raster64;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int lx = m_raster->getLx();
Shinya Kitaoka 120a6e
  int ly = m_raster->getLy();
Shinya Kitaoka 120a6e
  if (lx > 1 && ly > 1) {
Shinya Kitaoka 120a6e
    int i, j;
Shinya Kitaoka 120a6e
    if (is64bit) {
Shinya Kitaoka 120a6e
      for (j = 0; j < ly; j++) {
Shinya Kitaoka 120a6e
        TPixel64 *pix_64 = raster64->pixels(j);
Shinya Kitaoka 120a6e
        for (i = 0; i < lx; i++, pix_64++) {
Shinya Kitaoka 120a6e
          int mValue = (int)byteFromUshort(pix_64->m);
Shinya Kitaoka 120a6e
          if (mValue != 0) {
Shinya Kitaoka 120a6e
            ++m_channelValue[0][(int)byteFromUshort(pix_64->r)];
Shinya Kitaoka 120a6e
            ++m_channelValue[1][(int)byteFromUshort(pix_64->g)];
Shinya Kitaoka 120a6e
            ++m_channelValue[2][(int)byteFromUshort(pix_64->b)];
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
          ++m_channelValue[3][mValue];
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else if (isCmRaster) {
Shinya Kitaoka 120a6e
      assert(m_palette);
Shinya Kitaoka 120a6e
      for (j = 0; j < ly; j++) {
Shinya Kitaoka 120a6e
        TPixelCM32 *pix_cm = cmRaster->pixels(j);
Shinya Kitaoka 120a6e
        for (i = 0; i < lx; i++, pix_cm++) {
Shinya Kitaoka 120a6e
          int styleId =
Shinya Kitaoka 120a6e
              pix_cm->getTone() < 127 ? pix_cm->getInk() : pix_cm->getPaint();
Shinya Kitaoka 120a6e
          TColorStyle *colorStyle = m_palette->getStyle(styleId);
Shinya Kitaoka 120a6e
          if (!colorStyle) continue;
Shinya Kitaoka 120a6e
          TPixel color = colorStyle->getAverageColor();
Shinya Kitaoka 120a6e
          int mValue   = color.m;
Shinya Kitaoka 120a6e
          if (mValue != 0) {
Shinya Kitaoka 120a6e
            ++m_channelValue[0][color.r];
Shinya Kitaoka 120a6e
            ++m_channelValue[1][color.g];
Shinya Kitaoka 120a6e
            ++m_channelValue[2][color.b];
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
          ++m_channelValue[3][color.m];
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else  // 8bpc raster
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      for (j = 0; j < ly; j++) {
Shinya Kitaoka 120a6e
        TPixel *pix = (TPixel *)m_raster->getRawData(0, j);
Shinya Kitaoka 120a6e
        for (i = 0; i < lx; i++, pix++) {
Shinya Kitaoka 120a6e
          int mValue = pix->m;
Shinya Kitaoka 120a6e
          if (mValue != 0) {
Shinya Kitaoka 120a6e
            ++m_channelValue[0][pix->r];
Shinya Kitaoka 120a6e
            ++m_channelValue[1][pix->g];
Shinya Kitaoka 120a6e
            ++m_channelValue[2][pix->b];
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
          ++m_channelValue[3][pix->m];
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ComboHistogram::updateInfo(const TPixel32 &pix, const TPointD &imagePos) {
Shinya Kitaoka 120a6e
  if (pix == TPixel32::Transparent) {
Shinya Kitaoka 120a6e
    m_histograms[0]->showCurrentChannelValue(-1);
Shinya Kitaoka 120a6e
    m_histograms[1]->showCurrentChannelValue(-1);
Shinya Kitaoka 120a6e
    m_histograms[2]->showCurrentChannelValue(-1);
Shinya Kitaoka 120a6e
    m_rgbLabel->setColorAndUpdate(Qt::transparent);
Shinya Kitaoka 120a6e
    m_xPosLabel->setText("");
Shinya Kitaoka 120a6e
    m_yPosLabel->setText("");
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    // show picked color's channel values
Shinya Kitaoka 120a6e
    m_histograms[0]->showCurrentChannelValue((int)pix.r);
Shinya Kitaoka 120a6e
    m_histograms[1]->showCurrentChannelValue((int)pix.g);
Shinya Kitaoka 120a6e
    m_histograms[2]->showCurrentChannelValue((int)pix.b);
Shinya Kitaoka 120a6e
    m_rgbLabel->setColorAndUpdate(QColor((int)pix.r, (int)pix.g, (int)pix.b));
Shinya Kitaoka 120a6e
    m_xPosLabel->setText(QString::number(tround(imagePos.x)));
Shinya Kitaoka 120a6e
    m_yPosLabel->setText(QString::number(tround(imagePos.y)));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ComboHistogram::updateAverageColor(const TPixel32 &pix) {
Shinya Kitaoka 120a6e
  if (pix == TPixel32::Transparent) {
Shinya Kitaoka 120a6e
    m_rectAverageRgbLabel->setColorAndUpdate(Qt::transparent);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    m_rectAverageRgbLabel->setColorAndUpdate(
Shinya Kitaoka 120a6e
        QColor((int)pix.r, (int)pix.g, (int)pix.b));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------