Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

YA bitmap image example

64 views
Skip to first unread message

luser- -droog

unread,
Jul 18, 2013, 10:55:29 PM7/18/13
to
This is an appendix to my SO answer, illustrating the equivalence of reading binary data with `readstring` and hex-encoded ascii data with `readhexstring`. From an idea in the comment-section.

http://stackoverflow.com/a/15183845/733077

%!
%image example
%image origin: http://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Spacewar%21-PDP-1-20070512.jpg/320px-Spacewar%21-PDP-1-20070512.jpg
%
% bash commands to prepare image file:
%
% $ wget http://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Spacewar%21-PDP-1-20070512.jpg/320px-Spacewar%21-PDP-1-20070512.jpg
% $ identify 320px-Spacewar\!-PDP-1-20070512.jpg
% $ convert 320px-Spacewar\!-PDP-1-20070512.jpg Spacewar.pbm
% $ xxd -ps Spacewar.pbm > spacewar.asc


%/infile (spacewar.asc)(r)file def
/infile (spacewar.pbm)(r)file def
/buf 512 string def
%/readdata {readhexstring} def
/readdata {readstring} def

% use $ xxd Spacewar.pbm | head
% to find the length of the header and read that length
% into the buffer and discard, leaving only samples.
infile buf 0 16#5d getinterval readdata pop pop

320 215 1
[ 1 0 0 -1 0 215 ]
{ infile buf readdata pop } image

showpage
0 new messages