mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 07:37:35 +00:00
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. :^)
This commit is contained in:
parent
ed2303e2d8
commit
42755e98cf
10 changed files with 1245 additions and 2 deletions
1
Userland/.gitignore
vendored
1
Userland/.gitignore
vendored
|
@ -41,3 +41,4 @@ ping
|
|||
uc
|
||||
tc
|
||||
host
|
||||
qs
|
||||
|
|
|
@ -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 $<
|
||||
|
||||
|
|
44
Userland/qs.cpp
Normal file
44
Userland/qs.cpp
Normal file
|
@ -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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue