Cleanup code from last commit

This commit is contained in:
o9000 2016-03-22 08:25:09 +01:00
parent 1dcf9c676d
commit 4656f7fc94
5 changed files with 122 additions and 124 deletions

View file

@ -348,7 +348,7 @@ Imlib_Image scale_icon(Imlib_Image original, int icon_size)
adjust_asb(data,
icon_size,
icon_size,
launcher_alpha,
launcher_alpha / 100.0,
launcher_saturation / 100.0,
launcher_brightness / 100.0);
imlib_image_put_back_data(data);

View file

@ -1338,7 +1338,7 @@ void systray_render_icon_composited(void *t)
adjust_asb(data,
traywin->width,
traywin->height,
systray.alpha,
systray.alpha / 100.0,
systray.saturation / 100.0,
systray.brightness / 100.0);
imlib_image_put_back_data(data);

View file

@ -315,7 +315,7 @@ void task_update_icon(Task *task)
adjust_asb(data32,
task->icon_width,
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.brightness[k] / 100.0);
imlib_image_put_back_data(data32);

View file

@ -238,46 +238,35 @@ 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;
unsigned int argb;
int a, r, g, b;
unsigned long id;
int cmax, cmin;
float h2, f, p, q, t;
float hue, saturation, brightness;
float redc, greenc, bluec;
for (y = 0; y < h; y++) {
for (id = y * w, x = 0; x < w; x++, id++) {
argb = data[id];
a = (argb >> 24) & 0xff;
for (int id = 0; id < w * h; id++) {
unsigned int argb = data[id];
int a = (argb >> 24) & 0xff;
// transparent => nothing to do.
if (a == 0)
continue;
r = (argb >> 16) & 0xff;
g = (argb >> 8) & 0xff;
b = (argb)&0xff;
int r = (argb >> 16) & 0xff;
int g = (argb >> 8) & 0xff;
int b = (argb) & 0xff;
// convert RGB to HSB
cmax = (r > g) ? r : g;
if (b > cmax)
cmax = b;
cmin = (r < g) ? r : g;
if (b < cmin)
cmin = b;
brightness = ((float)cmax) / 255.0f;
// Convert RGB to HSV
int cmax = MAX3(r, g, b);
int cmin = MIN3(r, g, b);
int delta = cmax - cmin;
float brightness = cmax / 255.0f;
float saturation;
if (cmax != 0)
saturation = ((float)(cmax - cmin)) / ((float)cmax);
saturation = delta / (float)cmax;
else
saturation = 0;
if (saturation == 0)
float hue;
if (saturation == 0) {
hue = 0;
else {
redc = ((float)(cmax - r)) / ((float)(cmax - cmin));
greenc = ((float)(cmax - g)) / ((float)(cmax - cmin));
bluec = ((float)(cmax - b)) / ((float)(cmax - cmin));
} else {
float redc = (cmax - r) / (float)delta;
float greenc = (cmax - g) / (float)delta;
float bluec = (cmax - b) / (float)delta;
if (r == cmax)
hue = bluec - greenc;
else if (g == cmax)
@ -289,29 +278,23 @@ void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright
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;
// Adjust H, S
saturation += satur_adjust;
saturation = CLAMP(saturation, 0.0, 1.0);
// convert HSB to RGB
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 {
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)));
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);
@ -346,13 +329,13 @@ void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright
}
}
r += bright * 255;
g += bright * 255;
b += bright * 255;
r += bright_adjust * 255;
g += bright_adjust * 255;
b += bright_adjust * 255;
r = MAX(0, MIN(255, r));
g = MAX(0, MIN(255, g));
b = MAX(0, MIN(255, b));
r = CLAMP(r, 0, 255);
g = CLAMP(g, 0, 255);
b = CLAMP(b, 0, 255);
argb = a;
argb = (argb << 8) + r;
@ -360,7 +343,6 @@ void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright
argb = (argb << 8) + b;
data[id] = argb;
}
}
}
void create_heuristic_mask(DATA32 *data, int w, int h)
@ -511,7 +493,7 @@ Imlib_Image adjust_icon(Imlib_Image original, int alpha, int saturation, int bri
adjust_asb(data,
imlib_image_get_width(),
imlib_image_get_height(),
alpha,
alpha / 100.0,
saturation / 100.0,
brightness / 100.0);
imlib_image_put_back_data(data);

View file

@ -8,6 +8,7 @@
#define WM_CLASS_TINT "panel"
#include <glib.h>
#include <Imlib2.h>
#include <pango/pangocairo.h>
#include "area.h"
@ -18,6 +19,9 @@
#define BLUE "\033[1;34m"
#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
typedef enum MouseAction {
NONE = 0,
@ -67,8 +71,20 @@ void get_color(char *hex, double *rgb);
Imlib_Image load_image(const char *path, int cached);
// 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.
void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright);
// Parameters:
// * 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);
void create_heuristic_mask(DATA32 *data, int w, int h);