diff --git a/ui/zenoedit/panel/zenoimagepanel.cpp b/ui/zenoedit/panel/zenoimagepanel.cpp index 8fae5ca268..3d66974a54 100644 --- a/ui/zenoedit/panel/zenoimagepanel.cpp +++ b/ui/zenoedit/panel/zenoimagepanel.cpp @@ -9,7 +9,7 @@ #include "zeno/utils/format.h" #include #include -#include +#include "zeno/utils/vec.h" #include "zeno/utils/log.h" #include "zenoapplication.h" #include "zassert.h" @@ -43,7 +43,6 @@ void ZenoImagePanel::setPrim(std::string primid) { return; bool enableGamma = pGamma->checkState() == Qt::Checked; - bool enableAlpha = pAlpha->checkState() == Qt::Checked; bool found = false; for (auto const &[key, ptr]: scene->objectsMan->pairs()) { if ((key.substr(0, key.find(":"))) != primid) { @@ -58,52 +57,46 @@ void ZenoImagePanel::setPrim(std::string primid) { int width = ud.get2("w"); int height = ud.get2("h"); if (image_view) { - QImage img(width, height, QImage::Format_RGB32); - int gridSize = 50; - if (obj->verts.has_attr("alpha")&&enableAlpha) { - auto &alpha = obj->verts.attr("alpha"); + if (pMode->currentText() != "Alpha") { + QImage img(width, height, QImage::Format_RGB32); for (auto i = 0; i < obj->verts.size(); i++) { int h = i / width; - //int h = i % height; check image vert order int w = i % width; - //int w = i / height; - auto foreground = obj->verts[i]; + auto c = obj->verts[i]; if (enableGamma) { - foreground = zeno::pow(foreground, 1.0f / 2.2f); - } - zeno::vec3f background; - if ((h / gridSize) % 2 == (w / gridSize) % 2) { - background = {1, 1, 1}; - } - else { - background = {0.86, 0.86, 0.86}; + c = zeno::pow(c, 1.0f / 2.2f); } - zeno::vec3f c = zeno::mix(background, foreground, alpha[i]); - - int r = glm::clamp(int(c[0] * 255.99), 0, 255); - int g = glm::clamp(int(c[1] * 255.99), 0, 255); - int b = glm::clamp(int(c[2] * 255.99), 0, 255); + auto index = std::map{ + {"RGB", {0, 1, 2}}, + {"Red", {0, 0, 0}}, + {"Green", {1, 1, 1}}, + {"Blue", {2, 2, 2}}, + }.at(pMode->currentText()); + int r = glm::clamp(int(c[index[0]] * 255.99), 0, 255); + int g = glm::clamp(int(c[index[1]] * 255.99), 0, 255); + int b = glm::clamp(int(c[index[2]] * 255.99), 0, 255); img.setPixel(w, height - 1 - h, qRgb(r, g, b)); - //img.setPixel(width - 1 - w, h, qRgb(r, g, b)); } + image_view->setImage(img); } - else{ - for (auto i = 0; i < obj->verts.size(); i++) { - int h = i / width; - int w = i % width; - auto c = obj->verts[i]; - if (enableGamma) { - c = zeno::pow(c, 1.0f / 2.2f); - } - int r = glm::clamp(int(c[0] * 255.99), 0, 255); - int g = glm::clamp(int(c[1] * 255.99), 0, 255); - int b = glm::clamp(int(c[2] * 255.99), 0, 255); + else if (pMode->currentText() == "Alpha") { + QImage img(width, height, QImage::Format_RGB32); + if (obj->verts.has_attr("alpha")) { + auto &alpha = obj->verts.attr("alpha"); + for (auto i = 0; i < obj->verts.size(); i++) { + int h = i / width; + int w = i % width; + auto c = alpha[i]; + int r = glm::clamp(int(c * 255.99), 0, 255); + int g = glm::clamp(int(c * 255.99), 0, 255); + int b = glm::clamp(int(c * 255.99), 0, 255); - img.setPixel(w, height - 1 - h, qRgb(r, g, b)); + img.setPixel(w, height - 1 - h, qRgb(r, g, b)); + } } + image_view->setImage(img); } - image_view->setImage(img); } QString statusInfo = QString(zeno::format("width: {}, height: {}", width, height).c_str()); pStatusBar->setText(statusInfo); @@ -140,9 +133,13 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) { pGamma->setCheckState(Qt::Checked); pTitleLayout->addWidget(pGamma); - pAlpha->setStyleSheet("color: white;"); - pAlpha->setCheckState(Qt::Unchecked); - pTitleLayout->addWidget(pAlpha); + pMode->addItem("RGB"); + pMode->addItem("Red"); + pMode->addItem("Green"); + pMode->addItem("Blue"); + pMode->addItem("Alpha"); + pMode->setCurrentIndex(0); + pTitleLayout->addWidget(pMode); pFit->setProperty("cssClass", "grayButton"); pTitleLayout->addWidget(pFit); @@ -197,7 +194,7 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) { } } }); - connect(pAlpha, &QCheckBox::stateChanged, this, [=](int state) { + connect(pMode, &ZComboBox::_textActivated, [=](const QString& text) { std::string prim_name = pPrimName->text().toStdString(); Zenovis* zenovis = wids[0]->getZenoVis(); ZASSERT_EXIT(zenovis); @@ -245,17 +242,30 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) { int height = ud.get2("h"); int w = int(zeno::clamp(x, 0, width - 1)); int h = int(zeno::clamp(y, 0, height - 1)); - int i = h * width + w; + int i = (height - 1 - h) * width + w; auto c = obj->verts[i]; - QString statusInfo = QString(zeno::format("width: {}, height: {} | ({}, {}) : ({}, {}, {})" - , width - , height - , w - , h - , c[0] - , c[1] - , c[2] - ).c_str()); + std::string info = zeno::format("width: {}, height: {}", width, height); + info += zeno::format(" | x: {}, y: {}", w, h); + if (pMode->currentText() == "RGB") { + info += zeno::format(" | value: {}, {}, {}", c[0], c[1], c[2]); + } + else if (pMode->currentText() == "Red") { + info += zeno::format(" | value: {}", c[0]); + } + else if (pMode->currentText() == "Green") { + info += zeno::format(" | value: {}", c[1]); + } + else if (pMode->currentText() == "Blue") { + info += zeno::format(" | value: {}", c[2]); + } + else if (pMode->currentText() == "Alpha") { + if (obj->verts.has_attr("alpha")) { + auto &alpha = obj->verts.attr("alpha"); + info += zeno::format(" | value: {}", alpha[i]); + } + } + + QString statusInfo = QString(info.c_str()); pStatusBar->setText(statusInfo); } } diff --git a/ui/zenoedit/panel/zenoimagepanel.h b/ui/zenoedit/panel/zenoimagepanel.h index b7a9ffb42d..b4e0b21b76 100644 --- a/ui/zenoedit/panel/zenoimagepanel.h +++ b/ui/zenoedit/panel/zenoimagepanel.h @@ -6,6 +6,7 @@ #define ZENO_ZENOIMAGEPANEL_H #include +#include class ZenoImageView: public QGraphicsView { Q_OBJECT @@ -92,7 +93,7 @@ class ZenoImagePanel : public QWidget { QLabel* pStatusBar = new QLabel(); QLabel* pPrimName = new QLabel(); QCheckBox *pGamma = new QCheckBox("Gamma"); - QCheckBox *pAlpha = new QCheckBox("Checkerboard"); + ZComboBox *pMode = new ZComboBox(); QPushButton *pFit = new QPushButton("Fit"); ZenoImageView *image_view = nullptr;