Skip to content

Commit

Permalink
Remove deprecated DDS<->JPG conversion functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Deledrius committed Oct 23, 2022
1 parent 85240f8 commit 77185a9
Showing 1 changed file with 0 additions and 129 deletions.
129 changes: 0 additions & 129 deletions src/PrpShop/PRP/Surface/QMipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,135 +338,6 @@ QMipmap::QMipmap(plCreatable* pCre, QWidget* parent)
connect(iPort, &QLinkLabel::activated, this, &QMipmap::onImportImage);
}

static void swapColorChannels(unsigned char* data, size_t size)
{
unsigned int* dp = reinterpret_cast<unsigned int*>(data);
for (size_t i=0; i<size; i += 4) {
*dp = (*dp & 0xFF00FF00)
| (*dp & 0x00FF0000) >> 16
| (*dp & 0x000000FF) << 16;
dp++;
}
}

static void makeJColorSurface(const plMipmap* tex, hsStream* S)
{
if (tex->getCompressionType() != plBitmap::kJPEGCompression) {
QMessageBox::critical(NULL, QObject::tr("Error exporting JPEG"),
QObject::tr("Texture is not in a supported export format"),
QMessageBox::Ok);
return;
}

plDDSurface dds;
dds.fFlags = plDDSurface::DDSD_CAPS | plDDSurface::DDSD_HEIGHT
| plDDSurface::DDSD_WIDTH | plDDSurface::DDSD_PIXELFORMAT
| plDDSurface::DDSD_LINEARSIZE;
dds.fCaps = plDDSurface::DDSCAPS_TEXTURE;
dds.fHeight = tex->getHeight();
dds.fWidth = tex->getWidth();
dds.fLinearSize = dds.fHeight * dds.fWidth * 3;
dds.fPixelFormat.fFlags = plDDSurface::DDPF_RGB;
dds.fPixelFormat.fBitDepth = 24;
dds.fPixelFormat.fRBitMask = 0xFF0000;
dds.fPixelFormat.fGBitMask = 0x00FF00;
dds.fPixelFormat.fBBitMask = 0x0000FF;

// Strip down data to 24 bit color
unsigned char* data = new unsigned char[dds.fLinearSize];
tex->extractColorData(data, dds.fLinearSize);
swapColorChannels(data, dds.fLinearSize);
dds.setData(dds.fLinearSize, data);
delete[] data;

dds.write(S);
}

static void makeJAlphaSurface(const plMipmap* tex, hsStream* S)
{
if (tex->getCompressionType() != plBitmap::kJPEGCompression) {
QMessageBox::critical(NULL, QObject::tr("Error exporting JPEG"),
QObject::tr("Texture is not in a supported export format"),
QMessageBox::Ok);
return;
}

plDDSurface dds;
dds.fFlags = plDDSurface::DDSD_CAPS | plDDSurface::DDSD_HEIGHT
| plDDSurface::DDSD_WIDTH | plDDSurface::DDSD_PIXELFORMAT
| plDDSurface::DDSD_LINEARSIZE;
dds.fCaps = plDDSurface::DDSCAPS_TEXTURE;
dds.fHeight = tex->getHeight();
dds.fWidth = tex->getWidth();
dds.fLinearSize = dds.fHeight * dds.fWidth;
dds.fPixelFormat.fFlags = plDDSurface::DDPF_LUMINANCE;
dds.fPixelFormat.fBitDepth = 8;
dds.fPixelFormat.fLuminanceBitMask = 0xFF;

// Strip down data to alpha luminance
unsigned char* data = new unsigned char[dds.fLinearSize];
tex->extractAlphaData(data, dds.fLinearSize);
dds.setData(dds.fLinearSize, data);
delete[] data;

dds.write(S);
}

static bool getJColorSurface(const plDDSurface& dds, plMipmap* tex)
{
if ((dds.fFlags & plDDSurface::DDSD_HEIGHT) == 0 ||
(dds.fFlags & plDDSurface::DDSD_WIDTH) == 0 ||
(dds.fFlags & plDDSurface::DDSD_PIXELFORMAT) == 0) {
QMessageBox::critical(NULL, QObject::tr("Error importing JPEG"),
QObject::tr("DDSurface does not contain required fields"),
QMessageBox::Ok);
return false;
}
if ((dds.fPixelFormat.fFlags & plDDSurface::DDPF_RGB) == 0 ||
(dds.fPixelFormat.fBitDepth != 24) ||
(dds.fPixelFormat.fRBitMask != 0xFF0000) ||
(dds.fPixelFormat.fGBitMask != 0x00FF00) ||
(dds.fPixelFormat.fBBitMask != 0x0000FF)) {
QMessageBox::critical(NULL, QObject::tr("Error importing JPEG"),
QObject::tr("DDS file should be in RGB888 format"));
return false;
}

tex->Create(dds.fWidth, dds.fHeight, 0, plBitmap::kJPEGCompression, plBitmap::kRGB8888);
tex->setColorData(dds.getData(), dds.getDataSize());
swapColorChannels(reinterpret_cast<unsigned char*>(tex->getImageData()), dds.getDataSize());
return true;
}

static bool getJAlphaSurface(const plDDSurface& dds, plMipmap* tex)
{
if ((dds.fFlags & plDDSurface::DDSD_HEIGHT) == 0 ||
(dds.fFlags & plDDSurface::DDSD_WIDTH) == 0 ||
(dds.fFlags & plDDSurface::DDSD_PIXELFORMAT) == 0) {
QMessageBox::critical(NULL, QObject::tr("Error importing JPEG"),
QObject::tr("DDSurface does not contain required fields"),
QMessageBox::Ok);
return false;
}
if ((dds.fPixelFormat.fFlags & plDDSurface::DDPF_LUMINANCE) == 0 ||
(dds.fPixelFormat.fBitDepth != 8) ||
(dds.fPixelFormat.fLuminanceBitMask != 0xFF)) {
QMessageBox::critical(NULL, QObject::tr("Error importing JPEG"),
QObject::tr("DDS file should be in Luminance 8-bit format"),
QMessageBox::Ok);
return false;
}

if (tex->getWidth() != dds.fWidth || tex->getHeight() != dds.fHeight) {
QMessageBox::critical(NULL, QObject::tr("Error importing JPEG"),
QObject::tr("Alpha DDS size does not match image size"),
QMessageBox::Ok);
return false;
}
tex->setAlphaData(dds.getData(), dds.getDataSize());
return true;
}

void QMipmap::onExportImage() {
QString exportDir = getExportDir();
plMipmap* tex = plMipmap::Convert(fCreatable);
Expand Down

0 comments on commit 77185a9

Please sign in to comment.