pngoverlay.bac 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. ' *****************************************************
  2. ' PROGRAM: gtkoverlay.bac
  3. ' PURPOSE: to overlay png images from the command line
  4. ' AUTHOR: vovchik (Puppy Linux forum)
  5. ' MODDED: PvE (thanks for the help)
  6. ' DEPENDS: gcc, bacon, bash, gtk
  7. ' PLATFORM: Puppy Linux (actually, any *nix)
  8. ' DATE: 09-11-2010
  9. ' NOTES:
  10. ' *****************************************************
  11. ' 110720 BK pngoverlay.
  12. ' *********************
  13. ' DEF ERROR HANDER
  14. ' *********************
  15. TRAP LOCAL
  16. CATCH GOTO PRINT_ERROR
  17. ' *********************
  18. ' END DEF ERROR HANDER
  19. ' *********************
  20. ' *********************
  21. ' CONSTANTS
  22. ' *********************
  23. CONST GDK_INTERP_HYPER = 3
  24. CONST Gtk$ = "libgtk-x11-2.0.so.0"
  25. CONST Gdk$ = "libgdk-x11-2.0.so.0"
  26. CONST Gdk_pixbuf$ = "libgdk_pixbuf-2.0.so.0"
  27. CONST Gobject$ = "libgobject-2.0.so.0"
  28. CONST MY_VERSION$ = "v.0.1a by vovchik, Puppy Linux Forum"
  29. CONST BACON_BLURB$ = "Check out BaCon at www.basic-converter.org"
  30. ' *********************
  31. ' END CONSTANTS
  32. ' *********************
  33. ' *********************
  34. ' DECLARATIONS
  35. ' *********************
  36. DECLARE img1_size, img2_size, window, img TYPE int
  37. DECLARE NUL, BackImage$, FrontImage$, NewImage$ TYPE STRING
  38. DECLARE GTK_WINDOW_TOPLEVEL, GDK_INTERP_BILINEAR TYPE int
  39. DECLARE OVERALL_ALPHA TYPE int
  40. DECLARE dest_x, dest_y, dest_wdth, dest_height TYPE int
  41. DECLARE offset_x, offset_y, scale_x, scale_y TYPE double
  42. GLOBAL clarray$ TYPE STRING
  43. GLOBAL clitems TYPE NUMBER
  44. GLOBAL hei_img1, wid_img1, hei_img2, wid_img2 TYPE NUMBER
  45. GLOBAL img_dst, img_scr TYPE long
  46. ' *********************
  47. ' END DECLARATIONS
  48. ' *********************
  49. ' *********************
  50. ' IMPORTS
  51. ' *********************
  52. IMPORT "g_object_unref(long)" FROM Gobject$ TYPE void
  53. REM IMPORT "g_signal_connect_data(long,char*,void*,long,long,int)" FROM Gobject$ TYPE void
  54. REM IMPORT "gtk_container_add(long, long)" FROM Gtk$ TYPE void
  55. IMPORT "gtk_exit(int)" FROM Gtk$ TYPE void
  56. IMPORT "gtk_init(int*, void*)" FROM Gtk$ TYPE void
  57. IMPORT "gtk_image_new_from_pixbuf(long)" FROM Gtk$ TYPE long
  58. REM IMPORT "gtk_main" FROM Gtk$ TYPE void
  59. IMPORT "gtk_main_quit(void)" FROM Gtk$ TYPE void
  60. REM IMPORT "gtk_widget_show(long)" FROM Gtk$ TYPE void
  61. IMPORT "gtk_widget_show_all(long)" FROM Gtk$ TYPE void
  62. REM IMPORT "gtk_window_new(int)" FROM Gtk$ TYPE long
  63. IMPORT "gdk_pixbuf_composite(int, int, int, int, int, int, double, double, double, double, int, int)" FROM Gdk_pixbuf$ TYPE void
  64. REM IMPORT "gdk_pixbuf_new_from_file_at_size(char*, int, int, void*)" FROM Gdk_pixbuf$ TYPE int
  65. IMPORT "gdk_pixbuf_save(long,char*,char*,void*,...)" FROM Gdk_pixbuf$ TYPE int
  66. IMPORT "gdk_pixbuf_new_from_file(char*,void*)" FROM Gdk_pixbuf$ TYPE long
  67. IMPORT "gdk_pixbuf_get_width(int)" FROM Gdk_pixbuf$ TYPE int
  68. IMPORT "gdk_pixbuf_get_height(int)" FROM Gdk_pixbuf$ TYPE int
  69. ' *********************
  70. ' END IMPORTS
  71. ' *********************
  72. ' *********************
  73. ' FUNCTIONS & SUBS
  74. ' *********************
  75. SUB get_cl_func()
  76. SPLIT ARGUMENT$ BY " " TO clarray$ SIZE clitems
  77. IF clitems = 1 THEN
  78. PRINT "Usage: front-png back-png output-png"
  79. ENDIF
  80. IF clitems < 4 THEN END 1
  81. IF NOT(FILEEXISTS(clarray$[1])) THEN END 2
  82. IF NOT(FILEEXISTS(clarray$[0])) THEN END 3
  83. BackImage$=clarray$[2]
  84. FrontImage$=clarray$[1]
  85. NewImage$=clarray$[3]
  86. IF FILEEXISTS(NewImage$) THEN DELETE FILE NewImage$
  87. END SUB
  88. '-----------------
  89. SUB bacmain_func()
  90. '-----------------
  91. GDK_INTERP_BILINEAR = 2
  92. 'GDK_INTERP_HYPER = 3
  93. GTK_WINDOW_TOPLEVEL = 0
  94. OVERALL_ALPHA = 255
  95. window = 0
  96. img = 0
  97. REM img1_size = 128
  98. REM img2_size = 128
  99. scale_x = 1
  100. scale_y = 1
  101. dest_x = 0
  102. dest_y = 0
  103. offset_x = 0
  104. gtk_init(0, 0)
  105. REM img_dst = gdk_pixbuf_new_from_file_at_size(FrontImage$, img1_size, img1_size, 0)
  106. img_dst = gdk_pixbuf_new_from_file(FrontImage$, 0)
  107. hei_img1 = gdk_pixbuf_get_height(img_dst)
  108. wid_img1 = gdk_pixbuf_get_width(img_dst)
  109. REM img_scr = gdk_pixbuf_new_from_file_at_size(BackImage$, img2_size, img2_size, 0)
  110. img_scr = gdk_pixbuf_new_from_file(BackImage$, 0)
  111. hei_img2 = gdk_pixbuf_get_height(img_scr)
  112. wid_img2 = gdk_pixbuf_get_width(img_scr)
  113. img1_size=wid_img1
  114. img2_size=wid_img2
  115. IF NOT(img_dst) OR NOT(img_scr) THEN
  116. PRINT "Error loading one of the images!", NL$
  117. IF img_dst THEN
  118. g_object_unref(img_dst)
  119. ELSE
  120. g_object_unref(img_scr)
  121. END IF
  122. END
  123. END IF
  124. ' gdk_composite args (12 nums - some ints some doubles):
  125. ' src, dst,
  126. ' dest_x, dest_y,
  127. ' dest_wdth, dest_height,
  128. ' offset_x, offset_y,
  129. ' scale_x, scale_y,
  130. ' interp_type, overall_alpha
  131. REM gdk_pixbuf_composite(img_scr, img_dst, \
  132. REM dest_x, img1_size - img2_size, \
  133. REM img2_size, img2_size, \
  134. REM offset_x, img1_size - img2_size, \
  135. REM scale_x, scale_y, \
  136. REM GDK_INTERP_HYPER, OVERALL_ALPHA)
  137. IF (hei_img1 - hei_img2) >= 0 THEN
  138. gdk_pixbuf_composite(img_scr, img_dst, dest_x, hei_img1 - hei_img2, wid_img2, hei_img2, offset_x, hei_img1 - hei_img2, scale_x, scale_y, GDK_INTERP_HYPER, OVERALL_ALPHA)
  139. ELSE
  140. gdk_pixbuf_composite(img_scr, img_dst, dest_x, hei_img2 - hei_img1, wid_img2, hei_img2, offset_x, hei_img2 - hei_img1, scale_x, scale_y, GDK_INTERP_HYPER, OVERALL_ALPHA)
  141. ENDIF
  142. img = gtk_image_new_from_pixbuf(img_dst)
  143. g_object_unref(img_dst)
  144. g_object_unref(img_scr)
  145. REM window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
  146. REM g_signal_connect_data(window, "destroy", gtk_main_quit, 0, 0, 0)
  147. REM gtk_container_add(window, img)
  148. REM gtk_widget_show_all(window)
  149. gdk_pixbuf_save(img_dst, NewImage$, "png" ,NULL, NULL)
  150. REM gtk_main()
  151. END SUB
  152. ' -----------
  153. SUB REPORT_RESULTS()
  154. ' -----------
  155. IF FILEEXISTS(NewImage$) THEN
  156. PRINT "File ", NewImage$, " created."
  157. ELSE
  158. PRINT "OOPS.. something terrible happened and ", NewImage$, " was not created."
  159. END IF
  160. gtk_exit(0)
  161. END SUB
  162. ' *********************
  163. ' END FUNCTIONS & SUBS
  164. ' *********************
  165. ' *********************
  166. ' MAIN
  167. ' *********************
  168. get_cl_func
  169. bacmain_func
  170. REPORT_RESULTS
  171. END
  172. ' *********************
  173. ' END MAIN
  174. ' *********************
  175. ' *********************
  176. ' ERROR HANDLER
  177. ' *********************
  178. LABEL PRINT_ERROR
  179. PRINT "GTK library ", Gtk$, " is not available on this platform!"
  180. END