From ccb0043ddbe22894b92c54a0009e3f2c77f822a5 Mon Sep 17 00:00:00 2001 From: camargo Date: Fri, 3 Aug 2018 18:17:10 -0300 Subject: [PATCH 1/1] Initial commit --- README.md | 3 +++ main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ rgb565conv.pro | 12 ++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 README.md create mode 100644 main.cpp create mode 100644 rgb565conv.pro diff --git a/README.md b/README.md new file mode 100644 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 index 0000000..8e057ef --- /dev/null +++ b/main.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +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 index 0000000..6fea8a8 --- /dev/null +++ b/rgb565conv.pro @@ -0,0 +1,12 @@ +QT += core +#QT -= gui + +CONFIG += c++11 + +TARGET = rgb565conv +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += main.cpp -- 2.26.2