50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
#include "texturecrafter.h"
|
|
|
|
TextureCrafter::TextureCrafter(QObject *parent)
|
|
: QObject{parent}
|
|
{}
|
|
|
|
void TextureCrafter::packChannels(QVector<QUrl> imagePaths) {
|
|
QVector<QImage> sourceImages;
|
|
int width = 0, height = 0;
|
|
QImage::Format format = QImage::Format_RGB888;
|
|
|
|
for (int i = 0; i < imagePaths.length(); i++) {
|
|
// if the ui layer did its job this will always be a file:// url
|
|
QString rawPath = imagePaths[i].path();
|
|
QImage newImage(rawPath); // would this cause a use after free idk
|
|
|
|
// we just use the first image's dimensions and force the others to conform hehe
|
|
if (width == 0) {
|
|
width = newImage.width();
|
|
}
|
|
if (height == 0) {
|
|
height = newImage.height();
|
|
}
|
|
|
|
sourceImages.append(newImage);
|
|
}
|
|
|
|
QImage outImage(width, height, format);
|
|
|
|
// theres probably a faster way to do this but eh
|
|
for (int i = 0; i < width; i++) {
|
|
for (int j = 0; j < height; j++) {
|
|
int r, g, b;
|
|
|
|
// too eepy for dry
|
|
r = sourceImages.at(0).pixelColor(i, j).red();
|
|
g = sourceImages.at(1).pixelColor(i, j).green();
|
|
b = sourceImages.at(2).pixelColor(i, j).blue();
|
|
|
|
QColor newColor(r, g, b);
|
|
|
|
outImage.setPixelColor(i, j, newColor);
|
|
}
|
|
}
|
|
|
|
outImage.save("/tmp/out.png");
|
|
|
|
//do we need to close these??? idk lets hope qt handles it
|
|
}
|