mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-07 01:49:47 +00:00
merge #11
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@582 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -106,9 +106,9 @@ struct _MwFont {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct _MwRGB {
|
struct _MwRGB {
|
||||||
MwU32 red;
|
MwU16 red;
|
||||||
MwU32 green;
|
MwU16 green;
|
||||||
MwU32 blue;
|
MwU16 blue;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -20,36 +20,34 @@
|
|||||||
#define HSV_VAL_MAX 255.
|
#define HSV_VAL_MAX 255.
|
||||||
|
|
||||||
typedef struct _MwHSV {
|
typedef struct _MwHSV {
|
||||||
double h; /* angle in degrees */
|
MwBool generated : 1;
|
||||||
double s; /* a fraction between 0 and 1 */
|
MwU16 h : 11;
|
||||||
double v; /* a fraction between 0 and 1 */
|
MwU8 s;
|
||||||
MwBool generated;
|
MwU8 v;
|
||||||
} MwHSV;
|
} MwHSV;
|
||||||
|
|
||||||
typedef struct color_picker {
|
typedef struct color_picker {
|
||||||
MwWidget parent;
|
MwWidget parent;
|
||||||
MwWidget color_picker_img;
|
MwWidget color_picker_img;
|
||||||
MwWidget value_slider;
|
MwWidget value_slider;
|
||||||
MwWidget color_display;
|
MwWidget color_display;
|
||||||
MwWidget color_display_text;
|
MwWidget color_display_text;
|
||||||
MwWidget finish;
|
MwWidget finish;
|
||||||
MwLLPixmap color_picker_pixmap;
|
MwLLPixmap color_picker_pixmap;
|
||||||
double value;
|
double value;
|
||||||
unsigned char* color_picker_image_data;
|
MwRGB chosen_color;
|
||||||
MwPoint point;
|
unsigned char color_picker_image_data[PICKER_SIZE * PICKER_SIZE * 4];
|
||||||
double dist_table[PICKER_SIZE][PICKER_SIZE];
|
MwHSV hue_table[101753];
|
||||||
MwHSV hue_table[PICKER_SIZE][PICKER_SIZE];
|
|
||||||
MwRGB chosen_color;
|
|
||||||
} color_picker_t;
|
} color_picker_t;
|
||||||
|
|
||||||
static void hsv2rgb(MwU32 h, MwU32 s, MwU32 v, MwU32* r, MwU32* g, MwU32* b) {
|
static void hsv2rgb(MwU32 h, MwU32 s, MwU32 v, MwU16* r, MwU16* g, MwU16* b) {
|
||||||
MwU8 sextant = h >> 8;
|
MwU8 sextant = h >> 8;
|
||||||
MwU16 ww;
|
MwU16 ww;
|
||||||
MwU32 h_fraction, d;
|
MwU32 h_fraction, d;
|
||||||
|
|
||||||
#define HSV_SWAPPTR(a, b) \
|
#define HSV_SWAPPTR(a, b) \
|
||||||
do { \
|
do { \
|
||||||
MwU32* tmp = a; \
|
MwU16* tmp = a; \
|
||||||
a = b; \
|
a = b; \
|
||||||
b = tmp; \
|
b = tmp; \
|
||||||
} while(0)
|
} while(0)
|
||||||
@@ -99,18 +97,14 @@ static void hsv2rgb(MwU32 h, MwU32 s, MwU32 v, MwU32* r, MwU32* g, MwU32* b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void color_picker_image_update(color_picker_t* picker) {
|
static void color_picker_image_update(color_picker_t* picker) {
|
||||||
int y, x;
|
MwU16 y, x;
|
||||||
|
int n = 0;
|
||||||
for(y = 0; y < PICKER_SIZE; y++) {
|
for(y = 0; y < PICKER_SIZE; y++) {
|
||||||
for(x = 0; x < PICKER_SIZE; x++) {
|
for(x = 0; x < PICKER_SIZE; x++) {
|
||||||
int i = ((y * PICKER_SIZE) + x) * 4;
|
int i = ((y * PICKER_SIZE) + x) * 4;
|
||||||
int _x = x - (PICKER_SIZE / 2);
|
int _x = x - (PICKER_SIZE / 2);
|
||||||
int _y = y - (PICKER_SIZE / 2);
|
int _y = y - (PICKER_SIZE / 2);
|
||||||
double dist;
|
double dist = sqrt(_x * _x + _y * _y);
|
||||||
|
|
||||||
if(picker->dist_table[y][x] == 0) {
|
|
||||||
picker->dist_table[y][x] = sqrt(_x * _x + _y * _y);
|
|
||||||
}
|
|
||||||
dist = picker->dist_table[y][x];
|
|
||||||
|
|
||||||
if(dist >= 180.) {
|
if(dist >= 180.) {
|
||||||
picker->color_picker_image_data[i] = 0;
|
picker->color_picker_image_data[i] = 0;
|
||||||
@@ -120,7 +114,7 @@ static void color_picker_image_update(color_picker_t* picker) {
|
|||||||
} else {
|
} else {
|
||||||
MwHSV hsv_v;
|
MwHSV hsv_v;
|
||||||
MwRGB color;
|
MwRGB color;
|
||||||
if(picker->hue_table[y][x].generated == 0) {
|
if(picker->hue_table[n].generated == 0) {
|
||||||
double xd = (M_PI / 180.) * ((double)_x);
|
double xd = (M_PI / 180.) * ((double)_x);
|
||||||
double yd = (M_PI / 180.) * ((double)_y);
|
double yd = (M_PI / 180.) * ((double)_y);
|
||||||
|
|
||||||
@@ -130,13 +124,13 @@ static void color_picker_image_update(color_picker_t* picker) {
|
|||||||
if(hue < 0.0) {
|
if(hue < 0.0) {
|
||||||
hue += 360;
|
hue += 360;
|
||||||
}
|
}
|
||||||
hsv_v.h = (hue) * (HSV_HUE_STEPS / 360.);
|
hsv_v.h = (hue) * (HSV_HUE_STEPS / 360.);
|
||||||
hsv_v.s = (dist) * (HSV_SAT_MAX / 180.);
|
hsv_v.s = (dist) * (HSV_SAT_MAX / 180.);
|
||||||
picker->hue_table[y][x] = hsv_v;
|
picker->hue_table[n] = hsv_v;
|
||||||
picker->hue_table[y][x].generated = 1;
|
picker->hue_table[n].generated = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hsv_v = picker->hue_table[y][x];
|
hsv_v = picker->hue_table[n];
|
||||||
hsv_v.v = HSV_VAL_MAX - (picker->value * HSV_VAL_MAX);
|
hsv_v.v = HSV_VAL_MAX - (picker->value * HSV_VAL_MAX);
|
||||||
|
|
||||||
hsv2rgb(hsv_v.h, hsv_v.s, hsv_v.v, &color.red, &color.green, &color.blue);
|
hsv2rgb(hsv_v.h, hsv_v.s, hsv_v.v, &color.red, &color.green, &color.blue);
|
||||||
@@ -146,6 +140,7 @@ static void color_picker_image_update(color_picker_t* picker) {
|
|||||||
picker->color_picker_image_data[i + 2] = color.blue;
|
picker->color_picker_image_data[i + 2] = color.blue;
|
||||||
|
|
||||||
picker->color_picker_image_data[i + 3] = 255;
|
picker->color_picker_image_data[i + 3] = 255;
|
||||||
|
n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,6 +152,7 @@ static void color_picker_image_update(color_picker_t* picker) {
|
|||||||
picker->parent, picker->color_picker_image_data, PICKER_SIZE, PICKER_SIZE, picker->color_picker_pixmap);
|
picker->parent, picker->color_picker_image_data, PICKER_SIZE, PICKER_SIZE, picker->color_picker_pixmap);
|
||||||
}
|
}
|
||||||
MwVaApply(picker->color_picker_img, MwNpixmap, picker->color_picker_pixmap, NULL);
|
MwVaApply(picker->color_picker_img, MwNpixmap, picker->color_picker_pixmap, NULL);
|
||||||
|
// printf("%d\n", n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void color_picker_click(MwWidget handle, void* user, void* call) {
|
static void color_picker_click(MwWidget handle, void* user, void* call) {
|
||||||
@@ -208,7 +204,6 @@ static void color_picker_on_change_value(MwWidget handle, void* user,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void color_picker_destroy(color_picker_t* picker) {
|
static void color_picker_destroy(color_picker_t* picker) {
|
||||||
free(picker->color_picker_image_data);
|
|
||||||
MwLLDestroyPixmap(picker->color_picker_pixmap);
|
MwLLDestroyPixmap(picker->color_picker_pixmap);
|
||||||
free(picker);
|
free(picker);
|
||||||
}
|
}
|
||||||
@@ -245,7 +240,7 @@ color_picker_t* color_picker_setup(MwWidget parent, int w, int h) {
|
|||||||
MwVaCreateWidget(MwImageClass, "image", picker->parent, IMG_POS_X(w), IMG_POS_Y(h),
|
MwVaCreateWidget(MwImageClass, "image", picker->parent, IMG_POS_X(w), IMG_POS_Y(h),
|
||||||
PICKER_SIZE, PICKER_SIZE, NULL);
|
PICKER_SIZE, PICKER_SIZE, NULL);
|
||||||
|
|
||||||
picker->color_picker_image_data = malloc(PICKER_SIZE * PICKER_SIZE * 4);
|
// picker->color_picker_image_data = malloc(PICKER_SIZE * PICKER_SIZE * 4);
|
||||||
|
|
||||||
picker->color_picker_pixmap = NULL;
|
picker->color_picker_pixmap = NULL;
|
||||||
picker->value = 0;
|
picker->value = 0;
|
||||||
@@ -299,7 +294,6 @@ color_picker_t* color_picker_setup(MwWidget parent, int w, int h) {
|
|||||||
MwAddUserHandler(picker->finish, MwNactivateHandler,
|
MwAddUserHandler(picker->finish, MwNactivateHandler,
|
||||||
color_picker_finish, picker);
|
color_picker_finish, picker);
|
||||||
|
|
||||||
memset(picker->dist_table, 0, sizeof(picker->dist_table));
|
|
||||||
memset(picker->hue_table, 0, sizeof(picker->hue_table));
|
memset(picker->hue_table, 0, sizeof(picker->hue_table));
|
||||||
|
|
||||||
return picker;
|
return picker;
|
||||||
|
|||||||
Reference in New Issue
Block a user