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
29 static GdkPixbuf *draw_pixpuf(int i)
35 float bright, contrast;
36 double r, g, b, y, u, v;
38 cr = mark_palette[i].r;
39 cg = mark_palette[i].g;
40 cb = mark_palette[i].b;
41 bright = mark_palette[i].bright;
42 contrast = mark_palette[i].contrast;
46 rgb2yuv_pixle(r, g, b, &y, &u, &v);
48 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, COLOR_WIDTH, COLOR_HEIGHT);
49 data = gdk_pixbuf_get_pixels(pixbuf);
50 rs = gdk_pixbuf_get_rowstride(pixbuf);
51 if (cr == 255 && cg == 255 && cb == 255) {
52 for (k = 0; k < COLOR_WIDTH; k++) {
53 for (j = 0; j < COLOR_HEIGHT; j++) {
54 data[j * rs + k * 3 + 0] = 255;
55 data[j * rs + k * 3 + 1] = 255;
56 data[j * rs + k * 3 + 2] = 255;
60 for (k = 0; k < COLOR_WIDTH; k++) {
61 /* we use height as horizontal size of original color area */
62 if (k >= COLOR_HEIGHT+3) {
63 y = (double)(k-COLOR_HEIGHT-3) / (double)((COLOR_WIDTH-COLOR_HEIGHT-3)-1);
64 y = (y - 0.5) * contrast + 0.5;
70 yuv2rgb_pixle(y, u, v, &r, &g, &b);
87 if (k >= COLOR_HEIGHT) {
92 for (j = 0; j < COLOR_HEIGHT; j++) {
93 data[j * rs + k * 3 + 0] = cr;
94 data[j * rs + k * 3 + 1] = cg;
95 data[j * rs + k * 3 + 2] = cb;
100 /* indicate a change in brightness + contrast */
101 if (bright != 0 || contrast != 1) {
102 for (k = 0; k < 11; k++) {
103 for (j = 0; j < 11; j++) {
104 if (bc_pic[j][k] == '*') {
105 data[j * rs + k * 3 + 0] = 255;
106 data[j * rs + k * 3 + 1] = 0;
107 data[j * rs + k * 3 + 2] = 0;
116 void create_palette(void)
118 GtkListStore *palette_store;
124 for (i = 0; i < 255; i++) {
125 strcpy(mark_palette[i].name, "");
126 mark_palette[i].r = 0;
127 mark_palette[i].g = 0;
128 mark_palette[i].b = 0;
129 mark_palette[i].bright = 0;
130 mark_palette[i].contrast = 1;
133 strcpy(mark_palette[0].name, "red");
134 mark_palette[0].r = 255;
135 mark_palette[0].g = 0;
136 mark_palette[0].b = 0;
137 strcpy(mark_palette[1].name, "green");
138 mark_palette[1].r = 0;
139 mark_palette[1].g = 255;
140 mark_palette[1].b = 0;
141 strcpy(mark_palette[2].name, "blue");
142 mark_palette[2].r = 0;
143 mark_palette[2].g = 0;
144 mark_palette[2].b = 255;
146 palette_store = gtk_list_store_new(3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING);
147 gtk_tree_view_set_model(GTK_TREE_VIEW(palette_treeview), GTK_TREE_MODEL(palette_store));
148 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(palette_treeview), FALSE);
150 for (i = 0; i < 255; i++) {
151 gtk_list_store_append(palette_store, &iter);
152 sprintf(number, "%d", i+1);
153 color = draw_pixpuf(i);
154 gtk_list_store_set(palette_store, &iter, 0, number, 1, color, 2, mark_palette[i].name, -1);
155 g_object_unref(color);
156 if (i == mark_selected) {
157 GtkTreeSelection *selection;
159 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(palette_treeview));
160 gtk_tree_selection_select_iter(selection, &iter);
161 path = gtk_tree_model_get_path(GTK_TREE_MODEL(palette_store), &iter);
162 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(palette_treeview), path, NULL, FALSE, 0,0);
163 gtk_tree_path_free(path);
167 g_object_unref(palette_store);
171 int get_iter_by_path_name(GtkTreeIter *iter, GtkTreeModel *model, int entry)
175 sprintf(path_name, "%d", entry);
176 if (gtk_tree_model_get_iter_from_string(model, iter, path_name))
181 void update_color(int entry)
187 color = draw_pixpuf(entry);
189 model = gtk_tree_view_get_model(GTK_TREE_VIEW(palette_treeview));
190 if (get_iter_by_path_name(&iter, model, entry))
191 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, color, 2, mark_palette[entry].name, -1);
194 void pick_color(int x, int y)
196 GdkDrawable *draw = gtk_widget_get_window(img_drawing_area);
197 int window_width, window_height;
199 gdk_drawable_get_size (draw, &window_width, &window_height);
201 if (!img_mark_buffer)
204 /* we need to calculate an offset, since the drawing area is now larger */
205 x -= (window_width - img_width*img_scale_x/16) / 2;
206 y -= (window_height - img_height*img_scale_y/16) / 2;
208 x = x*16/img_scale_x;
209 y = y*16/img_scale_y;
211 if (x < 0 || x >= img_width || y < 0 || y >= img_height)
214 c = img_mark_buffer[img_width*y+x];
218 GtkTreeSelection *selection;
221 mark_selected = c - 1;
222 model = gtk_tree_view_get_model(GTK_TREE_VIEW(palette_treeview));
223 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(palette_treeview));
224 if (get_iter_by_path_name(&iter, model, mark_selected)) {
225 gtk_tree_selection_select_iter(selection, &iter);
226 path = gtk_tree_model_get_path(model, &iter);
227 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(palette_treeview), path, NULL, FALSE, 0,0);
228 gtk_tree_path_free(path);