Initial commit master
authorcamargo <camargo@lisha.ufsc.br>
Fri, 3 Aug 2018 21:17:10 +0000 (18:17 -0300)
committercamargo <camargo@lisha.ufsc.br>
Fri, 3 Aug 2018 21:17:10 +0000 (18:17 -0300)
README.md [new file with mode: 0644]
main.cpp [new file with mode: 0644]
rgb565conv.pro [new file with mode: 0644]

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..524b28c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# rgb565conv
+
+Small utility to convert an image to a binary RGB565 representation (to be used in a FPGA project).
diff --git a/main.cpp b/main.cpp
new file mode 100644 (file)
index 0000000..8e057ef
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,46 @@
+#include <QCoreApplication>
+#include <QImage>
+#include <QRgb>
+#include <QFile>
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication app(argc, argv);
+    QImage image;
+    image.load(argv[1]);
+
+    QImage image2 = image.convertToFormat(QImage::Format_RGB16);
+
+    unsigned short out[image.width() * image.height()];
+
+    /*
+    for(int y = 0; y < image.height(); y++)
+    {
+        for(int x = 0; x < image.width(); x++)
+        {
+            QColor color(image.pixel(x, y));
+            out[x + y*image.width()] = ((color.red() >> 3 & 0b11111) << 11) | ((color.green() >> 2 & 0b111111) << 5) | ((color.blue() >> 3 & 0b11111)) ;
+        }
+    }*/
+
+    memcpy(out, image2.bits(), image.width() * image.height() * 2);
+
+
+    QImage result( (const uchar*)out, image.width(), image.height(), QImage::Format_RGB16);
+    result.save("debug.png");
+
+
+    for(int y = 0; y < image.height(); y++)
+    {
+        for(int x = 0; x < image.width(); x++)
+        {
+            int offset = x  + y*image.width();
+            out[offset] = ((out[offset] & 0x00ff) << 8) | ((out[offset] & 0xff00) >> 8);
+        }
+    }
+
+    QFile outf(argv[2]);
+    outf.open(QFile::WriteOnly);
+    outf.write((const char *)out, image.width() * image.height() * 2);
+    outf.close();
+}
diff --git a/rgb565conv.pro b/rgb565conv.pro
new file mode 100644 (file)
index 0000000..6fea8a8
--- /dev/null
@@ -0,0 +1,12 @@
+QT += core
+#QT -= gui
+
+CONFIG += c++11
+
+TARGET = rgb565conv
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+SOURCES += main.cpp