home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilss / spr2jpeg / !Spr2Jpeg / !RunImage (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1995-02-04  |  17KB  |  647 lines

  1.  !RunImage for Sprite 2 Jpeg
  2.  David Rodgman '95
  3.  Freeware !
  4.  See Help file for details
  5. $+" at line "+
  6. ONERROR PROCerror("Error from Sprite 2 Jpeg",%11,REPORT$+" at line "+STR$ERL,1)
  7.  "WimpExt_PrePoll"
  8.  "Wimp_Poll",,q% 
  9.  reason%
  10.  "WimpExt_Action",s2jpeg%,q%,reason% 
  11.  reason%
  12.  reason% 
  13.  "WimpExt_AutoRedraw",,q%
  14.  "WimpExt_OpenLinked",,q%
  15.  "WimpExt_CloseLinked",,q%:
  16.  !q%=save% 
  17. empty_scrap
  18. click
  19. drag_end
  20.  !q%=innards% 
  21.  q%!24=13 
  22.  "WimpExt_SlabIcon",,,options%,2:sl%=-1 
  23.  "Wimp_ProcessKey",q%!24:sl%=-1
  24. menu_sel
  25.  17,18,19:
  26. recieve
  27.  sl% 
  28.  q%!12=options%:q%!16=2:sl%=
  29. click
  30.  quit%=
  31. empty_scrap
  32. *Unset S2J$Dir
  33.  "WimpExt_CloseDown",s2jpeg%
  34.  "Wimp_CloseDown"
  35. click
  36. slab%=q%!16
  37.  q%!12 
  38.  info%:
  39.  q%!16=2 
  40. author
  41.  q%!16=iconbar% 
  42. icon_click
  43.  save%:
  44. save_click
  45.  options%:
  46. options
  47.  innards%:
  48. innards
  49. SYS "XWimpExt_SlabIcon",,,0,slab%,0
  50. author
  51.  "WimpExt_GetIcon",,,info%,2 
  52.  ,,,t%:t$=
  53. string(t%,-1)
  54. t$,5)="David" 
  55.  t$="The Intelligent Stoat" 
  56.  t$="David Rodgman"
  57.  "WimpExt_SetIconString",0,,info%,2,t$
  58. icon_click
  59.  q%!8=2 
  60.  "WimpExt_CreateMenu",,main_menu%,!q%-64,96+44*2:menu%=main_menu%
  61. set_vars:!q%=options%
  62.  "Wimp_GetWindowState",,q%
  63.  "WimpExt_OpenLinked",,q%
  64.  "WimpExt_PutCaretIcon",,,innards%,4
  65. options
  66.  q%!8=2 
  67.  q%!8<>1 
  68.  !q%=options%:
  69.  "WimpExt_CloseLinked",,q%
  70.  q%!16 
  71. set_vars
  72. read_vars:
  73. save_options
  74. read_vars
  75. innards
  76. menu_sel
  77.  menu% 
  78.  main_menu%
  79.  !q% 
  80.  1:quit%=
  81.  type_menu%
  82.  item%=!q%
  83. type_tick(type_tick%,0)
  84. type_tick(item%,1)
  85.  type_tick%=item%
  86. type_tick(item%,tick%)
  87.  tick%=0 
  88. Z<type_menu%!(28+24*item%)=type_menu%!(28+24*item%) 
  89. \9type_menu%!(28+24*item%)=type_menu%!(28+24*item%) 
  90.  tick%=1 
  91.  item%<6 
  92.  item% 
  93.  1:t$="file_690":i$="Clear"
  94.  2:t$="file_ff9":i$="8-bit Sprite"
  95.  3:t$="file_ff9":i$="24-bit Sprite"
  96.  4:t$="file_695":i$="GIF"
  97.  5:t$="file_69d":i$="Targa"
  98. outspr$=t$
  99. g#t$="S"+t$+";wpptr_hand,6,1"+
  100. h/!q%=save%:q%!4=3:
  101.  "Wimp_GetIconState",,q%
  102. $(q%!32)=t$:q%!8=0:q%!12=0
  103.  "Wimp_SetIconState",,q%
  104. k/!q%=save%:q%!4=4:
  105.  "Wimp_GetIconState",,q%
  106. $(q%!28)=i$:q%!8=0:q%!12=0
  107.  "Wimp_SetIconState",,q%
  108. recieve
  109.  i%:i%=q%!16:
  110.  0:quit%=
  111. save_to_disc
  112. load_from_disc
  113.  **** Filing routines
  114. empty_scrap
  115. SYS "OS_FSControl",9,"<Wimp$ScrapDir>.S2Jpeg" TO ,,,,size%
  116. IF size%<=10240 THEN ENDPROC:REM 10k is not worth the hassle
  117.  "XOS_CLI","Wipe <Wimp$ScrapDir>.S2Jpeg ~CF~VR"
  118.  "XOS_CLI","CDir <Wimp$ScrapDir>.S2Jpeg"
  119. load_from_disc
  120. err_click%=0
  121. &sender%=q%!4:
  122.  sender%=s2jpeg% 
  123. ;type%=q%!40:
  124.  type%<>&FF9 
  125.  type%<>&690 
  126.  type%<>&C85 
  127. error("Message from Sprite 2 Jpeg",%011,"This does not look like an image file - continue ?",0)
  128.  err_click%=1 
  129. !fn$=
  130. string(q%+44,-1):in$=fn$
  131. 4!q%=256:q%!16=4:
  132.  "Wimp_SendMessage",17,q%,q%!4
  133.  type% 
  134.  &FF9,&690:dodgy%=
  135. :outspr$="file_c85":
  136. cjpeg
  137.  &c85:outspr$="file_690":
  138. open_save
  139. &outspr$="file_c85":dodgy%=
  140. cjpeg
  141. open_save
  142.  type%<>&C85 
  143.  ot$="Jpeg"
  144.  i%=0 
  145.  i%=0 s%=0 
  146.  s%=1
  147.  s%=1 
  148. B type_menu%!(28+(24*i%)+8)=type_menu%!(28+(24*i%)+8) 
  149.  (1<<22)
  150. C type_menu%!(28+(24*i%)+8)=type_menu%!(28+(24*i%)+8) 
  151. (1<<22)
  152.  ot$="Clear":type_tick%=1
  153.  i%=0 
  154.  i%<>0 s%=0 
  155.  s%=1
  156. type_tick(i%,0)
  157.  s%=1 
  158. B type_menu%!(28+(24*i%)+8)=type_menu%!(28+(24*i%)+8) 
  159.  (1<<22)
  160. C type_menu%!(28+(24*i%)+8)=type_menu%!(28+(24*i%)+8) 
  161. (1<<22)
  162. type_tick(1,1)
  163.  "WimpExt_SetIconString",0,,save%,4,ot$
  164.  "WimpExt_SetIconString",0,,save%,2,fn$
  165. *!q%=save%:
  166.  "Wimp_GetWindowState",,q%
  167.  "Wimp_OpenWindow",,q%
  168.  "WimpExt_PutCaretIcon",,,save%,2
  169. save_click
  170.  q%!16 
  171. begin_drag
  172.  5:!q%=save%:
  173.  "Wimp_GetWindowState",,q%:ox%=q%!4-q%!20:oy%=q%!16-q%!24
  174.  "WimpExt_CreateMenu",,type_menu%,ox%+266,oy%-200:menu%=type_menu%
  175. save_to_disc
  176. string(q%+44,-1)
  177. do_save(fn$)
  178. begin_drag
  179.  os%>=310 
  180.  sol%=
  181.  sol%=
  182.  "XOS_SWINumberFromString",,"DragASprite_Start" 
  183.  (e% 
  184.  1)=1 
  185.  sol%=
  186.  sol% 
  187. solid_drag 
  188. outline_drag
  189. drag%=
  190. solid_drag
  191.  f%=%01000101:
  192. bbox(q%,q%+16)
  193. s$=outspr$
  194.  "DragASprite_Start",f%,1,s$,q%,q%+16
  195. outline_drag
  196. &!q%=save%:q%!4=5:
  197. bbox(q%+8,q%+24)
  198.  "Wimp_DragBox",,q%
  199. bbox(cbox%,bbox%)
  200. 4!buffer%=save%:
  201.  "Wimp_GetWindowState",,buffer%
  202. 6ox%=buffer%!4-buffer%!20:oy%=buffer%!16-buffer%!24
  203. /buffer%!4=3:
  204.  "Wimp_GetIconState",,buffer%
  205. 0cbox%!0=ox%+buffer%!8:cbox%!4=oy%+buffer%!12
  206. 2cbox%!8=ox%+buffer%!16:cbox%!12=oy%+buffer%!20
  207. :bbox%!0=0:bbox%!4=0:bbox%!8=&7FFFFFFF:bbox%!12=bbox%!8
  208.  "WimpExt_GetIcon",,,save%,2 
  209.  ,,,t%:out$=
  210. string(t%,-1)
  211. do_save(out$)
  212. drag_end
  213. drag%=
  214.  sol% 
  215.  "XDragASprite_Stop" 
  216.  "XWimp_DragBox",,-1
  217. check_save
  218. check_save
  219.  "WimpExt_GetIcon",,,save%,2 
  220.  ,,,t%:t$=
  221. string(t%,-1)
  222.  "WimpExt_FindLeaf",t$ 
  223.  leaf$
  224.  "OS_File",17,"<Wimp$ScrapDir>.S2Jpeg.Jpeg" 
  225.  ,,,,size%
  226.  "Wimp_GetPointerInfo",,q%:win%=q%!12:ic%=q%!16
  227. =q%!16=1:q%!20=win%:q%!24=ic%:q%!28=!q%:q%!32=q%!4:!q%=100
  228. ,q%!36=size%:q%!40=&c85:$(q%+44)=leaf$+
  229.  "Wimp_SendMessage",17,q%,win% 
  230.  reciever%
  231. do_save(out$)
  232.  "XOS_File",17,out$ 
  233.  e%:go%=
  234. error("Message from Sprite 2 Jpeg",%10,"A directory exists with this name",0):go%=
  235. error("Message from Sprite 2 Jpeg",%111,"This file already exists - continue ?",0)
  236. !       
  237.  err_click%=0 
  238.  go%=
  239.  No file exists here
  240.  go% 
  241.  outspr$<>"file_c85" 
  242. djpeg
  243.  "OS_SetVarVal","Temp$Temp",out$
  244.  "Wimp_StartTask","Copy <S2J$Scrap>.Jpeg <Temp$Temp> D~V~CFSL~N~PQ~R~T"
  245.  "OS_CLI","Unset Temp$Temp"
  246. '!q%=save%:
  247.  "Wimp_CloseWindow",,q%
  248. cjpeg
  249. <switches$="-Q "+
  250. quality%:
  251.  optimise% 
  252.  switches$+=" -o"
  253.  cdebug% 
  254.  switches$+=" -d"
  255.  interleave% 
  256.  switches$+=" -I"
  257.  arithmetic% 
  258.  switches$+=" -a"
  259.  cxtra$<>"" 
  260.  switches$+=cxtra$
  261.  "OS_SetVarVal","Temp$Temp",fn$
  262. Lcomm$="<ChangeFSI$Dir>.ChangeFSI <Temp$Temp> <S2J$Scrap>.PBM P6 -nomode"
  263.  "Wimp_StartTask",comm$
  264.     Xredir$=" { > <Wimp$ScrapDir>.S2Jpeg.Output }":
  265.  dodgy%) 
  266.  (cdebug%=
  267.  redir$=""
  268. Kcomm$="S2J:cjpeg "+switches$+" <S2J$Scrap>.PBM <S2J$Scrap>.Jpeg"+redir$
  269.  dodgy%=
  270.  "XOS_CLI","Remove <Wimp$ScrapDir>.S2Jpeg.Output"
  271.  "Wimp_StartTask",comm$
  272.  "XOS_File",17,"<S2J$Scrap>.Jpeg" 
  273.  e%<>1 
  274. error("Message from Sprite 2 Jpeg",1,"Sorry, something went wrong",0):
  275.  "XOS_CLI","Remove <S2J$Scrap>.PBM"
  276.  "XOS_CLI","X SetType <S2J$Scrap>.Jpeg c85"
  277.  "OS_CLI","Unset Temp$Temp"
  278. open_save
  279. djpeg
  280.  type_tick% 
  281.  1:cfo$=""
  282.  2:cfo$="28"
  283.  3:cfo$="s32"
  284.  4:cfo$=""
  285.  5:cfo$=""
  286. :switches$=""
  287.  quantize% 
  288.  switches$="-q "+
  289. quant_to%
  290.  passes% 
  291.  switches$+=" -1"
  292.  dither% 
  293.  switches$+=" -D"
  294.  grey% 
  295.  switches$+=" -g"
  296.  xblock% 
  297.  switches$+=" -b"
  298.  ddebug% 
  299.  switches$+=" -d"
  300.  dxtra$<>"" 
  301.  switches$+=dxtra$
  302.  type_tick% 
  303.  1,2,3:switches$+=" -P"
  304.  4:switches$+=" -G"
  305.  5:switches$+=" -T"
  306.  "OS_SetVarVal","Temp$Temp",in$
  307. *Kredir$=" { > <Wimp$ScrapDir>.S2Jpeg.Output }":
  308.  (ddebug%=
  309.  redir$=""
  310. +Hcomm$="S2J:djpeg "+switches$+" <Temp$Temp> <S2J$Scrap>.Jpeg2"+redir$
  311.  "Wimp_StartTask",comm$
  312.  "WimpExt_PrePoll"
  313.  "Wimp_Poll",,q% 
  314.  reason%
  315.  "WimpExt_Action",s2jpeg%,q%,reason% 
  316.  reason%
  317.  reason% 
  318.  17,18,19:
  319.  q%!16=0 
  320.  quit%=
  321.  "XOS_File",17,"<S2J$Scrap>.Jpeg2" 
  322.  e%=1
  323.  grey% 
  324.  s$=" -d" 
  325.  s$=""
  326.  type_tick% 
  327. pbm_clear("<S2J$Scrap>.Jpeg2","<S2J$Scrap>.Jpeg",0)
  328. :4       
  329. SYS "XOS_CLI","Remove <S2J$Scrap>.Jpeg2"
  330.  2:comm$="<ChangeFSI$Dir>.ChangeFSI <S2J$Scrap>.Jpeg2 <S2J$Scrap>.Jpeg 28 -nomode"+s$
  331. <L       
  332.  "Wimp_StartTask",comm$:
  333.  "XOS_CLI","Remove <S2J$Scrap>.Jpeg2"
  334.  3:comm$="<ChangeFSI$Dir>.ChangeFSI <S2J$Scrap>.Jpeg2 <S2J$Scrap>.Jpeg S32,90,90 -nomode"
  335. >L       
  336.  "Wimp_StartTask",comm$:
  337.  "XOS_CLI","Remove <S2J$Scrap>.Jpeg2"
  338.  "XOS_CLI","SetType <S2J$Scrap>.Jpeg2 695"
  339. @C       
  340.  "XOS_CLI","Rename <S2J$Scrap>.Jpeg2 <S2J$Scrap>.Jpeg"
  341.  "XOS_CLI","SetType <S2J$Scrap>.Jpeg2 69D"
  342. BC       
  343.  "XOS_CLI","Rename <S2J$Scrap>.Jpeg2 <S2J$Scrap>.Jpeg"
  344. string(a%,l%)
  345. d$="":
  346.  l%>0 
  347.  i%=0 
  348.  l%-1
  349.  d$+=
  350. (a%?i%)
  351. L# i%=0:max%=255:
  352.  l%<-1 max%=-l%
  353. d$,1)<>
  354. d$,1)<>
  355.  i%<=max%
  356.  d$+=
  357. (a%?i%):i%+=1
  358. d$,1)=
  359. d$-1)
  360. error(title$,buttons%,mess$,fatal%)
  361. LOCAL ERROR:ONERROR ERROR 0,REPORT$+" in error handler at line "+STR$ERL:END
  362.  buttons% 
  363.  0:$buffer%="OK"+
  364. 0:die%=-1
  365.  1:$buffer%="OK"+
  366. 0:die%=-1
  367.  2:$buffer%="Cancel"+
  368. 0:die%=0
  369.  3:$buffer%="OK"+
  370. 0+"Cancel"+
  371. 0:die%=1
  372.  7:$buffer%="Cancel"+
  373. 0+"OK"+
  374. 0:die%=0
  375.  "WimpExt_OpenRequester",,,title$,mess$,buffer%,die%
  376.  "WimpExt_PrePoll"
  377.  "Wimp_Poll",,buffer% 
  378.  reason%
  379.  "WimpExt_Action",s2jpeg%,buffer%,reason% 
  380.  reason%
  381.  reason% 
  382.  "WimpExt_AutoRedraw",,buffer%
  383.  "WimpExt_OpenLinked",,buffer%
  384.  "WimpExt_CloseLinked",,buffer%
  385.  buffer%!16=die% 
  386.  fatal%=1 
  387.  quit%=
  388.  17,18,19:
  389. recieve
  390.  ((reason%=6 
  391.  buffer%!12=-3) 
  392.  quit%=
  393. err_click%=buffer%!16
  394.  "Wimp_Initialise",200,&4B534154,"Sprite 2 Jpeg" 
  395.