Cleanup code from last commit
This commit is contained in:
@@ -348,7 +348,7 @@ Imlib_Image scale_icon(Imlib_Image original, int icon_size)
|
|||||||
adjust_asb(data,
|
adjust_asb(data,
|
||||||
icon_size,
|
icon_size,
|
||||||
icon_size,
|
icon_size,
|
||||||
launcher_alpha,
|
launcher_alpha / 100.0,
|
||||||
launcher_saturation / 100.0,
|
launcher_saturation / 100.0,
|
||||||
launcher_brightness / 100.0);
|
launcher_brightness / 100.0);
|
||||||
imlib_image_put_back_data(data);
|
imlib_image_put_back_data(data);
|
||||||
|
|||||||
@@ -1338,7 +1338,7 @@ void systray_render_icon_composited(void *t)
|
|||||||
adjust_asb(data,
|
adjust_asb(data,
|
||||||
traywin->width,
|
traywin->width,
|
||||||
traywin->height,
|
traywin->height,
|
||||||
systray.alpha,
|
systray.alpha / 100.0,
|
||||||
systray.saturation / 100.0,
|
systray.saturation / 100.0,
|
||||||
systray.brightness / 100.0);
|
systray.brightness / 100.0);
|
||||||
imlib_image_put_back_data(data);
|
imlib_image_put_back_data(data);
|
||||||
|
|||||||
@@ -315,7 +315,7 @@ void task_update_icon(Task *task)
|
|||||||
adjust_asb(data32,
|
adjust_asb(data32,
|
||||||
task->icon_width,
|
task->icon_width,
|
||||||
task->icon_height,
|
task->icon_height,
|
||||||
panel->g_task.alpha[k],
|
panel->g_task.alpha[k] / 100.0,
|
||||||
panel->g_task.saturation[k] / 100.0,
|
panel->g_task.saturation[k] / 100.0,
|
||||||
panel->g_task.brightness[k] / 100.0);
|
panel->g_task.brightness[k] / 100.0);
|
||||||
imlib_image_put_back_data(data32);
|
imlib_image_put_back_data(data32);
|
||||||
|
|||||||
@@ -238,128 +238,110 @@ void extract_values(const char *value, char **value1, char **value2, char **valu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright)
|
void adjust_asb(DATA32 *data, int w, int h, float alpha_adjust, float satur_adjust, float bright_adjust)
|
||||||
{
|
{
|
||||||
unsigned int x, y;
|
for (int id = 0; id < w * h; id++) {
|
||||||
unsigned int argb;
|
unsigned int argb = data[id];
|
||||||
int a, r, g, b;
|
int a = (argb >> 24) & 0xff;
|
||||||
unsigned long id;
|
// transparent => nothing to do.
|
||||||
int cmax, cmin;
|
if (a == 0)
|
||||||
float h2, f, p, q, t;
|
continue;
|
||||||
float hue, saturation, brightness;
|
int r = (argb >> 16) & 0xff;
|
||||||
float redc, greenc, bluec;
|
int g = (argb >> 8) & 0xff;
|
||||||
|
int b = (argb) & 0xff;
|
||||||
|
|
||||||
for (y = 0; y < h; y++) {
|
// Convert RGB to HSV
|
||||||
for (id = y * w, x = 0; x < w; x++, id++) {
|
int cmax = MAX3(r, g, b);
|
||||||
argb = data[id];
|
int cmin = MIN3(r, g, b);
|
||||||
a = (argb >> 24) & 0xff;
|
int delta = cmax - cmin;
|
||||||
// transparent => nothing to do.
|
float brightness = cmax / 255.0f;
|
||||||
if (a == 0)
|
float saturation;
|
||||||
continue;
|
if (cmax != 0)
|
||||||
r = (argb >> 16) & 0xff;
|
saturation = delta / (float)cmax;
|
||||||
g = (argb >> 8) & 0xff;
|
else
|
||||||
b = (argb)&0xff;
|
saturation = 0;
|
||||||
|
float hue;
|
||||||
// convert RGB to HSB
|
if (saturation == 0) {
|
||||||
cmax = (r > g) ? r : g;
|
hue = 0;
|
||||||
if (b > cmax)
|
} else {
|
||||||
cmax = b;
|
float redc = (cmax - r) / (float)delta;
|
||||||
cmin = (r < g) ? r : g;
|
float greenc = (cmax - g) / (float)delta;
|
||||||
if (b < cmin)
|
float bluec = (cmax - b) / (float)delta;
|
||||||
cmin = b;
|
if (r == cmax)
|
||||||
brightness = ((float)cmax) / 255.0f;
|
hue = bluec - greenc;
|
||||||
if (cmax != 0)
|
else if (g == cmax)
|
||||||
saturation = ((float)(cmax - cmin)) / ((float)cmax);
|
hue = 2.0f + redc - bluec;
|
||||||
else
|
else
|
||||||
saturation = 0;
|
hue = 4.0f + greenc - redc;
|
||||||
if (saturation == 0)
|
hue = hue / 6.0f;
|
||||||
hue = 0;
|
if (hue < 0)
|
||||||
else {
|
hue = hue + 1.0f;
|
||||||
redc = ((float)(cmax - r)) / ((float)(cmax - cmin));
|
|
||||||
greenc = ((float)(cmax - g)) / ((float)(cmax - cmin));
|
|
||||||
bluec = ((float)(cmax - b)) / ((float)(cmax - cmin));
|
|
||||||
if (r == cmax)
|
|
||||||
hue = bluec - greenc;
|
|
||||||
else if (g == cmax)
|
|
||||||
hue = 2.0f + redc - bluec;
|
|
||||||
else
|
|
||||||
hue = 4.0f + greenc - redc;
|
|
||||||
hue = hue / 6.0f;
|
|
||||||
if (hue < 0)
|
|
||||||
hue = hue + 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// adjust
|
|
||||||
saturation += satur;
|
|
||||||
if (saturation < 0.0)
|
|
||||||
saturation = 0.0;
|
|
||||||
if (saturation > 1.0)
|
|
||||||
saturation = 1.0;
|
|
||||||
//brightness += bright;
|
|
||||||
if (brightness < 0.0)
|
|
||||||
brightness = 0.0;
|
|
||||||
if (brightness > 1.0)
|
|
||||||
brightness = 1.0;
|
|
||||||
if (alpha != 100)
|
|
||||||
a = (a * alpha) / 100;
|
|
||||||
|
|
||||||
// convert HSB to RGB
|
|
||||||
if (saturation == 0) {
|
|
||||||
r = g = b = (int)(brightness * 255.0f + 0.5f);
|
|
||||||
} else {
|
|
||||||
h2 = (hue - (int)hue) * 6.0f;
|
|
||||||
f = h2 - (int)(h2);
|
|
||||||
p = brightness * (1.0f - saturation);
|
|
||||||
q = brightness * (1.0f - saturation * f);
|
|
||||||
t = brightness * (1.0f - (saturation * (1.0f - f)));
|
|
||||||
switch ((int)h2) {
|
|
||||||
case 0:
|
|
||||||
r = (int)(brightness * 255.0f + 0.5f);
|
|
||||||
g = (int)(t * 255.0f + 0.5f);
|
|
||||||
b = (int)(p * 255.0f + 0.5f);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
r = (int)(q * 255.0f + 0.5f);
|
|
||||||
g = (int)(brightness * 255.0f + 0.5f);
|
|
||||||
b = (int)(p * 255.0f + 0.5f);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
r = (int)(p * 255.0f + 0.5f);
|
|
||||||
g = (int)(brightness * 255.0f + 0.5f);
|
|
||||||
b = (int)(t * 255.0f + 0.5f);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
r = (int)(p * 255.0f + 0.5f);
|
|
||||||
g = (int)(q * 255.0f + 0.5f);
|
|
||||||
b = (int)(brightness * 255.0f + 0.5f);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
r = (int)(t * 255.0f + 0.5f);
|
|
||||||
g = (int)(p * 255.0f + 0.5f);
|
|
||||||
b = (int)(brightness * 255.0f + 0.5f);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
r = (int)(brightness * 255.0f + 0.5f);
|
|
||||||
g = (int)(p * 255.0f + 0.5f);
|
|
||||||
b = (int)(q * 255.0f + 0.5f);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r += bright * 255;
|
|
||||||
g += bright * 255;
|
|
||||||
b += bright * 255;
|
|
||||||
|
|
||||||
r = MAX(0, MIN(255, r));
|
|
||||||
g = MAX(0, MIN(255, g));
|
|
||||||
b = MAX(0, MIN(255, b));
|
|
||||||
|
|
||||||
argb = a;
|
|
||||||
argb = (argb << 8) + r;
|
|
||||||
argb = (argb << 8) + g;
|
|
||||||
argb = (argb << 8) + b;
|
|
||||||
data[id] = argb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adjust H, S
|
||||||
|
saturation += satur_adjust;
|
||||||
|
saturation = CLAMP(saturation, 0.0, 1.0);
|
||||||
|
|
||||||
|
a *= alpha_adjust;
|
||||||
|
a = CLAMP(a, 0, 255);
|
||||||
|
|
||||||
|
// Convert HSV to RGB
|
||||||
|
if (saturation == 0) {
|
||||||
|
r = g = b = (int)(brightness * 255.0f + 0.5f);
|
||||||
|
} else {
|
||||||
|
float h2 = (hue - (int)hue) * 6.0f;
|
||||||
|
float f = h2 - (int)(h2);
|
||||||
|
float p = brightness * (1.0f - saturation);
|
||||||
|
float q = brightness * (1.0f - saturation * f);
|
||||||
|
float t = brightness * (1.0f - (saturation * (1.0f - f)));
|
||||||
|
|
||||||
|
switch ((int)h2) {
|
||||||
|
case 0:
|
||||||
|
r = (int)(brightness * 255.0f + 0.5f);
|
||||||
|
g = (int)(t * 255.0f + 0.5f);
|
||||||
|
b = (int)(p * 255.0f + 0.5f);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
r = (int)(q * 255.0f + 0.5f);
|
||||||
|
g = (int)(brightness * 255.0f + 0.5f);
|
||||||
|
b = (int)(p * 255.0f + 0.5f);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
r = (int)(p * 255.0f + 0.5f);
|
||||||
|
g = (int)(brightness * 255.0f + 0.5f);
|
||||||
|
b = (int)(t * 255.0f + 0.5f);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
r = (int)(p * 255.0f + 0.5f);
|
||||||
|
g = (int)(q * 255.0f + 0.5f);
|
||||||
|
b = (int)(brightness * 255.0f + 0.5f);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
r = (int)(t * 255.0f + 0.5f);
|
||||||
|
g = (int)(p * 255.0f + 0.5f);
|
||||||
|
b = (int)(brightness * 255.0f + 0.5f);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
r = (int)(brightness * 255.0f + 0.5f);
|
||||||
|
g = (int)(p * 255.0f + 0.5f);
|
||||||
|
b = (int)(q * 255.0f + 0.5f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r += bright_adjust * 255;
|
||||||
|
g += bright_adjust * 255;
|
||||||
|
b += bright_adjust * 255;
|
||||||
|
|
||||||
|
r = CLAMP(r, 0, 255);
|
||||||
|
g = CLAMP(g, 0, 255);
|
||||||
|
b = CLAMP(b, 0, 255);
|
||||||
|
|
||||||
|
argb = a;
|
||||||
|
argb = (argb << 8) + r;
|
||||||
|
argb = (argb << 8) + g;
|
||||||
|
argb = (argb << 8) + b;
|
||||||
|
data[id] = argb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,7 +493,7 @@ Imlib_Image adjust_icon(Imlib_Image original, int alpha, int saturation, int bri
|
|||||||
adjust_asb(data,
|
adjust_asb(data,
|
||||||
imlib_image_get_width(),
|
imlib_image_get_width(),
|
||||||
imlib_image_get_height(),
|
imlib_image_get_height(),
|
||||||
alpha,
|
alpha / 100.0,
|
||||||
saturation / 100.0,
|
saturation / 100.0,
|
||||||
brightness / 100.0);
|
brightness / 100.0);
|
||||||
imlib_image_put_back_data(data);
|
imlib_image_put_back_data(data);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#define WM_CLASS_TINT "panel"
|
#define WM_CLASS_TINT "panel"
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
#include <Imlib2.h>
|
#include <Imlib2.h>
|
||||||
#include <pango/pangocairo.h>
|
#include <pango/pangocairo.h>
|
||||||
#include "area.h"
|
#include "area.h"
|
||||||
@@ -18,6 +19,9 @@
|
|||||||
#define BLUE "\033[1;34m"
|
#define BLUE "\033[1;34m"
|
||||||
#define RESET "\033[0m"
|
#define RESET "\033[0m"
|
||||||
|
|
||||||
|
#define MAX3(a, b, c) MAX(MAX(a, b), c)
|
||||||
|
#define MIN3(a, b, c) MIN(MIN(a, b), c)
|
||||||
|
|
||||||
// mouse actions
|
// mouse actions
|
||||||
typedef enum MouseAction {
|
typedef enum MouseAction {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
@@ -67,8 +71,20 @@ void get_color(char *hex, double *rgb);
|
|||||||
Imlib_Image load_image(const char *path, int cached);
|
Imlib_Image load_image(const char *path, int cached);
|
||||||
|
|
||||||
// Adjusts the alpha/saturation/brightness on an ARGB image.
|
// Adjusts the alpha/saturation/brightness on an ARGB image.
|
||||||
// Parameters: alpha from 0 to 100, satur from 0 to 1, bright from 0 to 1.
|
// Parameters:
|
||||||
void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright);
|
// * alpha_adjust: multiplicative:
|
||||||
|
// * 0 = full transparency
|
||||||
|
// * 1 = no adjustment
|
||||||
|
// * 2 = twice the current opacity
|
||||||
|
// * satur_adjust: additive:
|
||||||
|
// * -1 = full grayscale
|
||||||
|
// * 0 = no adjustment
|
||||||
|
// * 1 = full color
|
||||||
|
// * bright_adjust: additive:
|
||||||
|
// * -1 = black
|
||||||
|
// * 0 = no adjustment
|
||||||
|
// * 1 = white
|
||||||
|
void adjust_asb(DATA32 *data, int w, int h, float alpha_adjust, float satur_adjust, float bright_adjust);
|
||||||
Imlib_Image adjust_icon(Imlib_Image original, int alpha, int saturation, int brightness);
|
Imlib_Image adjust_icon(Imlib_Image original, int alpha, int saturation, int brightness);
|
||||||
|
|
||||||
void create_heuristic_mask(DATA32 *data, int w, int h);
|
void create_heuristic_mask(DATA32 *data, int w, int h);
|
||||||
|
|||||||
Reference in New Issue
Block a user