Advertisement
palmerstone

Gtk 17

Nov 28th, 2011
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.07 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;
  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, *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), "Show Original", "Show Original");
  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), "Show Original", "Show Original");
  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. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  238. filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  239. strcpy(slide, filename);
  240. get_list(filename);
  241. store_list();
  242. system(str2);
  243. zoom_width = width, zoom_height = height;
  244. img = gtk_image_new_from_file(filename);
  245. img2 = img;
  246. mypic = gdk_pixbuf_new_from_file(filename, NULL);
  247. windowicon = gdk_pixbuf_new_from_file(filename, NULL);
  248. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  249. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  250. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  251. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  252. gtk_widget_show(img);
  253. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  254. g_free (filename);
  255. }
  256. gtk_widget_destroy (dialog);
  257. }
  258.  
  259. void zoom_in()
  260. {
  261. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  262. double x = zoom_width;
  263. double y = zoom_height;
  264. x = x * ratio, y = y * ratio;
  265. zoom_width = x, zoom_height = y;
  266. pixbuf = gdk_pixbuf_scale_simple(pixbuf, zoom_width, zoom_height, GDK_INTERP_BILINEAR);
  267. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  268. }
  269.  
  270. void image_greyscale()
  271. {
  272. image_flag = 0;
  273. GtkWidget *img;
  274. gtk_widget_hide(GTK_WIDGET(greyscalebutton));
  275. gtk_widget_show(GTK_WIDGET(restorebutton2));
  276.  
  277. if (image_flag2 == 0)
  278. {
  279. char *sp, *dp;
  280. int localwidth, localheight, line, result_rowstride, mypic_rowstride, bytes_per_pixel;
  281.  
  282. result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (mypic),
  283. gdk_pixbuf_get_has_alpha (mypic),
  284. gdk_pixbuf_get_bits_per_sample (mypic),
  285. gdk_pixbuf_get_width (mypic),
  286. gdk_pixbuf_get_height (mypic));
  287.  
  288. localwidth = gdk_pixbuf_get_width (result_pixbuf);
  289. localheight = gdk_pixbuf_get_height (result_pixbuf);
  290. result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
  291. mypic_rowstride = gdk_pixbuf_get_rowstride (mypic);
  292. bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;
  293.  
  294. sp = gdk_pixbuf_get_pixels (mypic);
  295. dp = gdk_pixbuf_get_pixels (result_pixbuf);
  296. for (line = 0; line < localheight; line ++)
  297. {
  298. char *sq = sp;
  299. char *dq = dp;
  300. int i;
  301.  
  302. for (i = 0; i < localwidth; i ++)
  303. {
  304. dq[0] = (sq[0] + sq[1] + sq[2]) / 10;
  305. dq[1] = dq[0];
  306. dq[2] = dq[0];
  307.  
  308. dq += bytes_per_pixel;
  309. sq += bytes_per_pixel;
  310. }
  311.  
  312. sp += mypic_rowstride;
  313. dp += result_rowstride;
  314. }
  315. }
  316. img = gtk_image_new();
  317. result_pixbuf = gdk_pixbuf_scale_simple(result_pixbuf, width, height, GDK_INTERP_BILINEAR);
  318. gtk_image_set_from_pixbuf(GTK_IMAGE(img), result_pixbuf);
  319. gtk_widget_show(img);
  320. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  321. image_flag2 = 1;
  322. }
  323.  
  324. void show_original2()
  325. {
  326. GtkWidget *img3;
  327. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img2));
  328. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  329. img3 = gtk_image_new();
  330. gtk_image_set_from_pixbuf(GTK_IMAGE(img3), pixbuf);
  331. gtk_widget_show(img3);
  332. gtk_container_add(GTK_CONTAINER(fixed_layout), img3);
  333. gtk_widget_hide(GTK_WIDGET(restorebutton2));
  334. gtk_widget_show(GTK_WIDGET(greyscalebutton));
  335. }
  336.  
  337. void image_negative()
  338. {
  339. image_flag2 = 0;
  340. GtkWidget *img;
  341. gtk_widget_hide(GTK_WIDGET(negativebutton));
  342. gtk_widget_show(GTK_WIDGET(restorebutton1));
  343.  
  344. if (image_flag == 0)
  345. {
  346. char *sp, *dp;
  347. int localwidth, localheight, line, result_rowstride, mypic_rowstride, bytes_per_pixel;
  348.  
  349. result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (mypic),
  350. gdk_pixbuf_get_has_alpha (mypic),
  351. gdk_pixbuf_get_bits_per_sample (mypic),
  352. gdk_pixbuf_get_width (mypic),
  353. gdk_pixbuf_get_height (mypic));
  354.  
  355. localwidth = gdk_pixbuf_get_width (result_pixbuf);
  356. localheight = gdk_pixbuf_get_height (result_pixbuf);
  357. result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
  358. mypic_rowstride = gdk_pixbuf_get_rowstride (mypic);
  359. bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;
  360.  
  361. sp = gdk_pixbuf_get_pixels (mypic);
  362. dp = gdk_pixbuf_get_pixels (result_pixbuf);
  363.  
  364. for (line = 0; line < localheight; line++)
  365. {
  366. char *sq = sp;
  367. char *dq = dp;
  368. int i;
  369.  
  370. for (i = 0; i < localwidth; i++)
  371. {
  372. dq[0] = 255 - sq[0];
  373. dq[1] = 255 - sq[1];
  374. dq[2] = 255 - sq[2];
  375.  
  376. dq += bytes_per_pixel;
  377. sq += bytes_per_pixel;
  378. }
  379.  
  380. sp += mypic_rowstride;
  381. dp += result_rowstride;
  382. }
  383. }
  384. img = gtk_image_new();
  385. result_pixbuf = gdk_pixbuf_scale_simple(result_pixbuf, width, height, GDK_INTERP_BILINEAR);
  386. gtk_image_set_from_pixbuf(GTK_IMAGE(img), result_pixbuf);
  387. gtk_widget_show(img);
  388. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  389. image_flag = 1;
  390. }
  391.  
  392. void show_original1()
  393. {
  394. GtkWidget *img3;
  395. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img2));
  396. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  397. img3 = gtk_image_new();
  398. gtk_image_set_from_pixbuf(GTK_IMAGE(img3), pixbuf);
  399. gtk_widget_show(img3);
  400. gtk_container_add(GTK_CONTAINER(fixed_layout), img3);
  401. gtk_widget_hide(GTK_WIDGET(restorebutton1));
  402. gtk_widget_show(GTK_WIDGET(negativebutton));
  403. }
  404.  
  405. static unsigned char apply_brightness (unsigned char u_value, float brightness)
  406. {
  407. float nvalue, value;
  408. double power;
  409.  
  410. value = (float) u_value / 255.0;
  411.  
  412. if (brightness < 0.0) value = value * (1.0 + brightness);
  413. else value = value + ((1.0 - value) * brightness);
  414.  
  415. return (guchar) (value * 255);
  416. }
  417.  
  418. static unsigned char apply_contrast (unsigned char u_value, float contrast)
  419. {
  420. float nvalue;
  421. double power;
  422. float value;
  423. value = (float) u_value / 255.0;
  424.  
  425. if (contrast < 0.0)
  426. {
  427. if (value > 0.5) nvalue = 1.0 - value;
  428. else nvalue = value;
  429.  
  430. if (nvalue < 0.0) nvalue = 0.0;
  431. nvalue = 0.5 * pow (nvalue * 2.0 , (double) (1.0 + contrast));
  432.  
  433. if (value > 0.5) value = 1.0 - nvalue;
  434. else value = nvalue;
  435. }
  436. else
  437. {
  438. if (value > 0.5) nvalue = 1.0 - value;
  439. else nvalue = value;
  440.  
  441. if (nvalue < 0.0) nvalue = 0.0;
  442. power = (contrast == 1.0) ? 127 : 1.0 / (1.0 - contrast);
  443. nvalue = 0.5 * pow (2.0 * nvalue, power);
  444. if (value > 0.5) value = 1.0 - nvalue;
  445. else value = nvalue;
  446. }
  447. return (guchar) (value * 255);
  448. }
  449.  
  450. void image_contrast()
  451. {
  452. GtkWidget *img;
  453. GdkPixbuf *result_pixbuf;
  454. char *sp, *dp;
  455. int localwidth, localheight, line, result_rowstride, mypic_rowstride, bytes_per_pixel;
  456. g_return_val_if_fail ((contrast_val > -1.0 ) && (contrast_val < 1.0 ), NULL);
  457.  
  458. result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (mypic),
  459. gdk_pixbuf_get_has_alpha (mypic),
  460. gdk_pixbuf_get_bits_per_sample (mypic),
  461. gdk_pixbuf_get_width (mypic),
  462. gdk_pixbuf_get_height (mypic));
  463.  
  464. localwidth = gdk_pixbuf_get_width (result_pixbuf);
  465. localheight = gdk_pixbuf_get_height (result_pixbuf);
  466. result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
  467. mypic_rowstride = gdk_pixbuf_get_rowstride (mypic);
  468. bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;
  469. sp = gdk_pixbuf_get_pixels (mypic);
  470. dp = gdk_pixbuf_get_pixels (result_pixbuf);
  471.  
  472. for (line = 0; line < localheight; line ++)
  473. {
  474. char *sq = sp;
  475. char *dq = dp;
  476. int i;
  477.  
  478. for (i = 0; i < localwidth; i ++)
  479. {
  480. dq[0] = apply_contrast (sq[0], contrast_val);
  481. dq[1] = apply_contrast (sq[1], contrast_val);
  482. dq[2] = apply_contrast (sq[2], contrast_val);
  483. dq += bytes_per_pixel;
  484. sq += bytes_per_pixel;
  485. }
  486. sp += mypic_rowstride;
  487. dp += result_rowstride;
  488. }
  489.  
  490. img = gtk_image_new();
  491. result_pixbuf = gdk_pixbuf_scale_simple(result_pixbuf, width, height, GDK_INTERP_BILINEAR);
  492. gtk_image_set_from_pixbuf(GTK_IMAGE(img), result_pixbuf);
  493. gtk_widget_show(img);
  494. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  495. }
  496.  
  497. void image_brightness()
  498. {
  499. GtkWidget *img;
  500. char *sp, *dp;
  501. int localwidth, localheight, line, result_rowstride, mypic_rowstride, bytes_per_pixel;
  502.  
  503. g_return_val_if_fail ((brightness_val > -1.0 ) && (brightness_val < 1.0 ), NULL);
  504. result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (mypic),
  505. gdk_pixbuf_get_has_alpha (mypic),
  506. gdk_pixbuf_get_bits_per_sample (mypic),
  507. gdk_pixbuf_get_width (mypic),
  508. gdk_pixbuf_get_height (mypic));
  509.  
  510. localwidth = gdk_pixbuf_get_width (result_pixbuf);
  511. localheight = gdk_pixbuf_get_height (result_pixbuf);
  512. result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
  513. mypic_rowstride = gdk_pixbuf_get_rowstride (mypic);
  514. bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;
  515. sp = gdk_pixbuf_get_pixels (mypic);
  516. dp = gdk_pixbuf_get_pixels (result_pixbuf);
  517.  
  518. for (line = 0; line < localheight; line ++)
  519. {
  520. char *sq = sp;
  521. char *dq = dp;
  522. int i;
  523.  
  524. for (i = 0; i < localwidth; i ++)
  525. {
  526. dq[0] = apply_brightness (sq[0], brightness_val);
  527. dq[1] = apply_brightness (sq[1], brightness_val);
  528. dq[2] = apply_brightness (sq[2], brightness_val);
  529. dq += bytes_per_pixel;
  530. sq += bytes_per_pixel;
  531. }
  532. sp += mypic_rowstride;
  533. dp += result_rowstride;
  534. }
  535. img = gtk_image_new();
  536. result_pixbuf = gdk_pixbuf_scale_simple(result_pixbuf, width, height, GDK_INTERP_BILINEAR);
  537. gtk_image_set_from_pixbuf(GTK_IMAGE(img), result_pixbuf);
  538. gtk_widget_show(img);
  539. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  540. }
  541.  
  542. void zoom_out()
  543. {
  544. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  545. double x = zoom_width;
  546. double y = zoom_height;
  547. double d = (double) 1 / ratio;
  548. x = x * d, y = y * d;
  549. zoom_width = x, zoom_height = y;
  550. pixbuf = gdk_pixbuf_scale_simple(pixbuf, zoom_width, zoom_height, GDK_INTERP_BILINEAR);
  551. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  552. }
  553.  
  554. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data)
  555. {
  556. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_q || lol->keyval == GDK_KEY_Q))
  557. goodbye_dialog();
  558. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_O || lol->keyval == GDK_KEY_o))
  559. open_file();
  560. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_N || lol->keyval == GDK_KEY_n))
  561. image_negative();
  562. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_G || lol->keyval == GDK_KEY_g))
  563. image_greyscale();
  564. if (lol->keyval == GDK_KEY_Right)
  565. show_next2();
  566. if (lol->keyval == GDK_KEY_Left)
  567. show_previous();
  568. if (lol->keyval == GDK_KEY_space)
  569. {
  570. if (flag == 0) flag = 1;
  571. else flag = 0;
  572. if (flag == 1) start_slide();
  573. else stop_slide();
  574. }
  575. if (lol->keyval == GDK_KEY_Page_Up)
  576. goto_first();
  577. if (lol->keyval == GDK_KEY_Page_Down)
  578. goto_last();
  579. if (lol->keyval == GDK_KEY_plus)
  580. zoom_in();
  581. if (lol->keyval == GDK_KEY_minus)
  582. zoom_out();
  583. return TRUE;
  584. }
  585.  
  586.  
  587. void start_slide()
  588. {
  589. flag = 1;
  590. gint func_ref = g_timeout_add(3000, show_next, (gpointer)32);
  591. gtk_widget_hide(GTK_WIDGET(playbutton));
  592. gtk_widget_hide(GTK_WIDGET(openbutton));
  593. gtk_widget_hide(GTK_WIDGET(closebutton));
  594. gtk_widget_hide(GTK_WIDGET(zoom_in_button));
  595. gtk_widget_hide(GTK_WIDGET(zoom_out_button));
  596. gtk_widget_hide(GTK_WIDGET(gotofirstbutton));
  597. gtk_widget_hide(GTK_WIDGET(gotolastbutton));
  598. gtk_widget_hide(GTK_WIDGET(nextbutton));
  599. gtk_widget_hide(GTK_WIDGET(previousbutton));
  600. gtk_widget_hide(GTK_WIDGET(aboutbutton));
  601. gtk_widget_hide(GTK_WIDGET(negativebutton));
  602. gtk_widget_hide(GTK_WIDGET(restorebutton1));
  603. gtk_widget_hide(GTK_WIDGET(restorebutton2));
  604. gtk_widget_hide(GTK_WIDGET(greyscalebutton));
  605. gtk_widget_hide(GTK_WIDGET(contrastbutton));
  606. gtk_widget_hide(GTK_WIDGET(contrastbutton2));
  607. gtk_widget_hide(GTK_WIDGET(brightnessbutton));
  608. gtk_widget_hide(GTK_WIDGET(brightnessbutton2));
  609. gtk_widget_show(GTK_WIDGET(stopbutton));
  610.  
  611. }
  612.  
  613. void stop_slide()
  614. {
  615. flag = 0;
  616. gint func_ref = g_timeout_add(10000000, show_next, (gpointer)32);
  617. gtk_widget_hide(GTK_WIDGET(stopbutton));
  618. gtk_widget_show(GTK_WIDGET(playbutton));
  619. gtk_widget_show(GTK_WIDGET(openbutton));
  620. gtk_widget_show(GTK_WIDGET(closebutton));
  621. gtk_widget_show(GTK_WIDGET(zoom_in_button));
  622. gtk_widget_show(GTK_WIDGET(zoom_out_button));
  623. gtk_widget_show(GTK_WIDGET(gotofirstbutton));
  624. gtk_widget_show(GTK_WIDGET(gotolastbutton));
  625. gtk_widget_show(GTK_WIDGET(nextbutton));
  626. gtk_widget_show(GTK_WIDGET(previousbutton));
  627. gtk_widget_show(GTK_WIDGET(negativebutton));
  628. gtk_widget_show(GTK_WIDGET(greyscalebutton));
  629. gtk_widget_show(GTK_WIDGET(contrastbutton));
  630. gtk_widget_show(GTK_WIDGET(contrastbutton2));
  631. gtk_widget_show(GTK_WIDGET(brightnessbutton));
  632. gtk_widget_show(GTK_WIDGET(brightnessbutton2));
  633. gtk_widget_show(GTK_WIDGET(aboutbutton));
  634. }
  635.  
  636. void get_list(char filename[500])
  637. {
  638. int k = 0, j, l = 0, x;
  639. int len = strlen(filename);
  640. for (j = len - 1; filename[j] != '\\'; j--) x = 1;
  641. str[0] = 0;
  642. strcat(str, "cd /d ");
  643. for (k = 0; k < j; k++) str4[l++] = filename[k];
  644. str4[l] = 0;
  645. str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
  646. system(str3);
  647. strcat(str, str4);
  648. strcpy(str2, str);
  649. strcat(str, " && dir /b >> dir_listing.txt");
  650. strcat(str2, " && del dir_listing.txt");
  651. system(str);
  652. strcat(str4, "\\dir_listing.txt");
  653. }
  654.  
  655. void store_list()
  656. {
  657. FILE *input;
  658. input = fopen(str4, "r");
  659. for (global = 0; ;global++)
  660. {
  661. if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
  662. fgetc(input);
  663. }
  664. fclose(input);
  665. }
  666.  
  667. gboolean show_next(gpointer userdata)
  668. {
  669. if (flag == 0) return FALSE;
  670. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  671. for (; ;)
  672. {
  673. for (i = 0; i < global; i++)
  674. {
  675. strcpy(str3, image_list[i]);
  676. l = 0, len = strlen(slide);
  677. str5[0] = 0;
  678. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  679. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  680. str5[l] = 0, k = 0;
  681. strcat(str5, str3), len = strlen(str3);
  682. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  683. str6[k] = 0;
  684. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  685. {
  686. if (flag2 == 1)
  687. {
  688. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  689. zoom_width = width, zoom_height = height;
  690. img = gtk_image_new_from_file(str5);
  691. img2 = img;
  692. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  693. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  694. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  695. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  696. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  697. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  698. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  699. gtk_widget_show(img);
  700. strcpy(slide, str5);
  701. flag3 = 1;
  702. break;
  703.  
  704. }
  705. if (strcmp(str5, slide) == 0) flag2 = 1;
  706. }
  707. }
  708. if (flag3 == 1) break;
  709. }
  710. return TRUE;
  711. }
  712.  
  713. void show_next2()
  714. {
  715. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  716. for (; ;)
  717. {
  718. for (i = 0; i < global; i++)
  719. {
  720. strcpy(str3, image_list[i]);
  721. l = 0, len = strlen(slide);
  722. str5[0] = 0;
  723. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  724. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  725. str5[l] = 0, k = 0;
  726. strcat(str5, str3), len = strlen(str3);
  727. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  728. str6[k] = 0;
  729. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  730. {
  731. if (flag2 == 1)
  732. {
  733. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  734. zoom_width = width, zoom_height = height;
  735. img = gtk_image_new_from_file(str5);
  736. img2 = img;
  737. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  738. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  739. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  740. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  741. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  742. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  743. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  744. gtk_widget_show(img);
  745. strcpy(slide, str5);
  746. flag3 = 1;
  747. break;
  748.  
  749. }
  750. if (strcmp(str5, slide) == 0) flag2 = 1;
  751. }
  752. }
  753. if (flag3 == 1) break;
  754. }
  755. }
  756.  
  757. void show_previous()
  758. {
  759. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  760. for (; ;)
  761. {
  762. for (i = global - 1; i >= 0; i--)
  763. {
  764. strcpy(str3, image_list[i]);
  765. l = 0, len = strlen(slide);
  766. str5[0] = 0;
  767. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  768. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  769. str5[l] = 0, k = 0;
  770. strcat(str5, str3), len = strlen(str3);
  771. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  772. str6[k] = 0;
  773. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  774. {
  775. if (flag2 == 1)
  776. {
  777. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  778. zoom_width = width, zoom_height = height;
  779. img = gtk_image_new_from_file(str5);
  780. img2 = img;
  781. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  782. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  783. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  784. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  785. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  786. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  787. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  788. gtk_widget_show(img);
  789. strcpy(slide, str5);
  790. flag3 = 1;
  791. break;
  792.  
  793. }
  794. if (strcmp(str5, slide) == 0) flag2 = 1;
  795. }
  796. }
  797. if (flag3 == 1) break;
  798. }
  799. }
  800.  
  801. void goto_first()
  802. {
  803. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  804. for (i = 0; i < global; i++)
  805. {
  806. strcpy(str3, image_list[i]);
  807. l = 0, len = strlen(slide);
  808. str5[0] = 0;
  809. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  810. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  811. str5[l] = 0, k = 0;
  812. strcat(str5, str3), len = strlen(str3);
  813. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  814. str6[k] = 0;
  815. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  816. {
  817. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  818. zoom_width = width, zoom_height = height;
  819. img = gtk_image_new_from_file(str5);
  820. img2 = img;
  821. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  822. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  823. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  824. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  825. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  826. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  827. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  828. gtk_widget_show(img);
  829. strcpy(slide, str5);
  830. flag3 = 1;
  831. break;
  832. }
  833. }
  834. }
  835.  
  836. void increase_brightness()
  837. {
  838. if (brightness_val == 1.0) brightness_val = 0.999;
  839. if (brightness_val <= 1.0)
  840. {
  841. brightness_val += 0.10;
  842. image_brightness();
  843. }
  844. }
  845.  
  846. void decrease_brightness()
  847. {
  848. if (brightness_val == -1.0) brightness_val = -0.999;
  849. if(brightness_val >= -1.0)
  850. {
  851. brightness_val -= 0.10;
  852. image_brightness();
  853. }
  854.  
  855. }
  856.  
  857. void increase_contrast()
  858. {
  859. if (contrast_val == 1.0) contrast_val = 0.999;
  860. if (contrast_val <= 1.0)
  861. {
  862. contrast_val += 0.10;
  863. image_contrast();
  864. }
  865. }
  866.  
  867. void decrease_contrast()
  868. {
  869. if (contrast_val == -1.0) contrast_val = -0.999;
  870. if(contrast_val >= -1.0)
  871. {
  872. contrast_val -= 0.10;
  873. image_contrast();
  874. }
  875.  
  876. }
  877.  
  878. void goto_last()
  879. {
  880. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  881. for (i = global - 1; i >= 0; i--)
  882. {
  883. strcpy(str3, image_list[i]);
  884. l = 0, len = strlen(slide);
  885. str5[0] = 0;
  886. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  887. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  888. str5[l] = 0, k = 0;
  889. strcat(str5, str3), len = strlen(str3);
  890. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  891. str6[k] = 0;
  892. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  893. {
  894. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  895. zoom_width = width, zoom_height = height;
  896. img = gtk_image_new_from_file(str5);
  897. img2 = img;
  898. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  899. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  900. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  901. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  902. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  903. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  904. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  905. gtk_widget_show(img);
  906. strcpy(slide, str5);
  907. flag3 = 1;
  908. break;
  909. }
  910. }
  911. }
  912.  
  913. void goodbye_dialog()
  914. {
  915. 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.");
  916. gtk_window_set_position (GTK_WINDOW (gbdialog), GTK_WIN_POS_CENTER);
  917. gtk_dialog_run (GTK_DIALOG (gbdialog));
  918. gtk_widget_destroy (gbdialog);
  919. gtk_main_quit();
  920. }
  921.  
  922. int main(int argc, char *argv[])
  923. {
  924. gtk_init(&argc, &argv);
  925. width = gdk_screen_width();
  926. height = gdk_screen_height();
  927. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  928. gtk_window_set_skip_taskbar_hint (window, TRUE);
  929. gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
  930. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
  931. gtk_widget_set_size_request(GTK_WIDGET(window), width, height);
  932. gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  933. heightini = height;
  934. height = (height * 16) / 17;
  935. zoom_width = width, zoom_height = height;
  936.  
  937. fixed_layout = gtk_fixed_new();
  938. char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg";
  939. img = gtk_image_new_from_file(picturename);
  940. img2 = img;
  941. mypic = gdk_pixbuf_new_from_file(picturename, NULL);
  942. windowicon = gdk_pixbuf_new_from_file(picturename, NULL);
  943. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  944. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  945. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  946. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  947. strcpy(slide, picturename);
  948. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  949. create_toolbar();
  950. gtk_container_add(GTK_CONTAINER(window), fixed_layout);
  951. get_list(picturename);
  952. store_list();
  953. system(str2);
  954.  
  955. gtk_window_fullscreen(window);
  956. g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
  957. g_signal_connect(G_OBJECT(openbutton), "clicked", G_CALLBACK(open_file), NULL);
  958. g_signal_connect(G_OBJECT(gotofirstbutton), "clicked", G_CALLBACK(goto_first), NULL);
  959. g_signal_connect(G_OBJECT(gotolastbutton), "clicked", G_CALLBACK(goto_last), NULL);
  960. g_signal_connect(G_OBJECT(aboutbutton), "clicked", G_CALLBACK(show_about), NULL);
  961. g_signal_connect(G_OBJECT(closebutton), "clicked",G_CALLBACK(goodbye_dialog), NULL);
  962. g_signal_connect(G_OBJECT(playbutton), "clicked",G_CALLBACK(start_slide), NULL);
  963. g_signal_connect(G_OBJECT(stopbutton), "clicked",G_CALLBACK(stop_slide), NULL);
  964. g_signal_connect(G_OBJECT(nextbutton), "clicked",G_CALLBACK(show_next2), NULL);
  965. g_signal_connect(G_OBJECT(negativebutton), "clicked",G_CALLBACK(image_negative), NULL);
  966. g_signal_connect(G_OBJECT(brightnessbutton), "clicked",G_CALLBACK(increase_brightness), NULL);
  967. g_signal_connect(G_OBJECT(contrastbutton), "clicked",G_CALLBACK(increase_contrast), NULL);
  968. g_signal_connect(G_OBJECT(brightnessbutton2), "clicked",G_CALLBACK(decrease_brightness), NULL);
  969. g_signal_connect(G_OBJECT(contrastbutton2), "clicked",G_CALLBACK(decrease_contrast), NULL);
  970. g_signal_connect(G_OBJECT(restorebutton1), "clicked",G_CALLBACK(show_original1), NULL);
  971. g_signal_connect(G_OBJECT(restorebutton2), "clicked",G_CALLBACK(show_original2), NULL);
  972. g_signal_connect(G_OBJECT(greyscalebutton), "clicked",G_CALLBACK(image_greyscale), NULL);
  973. g_signal_connect(G_OBJECT(previousbutton), "clicked",G_CALLBACK(show_previous), NULL);
  974. g_signal_connect(G_OBJECT(zoom_in_button), "clicked",G_CALLBACK(zoom_in), NULL);
  975. g_signal_connect(G_OBJECT(zoom_out_button), "clicked",G_CALLBACK(zoom_out), NULL);
  976. g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
  977. gtk_widget_show_all(GTK_WIDGET(window));
  978. gtk_widget_hide(GTK_WIDGET(stopbutton)), gtk_widget_hide(GTK_WIDGET(restorebutton1)), gtk_widget_hide(GTK_WIDGET(restorebutton2));
  979. gtk_main();
  980.  
  981. return 0x0;
  982. }
  983.  
  984.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement