diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-21 03:57:42 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-21 03:57:42 +0100 |
commit | 42755e98cf2ce7d10f1899051b63513d442f92ec (patch) | |
tree | e6fbe05808cea137bd26fc0e5ae17534354448f5 /Userland | |
parent | ed2303e2d8f795a7c1bd597fed9f77afe526c228 (diff) | |
download | serenity-42755e98cf2ce7d10f1899051b63513d442f92ec.zip |
SharedGraphics: Implement a simple PNG decoder.
This is extremely unoptimized, but it does successfully load "folder32.png"
so it must be at least somewhat correct. :^)
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/.gitignore | 1 | ||||
-rw-r--r-- | Userland/Makefile | 5 | ||||
-rw-r--r-- | Userland/qs.cpp | 44 |
3 files changed, 50 insertions, 0 deletions
diff --git a/Userland/.gitignore b/Userland/.gitignore index b3e6580898..3d207bf5d7 100644 --- a/Userland/.gitignore +++ b/Userland/.gitignore @@ -41,3 +41,4 @@ ping uc tc host +qs diff --git a/Userland/Makefile b/Userland/Makefile index b9e65cb5fa..d09d11c223 100644 --- a/Userland/Makefile +++ b/Userland/Makefile @@ -37,6 +37,7 @@ OBJS = \ uc.o \ tc.o \ host.o \ + qs.o \ rm.o APPS = \ @@ -79,6 +80,7 @@ APPS = \ uc \ tc \ host \ + qs \ rm ARCH_FLAGS = @@ -218,6 +220,9 @@ tc: tc.o host: host.o $(LD) -o $@ $(LDFLAGS) $< -lc +qs: qs.o + $(LD) -o $@ $(LDFLAGS) -L../LibGUI $< -lgui -lc + .cpp.o: @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< diff --git a/Userland/qs.cpp b/Userland/qs.cpp new file mode 100644 index 0000000000..148c36b8dc --- /dev/null +++ b/Userland/qs.cpp @@ -0,0 +1,44 @@ +#include <SharedGraphics/PNGLoader.h> +#include <LibGUI/GApplication.h> +#include <LibGUI/GWindow.h> +#include <LibGUI/GLabel.h> +#include <stdio.h> + +int main(int argc, char** argv) +{ + GApplication app(argc, argv); + +#if 0 + if (argc != 2) { + printf("usage: qs <image-file>\n"); + return 0; + } +#endif + + const char* path = "/res/icons/folder32.png"; + if (argc > 1) + path = argv[1]; + + auto bitmap = load_png(path); + if (!bitmap) { + fprintf(stderr, "Failed to load %s\n", path); + return 1; + } + + auto* window = new GWindow; + window->set_title(String::format("qs: %s", path)); + window->set_rect(200, 200, bitmap->width(), bitmap->height()); + + auto* widget = new GWidget; + widget->set_fill_with_background_color(true); + window->set_main_widget(widget); + + auto* label = new GLabel(widget); + label->set_relative_rect({ 0, 0, bitmap->width(), bitmap->height() }); + label->set_icon(move(bitmap)); + + window->set_should_exit_event_loop_on_close(true); + window->show(); + + return app.exec(); +} |