Advertisement
palmerstone

Gtk 22

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