mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Use the PNG loader for all images, and get rid of the .rgb files.
This commit is contained in:
parent
c2a38c86cf
commit
7c0a185970
56 changed files with 90 additions and 74 deletions
|
@ -11,7 +11,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto* window = new GWindow;
|
||||
window->set_title("About Serenity");
|
||||
Rect window_rect { 0, 0, 240, 120 };
|
||||
Rect window_rect { 0, 0, 240, 150 };
|
||||
window_rect.center_within({ 0, 0, 1024, 768 });
|
||||
window->set_rect(window_rect);
|
||||
window->set_should_exit_event_loop_on_close(true);
|
||||
|
@ -24,9 +24,9 @@ int main(int argc, char** argv)
|
|||
widget->layout()->set_spacing(8);
|
||||
|
||||
auto* icon_label = new GLabel(widget);
|
||||
icon_label->set_icon(GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/Serenity.rgb", { 32, 32 }));
|
||||
icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/serenity.png"));
|
||||
icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
icon_label->set_preferred_size({ 32, 32 });
|
||||
icon_label->set_preferred_size(icon_label->icon()->size());
|
||||
|
||||
auto* label = new GLabel(widget);
|
||||
label->set_font(Font::default_bold_font());
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
|
||||
DirectoryTableModel::DirectoryTableModel()
|
||||
{
|
||||
m_directory_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/folder16.rgb", { 16, 16 });
|
||||
m_file_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/file16.rgb", { 16, 16 });
|
||||
m_symlink_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/link16.rgb", { 16, 16 });
|
||||
m_socket_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/socket16.rgb", { 16, 16 });
|
||||
m_executable_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/executable16.rgb", { 16, 16 });
|
||||
m_directory_icon = GraphicsBitmap::load_from_file("/res/icons/folder16.png");
|
||||
m_file_icon = GraphicsBitmap::load_from_file("/res/icons/file16.png");
|
||||
m_symlink_icon = GraphicsBitmap::load_from_file("/res/icons/link16.png");
|
||||
m_socket_icon = GraphicsBitmap::load_from_file("/res/icons/socket16.png");
|
||||
m_executable_icon = GraphicsBitmap::load_from_file("/res/icons/executable16.png");
|
||||
|
||||
setpwent();
|
||||
while (auto* passwd = getpwent())
|
||||
|
|
|
@ -54,11 +54,11 @@ int main(int argc, char** argv)
|
|||
directory_table_view->open(editor.text());
|
||||
};
|
||||
|
||||
auto open_parent_directory_action = GAction::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/parentdirectory16.rgb", { 16, 16 }), [directory_table_view] (const GAction&) {
|
||||
auto open_parent_directory_action = GAction::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/parentdirectory16.png"), [directory_table_view] (const GAction&) {
|
||||
directory_table_view->open_parent_directory();
|
||||
});
|
||||
|
||||
auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/mkdir.rgb", { 16, 16 }), [&] (const GAction&) {
|
||||
auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&] (const GAction&) {
|
||||
GInputBox input_box("Enter name:", "New directory", window);
|
||||
if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) {
|
||||
auto new_dir_path = String::format("%s/%s",
|
||||
|
@ -75,11 +75,11 @@ int main(int argc, char** argv)
|
|||
}
|
||||
});
|
||||
|
||||
auto copy_action = GAction::create("Copy", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/copyfile16.rgb", { 16, 16 }), [] (const GAction&) {
|
||||
auto copy_action = GAction::create("Copy", GraphicsBitmap::load_from_file("/res/icons/copyfile16.png"), [] (const GAction&) {
|
||||
dbgprintf("'Copy' action activated!\n");
|
||||
});
|
||||
|
||||
auto delete_action = GAction::create("Delete", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/delete.rgb", { 16, 16 }), [] (const GAction&) {
|
||||
auto delete_action = GAction::create("Delete", GraphicsBitmap::load_from_file("/res/icons/16x16/delete.png"), [] (const GAction&) {
|
||||
dbgprintf("'Delete' action activated!\n");
|
||||
});
|
||||
|
||||
|
|
|
@ -56,33 +56,33 @@ void IRCAppWindow::setup_client()
|
|||
|
||||
void IRCAppWindow::setup_actions()
|
||||
{
|
||||
m_join_action = GAction::create("Join channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-join.rgb", { 16, 16 }), [&] (auto&) {
|
||||
m_join_action = GAction::create("Join channel", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-join.png"), [&] (auto&) {
|
||||
GInputBox input_box("Enter nickname:", "Join channel", this);
|
||||
if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty())
|
||||
m_client.handle_join_action(input_box.text_value());
|
||||
});
|
||||
|
||||
m_part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-part.rgb", { 16, 16 }), [] (auto&) {
|
||||
m_part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-part.png"), [] (auto&) {
|
||||
printf("FIXME: Implement part action\n");
|
||||
});
|
||||
|
||||
m_whois_action = GAction::create("Whois user", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-whois.rgb", { 16, 16 }), [&] (auto&) {
|
||||
m_whois_action = GAction::create("Whois user", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-whois.png"), [&] (auto&) {
|
||||
GInputBox input_box("Enter nickname:", "IRC WHOIS lookup", this);
|
||||
if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty())
|
||||
m_client.handle_whois_action(input_box.text_value());
|
||||
});
|
||||
|
||||
m_open_query_action = GAction::create("Open query", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-open-query.rgb", { 16, 16 }), [&] (auto&) {
|
||||
m_open_query_action = GAction::create("Open query", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-open-query.png"), [&] (auto&) {
|
||||
GInputBox input_box("Enter nickname:", "Open IRC query with...", this);
|
||||
if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty())
|
||||
m_client.handle_open_query_action(input_box.text_value());
|
||||
});
|
||||
|
||||
m_close_query_action = GAction::create("Close query", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-close-query.rgb", { 16, 16 }), [] (auto&) {
|
||||
m_close_query_action = GAction::create("Close query", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-close-query.png"), [] (auto&) {
|
||||
printf("FIXME: Implement close-query action\n");
|
||||
});
|
||||
|
||||
m_change_nick_action = GAction::create("Change nickname", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-nick.rgb", { 16, 16 }), [this] (auto&) {
|
||||
m_change_nick_action = GAction::create("Change nickname", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-nick.png"), [this] (auto&) {
|
||||
GInputBox input_box("Enter nickname:", "Change nickname", this);
|
||||
if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty())
|
||||
m_client.handle_change_nick_action(input_box.text_value());
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
, m_executable_path(exec_path)
|
||||
{
|
||||
set_button_style(GButtonStyle::CoolBar);
|
||||
set_icon(GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, icon_path, { 32, 32 }));
|
||||
set_icon(GraphicsBitmap::load_from_file(icon_path));
|
||||
set_preferred_size({ 50, 50 });
|
||||
set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
on_click = [this] (GButton&) {
|
||||
|
@ -69,10 +69,10 @@ GWindow* make_launcher_window()
|
|||
widget->layout()->set_margins({ 5, 5, 5, 5 });
|
||||
window->set_main_widget(widget);
|
||||
|
||||
new LauncherButton("/res/icons/Terminal.rgb", "/bin/Terminal", widget);
|
||||
new LauncherButton("/res/icons/FontEditor.rgb", "/bin/FontEditor", widget);
|
||||
new LauncherButton("/res/icons/folder32.rgb", "/bin/FileManager", widget);
|
||||
new LauncherButton("/res/icons/TextEditor.rgb", "/bin/TextEditor", widget);
|
||||
new LauncherButton("/res/icons/Terminal.png", "/bin/Terminal", widget);
|
||||
new LauncherButton("/res/icons/FontEditor.png", "/bin/FontEditor", widget);
|
||||
new LauncherButton("/res/icons/folder32.png", "/bin/FileManager", widget);
|
||||
new LauncherButton("/res/icons/TextEditor.png", "/bin/TextEditor", widget);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ ProcessTableModel::ProcessTableModel()
|
|||
m_usernames.set(passwd->pw_uid, passwd->pw_name);
|
||||
endpwent();
|
||||
|
||||
m_generic_process_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/gear16.rgb", { 16, 16 });
|
||||
m_high_priority_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/highpriority16.rgb", { 16, 16 });
|
||||
m_low_priority_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/lowpriority16.rgb", { 16, 16 });
|
||||
m_normal_priority_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/normalpriority16.rgb", { 16, 16 });
|
||||
m_generic_process_icon = GraphicsBitmap::load_from_file("/res/icons/gear16.png");
|
||||
m_high_priority_icon = GraphicsBitmap::load_from_file("/res/icons/highpriority16.png");
|
||||
m_low_priority_icon = GraphicsBitmap::load_from_file("/res/icons/lowpriority16.png");
|
||||
m_normal_priority_icon = GraphicsBitmap::load_from_file("/res/icons/normalpriority16.png");
|
||||
}
|
||||
|
||||
ProcessTableModel::~ProcessTableModel()
|
||||
|
|
|
@ -23,19 +23,19 @@ int main(int argc, char** argv)
|
|||
|
||||
new MemoryStatsWidget(widget);
|
||||
|
||||
auto kill_action = GAction::create("Kill process", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/kill16.rgb", { 16, 16 }), [process_table_view] (const GAction&) {
|
||||
auto kill_action = GAction::create("Kill process", GraphicsBitmap::load_from_file("/res/icons/kill16.png"), [process_table_view] (const GAction&) {
|
||||
pid_t pid = process_table_view->selected_pid();
|
||||
if (pid != -1)
|
||||
kill(pid, SIGKILL);
|
||||
});
|
||||
|
||||
auto stop_action = GAction::create("Stop process", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/stop16.rgb", { 16, 16 }), [process_table_view] (const GAction&) {
|
||||
auto stop_action = GAction::create("Stop process", GraphicsBitmap::load_from_file("/res/icons/stop16.png"), [process_table_view] (const GAction&) {
|
||||
pid_t pid = process_table_view->selected_pid();
|
||||
if (pid != -1)
|
||||
kill(pid, SIGSTOP);
|
||||
});
|
||||
|
||||
auto continue_action = GAction::create("Continue process", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/continue16.rgb", { 16, 16 }), [process_table_view] (const GAction&) {
|
||||
auto continue_action = GAction::create("Continue process", GraphicsBitmap::load_from_file("/res/icons/continue16.png"), [process_table_view] (const GAction&) {
|
||||
pid_t pid = process_table_view->selected_pid();
|
||||
if (pid != -1)
|
||||
kill(pid, SIGCONT);
|
||||
|
|
|
@ -44,40 +44,40 @@ int main(int argc, char** argv)
|
|||
text_editor->set_text(String::from_byte_buffer(file.read_all()));
|
||||
}
|
||||
|
||||
auto new_action = GAction::create("New document", { Mod_Ctrl, Key_N }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/new.rgb", { 16, 16 }), [] (const GAction&) {
|
||||
auto new_action = GAction::create("New document", { Mod_Ctrl, Key_N }, GraphicsBitmap::load_from_file("/res/icons/16x16/new.png"), [] (const GAction&) {
|
||||
dbgprintf("FIXME: Implement File/New\n");
|
||||
});
|
||||
|
||||
auto open_action = GAction::create("Open document", { Mod_Ctrl, Key_O }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/open.rgb", { 16, 16 }), [] (const GAction&) {
|
||||
auto open_action = GAction::create("Open document", { Mod_Ctrl, Key_O }, GraphicsBitmap::load_from_file("/res/icons/16x16/open.png"), [] (const GAction&) {
|
||||
dbgprintf("FIXME: Implement File/Open\n");
|
||||
});
|
||||
|
||||
auto save_action = GAction::create("Save document", { Mod_Ctrl, Key_S }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/save.rgb", { 16, 16 }), [&] (const GAction&) {
|
||||
auto save_action = GAction::create("Save document", { Mod_Ctrl, Key_S }, GraphicsBitmap::load_from_file("/res/icons/16x16/save.png"), [&] (const GAction&) {
|
||||
dbgprintf("Writing document to '%s'\n", path.characters());
|
||||
text_editor->write_to_file(path);
|
||||
});
|
||||
|
||||
auto undo_action = GAction::create("Undo", { Mod_Ctrl, Key_Z }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/undo.rgb", { 16, 16 }), [&] (const GAction&) {
|
||||
auto undo_action = GAction::create("Undo", { Mod_Ctrl, Key_Z }, GraphicsBitmap::load_from_file("/res/icons/16x16/undo.png"), [&] (const GAction&) {
|
||||
// FIXME: Undo
|
||||
});
|
||||
|
||||
auto redo_action = GAction::create("Redo", { Mod_Ctrl, Key_Y }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/redo.rgb", { 16, 16 }), [&] (const GAction&) {
|
||||
auto redo_action = GAction::create("Redo", { Mod_Ctrl, Key_Y }, GraphicsBitmap::load_from_file("/res/icons/16x16/redo.png"), [&] (const GAction&) {
|
||||
// FIXME: Redo
|
||||
});
|
||||
|
||||
auto cut_action = GAction::create("Cut", { Mod_Ctrl, Key_X }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/cut16.rgb", { 16, 16 }), [&] (const GAction&) {
|
||||
auto cut_action = GAction::create("Cut", { Mod_Ctrl, Key_X }, GraphicsBitmap::load_from_file("/res/icons/cut16.png"), [&] (const GAction&) {
|
||||
text_editor->cut();
|
||||
});
|
||||
|
||||
auto copy_action = GAction::create("Copy", { Mod_Ctrl, Key_C }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/copyfile16.rgb", { 16, 16 }), [&] (const GAction&) {
|
||||
auto copy_action = GAction::create("Copy", { Mod_Ctrl, Key_C }, GraphicsBitmap::load_from_file("/res/icons/copyfile16.png"), [&] (const GAction&) {
|
||||
text_editor->copy();
|
||||
});
|
||||
|
||||
auto paste_action = GAction::create("Paste", { Mod_Ctrl, Key_V }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/paste16.rgb", { 16, 16 }), [&] (const GAction&) {
|
||||
auto paste_action = GAction::create("Paste", { Mod_Ctrl, Key_V }, GraphicsBitmap::load_from_file("/res/icons/paste16.png"), [&] (const GAction&) {
|
||||
text_editor->paste();
|
||||
});
|
||||
|
||||
auto delete_action = GAction::create("Delete", { 0, Key_Delete }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/delete.rgb", { 16, 16 }), [&] (const GAction&) {
|
||||
auto delete_action = GAction::create("Delete", { 0, Key_Delete }, GraphicsBitmap::load_from_file("/res/icons/16x16/delete.png"), [&] (const GAction&) {
|
||||
text_editor->do_delete();
|
||||
});
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Base/res/icons/16x16/window.png
Normal file
BIN
Base/res/icons/16x16/window.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 171 B |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Base/res/icons/serenity.png
Normal file
BIN
Base/res/icons/serenity.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -9,7 +9,7 @@ static GraphicsBitmap& default_window_icon()
|
|||
{
|
||||
static GraphicsBitmap* s_icon;
|
||||
if (!s_icon)
|
||||
s_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/window16.rgb", { 16, 16 }).leak_ref();
|
||||
s_icon = GraphicsBitmap::load_from_file("/res/icons/16x16/window.png").leak_ref();
|
||||
return *s_icon;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "GraphicsBitmap.h"
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <SharedGraphics/PNGLoader.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -27,6 +28,11 @@ Retained<GraphicsBitmap> GraphicsBitmap::create_wrapper(Format format, const Siz
|
|||
return adopt(*new GraphicsBitmap(format, size, data));
|
||||
}
|
||||
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const String& path)
|
||||
{
|
||||
return load_png(path);
|
||||
}
|
||||
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(Format format, const String& path, const Size& size)
|
||||
{
|
||||
int fd = open(path.characters(), O_RDONLY, 0644);
|
||||
|
|
|
@ -14,6 +14,7 @@ public:
|
|||
|
||||
static Retained<GraphicsBitmap> create(Format, const Size&);
|
||||
static Retained<GraphicsBitmap> create_wrapper(Format, const Size&, RGBA32*);
|
||||
static RetainPtr<GraphicsBitmap> load_from_file(const String& path);
|
||||
static RetainPtr<GraphicsBitmap> load_from_file(Format, const String& path, const Size&);
|
||||
static Retained<GraphicsBitmap> create_with_shared_buffer(Format, Retained<SharedBuffer>&&, const Size&);
|
||||
~GraphicsBitmap();
|
||||
|
|
|
@ -152,6 +152,7 @@ RetainPtr<GraphicsBitmap> load_png(const String& path)
|
|||
|
||||
union [[gnu::packed]] Pixel {
|
||||
RGBA32 rgba { 0 };
|
||||
byte v[4];
|
||||
struct {
|
||||
byte r;
|
||||
byte g;
|
||||
|
@ -162,21 +163,29 @@ union [[gnu::packed]] Pixel {
|
|||
static_assert(sizeof(Pixel) == 4);
|
||||
|
||||
template<bool has_alpha, byte filter_type>
|
||||
[[gnu::always_inline]] static inline void unfilter_impl(const GraphicsBitmap& bitmap, int y, const void* dummy_scanline_data)
|
||||
[[gnu::always_inline]] static inline void unfilter_impl(GraphicsBitmap& bitmap, int y, const void* dummy_scanline_data)
|
||||
{
|
||||
auto* dummy_scanline = (const Pixel*)dummy_scanline_data;
|
||||
if constexpr (filter_type == 1) {
|
||||
if constexpr (filter_type == 0) {
|
||||
auto* pixels = (Pixel*)bitmap.scanline(y);
|
||||
for (int i = 0; i < bitmap.width(); ++i) {
|
||||
auto& x = pixels[i];
|
||||
swap(x.r, x.b);
|
||||
Pixel a;
|
||||
if (i != 0) a.rgba = bitmap.scanline(y)[i - 1];
|
||||
x.r += a.r;
|
||||
x.g += a.g;
|
||||
x.b += a.b;
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (filter_type == 1) {
|
||||
auto* pixels = (Pixel*)bitmap.scanline(y);
|
||||
swap(pixels[0].r, pixels[0].b);
|
||||
for (int i = 1; i < bitmap.width(); ++i) {
|
||||
auto& x = pixels[i];
|
||||
swap(x.r, x.b);
|
||||
auto& a = (const Pixel&)pixels[i - 1];
|
||||
x.v[0] += a.v[0];
|
||||
x.v[1] += a.v[1];
|
||||
x.v[2] += a.v[2];
|
||||
if constexpr (has_alpha)
|
||||
x.a += a.a;
|
||||
x.v[3] += a.v[3];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -186,17 +195,15 @@ template<bool has_alpha, byte filter_type>
|
|||
for (int i = 0; i < bitmap.width(); ++i) {
|
||||
auto& x = pixels[i];
|
||||
swap(x.r, x.b);
|
||||
Pixel b;
|
||||
b.rgba = pixels_y_minus_1[i].rgba;
|
||||
x.r += b.r;
|
||||
x.g += b.g;
|
||||
x.b += b.b;
|
||||
const Pixel& b = pixels_y_minus_1[i];
|
||||
x.v[0] += b.v[0];
|
||||
x.v[1] += b.v[1];
|
||||
x.v[2] += b.v[2];
|
||||
if constexpr (has_alpha)
|
||||
x.a += b.a;
|
||||
x.v[3] += b.v[3];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if constexpr (filter_type == 3) {
|
||||
auto* pixels = (Pixel*)bitmap.scanline(y);
|
||||
auto* pixels_y_minus_1 = y == 0 ? dummy_scanline : (Pixel*)bitmap.scanline(y - 1);
|
||||
|
@ -204,18 +211,16 @@ template<bool has_alpha, byte filter_type>
|
|||
auto& x = pixels[i];
|
||||
swap(x.r, x.b);
|
||||
Pixel a;
|
||||
Pixel b;
|
||||
if (i != 0) a.rgba = bitmap.scanline(y)[i - 1];
|
||||
b.rgba = pixels_y_minus_1[i].rgba;
|
||||
x.r = x.r + ((a.r + b.r) / 2);
|
||||
x.g = x.g + ((a.g + b.g) / 2);
|
||||
x.b = x.b + ((a.b + b.b) / 2);
|
||||
if (i != 0) a = pixels[i - 1];
|
||||
const Pixel& b = pixels_y_minus_1[i];
|
||||
x.v[0] = x.v[0] + ((a.v[0] + b.v[0]) / 2);
|
||||
x.v[1] = x.v[1] + ((a.v[1] + b.v[1]) / 2);
|
||||
x.v[2] = x.v[2] + ((a.v[2] + b.v[2]) / 2);
|
||||
if constexpr (has_alpha)
|
||||
x.a = x.a + ((a.a + b.a) / 2);
|
||||
x.v[3] = x.v[3] + ((a.v[3] + b.v[3]) / 2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if constexpr (filter_type == 4) {
|
||||
auto* pixels = (Pixel*)bitmap.scanline(y);
|
||||
auto* pixels_y_minus_1 = y == 0 ? dummy_scanline : (Pixel*)bitmap.scanline(y - 1);
|
||||
|
@ -223,18 +228,17 @@ template<bool has_alpha, byte filter_type>
|
|||
auto& x = pixels[i];
|
||||
swap(x.r, x.b);
|
||||
Pixel a;
|
||||
Pixel b;
|
||||
const Pixel& b = pixels_y_minus_1[i];
|
||||
Pixel c;
|
||||
if (i != 0) {
|
||||
a.rgba = bitmap.scanline(y)[i - 1];
|
||||
c.rgba = pixels_y_minus_1[i - 1].rgba;
|
||||
a = pixels[i - 1];
|
||||
c = pixels_y_minus_1[i - 1];
|
||||
}
|
||||
b.rgba = pixels_y_minus_1[i].rgba;
|
||||
x.r += paeth_predictor(a.r, b.r, c.r);
|
||||
x.g += paeth_predictor(a.g, b.g, c.g);
|
||||
x.b += paeth_predictor(a.b, b.b, c.b);
|
||||
x.v[0] += paeth_predictor(a.v[0], b.v[0], c.v[0]);
|
||||
x.v[1] += paeth_predictor(a.v[1], b.v[1], c.v[1]);
|
||||
x.v[2] += paeth_predictor(a.v[2], b.v[2], c.v[2]);
|
||||
if constexpr (has_alpha)
|
||||
x.a += paeth_predictor(a.a, b.a, c.a);
|
||||
x.v[3] += paeth_predictor(a.v[3], b.v[3], c.v[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -274,8 +278,13 @@ template<bool has_alpha, byte filter_type>
|
|||
Stopwatch sw("load_png_impl: unfilter: process");
|
||||
for (int y = 0; y < context.height; ++y) {
|
||||
auto filter = context.scanlines[y].filter;
|
||||
if (filter == 0)
|
||||
if (filter == 0) {
|
||||
if (context.has_alpha())
|
||||
unfilter_impl<true, 0>(*context.bitmap, y, dummy_scanline.pointer());
|
||||
else
|
||||
unfilter_impl<false, 0>(*context.bitmap, y, dummy_scanline.pointer());
|
||||
continue;
|
||||
}
|
||||
if (filter == 1) {
|
||||
if (context.has_alpha())
|
||||
unfilter_impl<true, 1>(*context.bitmap, y, dummy_scanline.pointer());
|
||||
|
@ -364,7 +373,7 @@ static RetainPtr<GraphicsBitmap> load_png_impl(const byte* data, int data_size)
|
|||
|
||||
{
|
||||
Stopwatch sw("load_png_impl: create bitmap");
|
||||
context.bitmap = GraphicsBitmap::create(GraphicsBitmap::Format::RGBA32, { context.width, context.height });
|
||||
context.bitmap = GraphicsBitmap::create(context.has_alpha() ? GraphicsBitmap::Format::RGBA32 : GraphicsBitmap::Format::RGB32, { context.width, context.height });
|
||||
}
|
||||
|
||||
unfilter(context);
|
||||
|
|
Loading…
Add table
Reference in a new issue