readline and the newline 
Author Message
 readline and the newline

     I'm converting grayscale image data into postscript for printing
and/or saving as EPS for inclusion in (e.g.) TeX. I've been a good chap
and encoded my 8-bit data as 2 character hex strings, which I then
read using `readhexstring' - this works just fine.

     Now I'm trying to cheat, to save time and space. As an Apple LWIINTX
only has 32 gray levels, I figured I could encode each of my 8-bit data
values into 1 ascii printable character (e.g. in the ascii range 33-117),
and use `readline' to get the data. I then use a transfer function to
renormalise the data in the range 0-255. This should result in files half
the size of full-up hex encoded data, print faster, and not lose any
grayscale dynamic range (at least on a IINTX).

     To write nice readable PostScript, I want each line of data to be
64 characters long in the EPS file. My images however often have row
lengths greater than 64 pixels, so I split them across several lines.
No problem for `readhexstring' as it ignores spaces, newlines, etc.
But `readline' is supposed to terminate on a newline character, i.e.
if you try and fill a 200 character string and a newline comes along
at character 51, `readline' should terminate and return with 50 characters.
To get round this, the Red Book (Second Edition) says you can precede
the newline with a backslash: then both the backslash and newline are
supposed to be ignored, allowing `readline' to go on collecting
characters until full.

     Fine. But that's not how it seems to be working. If I put in a
backslash immediately before the newline, it gets included and printed.
If I just have a regular newline, `readline' does NOT terminate, but
keeps on going until its string is full. Of course, this is ok, 'cos
that's what I want.

     But am I missing the point, or is the `readline' definition wrong?

     I'm running version 47.0 of PostScript apparently, so the old
habit of `readline' recognising only LF as a newline has been corrected
(again, source Red Book 2). Here's a typical bit of the code I'm using:

/origstate save def
100 dict begin
/row 256 string def
/drawimage { 256 256 8 [ 256 0 0 256 0 0 ]
image showpage } def
{0.1294117 sub 3.0357143 mul} settransfer
50 205 translate
510 510 scale
drawimage
!!"""###$$$%%%&&&'''((()))***+++,,,---...////0001112223334445556

KKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___``
`aaabbbcccdddeeefffgggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuu
!!"""###$$$%%%&&&'''((()))***+++,,,---...////0001112223334445556

KKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___``
`aaabbbcccdddeeefffgggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuu

(etc.)

end
origstate restore

     This works fine (the above is 2 lines of 256 pixels each)
without a backslash before the newlines: why?

     Please send e-mail: I don't often read this group (perhaps I
should!)

                                                 Mark

------------------------------------------------------------------------
Mark McCaughrean,   | University of Arizona | Phone: (602) 621 8347

------------------------------------------------------------------------



Mon, 29 Aug 1994 11:55:59 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Regular Expression - match newline followed by pattern, strip out ONLY the newline

2. Readline until EOF

3. gshell: ReadLine support for Ghostscript

4. problem invoking readline

5. Using the ReadLine method for TextStream object

6. Readline 2 rows below

7. TextStream: ReadLine - how to detect eof

8. a = a & tsIn.Readline - no output

9. Help with the ReadLine Method

10. Open a text file and edit using ReadLine method

11. .Readline syntax

12. limit imput or readline

 

 
Powered by phpBB® Forum Software