PikX, slight enhancement

new topic     » topic index » view thread      » older message » newer message

If PikX doesn't see a .bmp extension when you try to load one, it'll make
one for you. And another thing, when it says Usage, it does the Usa part
in red white and blue. smile Enjoy.
PikX.ex:
include wildcard.e
include get.e
include graphics.e
include user.e
include image.e
object cl,fname,action,vc,lines,prgname,pal,pixels,bname,mode
sequence pic
integer fn
cl=command_line()
prgname=cl[2]
if not find(".ex",prgname) then
prgname=prgname&".ex"
end if
if length(cl)<4 then
   puts(1,"PikX v1.0")
   text_color(12)
   puts(1,"\nU")
   text_color(15)
   puts(1,"S")
   text_color(9)
   puts(1,"A")
   text_color(7)
   puts(1,"ge: ex PikX load/save/bitmap filename")
   puts(1,"\nUse load to load a picture made with PikX")
   puts(1,"\nUse save to save a picture")
   puts(1,"\nUse bitmap to load and display a .BMP file")
   puts(1,"\nfilename is the file to read from or write to")
   abort(0)
end if
action=cl[3]
fname=cl[4]
vc=video_config()
action=upper(action)
if not compare(action,"SAVE") then
   pic=save_text_image({1,1},{vc[3],vc[4]})
   puts(1,"\nAttempting to save to "&fname&"...")
   if not compare(fname,prgname) then
   puts(1,"I can't let you overwrite me.")
   abort(0)
   end if
   fn=open(trim(fname),"w")
   if fn=-1 then
      puts(1,"\nThere was an error opening "&fname)
      puts(1,"\nWhat might have occured is an access denied error")
      puts(1,"\nError code: 1")
      abort(1)
   end if
   print(fn,pic)
   close(fn)
   abort(0)
elsif not compare(action,"LOAD") then
   puts(1,"Attempting to read from "&fname&"...")
   if not compare(fname,prgname) then
   puts(1,"I'm not an image!")
   abort(0)
   end if
   fn=open(fname,"r")
   if fn=-1 then
      puts(1,"\nThere was an error loading "&fname)
      puts(1,"\nWhat might have occured is a file not found")
      puts(1,"\nPlease check your typing and try again")
      puts(1,"\nError code: 2")
      abort(2)
    end if
   pic=get(fn)
      if pic[1]=GET_EOF then
         puts(1,"Reached the end of "&fname&" too soon.")
         puts(1,"\nError code: 3")
         abort(3)
      elsif pic[1]=GET_FAIL then
         puts(1,fname&" does not contain a valid image.")
         puts(1,"\nError code: 4")
         abort(4)
      end if
   close(fn)
   clear_screen()
   display_text_image({1,1},pic[2])
   if wait_key() then
   end if
   vc=video_config()
   lines=vc[3]
   position(lines-1,1)
   abort(0)
elsif not compare(action,"BITMAP") then
   if not find(".bmp",fname) then
      fname=fname&".bmp"
   end if
   bname=read_bitmap(fname)
   if atom(bname) then
      if bname=BMP_UNSUPPORTED_FORMAT then
         puts(1,"\nSorry, not a supported format")
         abort(5)
      elsif bname=BMP_UNEXPECTED_EOF then
         puts(1,"\nReached an unexpected End-Of-File marker")
         abort(5)
      elsif bname=BMP_OPEN_FAILED then
         puts(1,"\nPikX was unable to load "&fname)
         puts(1,"\nWhat might have just occurred is a file not found")
         puts(1,"\nerror. Please check your typing and try again.")
         abort(2)
      end if
   end if
   pal=bname[1]
   pal=pal/4
   pixels=bname[2]
   bname={}
   if length(pal)> 16 then
      mode=257
   else
      mode=18
   end if
   if graphics_mode(mode) then
   end if
   all_palette(pal)
   display_image({0,0},pixels)
   if wait_key() then
   end if
   if graphics_mode(-1) then
   end if
abort(0)
end if
puts(1,"\n"&action&": This is not a supported action")


-------------------------------------
When it comes to programming languages, Euphoria is a cut above -
matt1278 at juno.com and matt1421 at juno.com(and soon to be
irisnmatt at prodigy.net. Then again, maybe not) Euphoria programmer

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu