Compare commits
No commits in common. "3224199813415073f86a067a1806ab69ced6ce9b" and "f4190fbfab104accc1503630d2c88eb3eb80da37" have entirely different histories.
3224199813
...
f4190fbfab
|
@ -6,7 +6,6 @@ set(CMAKE_AUTOMOC ON)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
find_package(Qt6 6.2 REQUIRED COMPONENTS Quick QuickControls2)
|
find_package(Qt6 6.2 REQUIRED COMPONENTS Quick QuickControls2)
|
||||||
find_package(PNG REQUIRED)
|
|
||||||
|
|
||||||
|
|
||||||
qt_add_executable(apptexcrafting
|
qt_add_executable(apptexcrafting
|
||||||
|
@ -20,7 +19,6 @@ qt_add_qml_module(apptexcrafting
|
||||||
Main.qml
|
Main.qml
|
||||||
TexSlot.qml
|
TexSlot.qml
|
||||||
SOURCES texturecrafter.h texturecrafter.cpp
|
SOURCES texturecrafter.h texturecrafter.cpp
|
||||||
RESOURCES
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||||
|
@ -36,7 +34,6 @@ set_target_properties(apptexcrafting PROPERTIES
|
||||||
|
|
||||||
target_link_libraries(apptexcrafting
|
target_link_libraries(apptexcrafting
|
||||||
PRIVATE Qt6::Quick
|
PRIVATE Qt6::Quick
|
||||||
PNG::PNG
|
|
||||||
)
|
)
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
2
Main.qml
2
Main.qml
|
@ -8,7 +8,7 @@ ApplicationWindow {
|
||||||
width: 640
|
width: 640
|
||||||
height: 480
|
height: 480
|
||||||
visible: true
|
visible: true
|
||||||
title: qsTr("TexCrafting")
|
title: qsTr("Hello World")
|
||||||
|
|
||||||
TextureCrafter {
|
TextureCrafter {
|
||||||
id: crafter
|
id: crafter
|
||||||
|
|
|
@ -4,18 +4,6 @@ TextureCrafter::TextureCrafter(QObject *parent)
|
||||||
: QObject{parent}
|
: QObject{parent}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QString TextureCrafter::getOutFilename() {
|
|
||||||
QString outFileName;
|
|
||||||
if (outDir.isValid()) {
|
|
||||||
outFileName = outDir.path();
|
|
||||||
outFileName.append("/out.png");
|
|
||||||
} else {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return outFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl TextureCrafter::packChannels(QVector<QUrl> imagePaths) {
|
QUrl TextureCrafter::packChannels(QVector<QUrl> imagePaths) {
|
||||||
|
|
||||||
QVector<QImage> sourceImages;
|
QVector<QImage> sourceImages;
|
||||||
|
@ -38,83 +26,43 @@ QUrl TextureCrafter::packChannels(QVector<QUrl> imagePaths) {
|
||||||
sourceImages.append(newImage);
|
sourceImages.append(newImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
png_structp outPng;
|
QImage outImage(width, height, format);
|
||||||
png_infop outInfo;
|
|
||||||
FILE *outFile;
|
|
||||||
QString outFilename = getOutFilename();
|
|
||||||
unsigned char *rowBuffer;
|
|
||||||
|
|
||||||
// maybe abstract this?
|
|
||||||
outFile = fopen(outFilename.toLatin1().data(), "wb");
|
|
||||||
|
|
||||||
if (!outFile) {
|
|
||||||
return QUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
outPng = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
||||||
outInfo = png_create_info_struct(outPng);
|
|
||||||
rowBuffer = (unsigned char*)malloc(sizeof(char) * 3 * width);
|
|
||||||
|
|
||||||
png_init_io(outPng, outFile);
|
|
||||||
|
|
||||||
png_set_IHDR (outPng,
|
|
||||||
outInfo,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
8, // TODO: support other bit depths someday
|
|
||||||
PNG_COLOR_TYPE_RGB,
|
|
||||||
PNG_INTERLACE_NONE,
|
|
||||||
PNG_COMPRESSION_TYPE_DEFAULT,
|
|
||||||
PNG_FILTER_TYPE_DEFAULT);
|
|
||||||
|
|
||||||
png_write_info(outPng, outInfo);
|
|
||||||
|
|
||||||
// do the channel packing!!
|
// do the channel packing!!
|
||||||
// theres probably a faster way to do this but eh
|
// theres probably a faster way to do this but eh
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
memset(rowBuffer, 0, sizeof(char) * 3 * width);
|
for (int j = 0; j < height; j++) {
|
||||||
for (int j = 0; j < width; j++) {
|
int r, g, b;
|
||||||
unsigned char r, g, b;
|
|
||||||
|
|
||||||
// too eepy for dry
|
// too eepy for dry
|
||||||
r = sourceImages.at(0).pixelColor(j, i).red();
|
r = sourceImages.at(0).pixelColor(i, j).red();
|
||||||
g = sourceImages.at(1).pixelColor(j, i).green();
|
g = sourceImages.at(1).pixelColor(i, j).green();
|
||||||
b = sourceImages.at(2).pixelColor(j, i).blue();
|
b = sourceImages.at(2).pixelColor(i, j).blue();
|
||||||
|
|
||||||
rowBuffer[j*3+0] = r;
|
QColor newColor(r, g, b);
|
||||||
rowBuffer[j*3+1] = g;
|
|
||||||
rowBuffer[j*3+2] = b;
|
outImage.setPixelColor(i, j, newColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
png_write_row(outPng, rowBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
png_write_end(outPng, NULL);
|
// write it to a temp file
|
||||||
|
if (outDir.isValid()) {
|
||||||
|
QString outFileName = outDir.path();
|
||||||
|
outFileName.append("/out.png");
|
||||||
|
|
||||||
// good soldiers free their memory
|
printf("wrote to %s\n", outFileName.toLatin1().data());
|
||||||
free(rowBuffer);
|
|
||||||
png_destroy_write_struct(&outPng, &outInfo);
|
|
||||||
fclose(outFile);
|
|
||||||
return QUrl::fromLocalFile(outFilename);
|
|
||||||
|
|
||||||
// // write it to a temp file
|
//TODO: use libpng and do progressive write to update the progress bar
|
||||||
// if (outDir.isValid()) {
|
if (outImage.save(outFileName)) {
|
||||||
// QString outFileName = outDir.path();
|
printf("cool ^-^\n");
|
||||||
// outFileName.append("/out.png");
|
return QUrl::fromLocalFile(outFileName);
|
||||||
|
} else {
|
||||||
// printf("wrote to %s\n", outFileName.toLatin1().data());
|
//TODO: return some error value to show the user
|
||||||
|
printf("that dream is fucked it is fucking fucked\n");
|
||||||
// //TODO: use libpng and do progressive write to update the progress bar
|
}
|
||||||
// if (outImage.save(outFileName)) {
|
} else {
|
||||||
// printf("cool ^-^\n");
|
printf("chat its so over\n");
|
||||||
// return QUrl::fromLocalFile(outFileName);
|
}
|
||||||
// } else {
|
|
||||||
// //TODO: return some error value to show the user
|
|
||||||
// printf("that dream is fucked it is fucking fucked\n");
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// printf("chat its so over\n");
|
|
||||||
// }
|
|
||||||
|
|
||||||
return QUrl();
|
return QUrl();
|
||||||
//do we need to close these??? idk lets hope qt handles it
|
//do we need to close these??? idk lets hope qt handles it
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
|
|
||||||
#include <png.h>
|
|
||||||
|
|
||||||
class TextureCrafter : public QObject
|
class TextureCrafter : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -19,8 +17,6 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
private:
|
private:
|
||||||
QString getOutFilename();
|
|
||||||
|
|
||||||
QTemporaryDir outDir;
|
QTemporaryDir outDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue