5 #include "../src/mark.h"
6 #include "../src/yuv.h"
10 int mark_selected = 0;
12 #define COLOR_WIDTH 100
13 #define COLOR_HEIGHT 20
28 static GdkPixbuf *draw_pixpuf(int i)
34 float bright, contrast;
35 double r, g, b, y, u, v;
37 cr = mark_palette[i].r;
38 cg = mark_palette[i].g;
39 cb = mark_palette[i].b;
40 bright = mark_palette[i].bright;
41 contrast = mark_palette[i].contrast;
45 rgb2yuv_pixle(r, g, b, &y, &u, &v);
47 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, COLOR_WIDTH, COLOR_HEIGHT);
48 data = gdk_pixbuf_get_pixels(pixbuf);
49 rs = gdk_pixbuf_get_rowstride(pixbuf);
50 for (k = 0; k < COLOR_WIDTH; k++) {
51 /* we use height as horizontal size of original color area */
52 if (k >= COLOR_HEIGHT+3) {
53 y = (double)(k-COLOR_HEIGHT-3) / (double)((COLOR_WIDTH-COLOR_HEIGHT-3)-1);
54 y = (y - 0.5) * contrast + 0.5;
60 yuv2rgb_pixle(y, u, v, &r, &g, &b);
77 if (k >= COLOR_HEIGHT) {
82 for (j = 0; j < COLOR_HEIGHT; j++) {
83 data[j * rs + k * 3 + 0] = cr;
84 data[j * rs + k * 3 + 1] = cg;
85 data[j * rs + k * 3 + 2] = cb;
89 /* indicate a change in brightness + contrast */
90 if (bright != 0 || contrast != 1) {
91 for (k = 0; k < 11; k++) {
92 for (j = 0; j < 11; j++) {
93 if (bc_pic[j][k] == '*') {
94 data[j * rs + k * 3 + 0] = 255;
95 data[j * rs + k * 3 + 1] = 0;
96 data[j * rs + k * 3 + 2] = 0;
105 void create_palette(void)
107 GtkListStore *palette_store;
113 for (i = 0; i < 255; i++) {
114 strcpy(mark_palette[i].name, "");
115 mark_palette[i].r = 0;
116 mark_palette[i].g = 0;
117 mark_palette[i].b = 0;
118 mark_palette[i].bright = 0;
119 mark_palette[i].contrast = 1;
122 strcpy(mark_palette[0].name, "red");
123 mark_palette[0].r = 255;
124 mark_palette[0].g = 0;
125 mark_palette[0].b = 0;
126 strcpy(mark_palette[1].name, "green");
127 mark_palette[1].r = 0;
128 mark_palette[1].g = 255;
129 mark_palette[1].b = 0;
130 strcpy(mark_palette[2].name, "blue");
131 mark_palette[2].r = 0;
132 mark_palette[2].g = 0;
133 mark_palette[2].b = 255;
135 palette_store = gtk_list_store_new(3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING);
136 gtk_tree_view_set_model(GTK_TREE_VIEW(palette_treeview), GTK_TREE_MODEL(palette_store));
137 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(palette_treeview), FALSE);
139 for (i = 0; i < 255; i++) {
140 gtk_list_store_append(palette_store, &iter);
141 sprintf(number, "%d", i+1);
142 color = draw_pixpuf(i);
143 gtk_list_store_set(palette_store, &iter, 0, number, 1, color, 2, mark_palette[i].name, -1);
144 g_object_unref(color);
147 g_object_unref(palette_store);
151 void update_color(int entry)
155 color = draw_pixpuf(entry);
161 sprintf(path, "%d", entry);
162 model = gtk_tree_view_get_model(GTK_TREE_VIEW(palette_treeview));
163 if (gtk_tree_model_get_iter_from_string(model, &iter, path)) {
164 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, color, 2, mark_palette[entry].name, -1);