Log of #ghostscript at irc.freenode.net.

Search:
 <<<Back 1 day (to 2022/05/24)Fwd 1 day (to 2022/05/26) >>>20220525 
aformertransformer hey all! Quick quetsion. If I have a file out.bin that stores just a byte sequence of LZW encoded text, can I decode this with ghostscript?17:38.32 
  I know LZWdecode is a thing, but I can't figure out how to load the file into gs and run the decode function on it17:39.07 
artifexirc-bot <KenSharp> Yes, you need some PostScript17:59.35 
  <KenSharp> Firstly you need to allow Ghostscript to open the file on disk (this is the SAFER stuff) so you need to supply --permit-file-read=<filename> on the command line18:00.15 
  <KenSharp> Then you need to open the file with "(filename) (r) file"18:00.42 
  <KenSharp> which will leave a file object on the operand stack.18:00.50 
  <KenSharp> TO that you would apply the LZWDecode filter18:00.56 
  <KenSharp> If you wanted to supply an parameters to the LZWDecode you would supply them in a dictionayr, if not just push the filter name on the stack, let's assume no18:02.18 
  <KenSharp> So just /LZWDecode18:02.30 
  <KenSharp> That will again return a file object18:02.36 
  <KenSharp> At that point you just read from the file18:02.44 
  <KenSharp> Probably the easiest way to do this is something like :18:03.28 
  <KenSharp> /MyFile (filename) (r) file def18:03.28 
  <KenSharp> /MyFilteredFile MyFile /LZWDecode def18:03.29 
  <KenSharp> Then read in a loop:{MyFilteredFile 255 string readstring not {exit} if} loop18:05.53 
  <KenSharp> Then read in a loop:{MyFilteredFile 255 string readstring not {== flush exit} if ==} loop18:06.33 
  <KenSharp> If you want to write the output to a file instead of jjust printing it you'd replace the == with commands to write to a file18:06.50 
  <KenSharp> This is a program to do that, note you would need to permit file reading and writing on the relevant files:18:07.38 
  <KenSharp> /InFile (c:/tests/692779/image.lzw) (r) file /LZWDecode filter def18:07.38 
  <KenSharp> /OutFile (c:/tests/692779/image.bin) (w) file def18:07.39 
  <KenSharp> /Data 32768 string def18:07.40 
  <KenSharp> 18:07.42 
  <KenSharp> {18:07.43 
  <KenSharp> InFile Data readstring {18:07.44 
  <KenSharp> OutFile exch writestring18:07.45 
  <KenSharp> } {18:07.47 
  <KenSharp> OutFile exch writestring18:07.48 
  <KenSharp> exit18:07.49 
  <KenSharp> } ifelse18:07.51 
  <KenSharp> } loop18:07.52 
  <KenSharp> 18:07.53 
  <KenSharp> InFile closefile18:07.55 
  <KenSharp> OutFile closefile18:07.56 
aformertransformer nice! Thanks for the detailed explanation. I'm going to give this a try now18:28.58 
  I'm getting `Error: /typecheck in --readstring--` ... do you think that means this isn't actually correctly formed LZW?19:38.11 
 <<<Back 1 day (to 2022/05/24)Forward 1 day (to 2022/05/26)>>> 
ghostscript.com #mupdf
Search: