Advertisement
palmerstone

Gtk 18

Nov 29th, 2011
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.12 KB | None | 0 0
  1. #include <cairo.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <windows.h>
  5. #include <gtk/gtk.h>
  6. #include <gdk/gdk.h>
  7. #include <gtk/gtkscale.h>
  8. #include <gtk/gtkvscale.h>
  9. #include <gtk/gtkvscale.h>
  10. #include <gdk/gdkkeysyms.h>
  11. #include <gdk-pixbuf/gdk-pixbuf.h>
  12.  
  13. const int square_size = 30;
  14. const double ratio = 1.150;
  15. float brightness_val = 0.0, contrast_val = 0.0;
  16. int global, ini, total, flag = 0, image_flag = 0, image_flag2 = 0, remove_flag = 0;
  17. int width, height, heightini, zoom_width, zoom_height;
  18. char str[500], str2[500], str3[500], str4[500], str5[500], str6[500], slide[500];
  19. char image_list[5000][100];
  20.  
  21. gint offset;
  22. GtkWindow *window;
  23. GdkPixbuf *windowicon, *mypic, *result_pixbuf;
  24. GtkWidget *fixed_layout, *img, *img2, *img3, *dialog, *gbdialog, *grayscale, *brightness, *contrast, *negative;
  25. GtkButton *openbutton, *closebutton, *nextbutton, *previousbutton, *playbutton, *aboutbutton, *gotofirstbutton, *gotolastbutton, *zoom_in_button, *zoom_out_button, *stopbutton, *negativebutton, *greyscalebutton, *contrastbutton, *brightnessbutton, *restorebutton1, *restorebutton2, *brightnessbutton2, *contrastbutton2;
  26. GtkTooltips *opentooltip, *closetooltip, *nexttooltip, *previoustooltip, *playtooltip, *abouttooltip, *gotofirsttooltip, *gotolasttooltip, *zoom_in_tooltip, *zoom_out_tooltip, *stoptooltip, *negativetooltip, *greyscaletooltip, *contrasttooltip, *brightnesstooltip, *restoretooltip1, *restoretooltip2, *brightnesstooltip2, *contrasttooltip2;
  27.  
  28. static unsigned char apply_contrast (unsigned char u_value, float contrast);
  29. static unsigned char apply_brightness (unsigned char u_value, float brightness);
  30. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data);
  31. void create_menu();
  32. void create_toolbar();
  33. void show_about();
  34. void open_file();
  35. void start_slide();
  36. void stop_slide();
  37. void get_list(char filename[500]);
  38. void store_list();
  39. gboolean show_next(gpointer userdata);
  40. void show_next2();
  41. void show_previous();
  42. void image_brightness();
  43. void image_contrast();
  44. void goto_first();
  45. void goto_last();
  46. void image_negative();
  47. void increase_brightness();
  48. void decrease_brightness();
  49. void increase_contrast();
  50. void decrease_contrast();
  51. void image_greyscale();
  52. void show_original1();
  53. void show_original2();
  54. void zoom_in();
  55. void zoom_out();
  56. void goodbye_dialog();
  57.  
  58. void create_toolbar()
  59. {
  60. total = (5 * 30) + (10 * 4);
  61. ini = (width - total) / 2;
  62.  
  63. openbutton = gtk_button_new();
  64. opentooltip = gtk_tooltips_new();
  65. gtk_widget_set_size_request(GTK_WIDGET(openbutton), square_size, square_size);
  66. gtk_button_set_image (GTK_BUTTON(openbutton),gtk_image_new_from_stock(GTK_STOCK_ORIENTATION_PORTRAIT, GTK_ICON_SIZE_BUTTON));
  67. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(openbutton), ini, heightini - 40);
  68. gtk_tooltips_set_tip(opentooltip, GTK_WIDGET(openbutton), "Open (Ctrl+O)", "Open (Ctrl+O)");
  69.  
  70. ini += 40;
  71. gotofirstbutton = gtk_button_new();
  72. gotofirsttooltip = gtk_tooltips_new();
  73. gtk_widget_set_size_request(GTK_WIDGET(gotofirstbutton), square_size, square_size);
  74. gtk_button_set_image (GTK_BUTTON(gotofirstbutton),gtk_image_new_from_stock(GTK_STOCK_GOTO_FIRST, GTK_ICON_SIZE_BUTTON));
  75. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(gotofirstbutton), ini, heightini - 40);
  76. gtk_tooltips_set_tip(gotofirsttooltip, GTK_WIDGET(gotofirstbutton), "Go to first image (Page Up)", "Go to first image (Page Up)");
  77.  
  78. ini += 40;
  79. previousbutton = gtk_button_new();
  80. previoustooltip = gtk_tooltips_new();
  81. gtk_widget_set_size_request(GTK_WIDGET(previousbutton), square_size, square_size);
  82. gtk_button_set_image (GTK_BUTTON(previousbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PREVIOUS, GTK_ICON_SIZE_BUTTON));
  83. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(previousbutton), ini, heightini - 40);
  84. gtk_tooltips_set_tip(previoustooltip, GTK_WIDGET(previousbutton), "Show Previous (Left key)", "Show Previous (Left key)");
  85.  
  86. ini += 40;
  87. playbutton = gtk_button_new();
  88. playtooltip = gtk_tooltips_new();
  89. gtk_widget_set_size_request(GTK_WIDGET(playbutton), square_size, square_size);
  90. gtk_button_set_image (GTK_BUTTON(playbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_BUTTON));
  91. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(playbutton), ini, heightini - 40);
  92. gtk_tooltips_set_tip(playtooltip, GTK_WIDGET(playbutton), "Start Slideshow (Spacebar)", "Start Slideshow (Spacebar)");
  93.  
  94. stopbutton = gtk_button_new();
  95. stoptooltip = gtk_tooltips_new();
  96. gtk_widget_set_size_request(GTK_WIDGET(stopbutton), square_size, square_size);
  97. gtk_button_set_image (GTK_BUTTON(stopbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_BUTTON));
  98. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(stopbutton), ini, heightini - 40);
  99. gtk_tooltips_set_tip(stoptooltip, GTK_WIDGET(stopbutton), "Stop Slideshow (Spacebar)", "Stop Slideshow (Spacebar)");
  100.  
  101. ini += 40;
  102. nextbutton = gtk_button_new();
  103. nexttooltip = gtk_tooltips_new();
  104. gtk_widget_set_size_request(GTK_WIDGET(nextbutton), square_size, square_size);
  105. gtk_button_set_image (GTK_BUTTON(nextbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_NEXT, GTK_ICON_SIZE_BUTTON));
  106. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(nextbutton), ini, heightini - 40);
  107. gtk_tooltips_set_tip(nexttooltip, GTK_WIDGET(nextbutton), "Show Next (Right Key)", "Show Next (Right Key)");
  108.  
  109. ini += 40;
  110. gotolastbutton = gtk_button_new();
  111. gotolasttooltip = gtk_tooltips_new();
  112. gtk_widget_set_size_request(GTK_WIDGET(gotolastbutton), square_size, square_size);
  113. gtk_button_set_image (GTK_BUTTON(gotolastbutton),gtk_image_new_from_stock(GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON));
  114. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(gotolastbutton), ini, heightini - 40);
  115. gtk_tooltips_set_tip(gotolasttooltip, GTK_WIDGET(gotolastbutton), "Go to last image (Page Down)", "Go to last image (Page Down)");
  116.  
  117. ini = width - 40;
  118. closebutton = gtk_button_new();
  119. closetooltip = gtk_tooltips_new();
  120. gtk_widget_set_size_request(GTK_WIDGET(closebutton), square_size, square_size);
  121. gtk_button_set_image (GTK_BUTTON(closebutton),gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON));
  122. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(closebutton), ini, heightini - 40);
  123. gtk_tooltips_set_tip(closetooltip, GTK_WIDGET(closebutton), "Close :( (Ctrl+Q)", "Close :( (Ctrl+Q)");
  124.  
  125. ini -= 40;
  126. aboutbutton = gtk_button_new();
  127. abouttooltip = gtk_tooltips_new();
  128. gtk_widget_set_size_request(GTK_WIDGET(aboutbutton), square_size, square_size);
  129. gtk_button_set_image (GTK_BUTTON(aboutbutton),gtk_image_new_from_stock(GTK_STOCK_INFO, GTK_ICON_SIZE_BUTTON));
  130. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(aboutbutton), ini, heightini - 40);
  131. gtk_tooltips_set_tip(abouttooltip, GTK_WIDGET(aboutbutton), "About Us :)", "About Us :)");
  132.  
  133. ini = 10;
  134. zoom_out_button = gtk_button_new();
  135. zoom_out_tooltip = gtk_tooltips_new();
  136. gtk_widget_set_size_request(GTK_WIDGET(zoom_out_button), square_size, square_size);
  137. gtk_button_set_image (GTK_BUTTON(zoom_out_button),gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_BUTTON));
  138. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(zoom_out_button), ini, heightini - 40);
  139. gtk_tooltips_set_tip(zoom_out_tooltip, GTK_WIDGET(zoom_out_button), "Zoom Out (-)", "Zoom Out (-)");
  140.  
  141. ini += 40;
  142. zoom_in_button = gtk_button_new();
  143. zoom_in_tooltip = gtk_tooltips_new();
  144. gtk_widget_set_size_request(GTK_WIDGET(zoom_in_button), square_size, square_size);
  145. gtk_button_set_image (GTK_BUTTON(zoom_in_button),gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_BUTTON));
  146. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(zoom_in_button), ini, heightini - 40);
  147. gtk_tooltips_set_tip(zoom_in_tooltip, GTK_WIDGET(zoom_in_button), "Zoom In (+)", "Zoom In (+)");
  148.  
  149. ini += 40;
  150. negativebutton = gtk_button_new();
  151. negativetooltip = gtk_tooltips_new();
  152. gtk_widget_set_size_request(GTK_WIDGET(negativebutton), square_size, square_size);
  153. gtk_button_set_image (GTK_BUTTON(negativebutton),gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON));
  154. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(negativebutton), ini, heightini - 40);
  155. gtk_tooltips_set_tip(negativetooltip, GTK_WIDGET(negativebutton), "Show Negative (Ctrl+N)", "Show Negative (Ctrl+N)");
  156.  
  157. restorebutton1 = gtk_button_new();
  158. restoretooltip1 = gtk_tooltips_new();
  159. gtk_widget_set_size_request(GTK_WIDGET(restorebutton1), square_size, square_size);
  160. gtk_button_set_image (GTK_BUTTON(restorebutton1),gtk_image_new_from_stock(GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
  161. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(restorebutton1), ini, heightini - 40);
  162. gtk_tooltips_set_tip(restoretooltip1, GTK_WIDGET(restorebutton1), "Restore", "Restore");
  163.  
  164. ini += 40;
  165. greyscalebutton = gtk_button_new();
  166. greyscaletooltip = gtk_tooltips_new();
  167. gtk_widget_set_size_request(GTK_WIDGET(greyscalebutton), square_size, square_size);
  168. gtk_button_set_image (GTK_BUTTON(greyscalebutton),gtk_image_new_from_stock(GTK_STOCK_DISCARD, GTK_ICON_SIZE_BUTTON));
  169. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(greyscalebutton), ini, heightini - 40);
  170. gtk_tooltips_set_tip(greyscaletooltip, GTK_WIDGET(greyscalebutton), "Show Greyscale Image (Ctrl+G)", "Show Greyscale Image (Ctrl+G)");
  171.  
  172. restorebutton2 = gtk_button_new();
  173. restoretooltip2 = gtk_tooltips_new();
  174. gtk_widget_set_size_request(GTK_WIDGET(restorebutton2), square_size, square_size);
  175. gtk_button_set_image (GTK_BUTTON(restorebutton2),gtk_image_new_from_stock(GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
  176. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(restorebutton2), ini, heightini - 40);
  177. gtk_tooltips_set_tip(restoretooltip2, GTK_WIDGET(restorebutton2), "Restore", "Restore");
  178.  
  179. ini += 40;
  180. brightnessbutton2 = gtk_button_new();
  181. brightnesstooltip2 = gtk_tooltips_new();
  182. gtk_widget_set_size_request(GTK_WIDGET(brightnessbutton2), square_size, square_size);
  183. gtk_button_set_image (GTK_BUTTON(brightnessbutton2),gtk_image_new_from_stock(GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_BUTTON));
  184. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(brightnessbutton2), ini, heightini - 40);
  185. gtk_tooltips_set_tip(brightnesstooltip2, GTK_WIDGET(brightnessbutton2), "Decrease Brightness", "Decrease Brightness");
  186.  
  187. ini += 40;
  188. brightnessbutton = gtk_button_new();
  189. brightnesstooltip = gtk_tooltips_new();
  190. gtk_widget_set_size_request(GTK_WIDGET(brightnessbutton), square_size, square_size);
  191. gtk_button_set_image (GTK_BUTTON(brightnessbutton),gtk_image_new_from_stock(GTK_STOCK_GO_UP, GTK_ICON_SIZE_BUTTON));
  192. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(brightnessbutton), ini, heightini - 40);
  193. gtk_tooltips_set_tip(brightnesstooltip, GTK_WIDGET(brightnessbutton), "Increase Brightness", "Increase Brightness");
  194.  
  195. ini += 40;
  196. contrastbutton2 = gtk_button_new();
  197. contrasttooltip2 = gtk_tooltips_new();
  198. gtk_widget_set_size_request(GTK_WIDGET(contrastbutton2), square_size, square_size);
  199. gtk_button_set_image (GTK_BUTTON(contrastbutton2),gtk_image_new_from_stock(GTK_STOCK_UNDO, GTK_ICON_SIZE_BUTTON));
  200. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(contrastbutton2), ini, heightini - 40);
  201. gtk_tooltips_set_tip(contrasttooltip2, GTK_WIDGET(contrastbutton2), "Decrease Contrast", "Decrease Contrast");
  202.  
  203. ini += 40;
  204. contrastbutton = gtk_button_new();
  205. contrasttooltip = gtk_tooltips_new();
  206. gtk_widget_set_size_request(GTK_WIDGET(contrastbutton), square_size, square_size);
  207. gtk_button_set_image (GTK_BUTTON(contrastbutton),gtk_image_new_from_stock(GTK_STOCK_REDO, GTK_ICON_SIZE_BUTTON));
  208. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(contrastbutton), ini, heightini - 40);
  209. gtk_tooltips_set_tip(contrasttooltip, GTK_WIDGET(contrastbutton), "Increase Contrast", "Increase Contrast");
  210. }
  211.  
  212.  
  213.  
  214. void show_about()
  215. {
  216. GtkWidget *dialog;
  217. const char copyright[] = "Copyright @ Fireflight TM, 2011. All rights reserved.";
  218. const char *author[] = {"Scape", "mr.rana", "(And special thanks to Mehedi Hasan and Shadman Shadab)", "", "Contact information: sgtlaugh@gmail.com",NULL};
  219. dialog = gtk_about_dialog_new();
  220. gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"Firedlight Image Viewer v1.052 (beta)");
  221. gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
  222. gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), copyright);
  223. gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"A free image viewer :)");
  224. windowicon = gdk_pixbuf_new_from_file(slide, NULL);
  225. gtk_window_set_icon(GTK_WINDOW(dialog), windowicon);
  226. gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS);
  227. gtk_dialog_run(GTK_DIALOG(dialog));
  228. gtk_widget_destroy(dialog);
  229. }
  230.  
  231. void open_file()
  232. {
  233. char *filename;
  234. dialog = gtk_file_chooser_dialog_new ("Open File",window,GTK_FILE_CHOOSER_ACTION_OPEN,GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,NULL);
  235. if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  236. {
  237. if (remove_flag == 0) gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img));
  238. else gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img3));
  239. gtk_widget_hide(GTK_WIDGET(restorebutton1)), gtk_widget_hide(GTK_WIDGET(restorebutton2));
  240. gtk_widget_show(GTK_WIDGET(negativebutton)), gtk_widget_show(GTK_WIDGET(greyscalebutton));
  241. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  242. filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  243. strcpy(slide, filename);
  244. get_list(filename);
  245. store_list();
  246. system(str2);
  247. zoom_width = width, zoom_height = height;
  248. img = gtk_image_new_from_file(filename);
  249. img2 = img;
  250. mypic = gdk_pixbuf_new_from_file(filename, NULL);
  251. windowicon = gdk_pixbuf_new_from_file(filename, NULL);
  252. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  253. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  254. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  255. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  256. gtk_widget_show(img);
  257. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  258. remove_flag = 0;
  259. g_free (filename);
  260. }
  261. gtk_widget_destroy (dialog);
  262. }
  263.  
  264. void zoom_in()
  265. {
  266. double x = zoom_width;
  267. double y = zoom_height;
  268. x = x * ratio, y = y * ratio;
  269. zoom_width = x, zoom_height = y;
  270. //printf("%d %d\n", zoom_width, zoom_height);
  271. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  272. pixbuf = gdk_pixbuf_scale_simple(pixbuf, zoom_width, zoom_height, GDK_INTERP_BILINEAR);
  273. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  274. gtk_widget_show(img);
  275. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  276. remove_flag = 0;
  277. }
  278.  
  279. void image_greyscale()
  280. {
  281. image_flag = 0;
  282. GtkWidget *img;
  283. gtk_widget_hide(GTK_WIDGET(greyscalebutton));
  284. gtk_widget_show(GTK_WIDGET(restorebutton2));
  285.  
  286. if (image_flag2 == 0)
  287. {
  288. char *sp, *dp;
  289. int localwidth, localheight, line, result_rowstride, mypic_rowstride, bytes_per_pixel;
  290.  
  291. result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (mypic),
  292. gdk_pixbuf_get_has_alpha (mypic),
  293. gdk_pixbuf_get_bits_per_sample (mypic),
  294. gdk_pixbuf_get_width (mypic),
  295. gdk_pixbuf_get_height (mypic));
  296.  
  297. localwidth = gdk_pixbuf_get_width (result_pixbuf);
  298. localheight = gdk_pixbuf_get_height (result_pixbuf);
  299. result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
  300. mypic_rowstride = gdk_pixbuf_get_rowstride (mypic);
  301. bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;
  302.  
  303. sp = gdk_pixbuf_get_pixels (mypic);
  304. dp = gdk_pixbuf_get_pixels (result_pixbuf);
  305. for (line = 0; line < localheight; line ++)
  306. {
  307. char *sq = sp;
  308. char *dq = dp;
  309. int i;
  310.  
  311. for (i = 0; i < localwidth; i ++)
  312. {
  313. dq[0] = (sq[0] + sq[1] + sq[2]) / 10;
  314. dq[1] = dq[0];
  315. dq[2] = dq[0];
  316.  
  317. dq += bytes_per_pixel;
  318. sq += bytes_per_pixel;
  319. }
  320.  
  321. sp += mypic_rowstride;
  322. dp += result_rowstride;
  323. }
  324. }
  325. img = gtk_image_new();
  326. result_pixbuf = gdk_pixbuf_scale_simple(result_pixbuf, width, height, GDK_INTERP_BILINEAR);
  327. gtk_image_set_from_pixbuf(GTK_IMAGE(img), result_pixbuf);
  328. gtk_widget_show(img);
  329. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  330. image_flag2 = 1, remove_flag = 0;
  331. }
  332.  
  333. void show_original2()
  334. {
  335. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img2));
  336. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  337. if (remove_flag == 0) gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img));
  338. else gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img2));
  339. img3 = gtk_image_new();
  340. gtk_image_set_from_pixbuf(GTK_IMAGE(img3), pixbuf);
  341. gtk_widget_show(img3);
  342. gtk_container_add(GTK_CONTAINER(fixed_layout), img3);
  343. remove_flag = 1;
  344. gtk_widget_hide(GTK_WIDGET(restorebutton2));
  345. gtk_widget_show(GTK_WIDGET(greyscalebutton));
  346. }
  347.  
  348. void image_negative()
  349. {
  350. image_flag2 = 0;
  351. GtkWidget *img;
  352. gtk_widget_hide(GTK_WIDGET(negativebutton));
  353. gtk_widget_show(GTK_WIDGET(restorebutton1));
  354.  
  355. if (image_flag == 0)
  356. {
  357. char *sp, *dp;
  358. int localwidth, localheight, line, result_rowstride, mypic_rowstride, bytes_per_pixel;
  359.  
  360. result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (mypic),
  361. gdk_pixbuf_get_has_alpha (mypic),
  362. gdk_pixbuf_get_bits_per_sample (mypic),
  363. gdk_pixbuf_get_width (mypic),
  364. gdk_pixbuf_get_height (mypic));
  365.  
  366. localwidth = gdk_pixbuf_get_width (result_pixbuf);
  367. localheight = gdk_pixbuf_get_height (result_pixbuf);
  368. result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
  369. mypic_rowstride = gdk_pixbuf_get_rowstride (mypic);
  370. bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;
  371.  
  372. sp = gdk_pixbuf_get_pixels (mypic);
  373. dp = gdk_pixbuf_get_pixels (result_pixbuf);
  374.  
  375. for (line = 0; line < localheight; line++)
  376. {
  377. char *sq = sp;
  378. char *dq = dp;
  379. int i;
  380.  
  381. for (i = 0; i < localwidth; i++)
  382. {
  383. dq[0] = 255 - sq[0];
  384. dq[1] = 255 - sq[1];
  385. dq[2] = 255 - sq[2];
  386.  
  387. dq += bytes_per_pixel;
  388. sq += bytes_per_pixel;
  389. }
  390.  
  391. sp += mypic_rowstride;
  392. dp += result_rowstride;
  393. }
  394. }
  395. img = gtk_image_new();
  396. result_pixbuf = gdk_pixbuf_scale_simple(result_pixbuf, width, height, GDK_INTERP_BILINEAR);
  397. gtk_image_set_from_pixbuf(GTK_IMAGE(img), result_pixbuf);
  398. gtk_widget_show(img);
  399. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  400. image_flag = 1, remove_flag = 0;
  401. }
  402.  
  403. void show_original1()
  404. {
  405. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img2));
  406. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  407. if (remove_flag == 0) gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img));
  408. else gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img2));
  409. img3 = gtk_image_new();
  410. gtk_image_set_from_pixbuf(GTK_IMAGE(img3), pixbuf);
  411. gtk_widget_show(img3);
  412. gtk_container_add(GTK_CONTAINER(fixed_layout), img3);
  413. gtk_widget_hide(GTK_WIDGET(restorebutton1));
  414. gtk_widget_show(GTK_WIDGET(negativebutton));
  415. remove_flag = 1;
  416. }
  417.  
  418. static unsigned char apply_brightness (unsigned char u_value, float brightness)
  419. {
  420. float nvalue, value;
  421. double power;
  422.  
  423. value = (float) u_value / 255.0;
  424.  
  425. if (brightness < 0.0) value = value * (1.0 + brightness);
  426. else value = value + ((1.0 - value) * brightness);
  427.  
  428. return (guchar) (value * 255);
  429. }
  430.  
  431. static unsigned char apply_contrast (unsigned char u_value, float contrast)
  432. {
  433. float nvalue;
  434. double power;
  435. float value;
  436. value = (float) u_value / 255.0;
  437.  
  438. if (contrast < 0.0)
  439. {
  440. if (value > 0.5) nvalue = 1.0 - value;
  441. else nvalue = value;
  442.  
  443. if (nvalue < 0.0) nvalue = 0.0;
  444. nvalue = 0.5 * pow (nvalue * 2.0 , (double) (1.0 + contrast));
  445.  
  446. if (value > 0.5) value = 1.0 - nvalue;
  447. else value = nvalue;
  448. }
  449. else
  450. {
  451. if (value > 0.5) nvalue = 1.0 - value;
  452. else nvalue = value;
  453.  
  454. if (nvalue < 0.0) nvalue = 0.0;
  455. power = (contrast == 1.0) ? 127 : 1.0 / (1.0 - contrast);
  456. nvalue = 0.5 * pow (2.0 * nvalue, power);
  457. if (value > 0.5) value = 1.0 - nvalue;
  458. else value = nvalue;
  459. }
  460. return (guchar) (value * 255);
  461. }
  462.  
  463. void image_contrast()
  464. {
  465. GtkWidget *img;
  466. GdkPixbuf *result_pixbuf;
  467. char *sp, *dp;
  468. int localwidth, localheight, line, result_rowstride, mypic_rowstride, bytes_per_pixel;
  469. g_return_val_if_fail ((contrast_val > -1.0 ) && (contrast_val < 1.0 ), NULL);
  470.  
  471. result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (mypic),
  472. gdk_pixbuf_get_has_alpha (mypic),
  473. gdk_pixbuf_get_bits_per_sample (mypic),
  474. gdk_pixbuf_get_width (mypic),
  475. gdk_pixbuf_get_height (mypic));
  476.  
  477. localwidth = gdk_pixbuf_get_width (result_pixbuf);
  478. localheight = gdk_pixbuf_get_height (result_pixbuf);
  479. result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
  480. mypic_rowstride = gdk_pixbuf_get_rowstride (mypic);
  481. bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;
  482. sp = gdk_pixbuf_get_pixels (mypic);
  483. dp = gdk_pixbuf_get_pixels (result_pixbuf);
  484.  
  485. for (line = 0; line < localheight; line ++)
  486. {
  487. char *sq = sp;
  488. char *dq = dp;
  489. int i;
  490.  
  491. for (i = 0; i < localwidth; i ++)
  492. {
  493. dq[0] = apply_contrast (sq[0], contrast_val);
  494. dq[1] = apply_contrast (sq[1], contrast_val);
  495. dq[2] = apply_contrast (sq[2], contrast_val);
  496. dq += bytes_per_pixel;
  497. sq += bytes_per_pixel;
  498. }
  499. sp += mypic_rowstride;
  500. dp += result_rowstride;
  501. }
  502.  
  503. img = gtk_image_new();
  504. result_pixbuf = gdk_pixbuf_scale_simple(result_pixbuf, width, height, GDK_INTERP_BILINEAR);
  505. gtk_image_set_from_pixbuf(GTK_IMAGE(img), result_pixbuf);
  506. gtk_widget_show(img);
  507. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  508. remove_flag = 0;
  509. }
  510.  
  511. void image_brightness()
  512. {
  513. GtkWidget *img;
  514. char *sp, *dp;
  515. int localwidth, localheight, line, result_rowstride, mypic_rowstride, bytes_per_pixel;
  516.  
  517. g_return_val_if_fail ((brightness_val > -1.0 ) && (brightness_val < 1.0 ), NULL);
  518. result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (mypic),
  519. gdk_pixbuf_get_has_alpha (mypic),
  520. gdk_pixbuf_get_bits_per_sample (mypic),
  521. gdk_pixbuf_get_width (mypic),
  522. gdk_pixbuf_get_height (mypic));
  523.  
  524. localwidth = gdk_pixbuf_get_width (result_pixbuf);
  525. localheight = gdk_pixbuf_get_height (result_pixbuf);
  526. result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
  527. mypic_rowstride = gdk_pixbuf_get_rowstride (mypic);
  528. bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;
  529. sp = gdk_pixbuf_get_pixels (mypic);
  530. dp = gdk_pixbuf_get_pixels (result_pixbuf);
  531.  
  532. for (line = 0; line < localheight; line ++)
  533. {
  534. char *sq = sp;
  535. char *dq = dp;
  536. int i;
  537.  
  538. for (i = 0; i < localwidth; i ++)
  539. {
  540. dq[0] = apply_brightness (sq[0], brightness_val);
  541. dq[1] = apply_brightness (sq[1], brightness_val);
  542. dq[2] = apply_brightness (sq[2], brightness_val);
  543. dq += bytes_per_pixel;
  544. sq += bytes_per_pixel;
  545. }
  546. sp += mypic_rowstride;
  547. dp += result_rowstride;
  548. }
  549. img = gtk_image_new();
  550. result_pixbuf = gdk_pixbuf_scale_simple(result_pixbuf, width, height, GDK_INTERP_BILINEAR);
  551. gtk_image_set_from_pixbuf(GTK_IMAGE(img), result_pixbuf);
  552. gtk_widget_show(img);
  553. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  554. remove_flag = 0;
  555. }
  556.  
  557. void zoom_out()
  558. {
  559. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  560. double x = zoom_width;
  561. double y = zoom_height;
  562. double d = (double) 1 / ratio;
  563. x = x * d, y = y * d;
  564. zoom_width = x, zoom_height = y;
  565. pixbuf = gdk_pixbuf_scale_simple(pixbuf, zoom_width, zoom_height, GDK_INTERP_BILINEAR);
  566. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  567. gtk_widget_show(img);
  568. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  569. remove_flag = 0;
  570. }
  571.  
  572. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data)
  573. {
  574. //if (lol->state == GDK_CONTROL_MASK && lol->keyval == GDK_KEY_Q) exit (0);
  575. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_q || lol->keyval == GDK_KEY_Q))
  576. goodbye_dialog();
  577. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_O || lol->keyval == GDK_KEY_o))
  578. open_file();
  579. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_N || lol->keyval == GDK_KEY_n))
  580. image_negative();
  581. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_G || lol->keyval == GDK_KEY_g))
  582. image_greyscale();
  583. if (lol->keyval == GDK_KEY_Right)
  584. show_next2();
  585. if (lol->keyval == GDK_KEY_Left)
  586. show_previous();
  587. if (lol->keyval == GDK_KEY_space)
  588. {
  589. if (flag == 0) flag = 1;
  590. else flag = 0;
  591. if (flag == 1) start_slide();
  592. else stop_slide();
  593. }
  594. if (lol->keyval == GDK_KEY_Page_Up)
  595. goto_first();
  596. if (lol->keyval == GDK_KEY_Page_Down)
  597. goto_last();
  598. if (lol->keyval == GDK_KEY_plus)
  599. zoom_in();
  600. if (lol->keyval == GDK_KEY_minus)
  601. zoom_out();
  602. return TRUE;
  603. }
  604.  
  605.  
  606. void start_slide()
  607. {
  608. flag = 1;
  609. gint func_ref = g_timeout_add(3000, show_next, (gpointer)32);
  610. gtk_widget_hide(GTK_WIDGET(playbutton));
  611. gtk_widget_hide(GTK_WIDGET(openbutton));
  612. gtk_widget_hide(GTK_WIDGET(closebutton));
  613. gtk_widget_hide(GTK_WIDGET(zoom_in_button));
  614. gtk_widget_hide(GTK_WIDGET(zoom_out_button));
  615. gtk_widget_hide(GTK_WIDGET(gotofirstbutton));
  616. gtk_widget_hide(GTK_WIDGET(gotolastbutton));
  617. gtk_widget_hide(GTK_WIDGET(nextbutton));
  618. gtk_widget_hide(GTK_WIDGET(previousbutton));
  619. gtk_widget_hide(GTK_WIDGET(aboutbutton));
  620. gtk_widget_hide(GTK_WIDGET(negativebutton));
  621. gtk_widget_hide(GTK_WIDGET(restorebutton1));
  622. gtk_widget_hide(GTK_WIDGET(restorebutton2));
  623. gtk_widget_hide(GTK_WIDGET(greyscalebutton));
  624. gtk_widget_hide(GTK_WIDGET(contrastbutton));
  625. gtk_widget_hide(GTK_WIDGET(contrastbutton2));
  626. gtk_widget_hide(GTK_WIDGET(brightnessbutton));
  627. gtk_widget_hide(GTK_WIDGET(brightnessbutton2));
  628. gtk_widget_show(GTK_WIDGET(stopbutton));
  629.  
  630. }
  631.  
  632. void stop_slide()
  633. {
  634. flag = 0;
  635. gint func_ref = g_timeout_add(10000000, show_next, (gpointer)32);
  636. gtk_widget_hide(GTK_WIDGET(stopbutton));
  637. gtk_widget_show(GTK_WIDGET(playbutton));
  638. gtk_widget_show(GTK_WIDGET(openbutton));
  639. gtk_widget_show(GTK_WIDGET(closebutton));
  640. gtk_widget_show(GTK_WIDGET(zoom_in_button));
  641. gtk_widget_show(GTK_WIDGET(zoom_out_button));
  642. gtk_widget_show(GTK_WIDGET(gotofirstbutton));
  643. gtk_widget_show(GTK_WIDGET(gotolastbutton));
  644. gtk_widget_show(GTK_WIDGET(nextbutton));
  645. gtk_widget_show(GTK_WIDGET(previousbutton));
  646. gtk_widget_show(GTK_WIDGET(negativebutton));
  647. gtk_widget_show(GTK_WIDGET(greyscalebutton));
  648. gtk_widget_show(GTK_WIDGET(contrastbutton));
  649. gtk_widget_show(GTK_WIDGET(contrastbutton2));
  650. gtk_widget_show(GTK_WIDGET(brightnessbutton));
  651. gtk_widget_show(GTK_WIDGET(brightnessbutton2));
  652. gtk_widget_show(GTK_WIDGET(aboutbutton));
  653. }
  654.  
  655. void get_list(char filename[500])
  656. {
  657. int k = 0, j, l = 0, x;
  658. int len = strlen(filename);
  659. for (j = len - 1; filename[j] != '\\'; j--) x = 1;
  660. str[0] = 0;
  661. strcat(str, "cd /d ");
  662. for (k = 0; k < j; k++) str4[l++] = filename[k];
  663. str4[l] = 0;
  664. str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
  665. system(str3);
  666. strcat(str, str4);
  667. strcpy(str2, str);
  668. strcat(str, " && dir /b >> dir_listing.txt");
  669. strcat(str2, " && del dir_listing.txt");
  670. system(str);
  671. strcat(str4, "\\dir_listing.txt");
  672. }
  673.  
  674. void store_list()
  675. {
  676. FILE *input;
  677. input = fopen(str4, "r");
  678. for (global = 0; ;global++)
  679. {
  680. if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
  681. fgetc(input);
  682. }
  683. fclose(input);
  684. }
  685.  
  686. gboolean show_next(gpointer userdata)
  687. {
  688. if (flag == 0) return FALSE;
  689. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  690. for (; ;)
  691. {
  692. for (i = 0; i < global; i++)
  693. {
  694. strcpy(str3, image_list[i]);
  695. l = 0, len = strlen(slide);
  696. str5[0] = 0;
  697. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  698. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  699. str5[l] = 0, k = 0;
  700. strcat(str5, str3), len = strlen(str3);
  701. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  702. str6[k] = 0;
  703. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  704. {
  705. if (flag2 == 1)
  706. {
  707. if (remove_flag == 0) gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img));
  708. else gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img2));
  709. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0, remove_flag = 0;
  710. zoom_width = width, zoom_height = height;
  711. img = gtk_image_new_from_file(str5);
  712. img2 = img;
  713. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  714. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  715. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  716. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  717. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  718. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  719. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  720. gtk_widget_show(img);
  721. strcpy(slide, str5);
  722. flag3 = 1;
  723. break;
  724.  
  725. }
  726. if (strcmp(str5, slide) == 0) flag2 = 1;
  727. }
  728. }
  729. if (flag3 == 1) break;
  730. }
  731. return TRUE;
  732. }
  733.  
  734. void show_next2()
  735. {
  736. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  737. for (; ;)
  738. {
  739. for (i = 0; i < global; i++)
  740. {
  741. strcpy(str3, image_list[i]);
  742. l = 0, len = strlen(slide);
  743. str5[0] = 0;
  744. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  745. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  746. str5[l] = 0, k = 0;
  747. strcat(str5, str3), len = strlen(str3);
  748. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  749. str6[k] = 0;
  750. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  751. {
  752. if (flag2 == 1)
  753. {
  754. gtk_widget_hide(GTK_WIDGET(restorebutton1)), gtk_widget_hide(GTK_WIDGET(restorebutton2));
  755. gtk_widget_show(GTK_WIDGET(negativebutton)), gtk_widget_show(GTK_WIDGET(greyscalebutton));
  756. if (remove_flag == 0) gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img));
  757. else gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img2));
  758. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0, remove_flag = 0;
  759. zoom_width = width, zoom_height = height;
  760. img = gtk_image_new_from_file(str5);
  761. img2 = img;
  762. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  763. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  764. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  765. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  766. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  767. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  768. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  769. gtk_widget_show(img);
  770. strcpy(slide, str5);
  771. flag3 = 1;
  772. break;
  773.  
  774. }
  775. if (strcmp(str5, slide) == 0) flag2 = 1;
  776. }
  777. }
  778. if (flag3 == 1) break;
  779. }
  780. }
  781.  
  782. void show_previous()
  783. {
  784. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  785. for (; ;)
  786. {
  787. for (i = global - 1; i >= 0; i--)
  788. {
  789. strcpy(str3, image_list[i]);
  790. l = 0, len = strlen(slide);
  791. str5[0] = 0;
  792. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  793. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  794. str5[l] = 0, k = 0;
  795. strcat(str5, str3), len = strlen(str3);
  796. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  797. str6[k] = 0;
  798. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  799. {
  800. if (flag2 == 1)
  801. {
  802. gtk_widget_hide(GTK_WIDGET(restorebutton1)), gtk_widget_hide(GTK_WIDGET(restorebutton2));
  803. gtk_widget_show(GTK_WIDGET(negativebutton)), gtk_widget_show(GTK_WIDGET(greyscalebutton));
  804. if (remove_flag == 0) gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img));
  805. else gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img2));
  806. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0, remove_flag = 0;
  807. zoom_width = width, zoom_height = height;
  808. img = gtk_image_new_from_file(str5);
  809. img2 = img;
  810. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  811. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  812. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  813. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  814. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  815. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  816. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  817. gtk_widget_show(img);
  818. strcpy(slide, str5);
  819. flag3 = 1;
  820. break;
  821.  
  822. }
  823. if (strcmp(str5, slide) == 0) flag2 = 1;
  824. }
  825. }
  826. if (flag3 == 1) break;
  827. }
  828. }
  829.  
  830. void goto_first()
  831. {
  832. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  833. for (i = 0; i < global; i++)
  834. {
  835. strcpy(str3, image_list[i]);
  836. l = 0, len = strlen(slide);
  837. str5[0] = 0;
  838. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  839. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  840. str5[l] = 0, k = 0;
  841. strcat(str5, str3), len = strlen(str3);
  842. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  843. str6[k] = 0;
  844. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  845. {
  846. gtk_widget_hide(GTK_WIDGET(restorebutton1)), gtk_widget_hide(GTK_WIDGET(restorebutton2));
  847. gtk_widget_show(GTK_WIDGET(negativebutton)), gtk_widget_show(GTK_WIDGET(greyscalebutton));
  848. if (remove_flag == 0) gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img));
  849. else gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img2));
  850. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0, remove_flag = 0;
  851. zoom_width = width, zoom_height = height;
  852. img = gtk_image_new_from_file(str5);
  853. img2 = img;
  854. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  855. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  856. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  857. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  858. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  859. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  860. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  861. gtk_widget_show(img);
  862. strcpy(slide, str5);
  863. flag3 = 1;
  864. break;
  865. }
  866. }
  867. }
  868.  
  869. void increase_brightness()
  870. {
  871. if (brightness_val == 1.0) brightness_val = 0.999;
  872. if (brightness_val <= 1.0)
  873. {
  874. brightness_val += 0.10;
  875. image_brightness();
  876. }
  877. }
  878.  
  879. void decrease_brightness()
  880. {
  881. if (brightness_val == -1.0) brightness_val = -0.999;
  882. if(brightness_val >= -1.0)
  883. {
  884. brightness_val -= 0.10;
  885. image_brightness();
  886. }
  887.  
  888. }
  889.  
  890. void increase_contrast()
  891. {
  892. if (contrast_val == 1.0) contrast_val = 0.999;
  893. if (contrast_val <= 1.0)
  894. {
  895. contrast_val += 0.10;
  896. image_contrast();
  897. }
  898. }
  899.  
  900. void decrease_contrast()
  901. {
  902. if (contrast_val == -1.0) contrast_val = -0.999;
  903. if(contrast_val >= -1.0)
  904. {
  905. contrast_val -= 0.10;
  906. image_contrast();
  907. }
  908.  
  909. }
  910.  
  911. void goto_last()
  912. {
  913. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  914. for (i = global - 1; i >= 0; i--)
  915. {
  916. strcpy(str3, image_list[i]);
  917. l = 0, len = strlen(slide);
  918. str5[0] = 0;
  919. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  920. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  921. str5[l] = 0, k = 0;
  922. strcat(str5, str3), len = strlen(str3);
  923. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  924. str6[k] = 0;
  925. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  926. {
  927. gtk_widget_hide(GTK_WIDGET(restorebutton1)), gtk_widget_hide(GTK_WIDGET(restorebutton2));
  928. gtk_widget_show(GTK_WIDGET(negativebutton)), gtk_widget_show(GTK_WIDGET(greyscalebutton));
  929. if (remove_flag == 0) gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img));
  930. else gtk_container_remove(GTK_CONTAINER(fixed_layout), GTK_WIDGET(img2));
  931. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0, remove_flag = 0;
  932. zoom_width = width, zoom_height = height;
  933. img = gtk_image_new_from_file(str5);
  934. img2 = img;
  935. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  936. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  937. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  938. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  939. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  940. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  941. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  942. gtk_widget_show(img);
  943. strcpy(slide, str5);
  944. flag3 = 1;
  945. break;
  946. }
  947. }
  948. }
  949.  
  950. void goodbye_dialog()
  951. {
  952. gbdialog = gtk_message_dialog_new (GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Thank you for using this application!\nPlease click Ok to exit.");
  953. gtk_window_set_position (GTK_WINDOW (gbdialog), GTK_WIN_POS_CENTER);
  954. gtk_dialog_run (GTK_DIALOG (gbdialog));
  955. gtk_widget_destroy (gbdialog);
  956. gtk_main_quit();
  957. }
  958.  
  959. int main(int argc, char *argv[])
  960. {
  961. gtk_init(&argc, &argv);
  962. width = gdk_screen_width();
  963. height = gdk_screen_height();
  964. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  965. gtk_window_set_skip_taskbar_hint (window, TRUE);
  966. gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
  967. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
  968. gtk_widget_set_size_request(GTK_WIDGET(window), width, height);
  969. gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  970. heightini = height;
  971. height = (height * 16) / 17;
  972. zoom_width = width, zoom_height = height;
  973.  
  974. fixed_layout = gtk_fixed_new();
  975. char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg";
  976. img = gtk_image_new_from_file(picturename);
  977. img2 = img;
  978. mypic = gdk_pixbuf_new_from_file(picturename, NULL);
  979. windowicon = gdk_pixbuf_new_from_file(picturename, NULL);
  980. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  981. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  982. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  983. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  984. strcpy(slide, picturename);
  985. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  986. create_toolbar();
  987. gtk_container_add(GTK_CONTAINER(window), fixed_layout);
  988. get_list(picturename);
  989. store_list();
  990. system(str2);
  991.  
  992. gtk_window_fullscreen(window);
  993. g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
  994. g_signal_connect(G_OBJECT(openbutton), "clicked", G_CALLBACK(open_file), NULL);
  995. g_signal_connect(G_OBJECT(gotofirstbutton), "clicked", G_CALLBACK(goto_first), NULL);
  996. g_signal_connect(G_OBJECT(gotolastbutton), "clicked", G_CALLBACK(goto_last), NULL);
  997. g_signal_connect(G_OBJECT(aboutbutton), "clicked", G_CALLBACK(show_about), NULL);
  998. g_signal_connect(G_OBJECT(closebutton), "clicked",G_CALLBACK(goodbye_dialog), NULL);
  999. g_signal_connect(G_OBJECT(playbutton), "clicked",G_CALLBACK(start_slide), NULL);
  1000. g_signal_connect(G_OBJECT(stopbutton), "clicked",G_CALLBACK(stop_slide), NULL);
  1001. g_signal_connect(G_OBJECT(nextbutton), "clicked",G_CALLBACK(show_next2), NULL);
  1002. g_signal_connect(G_OBJECT(negativebutton), "clicked",G_CALLBACK(image_negative), NULL);
  1003. g_signal_connect(G_OBJECT(brightnessbutton), "clicked",G_CALLBACK(increase_brightness), NULL);
  1004. g_signal_connect(G_OBJECT(contrastbutton), "clicked",G_CALLBACK(increase_contrast), NULL);
  1005. g_signal_connect(G_OBJECT(brightnessbutton2), "clicked",G_CALLBACK(decrease_brightness), NULL);
  1006. g_signal_connect(G_OBJECT(contrastbutton2), "clicked",G_CALLBACK(decrease_contrast), NULL);
  1007. g_signal_connect(G_OBJECT(restorebutton1), "clicked",G_CALLBACK(show_original1), NULL);
  1008. g_signal_connect(G_OBJECT(restorebutton2), "clicked",G_CALLBACK(show_original2), NULL);
  1009. g_signal_connect(G_OBJECT(greyscalebutton), "clicked",G_CALLBACK(image_greyscale), NULL);
  1010. g_signal_connect(G_OBJECT(previousbutton), "clicked",G_CALLBACK(show_previous), NULL);
  1011. g_signal_connect(G_OBJECT(zoom_in_button), "clicked",G_CALLBACK(zoom_in), NULL);
  1012. g_signal_connect(G_OBJECT(zoom_out_button), "clicked",G_CALLBACK(zoom_out), NULL);
  1013. g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
  1014. gtk_widget_show_all(GTK_WIDGET(window));
  1015. gtk_widget_hide(GTK_WIDGET(stopbutton)), gtk_widget_hide(GTK_WIDGET(restorebutton1)), gtk_widget_hide(GTK_WIDGET(restorebutton2));
  1016. gtk_main();
  1017.  
  1018. return 0x0;
  1019. }
  1020.  
  1021.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement