From eb96117989453450041a8211c0edceff6db9e8d4 Mon Sep 17 00:00:00 2001 From: castano Date: Mon, 17 Dec 2007 05:26:14 +0000 Subject: [PATCH] Add ui tool temporarily called main... --- src/nvtt/tools/cmdline.h | 5 +- src/nvtt/tools/compress.cpp | 10 +- src/nvtt/tools/configdialog.cpp | 131 ++- src/nvtt/tools/configdialog.h | 37 +- src/nvtt/tools/configdialog.ui | 1554 +++++++++++++++++-------------- src/nvtt/tools/main.cpp | 34 + src/nvtt/tools/resize.cpp | 11 +- 7 files changed, 1072 insertions(+), 710 deletions(-) create mode 100644 src/nvtt/tools/main.cpp diff --git a/src/nvtt/tools/cmdline.h b/src/nvtt/tools/cmdline.h index 78fc706..f4b48b6 100644 --- a/src/nvtt/tools/cmdline.h +++ b/src/nvtt/tools/cmdline.h @@ -26,7 +26,10 @@ #include -#include +#include // stderr +#include // exit +#include // va_list + struct MyMessageHandler : public nv::MessageHandler { MyMessageHandler() { diff --git a/src/nvtt/tools/compress.cpp b/src/nvtt/tools/compress.cpp index afb1000..8942b5f 100644 --- a/src/nvtt/tools/compress.cpp +++ b/src/nvtt/tools/compress.cpp @@ -44,7 +44,7 @@ struct MyOutputHandler : public nvtt::OutputHandler virtual void setTotal(int t) { - total = t; + total = t + 128; } virtual void setDisplayProgress(bool b) { @@ -375,7 +375,7 @@ int main(int argc, char *argv[]) //compressionOptions.setQuality(nvtt::Quality_Production, 0.5f); //compressionOptions.setQuality(nvtt::Quality_Highest); } - compressionOptions.enableHardwareCompression(!nocuda); + compressionOptions.enableCudaCompression(!nocuda); compressionOptions.setColorWeights(1, 1, 1); if (externalCompressor != NULL) @@ -395,8 +395,10 @@ int main(int argc, char *argv[]) outputHandler.setTotal(nvtt::estimateSize(inputOptions, compressionOptions)); outputHandler.setDisplayProgress(!silent); - nvtt::OutputOptions outputOptions(&outputHandler, &errorHandler); - //nvtt::OutputOptions outputOptions(NULL, &errorHandler); + nvtt::OutputOptions outputOptions; + //outputOptions.setFileName(output); + outputOptions.setOutputHandler(&outputHandler); + outputOptions.setErrorHandler(&errorHandler); // printf("Press ENTER.\n"); // fflush(stdout); diff --git a/src/nvtt/tools/configdialog.cpp b/src/nvtt/tools/configdialog.cpp index 275b887..d08c62a 100644 --- a/src/nvtt/tools/configdialog.cpp +++ b/src/nvtt/tools/configdialog.cpp @@ -23,9 +23,138 @@ #include "configdialog.h" +#include + +#include + ConfigDialog::ConfigDialog(QWidget *parent/*=0*/) : QDialog(parent) { - ui.setupUi(this); + init(); } +ConfigDialog::ConfigDialog(const char * fileName, QWidget *parent/*=0*/) : QDialog(parent) +{ + init(); + + open(fileName); +} + +void ConfigDialog::init() +{ + ui.setupUi(this); + + connect(ui.openButton, SIGNAL(clicked()), this, SLOT(openClicked())); + connect(ui.generateMipmapsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(generateMipmapsChanged(int))); + connect(ui.mipmapFilterComboBox, SIGNAL(activated(QString)), this, SLOT(mipmapFilterChanged(QString))); + //connect(ui.mipmapFilterSettings, SIGNAL(clicked()), this, SLOT(mipmapFilterSettingsShow())); + + connect(ui.redSpinBox, SIGNAL(valueChanged(double)), this, SLOT(colorWeightChanged())); + connect(ui.greenSpinBox, SIGNAL(valueChanged(double)), this, SLOT(colorWeightChanged())); + connect(ui.blueSpinBox, SIGNAL(valueChanged(double)), this, SLOT(colorWeightChanged())); + connect(ui.uniformButton, SIGNAL(toggled(bool)), this, SLOT(uniformWeightToggled(bool))); + connect(ui.luminanceButton, SIGNAL(toggled(bool)), this, SLOT(luminanceWeightToggled(bool))); +} + + +void ConfigDialog::openClicked() +{ + // @@ Open file dialog. + + QString fileName; + + open(fileName); +} + +void ConfigDialog::generateMipmapsChanged(int state) +{ + Q_UNUSED(state); + + bool generateMipmapEnabled = ui.generateMipmapsCheckBox->isChecked(); + + ui.mipmapFilterLabel->setEnabled(generateMipmapEnabled); + ui.mipmapFilterComboBox->setEnabled(generateMipmapEnabled); + ui.limitMipmapsCheckBox->setEnabled(generateMipmapEnabled); + + bool enableFilterSettings = (ui.mipmapFilterComboBox->currentText() == "Kaiser"); + ui.mipmapFilterSettings->setEnabled(generateMipmapEnabled && enableFilterSettings); + + bool enableMaxLevel = ui.limitMipmapsCheckBox->isChecked(); + ui.maxLevelLabel->setEnabled(generateMipmapEnabled && enableMaxLevel); + ui.maxLevelSpinBox->setEnabled(generateMipmapEnabled && enableMaxLevel); +} + +void ConfigDialog::mipmapFilterChanged(QString name) +{ + bool enableFilterSettings = (name == "Kaiser"); + ui.mipmapFilterSettings->setEnabled(enableFilterSettings); +} + + +void ConfigDialog::colorWeightChanged() +{ + double r = ui.redSpinBox->value(); + double g = ui.greenSpinBox->value(); + double b = ui.blueSpinBox->value(); + + bool uniform = (r == 1.0 && g == 1.0 && b == 1.0); + bool luminance = (r == 0.3 && g == 0.59 && b == 0.11); + + ui.uniformButton->setChecked(uniform); + ui.luminanceButton->setChecked(luminance); +} + +void ConfigDialog::uniformWeightToggled(bool checked) +{ + if (checked) + { + ui.redSpinBox->setValue(1.0); + ui.greenSpinBox->setValue(1.0); + ui.blueSpinBox->setValue(1.0); + } +} + +void ConfigDialog::luminanceWeightToggled(bool checked) +{ + if (checked) + { + ui.redSpinBox->setValue(0.3); + ui.greenSpinBox->setValue(0.59); + ui.blueSpinBox->setValue(0.11); + } +} + + + + +bool ConfigDialog::open(QString fileName) +{ + // @@ Load image. + QImage image; + + // @@ If success. + { + ui.imagePathLineEdit->setText(fileName); + + // @@ Set image in graphics view. + + // @@ Set image description. + + // @@ Provide image to nvtt. + + int w = image.width(); + int h = image.height(); + void * data = NULL; + + inputOptions.setTextureLayout(nvtt::TextureType_2D, w, h); + inputOptions.setMipmapData(data, w, h); + + return true; + } + + return false; +} + + + + diff --git a/src/nvtt/tools/configdialog.h b/src/nvtt/tools/configdialog.h index c0799d2..f68201d 100644 --- a/src/nvtt/tools/configdialog.h +++ b/src/nvtt/tools/configdialog.h @@ -26,17 +26,42 @@ #include -#include "ui_nvdxtdialog.h" +#include "ui_configdialog.h" + +#include class ConfigDialog : public QDialog { Q_OBJECT - public: - ConfigDialog(QWidget *parent = 0); - - private: - Ui::ConfigDialog ui; +public: + ConfigDialog(QWidget *parent = 0); + ConfigDialog(const char * fileName, QWidget *parent = 0); + +protected slots: + + void openClicked(); + void generateMipmapsChanged(int state); + void mipmapFilterChanged(QString name); + + void colorWeightChanged(); + void uniformWeightToggled(bool checked); + void luminanceWeightToggled(bool checked); + + + bool open(QString fileName); + +private: + + void init(); + +private: + Ui::ConfigDialog ui; + + nvtt::InputOptions inputOptions; + nvtt::CompressionOptions compressionOptions; + nvtt::OutputOptions outputOptions; + }; diff --git a/src/nvtt/tools/configdialog.ui b/src/nvtt/tools/configdialog.ui index fdea83b..e6aa841 100644 --- a/src/nvtt/tools/configdialog.ui +++ b/src/nvtt/tools/configdialog.ui @@ -5,286 +5,221 @@ 0 0 - 626 - 532 + 591 + 510 - Dialog + NVIDIA Texture Tools + + + true - - 9 - - - 6 - - - 0 - - - 6 - - - - - 7 - 7 - 0 - 0 - - - - - 64 - 0 - - - - - 128 - 16777215 - - - - Qt::ScrollBarAlwaysOff - - - QListView::Static - - - QListView::TopToBottom - - - false - - - QListView::Adjust - - - QListView::IconMode - + - - Input - - - ../../../../../../castano-stuff/qshaderedit/src/images/win/fileopen.png - + + + + 0 + 0 + + + + + 64 + 0 + + + + + 128 + 16777215 + + + + Qt::ScrollBarAlwaysOff + + + QListView::Static + + + QListView::TopToBottom + + + false + + + QListView::Adjust + + + QListView::ListMode + + + + Input Options + + + + + Compression Options + + + + + Output Options + + + + + Preview + + + ../../../../../../castano-stuff/qshaderedit/src/images/colorpicker.png + + + - - - Output - - - ../../../../../../castano-stuff/qshaderedit/src/images/win/filesave.png - - - - - Settings - - - ../../../../../../castano-stuff/qshaderedit/src/images/toolbutton.png - - - - - Preview - - - ../../../../../../castano-stuff/qshaderedit/src/images/colorpicker.png - - - - - 3D Preview - - - ../../../../../../castano-stuff/qshaderedit/src/images/colorpicker.png - - - + - - - - 7 - 7 - 5 - 0 - - - - - 400 - 0 - - - - QTabWidget::North - - - QTabWidget::Rounded - + 0 - - - Input - + - - 9 + + 0 - - 6 + + 0 + + + 0 + + + 0 - - + + 0 - - 6 + + false - - - - - - - Open - - - - - - - - - 0 - - - 6 - - + + + File Path + - - 0 - - - 6 - - - - - 0 - 0 - 0 - 0 - + + + 6 - - - 172 - 172 - + + 0 - - - 172 - 172 - + + 0 - - true + + 0 - - Drop images here + + 0 - - QFrame::StyledPanel - - - - - - ../../../../../../castano-stuff/qshaderedit/src/images/default.png - - - true - - - 1 - - + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Open + + + + - - - false - + + + + - - 0 - 7 + 0 0 - + - 172 - 0 + 16777215 + 120 - - QFrame::StyledPanel + + true - - + + + + Image Settings + - - 0 - - - 4 - - + - - 5 - 5 + 0 0 - Type + Color Mode - - 4 - 0 + + 4 + + + 4 + + + 4 + + + 4 + - + RGB @@ -294,21 +229,7 @@ - - - RGBA - - - - - - - Monochrome - - - - - + Normal Map @@ -318,73 +239,110 @@ - - - false + + + + 0 + 0 + - - Alpha is opacity - - - - - - - false - - - Convert to normal map - - - - - - - Generate mipmaps - - - true + + Alpha Mode + + + 0 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + None + + + false + + + + + + + Transparency + + + true + + + + + + + Premultiplied + + + + - + 0 - - 6 + + 0 + + + 0 + + + 0 + + + 0 - + - Mipmap filter + Wrap Mode: - comboBox + mipmapFilterComboBox - + + + + 16777215 + 26 + + - Box + Mirror - Triangle + Repeat - Mitchell - - - - - Kaiser + Clamp @@ -393,41 +351,102 @@ - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + - - 1 - 5 + 0 0 - Gamma + Input Gamma: - gammaSpinBox + inputGammaSpinBox - + QAbstractSpinBox::UpDownArrows + + 0.050000000000000 + 4.000000000000000 + + 0.050000000000000 + + + 2.200000000000000 + + + + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Output Gamma: + + + inputGammaSpinBox + + + + + + + QAbstractSpinBox::UpDownArrows + 0.050000000000000 + + 4.000000000000000 + 0.050000000000000 @@ -438,6 +457,167 @@ + + + + Qt::Vertical + + + + 204 + 131 + + + + + + + + + Mipmap Settings + + + + + + Generate mipmaps + + + true + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Mipmap filter: + + + mipmapFilterComboBox + + + + + + + + 16777215 + 26 + + + + + Box + + + + + Triangle + + + + + Kaiser + + + + + + + + false + + + + 0 + 0 + + + + + 16777215 + 26 + + + + false + + + ... + + + + + + + + + + + + 0 + 0 + + + + Limit Mipmaps + + + + + + + false + + + + 0 + 0 + + + + Max Level: + + + + + + + false + + + + 0 + 0 + + + + + 80 + 16777215 + + + + + + @@ -452,126 +632,304 @@ - - + + + + Normal Map Settings + + + - - - Output - + - - 9 - - - 6 - - - 0 - - - 6 - - - - 0 - - - 6 - - - - - Format: - - - Qt::PlainText - - - Qt::NoTextInteraction - - - formatComboBox - - - - - - - - BC1 (DXT1) - - - - - BC2 (DXT3) - - - - - BC3 (DXT5) - - - - - - - - Color Space: - - - comboBox_2 - - - - - - - - RGB - - - - - YCoCg - - - - - JPEG LS (R-G, G, B-G) - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + - Export + Format: + + + Qt::PlainText + + + Qt::NoTextInteraction + + + formatComboBox + + + + + Uncompressed + + + + + BC1 (DXT1) + + + + + BC1a (DXT1a) + + + + + BC2 (DXT3) + + + + + BC3 (DXT5) + + + + + BC4 + + + + + BC5 + + + + + + + + + + Quality: + + + Qt::PlainText + + + Qt::NoTextInteraction + + + formatComboBox + + + + + + + 1 + + + + Fastest + + + + + Normal + + + + + Production + + + + + Highest + + + + + + + + + + + 0 + 0 + + + + Color Weights + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Red + + + redSpinBox + + + + + + + 1.000000000000000 + + + 0.050000000000000 + + + 1.000000000000000 + + + + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Green + + + greenSpinBox + + + + + + + 1.000000000000000 + + + 0.050000000000000 + + + 1.000000000000000 + + + + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Blue + + + blueSpinBox + + + + + + + 1.000000000000000 + + + 0.050000000000000 + + + 1.000000000000000 + + + + + + + + + + + + 16777215 + 22 + + + + Uniform Weights + + + true + + + true + + + + + + + + 16777215 + 22 + + + + Luminance Weights + + + true + + + + + + + + @@ -580,249 +938,67 @@ 20 - 40 + 191 - - - Settings - - - - - 10 - 10 - 202 - 242 - - - - - 0 - - - 6 - - - - - Quality - - - - 9 - - - 6 - - - - - 9 - - - 9 - - - Qt::Horizontal - - - - - - - QFrame::StyledPanel - - - QFrame::Plain - - - 9 - Best - - - Qt::PlainText - - - Qt::NoTextInteraction - - - horizontalSlider - - - - - - - 0 - - - 6 - - - - - Threshold - - - - - - - - - - - - - - - Color Weights - - - - 9 - - - 0 - - - - - 0 - - - 6 - - - - - Red - - - doubleSpinBox_2 - - - - - - - - - - - - 0 - - - 6 - - - - - Green - - - doubleSpinBox_3 - - - - - - - - - - - - 0 - - - 6 - - - - - Blue - - - doubleSpinBox_4 - - - - - - - - - - - - - - - - - Preview - + + - - 9 + + 0 - - 6 + + 0 + + + 0 + + + 0 - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + - - - Input - - - - 3 - - - 6 - - - - - - - - Output - - - - 3 - - - 6 - - - + - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -844,76 +1020,6 @@ - - - 3D Preview - - - - 9 - - - 6 - - - - - 0 - - - 6 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - Quad - - - - - Sphere - - - - - Cylinder - - - - - Teapot - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - @@ -927,12 +1033,21 @@ - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -942,12 +1057,21 @@ + + true + - 24 + 0 + + + true Qt::Horizontal + + false + @@ -966,16 +1090,64 @@ listWidget currentRowChanged(int) - tabWidget - setCurrentPage(int) + stackedWidget + setCurrentIndex(int) - 114 - 67 + 118 + 193 - 173 - 95 + 154 + 220 + + + + + pushButton + clicked() + ConfigDialog + accept() + + + 565 + 491 + + + 582 + 506 + + + + + limitMipmapsCheckBox + clicked(bool) + maxLevelSpinBox + setEnabled(bool) + + + 451 + 120 + + + 524 + 120 + + + + + limitMipmapsCheckBox + clicked(bool) + maxLevelLabel + setEnabled(bool) + + + 337 + 120 + + + 482 + 124 diff --git a/src/nvtt/tools/main.cpp b/src/nvtt/tools/main.cpp new file mode 100644 index 0000000..48b9532 --- /dev/null +++ b/src/nvtt/tools/main.cpp @@ -0,0 +1,34 @@ +// Copyright NVIDIA Corporation 2007 -- Ignacio Castano +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + +#include +#include "configdialog.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + ConfigDialog dialog; + return dialog.exec(); +} + + diff --git a/src/nvtt/tools/resize.cpp b/src/nvtt/tools/resize.cpp index 312b9a9..725d820 100644 --- a/src/nvtt/tools/resize.cpp +++ b/src/nvtt/tools/resize.cpp @@ -84,14 +84,14 @@ int main(int argc, char *argv[]) if (strcmp("-s", argv[i]) == 0) { if (i+1 < argc && argv[i+1][0] != '-') { - scale = (float)atof(argv[i+1]); + scale = atof(argv[i+1]); i++; } } else if (strcmp("-g", argv[i]) == 0) { if (i+1 < argc && argv[i+1][0] != '-') { - gamma = (float)atof(argv[i+1]); + gamma = atof(argv[i+1]); i++; } } @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) else if (strcmp("mitchell", argv[i]) == 0) filter = new nv::MitchellFilter(); else if (strcmp("lanczos", argv[i]) == 0) filter = new nv::LanczosFilter(); else if (strcmp("kaiser", argv[i]) == 0) { - filter = new nv::KaiserFilter(5); + filter = new nv::KaiserFilter(3); ((nv::KaiserFilter *)filter)->setParameters(4.0f, 1.0f); } } @@ -155,10 +155,7 @@ int main(int argc, char *argv[]) nv::FloatImage fimage(&image); fimage.toLinear(0, 3, gamma); - int w = int(image.width() * scale); - int h = int(image.height() * scale); - - nv::AutoPtr fresult(fimage.downSample(*filter, w, h, nv::FloatImage::WrapMode_Mirror)); + nv::AutoPtr fresult(fimage.downSample(*filter, image.width() * scale, image.height() * scale, nv::FloatImage::WrapMode_Mirror)); nv::AutoPtr result(fresult->createImageGammaCorrect(gamma));