5 #include "../src/mark.h"
6 #include "../src/yuv.h"
11 int mark_selected = 0;
13 #define COLOR_WIDTH 100
14 #define COLOR_HEIGHT 20
16 static char *bc_pic[] = {
30 static char *alpha_pic[] = {
43 static char *asis_pic[] = {
45 " **** ******** ** ******** ",
46 " ** ** *** *** ** *** *** ",
47 " ** ** ** ** ** ** **",
50 "************ ****** ** ****** ",
51 "************ ****** ** ****** ",
54 "** ** ** ** ** ** **",
55 "** ** *** *** ** *** *** ",
56 "** ** ******** ** ******** ",
57 "** ** **** ** **** ",
60 static GdkPixbuf *draw_pixpuf(int i)
65 int cr, cg, cb, asis = 0;
66 float bright, contrast, alpha;
67 double r, g, b, y, u, v, pat;
69 cr = mark_palette[i].r;
70 cg = mark_palette[i].g;
71 cb = mark_palette[i].b;
72 bright = mark_palette[i].bright;
73 contrast = mark_palette[i].contrast;
74 alpha = mark_palette[i].alpha;
78 if (cr == 255 && cg == 255 && cb == 255)
80 rgb2yuv_pixle(r, g, b, &y, &u, &v);
82 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, COLOR_WIDTH, COLOR_HEIGHT);
83 data = gdk_pixbuf_get_pixels(pixbuf);
84 rs = gdk_pixbuf_get_rowstride(pixbuf);
86 for (k = 0; k < COLOR_WIDTH; k++) {
87 if (k >= COLOR_HEIGHT+3) {
89 pat = ((k>>3)&1) ? 0.5 : 0.75;
90 r = alpha + pat * (1-alpha);
91 g = alpha + pat * (1-alpha);
92 b = alpha + pat * (1-alpha);
114 if (k >= COLOR_HEIGHT) {
119 for (j = 0; j < COLOR_HEIGHT; j++) {
120 data[j * rs + k * 3 + 0] = cr;
121 data[j * rs + k * 3 + 1] = cg;
122 data[j * rs + k * 3 + 2] = cb;
126 for (k = 0; k < COLOR_WIDTH; k++) {
127 /* we use height as horizontal size of original color area */
128 if (k >= COLOR_HEIGHT+3) {
129 y = (double)(k-COLOR_HEIGHT-3) / (double)((COLOR_WIDTH-COLOR_HEIGHT-3)-1);
130 y = (y - 0.5) * contrast + 0.5;
136 yuv2rgb_pixle(y, u, v, &r, &g, &b);
138 pat = ((k>>3)&1) ? 0.5 : 0.75;
139 r = r * alpha + pat * (1-alpha);
140 g = g * alpha + pat * (1-alpha);
141 b = b * alpha + pat * (1-alpha);
159 if (k >= COLOR_HEIGHT) {
164 for (j = 0; j < COLOR_HEIGHT; j++) {
165 data[j * rs + k * 3 + 0] = cr;
166 data[j * rs + k * 3 + 1] = cg;
167 data[j * rs + k * 3 + 2] = cb;
172 /* indicate a change in alpha */
174 for (k = 0, kk = COLOR_HEIGHT - 11; k < 11; k++, kk++) {
175 for (j = 0, jj = COLOR_HEIGHT - 11; j < 11; j++, jj++) {
176 if (alpha_pic[j][k] == '*') {
177 data[jj * rs + kk * 3 + 0] = 255;
178 data[jj * rs + kk * 3 + 1] = 0;
179 data[jj * rs + kk * 3 + 2] = 0;
185 /* indicate a change in brightness + contrast */
186 if (bright != 0 || contrast != 1) {
187 for (k = 0; k < 11; k++) {
188 for (j = 0; j < 11; j++) {
189 if (bc_pic[j][k] == '*') {
190 data[j * rs + k * 3 + 0] = 255;
191 data[j * rs + k * 3 + 1] = 0;
192 data[j * rs + k * 3 + 2] = 0;
198 /* indicate that the color is as it is on the image */
200 for (k = 0, kk = (COLOR_WIDTH - COLOR_HEIGHT - 3 - 48) / 2 + COLOR_HEIGHT + 3; k < 48; k++, kk++) {
201 for (j = 0, jj = COLOR_HEIGHT / 2 - 7; j < 14; j++, jj++) {
202 if (asis_pic[j][k] == '*') {
203 data[jj * rs + kk * 3 + 0] = 255;
204 data[jj * rs + kk * 3 + 1] = 0;
205 data[jj * rs + kk * 3 + 2] = 0;
214 void create_palette(void)
216 GtkListStore *palette_store;
222 for (i = 0; i < 255; i++) {
223 strcpy(mark_palette[i].name, "");
224 mark_palette[i].r = 0;
225 mark_palette[i].g = 0;
226 mark_palette[i].b = 0;
227 mark_palette[i].bright = 0;
228 mark_palette[i].contrast = 1;
229 mark_palette[i].alpha = 1;
232 strcpy(mark_palette[0].name, "red");
233 mark_palette[0].r = 255;
234 mark_palette[0].g = 0;
235 mark_palette[0].b = 0;
236 strcpy(mark_palette[1].name, "green");
237 mark_palette[1].r = 0;
238 mark_palette[1].g = 255;
239 mark_palette[1].b = 0;
240 strcpy(mark_palette[2].name, "blue");
241 mark_palette[2].r = 0;
242 mark_palette[2].g = 0;
243 mark_palette[2].b = 255;
245 palette_store = gtk_list_store_new(3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING);
246 gtk_tree_view_set_model(GTK_TREE_VIEW(palette_treeview), GTK_TREE_MODEL(palette_store));
247 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(palette_treeview), FALSE);
249 for (i = 0; i < 255; i++) {
250 gtk_list_store_append(palette_store, &iter);
251 sprintf(number, "%d", i+1);
252 color = draw_pixpuf(i);
253 gtk_list_store_set(palette_store, &iter, 0, number, 1, color, 2, mark_palette[i].name, -1);
254 g_object_unref(color);
255 if (i == mark_selected) {
256 GtkTreeSelection *selection;
258 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(palette_treeview));
259 gtk_tree_selection_select_iter(selection, &iter);
260 path = gtk_tree_model_get_path(GTK_TREE_MODEL(palette_store), &iter);
261 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(palette_treeview), path, NULL, FALSE, 0,0);
262 gtk_tree_path_free(path);
266 g_object_unref(palette_store);
270 int get_iter_by_path_name(GtkTreeIter *iter, GtkTreeModel *model, int entry)
274 sprintf(path_name, "%d", entry);
275 if (gtk_tree_model_get_iter_from_string(model, iter, path_name))
280 void update_color(int entry)
286 color = draw_pixpuf(entry);
288 model = gtk_tree_view_get_model(GTK_TREE_VIEW(palette_treeview));
289 if (get_iter_by_path_name(&iter, model, entry))
290 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, color, 2, mark_palette[entry].name, -1);
293 void pick_color(int x, int y)
295 GdkDrawable *draw = gtk_widget_get_window(img_drawing_area);
296 int window_width, window_height;
298 gdk_drawable_get_size (draw, &window_width, &window_height);
300 if (!img_mark_buffer)
303 /* we need to calculate an offset, since the drawing area is now larger */
304 x -= (window_width - img_width*img_scale_x/16) / 2;
305 y -= (window_height - img_height*img_scale_y/16) / 2;
307 x = x*16/img_scale_x;
308 y = y*16/img_scale_y;
310 if (x < 0 || x >= img_width || y < 0 || y >= img_height)
313 c = img_mark_buffer[img_width*y+x];
317 GtkTreeSelection *selection;
320 mark_selected = c - 1;
321 model = gtk_tree_view_get_model(GTK_TREE_VIEW(palette_treeview));
322 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(palette_treeview));
323 if (get_iter_by_path_name(&iter, model, mark_selected)) {
324 gtk_tree_selection_select_iter(selection, &iter);
325 path = gtk_tree_model_get_path(model, &iter);
326 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(palette_treeview), path, NULL, FALSE, 0,0);
327 gtk_tree_path_free(path);