mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 12:26:01 +01:00
Implemented recoloring
This commit is contained in:
parent
4806163e24
commit
00589a7295
5 changed files with 74 additions and 8 deletions
5
config.c
5
config.c
|
@ -14,6 +14,7 @@ config_load_default(zathura_t* zathura)
|
||||||
}
|
}
|
||||||
|
|
||||||
int int_value = 0;
|
int int_value = 0;
|
||||||
|
char* string_value = NULL;
|
||||||
girara_session_t* gsession = zathura->ui.session;
|
girara_session_t* gsession = zathura->ui.session;
|
||||||
|
|
||||||
/* general settings */
|
/* general settings */
|
||||||
|
@ -27,6 +28,10 @@ config_load_default(zathura_t* zathura)
|
||||||
int_value = 2;
|
int_value = 2;
|
||||||
girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL);
|
girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL);
|
||||||
|
|
||||||
|
string_value = "#FFFFFF";
|
||||||
|
girara_setting_add(gsession, "recolor-dark-color", string_value, STRING, false, "Recoloring (dark color)", NULL);
|
||||||
|
string_value = "#000000";
|
||||||
|
girara_setting_add(gsession, "recolor-light-color", string_value, STRING, false, "Recoloring (light color)", NULL);
|
||||||
|
|
||||||
/* define default shortcuts */
|
/* define default shortcuts */
|
||||||
girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL);
|
girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL);
|
||||||
|
|
33
render.c
33
render.c
|
@ -168,6 +168,39 @@ render(zathura_t* zathura, zathura_page_t* page)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* recolor */
|
||||||
|
if (zathura->global.recolor) {
|
||||||
|
/* recolor code based on qimageblitz library flatten() function
|
||||||
|
(http://sourceforge.net/projects/qimageblitz/) */
|
||||||
|
|
||||||
|
int r1 = zathura->ui.colors.recolor_dark_color.red / 257;
|
||||||
|
int g1 = zathura->ui.colors.recolor_dark_color.green / 257;
|
||||||
|
int b1 = zathura->ui.colors.recolor_dark_color.blue / 257;
|
||||||
|
int r2 = zathura->ui.colors.recolor_light_color.red / 257;
|
||||||
|
int g2 = zathura->ui.colors.recolor_light_color.green / 257;
|
||||||
|
int b2 = zathura->ui.colors.recolor_light_color.blue / 257;
|
||||||
|
|
||||||
|
int min = 0x00;
|
||||||
|
int max = 0xFF;
|
||||||
|
int mean = 0x00;
|
||||||
|
|
||||||
|
float sr = ((float) r2 - r1) / (max - min);
|
||||||
|
float sg = ((float) g2 - g1) / (max - min);
|
||||||
|
float sb = ((float) b2 - b1) / (max - min);
|
||||||
|
|
||||||
|
for (unsigned int y = 0; y < page_height; y++) {
|
||||||
|
unsigned char* data = image + y * rowstride;
|
||||||
|
|
||||||
|
for (unsigned int x = 0; x < page_width; x++) {
|
||||||
|
mean = (data[0] + data[1] + data[2]) / 3;
|
||||||
|
data[2] = sr * (mean - min) + r1 + 0.5;
|
||||||
|
data[1] = sg * (mean - min) + g1 + 0.5;
|
||||||
|
data[0] = sb * (mean - min) + b1 + 0.5;
|
||||||
|
data += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* draw to gtk widget */
|
/* draw to gtk widget */
|
||||||
page->surface = surface;
|
page->surface = surface;
|
||||||
gtk_widget_set_size_request(page->drawing_area, page_width, page_height);
|
gtk_widget_set_size_request(page->drawing_area, page_width, page_height);
|
||||||
|
|
|
@ -119,6 +119,11 @@ bool
|
||||||
sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int t)
|
sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int t)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(session != NULL, false);
|
g_return_val_if_fail(session != NULL, false);
|
||||||
|
g_return_val_if_fail(session->global.data != NULL, false);
|
||||||
|
zathura_t* zathura = session->global.data;
|
||||||
|
|
||||||
|
zathura->global.recolor = !zathura->global.recolor;
|
||||||
|
render_all(zathura);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
18
zathura.c
18
zathura.c
|
@ -104,10 +104,13 @@ zathura_init(int argc, char* argv[])
|
||||||
zathura->ui.page_view = NULL;
|
zathura->ui.page_view = NULL;
|
||||||
zathura->ui.index = NULL;
|
zathura->ui.index = NULL;
|
||||||
|
|
||||||
/* Print settings */
|
/* print settings */
|
||||||
zathura->print.settings = NULL;
|
zathura->print.settings = NULL;
|
||||||
zathura->print.page_setup = NULL;
|
zathura->print.page_setup = NULL;
|
||||||
|
|
||||||
|
/* global settings */
|
||||||
|
zathura->global.recolor = false;
|
||||||
|
|
||||||
/* load plugins */
|
/* load plugins */
|
||||||
zathura_document_plugins_load(zathura);
|
zathura_document_plugins_load(zathura);
|
||||||
|
|
||||||
|
@ -173,6 +176,19 @@ zathura_init(int argc, char* argv[])
|
||||||
gtk_table_set_row_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding);
|
gtk_table_set_row_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding);
|
||||||
gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding);
|
gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding);
|
||||||
|
|
||||||
|
/* parse colors */
|
||||||
|
char* string_value = girara_setting_get(zathura->ui.session, "recolor-dark-color");
|
||||||
|
if (string_value != NULL) {
|
||||||
|
gdk_color_parse(string_value, &(zathura->ui.colors.recolor_dark_color));
|
||||||
|
free(string_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
string_value = girara_setting_get(zathura->ui.session, "recolor-light-color");
|
||||||
|
if (string_value != NULL) {
|
||||||
|
gdk_color_parse(string_value, &(zathura->ui.colors.recolor_light_color));
|
||||||
|
free(string_value);
|
||||||
|
}
|
||||||
|
|
||||||
/* open document if passed */
|
/* open document if passed */
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t));
|
zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t));
|
||||||
|
|
21
zathura.h
21
zathura.h
|
@ -44,6 +44,12 @@ typedef struct zathura_s
|
||||||
girara_statusbar_item_t* page_number; /**> page number statusbar entry */
|
girara_statusbar_item_t* page_number; /**> page number statusbar entry */
|
||||||
} statusbar;
|
} statusbar;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
GdkColor recolor_dark_color; /**> Dark color for recoloring */
|
||||||
|
GdkColor recolor_light_color; /**> Light color for recoloring */
|
||||||
|
} colors;
|
||||||
|
|
||||||
GtkWidget *page_view; /**> Widget that contains all rendered pages */
|
GtkWidget *page_view; /**> Widget that contains all rendered pages */
|
||||||
GtkWidget *index; /**> Widget to show the index of the document */
|
GtkWidget *index; /**> Widget to show the index of the document */
|
||||||
} ui;
|
} ui;
|
||||||
|
@ -55,25 +61,26 @@ typedef struct zathura_s
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
girara_list_t* plugins;
|
girara_list_t* plugins; /**> List of plugins */
|
||||||
girara_list_t* path;
|
girara_list_t* path; /**> List of plugin paths */
|
||||||
} plugins;
|
} plugins;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
gchar* config_dir;
|
gchar* config_dir; /**> Path to the configuration directory */
|
||||||
gchar* data_dir;
|
gchar* data_dir; /**> Path to the data directory */
|
||||||
} config;
|
} config;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
GtkPrintSettings* settings;
|
GtkPrintSettings* settings; /**> Print settings */
|
||||||
GtkPageSetup* page_setup;
|
GtkPageSetup* page_setup; /**> Saved page setup */
|
||||||
} print;
|
} print;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
unsigned int page_padding;
|
unsigned int page_padding; /**> Padding between the pages */
|
||||||
|
bool recolor; /**> Recoloring mode switch */
|
||||||
} global;
|
} global;
|
||||||
|
|
||||||
zathura_document_t* document; /**> The current document */
|
zathura_document_t* document; /**> The current document */
|
||||||
|
|
Loading…
Reference in a new issue