Fix cuda compressor. Start work on new UI.

This commit is contained in:
castano 2010-10-18 08:47:50 +00:00
parent 5d80fb8219
commit 5d498d6824
7 changed files with 1887 additions and 1177 deletions

View File

@ -29,12 +29,6 @@
#define NUM_THREADS 64 // Number of threads per block.
#if __DEVICE_EMULATION__
#define __debugsync() __syncthreads()
#else
#define __debugsync()
#endif
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
@ -345,30 +339,6 @@ __device__ int packColors(float3 * values, float * weights, int * ranks)
__device__ void sortColors(const float * values, int * ranks)
{
#if __DEVICE_EMULATION__
if (threadIdx.x == 0)
{
for (int tid = 0; tid < 16; tid++)
{
int rank = 0;
for (int i = 0; i < 16; i++)
{
rank += (values[i] < values[tid]);
}
ranks[tid] = rank;
}
// Resolve elements with the same index.
for (int i = 0; i < 15; i++)
{
for (int tid = 0; tid < 16; tid++)
{
if (tid > i && ranks[tid] == ranks[i]) ++ranks[tid];
}
}
}
#else
const int tid = threadIdx.x;
int rank = 0;
@ -387,35 +357,10 @@ __device__ void sortColors(const float * values, int * ranks)
{
if ((tid > i) & (ranks[tid] == ranks[i])) ++ranks[tid];
}
#endif
}
__device__ void sortColors(const float * values, int * ranks, int count)
{
#if __DEVICE_EMULATION__
if (threadIdx.x == 0)
{
for (int tid = 0; tid < count; tid++)
{
int rank = 0;
for (int i = 0; i < count; i++)
{
rank += (values[i] < values[tid]);
}
ranks[tid] = rank;
}
// Resolve elements with the same index.
for (int i = 0; i < count-1; i++)
{
for (int tid = 0; tid < count; tid++)
{
if (tid > i && ranks[tid] == ranks[i]) ++ranks[tid];
}
}
}
#else
const int tid = threadIdx.x;
int rank = 0;
@ -434,7 +379,6 @@ __device__ void sortColors(const float * values, int * ranks, int count)
{
if ((tid > i) & (ranks[tid] == ranks[i])) ++ranks[tid];
}
#endif
}
@ -443,7 +387,7 @@ __device__ void sortColors(const float * values, int * ranks, int count)
// Load color block to shared mem
////////////////////////////////////////////////////////////////////////////////
/*__device__ void loadColorBlock(const uint * image, float3 colors[16], float3 sums[16], int xrefs[16], int * sameColor)
__device__ void loadColorBlockTex(uint firstBlock, uint blockWidth, float3 colors[16], float3 sums[16], int xrefs[16], int * sameColor)
{
const int bid = blockIdx.x;
const int idx = threadIdx.x;
@ -452,51 +396,8 @@ __device__ void sortColors(const float * values, int * ranks, int count)
if (idx < 16)
{
// Read color and copy to shared mem.
uint c = image[(bid) * 16 + idx];
colors[idx] = color32ToFloat3(c);
// No need to synchronize, 16 < warp size.
__debugsync();
// Sort colors along the best fit line.
colorSums(colors, sums);
float3 axis = bestFitLine(colors, sums[0], kColorMetric);
*sameColor = (axis == make_float3(0, 0, 0));
dps[idx] = dot(colors[idx], axis);
__debugsync();
sortColors(dps, xrefs);
float3 tmp = colors[idx];
__debugsync();
colors[xrefs[idx]] = tmp;
}
#if __DEVICE_EMULATION__
else
{
__debugsync();
__debugsync();
__debugsync();
}
#endif
}*/
__device__ void loadColorBlockTex(uint firstBlock, uint width, float3 colors[16], float3 sums[16], int xrefs[16], int * sameColor)
{
const int bid = blockIdx.x;
const int idx = threadIdx.x;
__shared__ float dps[16];
if (idx < 16)
{
float x = 4 * ((firstBlock + bid) % width) + idx % 4; // @@ Avoid mod and div by using 2D grid?
float y = 4 * ((firstBlock + bid) / width) + idx / 4;
float x = 4 * ((firstBlock + bid) % blockWidth) + idx % 4; // @@ Avoid mod and div by using 2D grid?
float y = 4 * ((firstBlock + bid) / blockWidth) + idx / 4;
// Read color and copy to shared mem.
float4 c = tex2D(tex, x, y);
@ -505,9 +406,6 @@ __device__ void loadColorBlockTex(uint firstBlock, uint width, float3 colors[16]
colors[idx].y = c.y;
colors[idx].z = c.x;
// No need to synchronize, 16 < warp size.
__debugsync();
// Sort colors along the best fit line.
colorSums(colors, sums);
float3 axis = bestFitLine(colors, sums[0], kColorMetric);
@ -516,22 +414,11 @@ __device__ void loadColorBlockTex(uint firstBlock, uint width, float3 colors[16]
dps[idx] = dot(colors[idx], axis);
__debugsync();
sortColors(dps, xrefs);
float3 tmp = colors[idx];
__debugsync();
colors[xrefs[idx]] = tmp;
}
#if __DEVICE_EMULATION__
else
{
__debugsync();
__debugsync();
__debugsync();
}
#endif
}
/*
@ -598,9 +485,6 @@ __device__ void loadColorBlockTex(uint firstBlock, uint width, float3 colors[16]
colors[idx] = rawColors[idx] * weights[idx];
// No need to synchronize, 16 < warp size.
__debugsync();
// Sort colors along the best fit line.
colorSums(colors, sums);
float3 axis = bestFitLine(colors, sums[0], kColorMetric);
@ -612,82 +496,15 @@ __device__ void loadColorBlockTex(uint firstBlock, uint width, float3 colors[16]
dps[idx] = dot(colors[idx], axis);
__debugsync();
sortColors(dps, xrefs);
float3 tmp = colors[idx];
float w = weights[idx];
__debugsync();
colors[xrefs[idx]] = tmp;
weights[xrefs[idx]] = w;
}
#if __DEVICE_EMULATION__
else
{
__debugsync();
__debugsync();
__debugsync();
}
#endif
}
/*
__device__ void loadColorBlock(const uint * image, float3 colors[16], float3 sums[16], float weights[16], int xrefs[16], int * sameColor)
{
const int bid = blockIdx.x;
const int idx = threadIdx.x;
__shared__ float3 rawColors[16];
__shared__ float dps[16];
if (idx < 16)
{
// Read color and copy to shared mem.
uint c = image[(bid) * 16 + idx];
rawColors[idx].z = ((c >> 0) & 0xFF) * (1.0f / 255.0f);
rawColors[idx].y = ((c >> 8) & 0xFF) * (1.0f / 255.0f);
rawColors[idx].x = ((c >> 16) & 0xFF) * (1.0f / 255.0f);
weights[idx] = (((c >> 24) & 0xFF) + 1) * (1.0f / 256.0f);
colors[idx] = rawColors[idx] * weights[idx];
// No need to synchronize, 16 < warp size.
__debugsync();
// Sort colors along the best fit line.
colorSums(colors, sums);
float3 axis = bestFitLine(colors, sums[0], kColorMetric);
*sameColor = (axis == make_float3(0, 0, 0));
// Single color compressor needs unweighted colors.
if (*sameColor) colors[idx] = rawColors[idx];
dps[idx] = dot(rawColors[idx], axis);
__debugsync();
sortColors(dps, xrefs);
float3 tmp = colors[idx];
float w = weights[idx];
__debugsync();
colors[xrefs[idx]] = tmp;
weights[xrefs[idx]] = w;
}
#if __DEVICE_EMULATION__
else
{
__debugsync();
__debugsync();
__debugsync();
}
#endif
}
*/
__device__ void loadColorBlock(const uint * image, float2 colors[16], float2 sums[16], int xrefs[16], int * sameColor)
{
const int bid = blockIdx.x;
@ -703,9 +520,6 @@ __device__ void loadColorBlock(const uint * image, float2 colors[16], float2 sum
colors[idx].y = ((c >> 8) & 0xFF) * (1.0f / 255.0f);
colors[idx].x = ((c >> 16) & 0xFF) * (1.0f / 255.0f);
// No need to synchronize, 16 < warp size.
__debugsync();
// Sort colors along the best fit line.
colorSums(colors, sums);
float2 axis = bestFitLine(colors, sums[0]);
@ -714,22 +528,11 @@ __device__ void loadColorBlock(const uint * image, float2 colors[16], float2 sum
dps[idx] = dot(colors[idx], axis);
__debugsync();
sortColors(dps, xrefs);
float2 tmp = colors[idx];
__debugsync();
colors[xrefs[idx]] = tmp;
}
#if __DEVICE_EMULATION__
else
{
__debugsync();
__debugsync();
__debugsync();
}
#endif
}
@ -1389,23 +1192,6 @@ __device__ int findMinError(float * errors)
__shared__ int indices[NUM_THREADS];
indices[idx] = idx;
#if __DEVICE_EMULATION__
for(int d = NUM_THREADS/2; d > 0; d >>= 1)
{
__syncthreads();
if (idx < d)
{
float err0 = errors[idx];
float err1 = errors[idx + d];
if (err1 < err0) {
errors[idx] = err1;
indices[idx] = indices[idx + d];
}
}
}
#else
for(int d = NUM_THREADS/2; d > 32; d >>= 1)
{
__syncthreads();
@ -1452,7 +1238,6 @@ __device__ int findMinError(float * errors)
indices[idx] = indices[idx + 1];
}
}
#endif
__syncthreads();
@ -1651,14 +1436,14 @@ __device__ void saveSingleColorBlockCTX1(float2 color, uint2 * result)
// Compress color block
////////////////////////////////////////////////////////////////////////////////
__global__ void compressDXT1(uint firstBlock, uint w, const uint * permutations, uint2 * result)
__global__ void compressDXT1(uint firstBlock, uint blockWidth, const uint * permutations, uint2 * result)
{
__shared__ float3 colors[16];
__shared__ float3 sums[16];
__shared__ int xrefs[16];
__shared__ int sameColor;
loadColorBlockTex(firstBlock, w, colors, sums, xrefs, &sameColor);
loadColorBlockTex(firstBlock, blockWidth, colors, sums, xrefs, &sameColor);
__syncthreads();
@ -1694,14 +1479,14 @@ __global__ void compressDXT1(uint firstBlock, uint w, const uint * permutations,
}
__global__ void compressLevel4DXT1(uint firstBlock, uint w, const uint * permutations, uint2 * result)
__global__ void compressLevel4DXT1(uint firstBlock, uint blockWidth, const uint * permutations, uint2 * result)
{
__shared__ float3 colors[16];
__shared__ float3 sums[16];
__shared__ int xrefs[16];
__shared__ int sameColor;
loadColorBlockTex(firstBlock, w, colors, sums, xrefs, &sameColor);
loadColorBlockTex(firstBlock, blockWidth, colors, sums, xrefs, &sameColor);
__syncthreads();
@ -1728,7 +1513,7 @@ __global__ void compressLevel4DXT1(uint firstBlock, uint w, const uint * permuta
}
}
__global__ void compressWeightedDXT1(uint firstBlock, uint w, const uint * permutations, uint2 * result)
__global__ void compressWeightedDXT1(uint firstBlock, uint blockWidth, const uint * permutations, uint2 * result)
{
__shared__ float3 colors[16];
__shared__ float3 sums[16];
@ -1736,7 +1521,7 @@ __global__ void compressWeightedDXT1(uint firstBlock, uint w, const uint * permu
__shared__ int xrefs[16];
__shared__ int sameColor;
loadColorBlockTex(firstBlock, w, colors, sums, weights, xrefs, &sameColor);
loadColorBlockTex(firstBlock, blockWidth, colors, sums, weights, xrefs, &sameColor);
__syncthreads();
@ -2165,33 +1950,33 @@ extern "C" void bindTextureToArray(cudaArray * d_data)
////////////////////////////////////////////////////////////////////////////////
// DXT1 compressors:
extern "C" void compressKernelDXT1(uint firstBlock, uint blockNum, uint w, uint * d_result, uint * d_bitmaps)
extern "C" void compressKernelDXT1(uint firstBlock, uint blockNum, uint blockWidth, uint * d_result, uint * d_bitmaps)
{
compressDXT1<<<blockNum, NUM_THREADS>>>(firstBlock, w, d_bitmaps, (uint2 *)d_result);
compressDXT1<<<blockNum, NUM_THREADS>>>(firstBlock, blockWidth, d_bitmaps, (uint2 *)d_result);
}
extern "C" void compressKernelDXT1_Level4(uint firstBlock, uint blockNum, uint w, uint * d_result, uint * d_bitmaps)
extern "C" void compressKernelDXT1_Level4(uint firstBlock, uint blockNum, uint blockWidth, uint * d_result, uint * d_bitmaps)
{
compressLevel4DXT1<<<blockNum, NUM_THREADS>>>(firstBlock, w, d_bitmaps, (uint2 *)d_result);
compressLevel4DXT1<<<blockNum, NUM_THREADS>>>(firstBlock, blockWidth, d_bitmaps, (uint2 *)d_result);
}
extern "C" void compressWeightedKernelDXT1(uint firstBlock, uint blockNum, uint w, uint * d_result, uint * d_bitmaps)
extern "C" void compressWeightedKernelDXT1(uint firstBlock, uint blockNum, uint blockWidth, uint * d_result, uint * d_bitmaps)
{
compressWeightedDXT1<<<blockNum, NUM_THREADS>>>(firstBlock, w, d_bitmaps, (uint2 *)d_result);
compressWeightedDXT1<<<blockNum, NUM_THREADS>>>(firstBlock, blockWidth, d_bitmaps, (uint2 *)d_result);
}
// @@ DXT1a compressors.
// @@ DXT3 compressors:
extern "C" void compressKernelDXT3(uint firstBlock, uint blockNum, uint w, uint * d_result, uint * d_bitmaps)
extern "C" void compressKernelDXT3(uint firstBlock, uint blockNum, uint blockWidth, uint * d_result, uint * d_bitmaps)
{
//compressDXT3<<<blockNum, NUM_THREADS>>>(firstBlock, w, d_bitmaps, (uint2 *)d_result);
//compressDXT3<<<blockNum, NUM_THREADS>>>(firstBlock, blockWidth, d_bitmaps, (uint2 *)d_result);
}
extern "C" void compressWeightedKernelDXT3(uint firstBlock, uint blockNum, uint w, uint * d_result, uint * d_bitmaps)
extern "C" void compressWeightedKernelDXT3(uint firstBlock, uint blockNum, uint blockWidth, uint * d_result, uint * d_bitmaps)
{
//compressWeightedDXT3<<<blockNum, NUM_THREADS>>>(firstBlock, w, d_bitmaps, (uint2 *)d_result);
//compressWeightedDXT3<<<blockNum, NUM_THREADS>>>(firstBlock, blockWidth, d_bitmaps, (uint2 *)d_result);
}

View File

@ -34,10 +34,10 @@
#include "nvtt/QuickCompressDXT.h"
#include "nvtt/OptimalCompressDXT.h"
#include <time.h>
#include <stdio.h>
#if defined HAVE_CUDA
#include <cuda_runtime_api.h>
@ -141,7 +141,7 @@ void CudaCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alp
}
else
{
#pragma message(NV_FILE_LINE "FIXME: Floating point textures not really supported by CUDA compressors.")
#pragma message(NV_FILE_LINE "FIXME: Floating point textures not really supported by CUDA compressors.") // @@ What's missing???
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 32, 32, 32, cudaChannelFormatKindFloat);
cudaMallocArray(&d_image, &channelDesc, w, h);
@ -156,7 +156,7 @@ void CudaCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alp
const uint blockNum = bw * bh;
const uint compressedSize = blockNum * bs;
void * h_result = malloc(min(blockNum, MAX_BLOCKS) * bs);
void * h_result = ::malloc(min(blockNum, MAX_BLOCKS) * bs);
setup(d_image, compressionOptions);
@ -164,11 +164,11 @@ void CudaCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alp
// timer.start();
uint bn = 0;
while(bn != blockNum)
while (bn != blockNum)
{
uint count = min(blockNum - bn, MAX_BLOCKS);
compressBlocks(bn, count, w, h, alphaMode, compressionOptions, h_result);
compressBlocks(bn, count, bw, bh, alphaMode, compressionOptions, h_result);
// Check for errors.
cudaError_t err = cudaGetLastError();
@ -198,10 +198,10 @@ void CudaCompressorDXT1::setup(cudaArray * image, const nvtt::CompressionOptions
bindTextureToArray(image);
}
void CudaCompressorDXT1::compressBlocks(uint first, uint count, uint w, uint h, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
void CudaCompressorDXT1::compressBlocks(uint first, uint count, uint bw, uint bh, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
{
// Launch kernel.
compressKernelDXT1(first, count, w, m_ctx.result, m_ctx.bitmapTable);
compressKernelDXT1(first, count, bw, m_ctx.result, m_ctx.bitmapTable);
// Copy result to host.
cudaMemcpy(output, m_ctx.result, count * 8, cudaMemcpyDeviceToHost);
@ -214,10 +214,10 @@ void CudaCompressorDXT3::setup(cudaArray * image, const nvtt::CompressionOptions
bindTextureToArray(image);
}
void CudaCompressorDXT3::compressBlocks(uint first, uint count, uint w, uint h, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
void CudaCompressorDXT3::compressBlocks(uint first, uint count, uint bw, uint bh, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
{
// Launch kernel.
compressKernelDXT3(first, count, w, m_ctx.result, m_ctx.bitmapTable);
compressKernelDXT3(first, count, bw, m_ctx.result, m_ctx.bitmapTable);
// Copy result to host.
cudaMemcpy(output, m_ctx.result, count * 16, cudaMemcpyDeviceToHost);
@ -230,10 +230,10 @@ void CudaCompressorDXT5::setup(cudaArray * image, const nvtt::CompressionOptions
bindTextureToArray(image);
}
void CudaCompressorDXT5::compressBlocks(uint first, uint count, uint w, uint h, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
void CudaCompressorDXT5::compressBlocks(uint first, uint count, uint bw, uint bh, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output)
{
/*// Launch kernel.
compressKernelDXT5(first, count, w, m_ctx.result, m_ctx.bitmapTable);
compressKernelDXT5(first, count, bw, m_ctx.result, m_ctx.bitmapTable);
// Copy result to host.
cudaMemcpy(output, m_ctx.result, count * 16, cudaMemcpyDeviceToHost);*/
@ -241,7 +241,7 @@ void CudaCompressorDXT5::compressBlocks(uint first, uint count, uint w, uint h,
// Launch kernel.
if (alphaMode == AlphaMode_Transparency)
{
// compressWeightedKernelDXT1(first, count, w, m_ctx.result, m_ctx.bitmapTable);
// compressWeightedKernelDXT1(first, count, bw, m_ctx.result, m_ctx.bitmapTable);
}
else
{

View File

@ -48,14 +48,13 @@ IF(GCONFTOOL2)
ENDIF(GCONFTOOL2)
# UI tools
IF(QT4_FOUND) # AND NOT MSVC)
IF(QT4_FOUND)
SET(QT_USE_QTOPENGL TRUE)
INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
SET(SRCS
ui/main.cpp
ui/configdialog.h
ui/configdialog.cpp)
compressdialog.h
compressdialog.cpp)
SET(LIBS
nvtt
@ -63,12 +62,12 @@ IF(QT4_FOUND) # AND NOT MSVC)
${QT_QTGUI_LIBRARY}
${QT_QTOPENGL_LIBRARY})
QT4_WRAP_UI(UICS ui/configdialog.ui)
QT4_WRAP_CPP(MOCS ui/configdialog.h)
QT4_WRAP_UI(UICS compressdialog.ui)
QT4_WRAP_CPP(MOCS compressdialog.h)
#QT4_ADD_RESOURCES(RCCS ui/configdialog.rc)
#ADD_EXECUTABLE(nvcompressui MACOSX_BUNDLE ${SRCS} ${UICS} ${MOCS})
#TARGET_LINK_LIBRARIES(nvcompressui ${LIBS})
ADD_EXECUTABLE(nvtt-diag MACOSX_BUNDLE ${SRCS} ${UICS} ${MOCS})
TARGET_LINK_LIBRARIES(nvtt-diag ${LIBS})
ENDIF(QT4_FOUND) # AND NOT MSVC)
ENDIF(QT4_FOUND)

View File

@ -0,0 +1,124 @@
#include "compressdialog.h"
#include "ui_compressdialog.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CompressDialog dialog("");
return dialog.exec();
}
CompressDialog::CompressDialog(const QString & fileName, QWidget *parent) : QDialog(parent)
{
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.formatComboBox, SIGNAL(activated(QString)), this, SLOT(formatChanged(QString)));
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)));
//connect(ui.rgbMapRadioButton, SIGNAL(toggled(bool)), this, SLOT(colorModeChanged()));
//connect(ui.normalMapRadioButton, SIGNAL(toggled(bool)), this, SLOT(normalMapModeChanged(bool)));
}
CompressDialog::~CompressDialog()
{
}
void CompressDialog::openClicked()
{
// @@ What is openButton?
}
void CompressDialog::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 CompressDialog::mipmapFilterChanged(QString name)
{
bool enableFilterSettings = (name == "Kaiser");
ui.mipmapFilterSettings->setEnabled(enableFilterSettings);
}
void CompressDialog::formatChanged(QString format)
{
if (format == "Uncompressed") {
ui.formatOptions->setCurrentIndex(1);
}
else {
ui.formatOptions->setCurrentIndex(0);
}
}
void CompressDialog::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 CompressDialog::uniformWeightToggled(bool checked)
{
if (checked)
{
ui.redSpinBox->setValue(1.0);
ui.greenSpinBox->setValue(1.0);
ui.blueSpinBox->setValue(1.0);
}
}
void CompressDialog::luminanceWeightToggled(bool checked)
{
if (checked)
{
ui.redSpinBox->setValue(0.3);
ui.greenSpinBox->setValue(0.59);
ui.blueSpinBox->setValue(0.11);
}
}
void CompressDialog::normalMapModeChanged(bool checked)
{
//ui.alphaModeGroupBox->setEnabled(!checked);
//ui.inputGammaSpinBox->setEnabled(!checked);
//ui.inputGammaLabel->setEnabled(!checked);
//ui.outputGammaSpinBox->setEnabled(!checked);
//ui.outputGammaLabel->setEnabled(!checked);
}

View File

@ -0,0 +1,34 @@
#ifndef COMPRESSDIALOG_H
#define COMPRESSDIALOG_H
#include <QtGui/QDialog>
#include "ui_compressdialog.h"
class CompressDialog : public QDialog
{
Q_OBJECT
public:
explicit CompressDialog(const QString & fileName, QWidget *parent = 0);
~CompressDialog();
protected slots:
void openClicked();
void generateMipmapsChanged(int state);
void mipmapFilterChanged(QString name);
void formatChanged(QString format);
void colorWeightChanged();
void uniformWeightToggled(bool checked);
void luminanceWeightToggled(bool checked);
void normalMapModeChanged(bool checked);
private:
Ui::CompressDialog ui;
};
#endif // COMPRESSDIALOG_H

View File

@ -0,0 +1,768 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CompressDialog</class>
<widget class="QDialog" name="CompressDialog">
<property name="minimumSize">
<size>
<width>280</width>
<height>540</height>
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>8</number>
</property>
<property name="margin">
<number>10</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>24</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QToolBox" name="toolBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="currentIndex">
<number>3</number>
</property>
<widget class="QWidget" name="page_info">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>249</width>
<height>367</height>
</rect>
</property>
<attribute name="label">
<string>Image Info</string>
</attribute>
</widget>
<widget class="QWidget" name="page_compression">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>249</width>
<height>367</height>
</rect>
</property>
<attribute name="label">
<string>Compression Options</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Format:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="formatComboBox">
<item>
<property name="text">
<string>Uncompressed</string>
</property>
</item>
<item>
<property name="text">
<string>BC1 (DXT1)</string>
</property>
</item>
<item>
<property name="text">
<string>BC1a (DXT1a)</string>
</property>
</item>
<item>
<property name="text">
<string>BC2 (DXT3)</string>
</property>
</item>
<item>
<property name="text">
<string>BC3 (DXT5)</string>
</property>
</item>
<item>
<property name="text">
<string>BC4</string>
</property>
</item>
<item>
<property name="text">
<string>BC5</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QStackedWidget" name="formatOptions">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="page_colorweights">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Color Weights</string>
</property>
<property name="alignment">
<set>Qt::AlignHCenter</set>
</property>
<layout class="QVBoxLayout" name="_2">
<property name="topMargin">
<number>12</number>
</property>
<item>
<layout class="QHBoxLayout" name="_3">
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Red</string>
</property>
<property name="buddy">
<cstring>redSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="redSpinBox">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.050000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="_4">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Green</string>
</property>
<property name="buddy">
<cstring>greenSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="greenSpinBox">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.050000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="_5">
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Blue</string>
</property>
<property name="buddy">
<cstring>blueSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="blueSpinBox">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.050000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="_6">
<item>
<widget class="QToolButton" name="uniformButton">
<property name="text">
<string>Uniform</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="luminanceButton">
<property name="text">
<string>Luminance</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_pixelformat">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>1</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>24</height>
</size>
</property>
<property name="text">
<string>Pixel Format:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="pixelformatComboBox">
<property name="currentIndex">
<number>1</number>
</property>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
<item>
<property name="text">
<string>R8G8B8A8</string>
</property>
</item>
<item>
<property name="text">
<string>R5G6B5</string>
</property>
</item>
<item>
<property name="text">
<string>A1</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Color Type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<item>
<property name="text">
<string>Fixed</string>
</property>
</item>
<item>
<property name="text">
<string>Float</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Red Bits:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="redbitSpinBox">
<property name="maximum">
<number>32</number>
</property>
<property name="value">
<number>8</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Green Bits:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="greenbitSpinBox">
<property name="maximum">
<number>32</number>
</property>
<property name="value">
<number>8</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Blue Bits:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="bluebitSpinBox">
<property name="maximum">
<number>32</number>
</property>
<property name="value">
<number>8</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Alpha Bits:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="alphabitSpinBox">
<property name="maximum">
<number>32</number>
</property>
<property name="value">
<number>8</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ditherColorCheckBox">
<property name="text">
<string>Dither Color</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Dither Alpha</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_resize">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>249</width>
<height>367</height>
</rect>
</property>
<attribute name="label">
<string>Resize Options</string>
</attribute>
</widget>
<widget class="QWidget" name="page_mipmap">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>241</width>
<height>357</height>
</rect>
</property>
<attribute name="label">
<string>Mipmap Options</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>6</number>
</property>
<item>
<widget class="QCheckBox" name="generateMipmapsCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Generate mipmaps</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="_8">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="QLabel" name="mipmapFilterLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>26</height>
</size>
</property>
<property name="text">
<string>Filter:</string>
</property>
<property name="buddy">
<cstring>mipmapFilterComboBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mipmapFilterComboBox">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>26</height>
</size>
</property>
<item>
<property name="text">
<string>Box</string>
</property>
</item>
<item>
<property name="text">
<string>Triangle</string>
</property>
</item>
<item>
<property name="text">
<string>Kaiser</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QToolButton" name="mipmapFilterSettings">
<property name="enabled">
<bool>false</bool>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="_9">
<item>
<widget class="QCheckBox" name="limitMipmapsCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Limit Mipmaps</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="maxLevelLabel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Max Level:</string>
</property>
<property name="buddy">
<cstring>maxLevelSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="maxLevelSpinBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CompressDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CompressDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>