Compare commits

..

No commits in common. "3224199813415073f86a067a1806ab69ced6ce9b" and "f4190fbfab104accc1503630d2c88eb3eb80da37" have entirely different histories.

4 changed files with 27 additions and 86 deletions

View file

@ -6,7 +6,6 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.2 REQUIRED COMPONENTS Quick QuickControls2)
find_package(PNG REQUIRED)
qt_add_executable(apptexcrafting
@ -20,7 +19,6 @@ qt_add_qml_module(apptexcrafting
Main.qml
TexSlot.qml
SOURCES texturecrafter.h texturecrafter.cpp
RESOURCES
)
# 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
PRIVATE Qt6::Quick
PNG::PNG
)
include(GNUInstallDirs)

View file

@ -8,7 +8,7 @@ ApplicationWindow {
width: 640
height: 480
visible: true
title: qsTr("TexCrafting")
title: qsTr("Hello World")
TextureCrafter {
id: crafter

View file

@ -4,18 +4,6 @@ TextureCrafter::TextureCrafter(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) {
QVector<QImage> sourceImages;
@ -38,83 +26,43 @@ QUrl TextureCrafter::packChannels(QVector<QUrl> imagePaths) {
sourceImages.append(newImage);
}
png_structp outPng;
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);
QImage outImage(width, height, format);
// do the channel packing!!
// theres probably a faster way to do this but eh
for (int i = 0; i < height; i++) {
memset(rowBuffer, 0, sizeof(char) * 3 * width);
for (int j = 0; j < width; j++) {
unsigned char r, g, b;
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(j, i).red();
g = sourceImages.at(1).pixelColor(j, i).green();
b = sourceImages.at(2).pixelColor(j, i).blue();
r = sourceImages.at(0).pixelColor(i, j).red();
g = sourceImages.at(1).pixelColor(i, j).green();
b = sourceImages.at(2).pixelColor(i, j).blue();
rowBuffer[j*3+0] = r;
rowBuffer[j*3+1] = g;
rowBuffer[j*3+2] = b;
QColor newColor(r, g, 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
free(rowBuffer);
png_destroy_write_struct(&outPng, &outInfo);
fclose(outFile);
return QUrl::fromLocalFile(outFilename);
printf("wrote to %s\n", outFileName.toLatin1().data());
// // write it to a temp file
// if (outDir.isValid()) {
// QString outFileName = outDir.path();
// outFileName.append("/out.png");
// printf("wrote to %s\n", outFileName.toLatin1().data());
// //TODO: use libpng and do progressive write to update the progress bar
// if (outImage.save(outFileName)) {
// printf("cool ^-^\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");
// }
//TODO: use libpng and do progressive write to update the progress bar
if (outImage.save(outFileName)) {
printf("cool ^-^\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();
//do we need to close these??? idk lets hope qt handles it

View file

@ -6,8 +6,6 @@
#include <QImage>
#include <QTemporaryDir>
#include <png.h>
class TextureCrafter : public QObject
{
Q_OBJECT
@ -19,8 +17,6 @@ public:
signals:
private:
QString getOutFilename();
QTemporaryDir outDir;
};