Skip to content

Commit

Permalink
GUI: Fix variables shadowing a Qt lib variable (somehow)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdde authored and DrMcCoy committed Dec 29, 2017
1 parent 66b907f commit c9aa452
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/gui/panelpreviewimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ void PanelPreviewImage::loadImage() {

_labelDimensions->setText(QString("(%1x%2)").arg(width).arg(height));

Common::ScopedArray<byte, Common::DeallocatorFree> data ((byte *) malloc(width * height * 4));
std::memset(data.get(), 0, width * height * 4);
Common::ScopedArray<byte, Common::DeallocatorFree> rgbData ((byte *) malloc(width * height * 4));
std::memset(rgbData.get(), 0, width * height * 4);

QImage::Format format;
convertImage(*image, data.get(), format);
convertImage(*image, rgbData.get(), format);

_originalPixmap = QPixmap::fromImage(QImage(data.get(), width, height, format).mirrored());
_originalPixmap = QPixmap::fromImage(QImage(rgbData.get(), width, height, format).mirrored());
_originalSize = _originalPixmap.size();
_labelImage->setPixmap(_originalPixmap);
_labelImage->adjustSize();
_labelImage->setFixedSize(_originalSize);

data.release();
rgbData.release();
}

void PanelPreviewImage::convertImage(const Images::Decoder &image, byte *data_out, QImage::Format &format) {
Expand All @@ -152,60 +152,60 @@ void PanelPreviewImage::convertImage(const Images::Decoder &image, byte *data_ou

for (size_t i = 0; i < image.getLayerCount(); i++) {
const Images::Decoder::MipMap &mipMap = image.getMipMap(0, i);
const byte *data = mipMap.data.get();
const byte *mipMapData = mipMap.data.get();

uint32 count = mipMap.width * mipMap.height;
while (count-- > 0)
writePixel(data, image.getFormat(), data_out, format);
writePixel(mipMapData, image.getFormat(), data_out, format);
}
}

void PanelPreviewImage::writePixel(const byte *&data, Images::PixelFormat format,
void PanelPreviewImage::writePixel(const byte *&data_in, Images::PixelFormat format,
byte *&data_out, QImage::Format &format_out) {
if (format == Images::kPixelFormatR8G8B8) {
format_out = QImage::Format_RGB888;
*data_out++ = data[0];
*data_out++ = data[1];
*data_out++ = data[2];
*data_out++ = data_in[0];
*data_out++ = data_in[1];
*data_out++ = data_in[2];
*data_out++ = 0xFF;
data += 3;
data_in += 3;
} else if (format == Images::kPixelFormatB8G8R8) {
format_out = QImage::Format_RGB888;
*data_out++ = data[2];
*data_out++ = data[1];
*data_out++ = data[0];
*data_out++ = data_in[2];
*data_out++ = data_in[1];
*data_out++ = data_in[0];
*data_out++ = 0xFF;
data += 3;
data_in += 3;
} else if (format == Images::kPixelFormatR8G8B8A8) {
format_out = QImage::Format_RGBA8888;
*data_out++ = data[0];
*data_out++ = data[1];
*data_out++ = data[2];
*data_out++ = data[3];
data += 4;
*data_out++ = data_in[0];
*data_out++ = data_in[1];
*data_out++ = data_in[2];
*data_out++ = data_in[3];
data_in += 4;
} else if (format == Images::kPixelFormatB8G8R8A8) {
format_out = QImage::Format_RGBA8888;
*data_out++ = data[2];
*data_out++ = data[1];
*data_out++ = data[0];
*data_out++ = data[3];
data += 4;
*data_out++ = data_in[2];
*data_out++ = data_in[1];
*data_out++ = data_in[0];
*data_out++ = data_in[3];
data_in += 4;
} else if (format == Images::kPixelFormatR5G6B5) {
format_out = QImage::Format_RGB555;
uint16 color = READ_LE_UINT16(data);
uint16 color = READ_LE_UINT16(data_in);
*data_out++ = color & 0x001F;
*data_out++ = (color & 0x07E0) >> 5;
*data_out++ = (color & 0xF800) >> 11;
*data_out++ = 0xFF;
data += 2;
data_in += 2;
} else if (format == Images::kPixelFormatA1R5G5B5) {
format_out = QImage::Format_ARGB8555_Premultiplied;
uint16 color = READ_LE_UINT16(data);
uint16 color = READ_LE_UINT16(data_in);
*data_out++ = color & 0x001F;
*data_out++ = (color & 0x03E0) >> 5;
*data_out++ = (color & 0x7C00) >> 10;
*data_out++ = (color & 0x8000) ? 0xFF : 0x00;
data += 2;
data_in += 2;
} else
throw Common::Exception("Unsupported pixel format: %d", (int) format);
}
Expand Down

0 comments on commit c9aa452

Please sign in to comment.