Initial commit
it works!!
This commit is contained in:
commit
3fe4a536c5
76
.gitignore
vendored
Normal file
76
.gitignore
vendored
Normal file
|
@ -0,0 +1,76 @@
|
|||
# This file is used to ignore files which are generated
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
*~
|
||||
*.autosave
|
||||
*.a
|
||||
*.core
|
||||
*.moc
|
||||
*.o
|
||||
*.obj
|
||||
*.orig
|
||||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
.#*
|
||||
*.*#
|
||||
core
|
||||
!core/
|
||||
tags
|
||||
.DS_Store
|
||||
.directory
|
||||
*.debug
|
||||
Makefile*
|
||||
*.prl
|
||||
*.app
|
||||
moc_*.cpp
|
||||
ui_*.h
|
||||
qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
CMakeLists.txt.user*
|
||||
|
||||
# xemacs temporary files
|
||||
*.flc
|
||||
|
||||
# Vim temporary files
|
||||
.*.swp
|
||||
|
||||
# Visual Studio generated files
|
||||
*.ib_pdb_index
|
||||
*.idb
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.sln
|
||||
*.suo
|
||||
*.vcproj
|
||||
*vcproj.*.*.user
|
||||
*.ncb
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.vcxproj
|
||||
*vcxproj.*
|
||||
|
||||
# MinGW generated files
|
||||
*.Debug
|
||||
*.Release
|
||||
|
||||
# Python byte code
|
||||
*.pyc
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
*.dll
|
||||
*.exe
|
||||
|
||||
# build dir
|
||||
build/
|
44
CMakeLists.txt
Normal file
44
CMakeLists.txt
Normal file
|
@ -0,0 +1,44 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(texcrafting VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.2 REQUIRED COMPONENTS Quick QuickControls2)
|
||||
|
||||
|
||||
qt_add_executable(apptexcrafting
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(apptexcrafting
|
||||
URI texcrafting
|
||||
VERSION 1.0
|
||||
QML_FILES
|
||||
Main.qml
|
||||
TexSlot.qml
|
||||
SOURCES texturecrafter.h texturecrafter.cpp
|
||||
)
|
||||
|
||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||
# If you are developing for iOS or macOS you should consider setting an
|
||||
# explicit, fixed bundle identifier manually though.
|
||||
set_target_properties(apptexcrafting PROPERTIES
|
||||
# MACOSX_BUNDLE_GUI_IDENTIFIER com.example.apptexcrafting
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(apptexcrafting
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS apptexcrafting
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
73
Main.qml
Normal file
73
Main.qml
Normal file
|
@ -0,0 +1,73 @@
|
|||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Controls
|
||||
|
||||
import texcrafting
|
||||
|
||||
ApplicationWindow {
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Hello World")
|
||||
|
||||
TextureCrafter {
|
||||
id: crafter
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
|
||||
TexSlot {
|
||||
id: texSlotR
|
||||
|
||||
rectColor: "red"
|
||||
}
|
||||
|
||||
TexSlot {
|
||||
id: texSlotG
|
||||
|
||||
rectColor: "green"
|
||||
}
|
||||
|
||||
TexSlot {
|
||||
id: texSlotB
|
||||
|
||||
rectColor: "blue"
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
|
||||
ProgressBar {
|
||||
value: 0.5
|
||||
}
|
||||
|
||||
Button {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
text: qsTr("Craft!")
|
||||
|
||||
onClicked: crafter.packChannels([texSlotR.filePath, texSlotG.filePath, texSlotB.filePath])
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
|
||||
TexSlot {
|
||||
|
||||
|
||||
rectColor: "green"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
TexSlot.qml
Normal file
58
TexSlot.qml
Normal file
|
@ -0,0 +1,58 @@
|
|||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Controls
|
||||
|
||||
DropArea {
|
||||
property string rectColor: "white"
|
||||
property url filePath: ""
|
||||
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
|
||||
width: 128
|
||||
height: 128
|
||||
|
||||
|
||||
Rectangle {
|
||||
id: rectangle
|
||||
anchors.fill: parent
|
||||
color: rectColor
|
||||
|
||||
Image {
|
||||
id: image
|
||||
|
||||
anchors.centerIn: parent
|
||||
|
||||
width: 96
|
||||
height: 96
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
id: huh
|
||||
|
||||
text: "無"
|
||||
}
|
||||
|
||||
onEntered: {
|
||||
rectangle.color = "cyan";
|
||||
drag.accept (Qt.LinkAction);
|
||||
}
|
||||
onDropped: {
|
||||
// TODO: handle dragging all channels at once
|
||||
var firstUrl = new URL(drop.urls[0]);
|
||||
if (firstUrl.protocol === "file:")
|
||||
{
|
||||
console.log(drop.urls);
|
||||
|
||||
filePath = drop.urls[0];
|
||||
huh.text = drop.urls[0];
|
||||
image.source = drop.urls[0];
|
||||
}
|
||||
rectangle.color = rectColor;
|
||||
}
|
||||
onExited: {
|
||||
rectangle.color = rectColor;
|
||||
}
|
||||
}
|
22
main.cpp
Normal file
22
main.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
const QUrl url(QStringLiteral("qrc:/texcrafting/Main.qml"));
|
||||
QObject::connect(
|
||||
&engine,
|
||||
&QQmlApplicationEngine::objectCreated,
|
||||
&app,
|
||||
[url](QObject *obj, const QUrl &objUrl) {
|
||||
if (!obj && url == objUrl)
|
||||
QCoreApplication::exit(-1);
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
engine.load(url);
|
||||
|
||||
return app.exec();
|
||||
}
|
49
texturecrafter.cpp
Normal file
49
texturecrafter.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#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
|
||||
}
|
21
texturecrafter.h
Normal file
21
texturecrafter.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef TEXTURECRAFTER_H
|
||||
#define TEXTURECRAFTER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
#include <QImage>
|
||||
|
||||
class TextureCrafter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
public:
|
||||
explicit TextureCrafter(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE void packChannels(QVector<QUrl> images);
|
||||
|
||||
signals:
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // TEXTURECRAFTER_H
|
Loading…
Reference in a new issue