Advertisement
palmerstone

Gtk 16

Nov 28th, 2011
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.84 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_EXECUTE, 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 = gtk_image_new_from_file(filename);
  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_NEAREST);
  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_NEAREST);
  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_NEAREST);
  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_NEAREST);
  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_NEAREST);
  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_NEAREST);
  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_NEAREST);
  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_NEAREST);
  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_NEAREST);
  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_show(GTK_WIDGET(stopbutton));
  606.  
  607. }
  608.  
  609. void stop_slide()
  610. {
  611. flag = 0;
  612. gint func_ref = g_timeout_add(10000000, show_next, (gpointer)32);
  613. gtk_widget_hide(GTK_WIDGET(stopbutton));
  614. gtk_widget_show(GTK_WIDGET(playbutton));
  615. gtk_widget_show(GTK_WIDGET(openbutton));
  616. gtk_widget_show(GTK_WIDGET(closebutton));
  617. gtk_widget_show(GTK_WIDGET(zoom_in_button));
  618. gtk_widget_show(GTK_WIDGET(zoom_out_button));
  619. gtk_widget_show(GTK_WIDGET(gotofirstbutton));
  620. gtk_widget_show(GTK_WIDGET(gotolastbutton));
  621. gtk_widget_show(GTK_WIDGET(nextbutton));
  622. gtk_widget_show(GTK_WIDGET(previousbutton));
  623. gtk_widget_show(GTK_WIDGET(negativebutton));
  624. gtk_widget_show(GTK_WIDGET(greyscalebutton));
  625. gtk_widget_show(GTK_WIDGET(aboutbutton));
  626. }
  627.  
  628. void get_list(char filename[500])
  629. {
  630. int k = 0, j, l = 0, x;
  631. int len = strlen(filename);
  632. for (j = len - 1; filename[j] != '\\'; j--) x = 1;
  633. str[0] = 0;
  634. strcat(str, "cd /d ");
  635. for (k = 0; k < j; k++) str4[l++] = filename[k];
  636. str4[l] = 0;
  637. str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
  638. system(str3);
  639. strcat(str, str4);
  640. strcpy(str2, str);
  641. strcat(str, " && dir /b >> dir_listing.txt");
  642. strcat(str2, " && del dir_listing.txt");
  643. system(str);
  644. strcat(str4, "\\dir_listing.txt");
  645. }
  646.  
  647. void store_list()
  648. {
  649. FILE *input;
  650. input = fopen(str4, "r");
  651. for (global = 0; ;global++)
  652. {
  653. if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
  654. fgetc(input);
  655. }
  656. fclose(input);
  657. }
  658.  
  659. gboolean show_next(gpointer userdata)
  660. {
  661. if (flag == 0) return FALSE;
  662. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  663. for (; ;)
  664. {
  665. for (i = 0; i < global; i++)
  666. {
  667. strcpy(str3, image_list[i]);
  668. l = 0, len = strlen(slide);
  669. str5[0] = 0;
  670. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  671. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  672. str5[l] = 0, k = 0;
  673. strcat(str5, str3), len = strlen(str3);
  674. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  675. str6[k] = 0;
  676. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  677. {
  678. if (flag2 == 1)
  679. {
  680. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  681. zoom_width = width, zoom_height = height;
  682. img = gtk_image_new_from_file(str5);
  683. img2 = gtk_image_new_from_file(str5);
  684. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  685. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  686. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  687. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  688. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  689. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  690. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  691. gtk_widget_show(img);
  692. strcpy(slide, str5);
  693. flag3 = 1;
  694. break;
  695.  
  696. }
  697. if (strcmp(str5, slide) == 0) flag2 = 1;
  698. }
  699. }
  700. if (flag3 == 1) break;
  701. }
  702. return TRUE;
  703. }
  704.  
  705. void show_next2()
  706. {
  707. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  708. for (; ;)
  709. {
  710. for (i = 0; i < global; i++)
  711. {
  712. strcpy(str3, image_list[i]);
  713. l = 0, len = strlen(slide);
  714. str5[0] = 0;
  715. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  716. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  717. str5[l] = 0, k = 0;
  718. strcat(str5, str3), len = strlen(str3);
  719. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  720. str6[k] = 0;
  721. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  722. {
  723. if (flag2 == 1)
  724. {
  725. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  726. zoom_width = width, zoom_height = height;
  727. img = gtk_image_new_from_file(str5);
  728. img2 = gtk_image_new_from_file(str5);
  729. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  730. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  731. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  732. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  733. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  734. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  735. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  736. gtk_widget_show(img);
  737. strcpy(slide, str5);
  738. flag3 = 1;
  739. break;
  740.  
  741. }
  742. if (strcmp(str5, slide) == 0) flag2 = 1;
  743. }
  744. }
  745. if (flag3 == 1) break;
  746. }
  747. }
  748.  
  749. void show_previous()
  750. {
  751. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  752. for (; ;)
  753. {
  754. for (i = global - 1; i >= 0; i--)
  755. {
  756. strcpy(str3, image_list[i]);
  757. l = 0, len = strlen(slide);
  758. str5[0] = 0;
  759. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  760. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  761. str5[l] = 0, k = 0;
  762. strcat(str5, str3), len = strlen(str3);
  763. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  764. str6[k] = 0;
  765. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  766. {
  767. if (flag2 == 1)
  768. {
  769. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  770. zoom_width = width, zoom_height = height;
  771. img = gtk_image_new_from_file(str5);
  772. img2 = gtk_image_new_from_file(str5);
  773. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  774. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  775. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  776. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  777. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  778. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  779. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  780. gtk_widget_show(img);
  781. strcpy(slide, str5);
  782. flag3 = 1;
  783. break;
  784.  
  785. }
  786. if (strcmp(str5, slide) == 0) flag2 = 1;
  787. }
  788. }
  789. if (flag3 == 1) break;
  790. }
  791. }
  792.  
  793. void goto_first()
  794. {
  795. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  796. for (i = 0; i < global; i++)
  797. {
  798. strcpy(str3, image_list[i]);
  799. l = 0, len = strlen(slide);
  800. str5[0] = 0;
  801. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  802. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  803. str5[l] = 0, k = 0;
  804. strcat(str5, str3), len = strlen(str3);
  805. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  806. str6[k] = 0;
  807. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  808. {
  809. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  810. zoom_width = width, zoom_height = height;
  811. img = gtk_image_new_from_file(str5);
  812. img2 = gtk_image_new_from_file(str5);
  813. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  814. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  815. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  816. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  817. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  818. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  819. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  820. gtk_widget_show(img);
  821. strcpy(slide, str5);
  822. flag3 = 1;
  823. break;
  824. }
  825. }
  826. }
  827.  
  828. void increase_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. void decrease_brightness()
  839. {
  840. if (brightness_val == -1.0) brightness_val = -0.999;
  841. if(brightness_val >= -1.0)
  842. {
  843. brightness_val -= 0.10;
  844. image_brightness();
  845. }
  846.  
  847. }
  848.  
  849. void increase_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. void decrease_contrast()
  860. {
  861. if (contrast_val == -1.0) contrast_val = -0.999;
  862. if(contrast_val >= -1.0)
  863. {
  864. contrast_val -= 0.10;
  865. image_contrast();
  866. }
  867.  
  868. }
  869.  
  870. void goto_last()
  871. {
  872. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  873. for (i = global - 1; i >= 0; i--)
  874. {
  875. strcpy(str3, image_list[i]);
  876. l = 0, len = strlen(slide);
  877. str5[0] = 0;
  878. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  879. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  880. str5[l] = 0, k = 0;
  881. strcat(str5, str3), len = strlen(str3);
  882. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  883. str6[k] = 0;
  884. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  885. {
  886. image_flag = 0, image_flag2 = 0, brightness_val = 0.0, contrast_val = 0.0;
  887. zoom_width = width, zoom_height = height;
  888. img = gtk_image_new_from_file(str5);
  889. img2 = gtk_image_new_from_file(str5);
  890. mypic = gdk_pixbuf_new_from_file(str5, NULL);
  891. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  892. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  893. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  894. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  895. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  896. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  897. gtk_widget_show(img);
  898. strcpy(slide, str5);
  899. flag3 = 1;
  900. break;
  901. }
  902. }
  903. }
  904.  
  905. void goodbye_dialog()
  906. {
  907. 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.");
  908. gtk_window_set_position (GTK_WINDOW (gbdialog), GTK_WIN_POS_CENTER);
  909. gtk_dialog_run (GTK_DIALOG (gbdialog));
  910. gtk_widget_destroy (gbdialog);
  911. gtk_main_quit();
  912. }
  913.  
  914. int main(int argc, char *argv[])
  915. {
  916. gtk_init(&argc, &argv);
  917. width = gdk_screen_width();
  918. height = gdk_screen_height();
  919. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  920. gtk_window_set_skip_taskbar_hint (window, TRUE);
  921. gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
  922. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
  923. gtk_widget_set_size_request(GTK_WIDGET(window), width, height);
  924. gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  925. heightini = height;
  926. height = (height * 16) / 17;
  927. zoom_width = width, zoom_height = height;
  928.  
  929. fixed_layout = gtk_fixed_new();
  930. char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg";
  931. img = gtk_image_new_from_file(picturename);
  932. img2 = gtk_image_new_from_file(picturename);
  933. mypic = gdk_pixbuf_new_from_file(picturename, NULL);
  934. windowicon = gdk_pixbuf_new_from_file(picturename, NULL);
  935. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  936. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  937. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  938. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  939. strcpy(slide, picturename);
  940. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  941. create_toolbar();
  942. gtk_container_add(GTK_CONTAINER(window), fixed_layout);
  943. get_list(picturename);
  944. store_list();
  945. system(str2);
  946.  
  947. gtk_window_fullscreen(window);
  948. g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
  949. g_signal_connect(G_OBJECT(openbutton), "clicked", G_CALLBACK(open_file), NULL);
  950. g_signal_connect(G_OBJECT(gotofirstbutton), "clicked", G_CALLBACK(goto_first), NULL);
  951. g_signal_connect(G_OBJECT(gotolastbutton), "clicked", G_CALLBACK(goto_last), NULL);
  952. g_signal_connect(G_OBJECT(aboutbutton), "clicked", G_CALLBACK(show_about), NULL);
  953. g_signal_connect(G_OBJECT(closebutton), "clicked",G_CALLBACK(goodbye_dialog), NULL);
  954. g_signal_connect(G_OBJECT(playbutton), "clicked",G_CALLBACK(start_slide), NULL);
  955. g_signal_connect(G_OBJECT(stopbutton), "clicked",G_CALLBACK(stop_slide), NULL);
  956. g_signal_connect(G_OBJECT(nextbutton), "clicked",G_CALLBACK(show_next2), NULL);
  957. g_signal_connect(G_OBJECT(negativebutton), "clicked",G_CALLBACK(image_negative), NULL);
  958. g_signal_connect(G_OBJECT(brightnessbutton), "clicked",G_CALLBACK(increase_brightness), NULL);
  959. g_signal_connect(G_OBJECT(contrastbutton), "clicked",G_CALLBACK(increase_contrast), NULL);
  960. g_signal_connect(G_OBJECT(brightnessbutton2), "clicked",G_CALLBACK(decrease_brightness), NULL);
  961. g_signal_connect(G_OBJECT(contrastbutton2), "clicked",G_CALLBACK(decrease_contrast), NULL);
  962. g_signal_connect(G_OBJECT(restorebutton1), "clicked",G_CALLBACK(show_original1), NULL);
  963. g_signal_connect(G_OBJECT(restorebutton2), "clicked",G_CALLBACK(show_original2), NULL);
  964. g_signal_connect(G_OBJECT(greyscalebutton), "clicked",G_CALLBACK(image_greyscale), NULL);
  965. g_signal_connect(G_OBJECT(previousbutton), "clicked",G_CALLBACK(show_previous), NULL);
  966. g_signal_connect(G_OBJECT(zoom_in_button), "clicked",G_CALLBACK(zoom_in), NULL);
  967. g_signal_connect(G_OBJECT(zoom_out_button), "clicked",G_CALLBACK(zoom_out), NULL);
  968. g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
  969. gtk_widget_show_all(GTK_WIDGET(window));
  970. gtk_widget_hide(GTK_WIDGET(stopbutton)), gtk_widget_hide(GTK_WIDGET(restorebutton1)), gtk_widget_hide(GTK_WIDGET(restorebutton2));
  971. gtk_main();
  972.  
  973. return 0x0;
  974. }
  975.  
  976.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement