Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #1229 > unrolled thread

Programmable bitmap hack

Started byluser- -droog <mijoryx@yahoo.com>
First post2013-01-23 23:42 -0800
Last post2013-10-29 02:50 -0700
Articles 6 — 2 participants

Back to article view | Back to comp.lang.postscript


Contents

  Programmable bitmap hack luser- -droog <mijoryx@yahoo.com> - 2013-01-23 23:42 -0800
    Re: Programmable bitmap hack Eli the Bearded <*@eli.users.panix.com> - 2013-01-31 23:01 +0000
      Re: Programmable bitmap hack Eli the Bearded <*@eli.users.panix.com> - 2013-01-31 23:29 +0000
      Re: Programmable bitmap hack luser- -droog <mijoryx@yahoo.com> - 2013-01-31 23:54 -0800
        Re: Programmable bitmap hack luser- -droog <mijoryx@yahoo.com> - 2013-07-19 00:34 -0700
        Re: Programmable bitmap hack luser- -droog <mijoryx@yahoo.com> - 2013-10-29 02:50 -0700

#1229 — Programmable bitmap hack

Fromluser- -droog <mijoryx@yahoo.com>
Date2013-01-23 23:42 -0800
SubjectProgrammable bitmap hack
Message-ID<c79e49e9-37e8-42d3-9e08-0cee983fc459@googlegroups.com>
Just a little bragging about my losing entry to
"Emulate a 7-segment display" 
http://codegolf.stackexchange.com/a/9308/2381

While not a winner in terms of size, I'm proud of this code because I think it illustrates a neat way to draw bitmaps
using the postscript `image` operator.

(1101101) %for each char in the input
{neg 49 add 255 mul %'0'->255,1->0
1 string dup 0 4 3 roll put}forall %wrap in 1byte string
(\377){@/g/f/e/d/c/b/a}{exch def}forall %define values
@ a a @ %describe bitmap, top->down, right->left
b @ @ f
b @ @ f
@ g g @
c @ @ e
c @ @ e
@ d d @
4 7 8[.01 0 0 .01 0 0]{}image showpage
%4-pix wide 7-pix tall 8-bits per pix
%[matrix sez: "un-shrink" by 1/100]
%emptry proc lets image find strings already on stack

But you could easily do sthg like

/_ (\0) def
/# (\377) def
_ _ _ #
_ _ # _
_ # _ _
# _ _ _
4 4 8
[.1 0 0 .1 0 0]{}image

Now PS art is as easy as ASCII art. Have fun!

[toc] | [next] | [standalone]


#1239

FromEli the Bearded <*@eli.users.panix.com>
Date2013-01-31 23:01 +0000
Message-ID<eli$1301311734@qz.little-neck.ny.us>
In reply to#1229
In comp.lang.postscript, luser- -droog  <mijoryx@yahoo.com> wrote:
> But you could easily do sthg like
> 
> /_ (\0) def
> /# (\377) def
> _ _ _ #
> _ _ # _
> _ # _ _
> # _ _ _
> 4 4 8
> [.1 0 0 .1 0 0]{}image
> 
> Now PS art is as easy as ASCII art. Have fun!

It's like xpm images in postscript! I like this. If you changed your matrix
to flip the image side-to-side, though, so the ASCII art matches the
orientation of the output, it would be easier to use:

  [-.1 0 0 .1 0 0]

Elijah
------
wikipedia has xpm examples if you don't know the format

[toc] | [prev] | [next] | [standalone]


#1240

FromEli the Bearded <*@eli.users.panix.com>
Date2013-01-31 23:29 +0000
Message-ID<eli$1301311829@qz.little-neck.ny.us>
In reply to#1239
In comp.lang.postscript, Eli the Bearded  <*@eli.users.panix.com> wrote:
> In comp.lang.postscript, luser- -droog  <mijoryx@yahoo.com> wrote:
[snip]
> > [.1 0 0 .1 0 0]{}image
> > Now PS art is as easy as ASCII art. Have fun!
> It's like xpm images in postscript!

Expansion to colorimage is a bit trickier than I hoped. This ascii image
is nothing like the color image that comes out.

306 392 translate
/_ (\0 \0 \0) def
/a (\77 \0 \0) def
/b (\0 \177 \0) def
/c (\0 \0 \277) def
/# (\377 \377 \377) def
a b b b b a
a _ _ _ # a
a _ _ # _ a
a _ # _ b b
a # _ _ c a
a b b b b a
6 6 8
[-.1 0 0 .1 0 0]{} false 3 colorimage

Elijah
------
does not find colorimage defined in his ancient red book

[toc] | [prev] | [next] | [standalone]


#1243

Fromluser- -droog <mijoryx@yahoo.com>
Date2013-01-31 23:54 -0800
Message-ID<d26539de-eafd-44e2-957c-3f1c9d7a7cb9@googlegroups.com>
In reply to#1239
On Thursday, January 31, 2013 5:01:59 PM UTC-6, Eli the Bearded wrote:
> In comp.lang.postscript, luser- -droog  <mijoryx@yahoo.com> wrote:
> > But you could easily do sthg like
> > /_ (\0) def
> > /# (\377) def
> > _ _ _ # 
> > _ _ # _ 
> > _ # _ _ 
> > # _ _ _ 
> > 4 4 8 
> > [.1 0 0 .1 0 0]{}image
> > Now PS art is as easy as ASCII art. Have fun!

> It's like xpm images in postscript! I like this. If you changed your matrix
> to flip the image side-to-side, though, so the ASCII art matches the
> orientation of the output, it would be easier to use: 

>   [-.1 0 0 .1 0 0] 

Yes. That's much better. But I'm now thinking there's no
advantage in leaving stuff on the stack and passing an 
empty procedure (except perhaps in Level-1 interpreters).
The image data might just as well be *in* the procedure.

[toc] | [prev] | [next] | [standalone]


#1482

Fromluser- -droog <mijoryx@yahoo.com>
Date2013-07-19 00:34 -0700
Message-ID<fef02c29-e54f-4e7a-8ff7-498bb915bba4@googlegroups.com>
In reply to#1243
On Friday, February 1, 2013 1:54:42 AM UTC-6, luser- -droog wrote:
> On Thursday, January 31, 2013 5:01:59 PM UTC-6, Eli the Bearded wrote:
> 
> > In comp.lang.postscript, luser- -droog  <mijoryx@yahoo.com> wrote:
> 
> > > But you could easily do sthg like
> > > /_ (\0) def
> > > /# (\377) def
> > > _ _ _ # 
> > > _ _ # _ 
> > > _ # _ _ 
> > > # _ _ _ 
> > > 4 4 8 
> > > [.1 0 0 .1 0 0]{}image
> > > Now PS art is as easy as ASCII art. Have fun!
> 
> > It's like xpm images in postscript! I like this. If you changed your matrix
> > to flip the image side-to-side, though, so the ASCII art matches the
> > orientation of the output, it would be easier to use: 
> 
> >   [-.1 0 0 .1 0 0] 
> 
> Yes. That's much better. But I'm now thinking there's no
> advantage in leaving stuff on the stack and passing an 
> empty procedure (except perhaps in Level-1 interpreters).
> The image data might just as well be *in* the procedure.

This is wrong. Remember that the procedure gets called each time `image` wants a new piece of data. The procedure *must*
do nothing. That's the whole trick here.

Here's the idea extended to an editable Type 3 bitmap font.

/bitfont <<
    /FontType 3
    /FontMatrix [.01 0 0 .01 0 0]
    /FontBBox [ 0 0 50 70]
    /Encoding 128 array
    /_ (\377)
    /# (\0)
    /charprocs <<

        /.notdef { 
            # # # # #
            # _ _ # #
            # _ _ # #
            # _ # _ #
            # _ # _ #
            # # _ _ #
            # # # # #
        }

        32 { 
            _ _ _ _ _
            _ _ _ _ _
            _ _ _ _ _
            _ _ _ _ _
            _ _ _ _ _
            _ _ _ _ _
            _ _ _ _ _
        }
        48 { 
            _ # # # _
            # _ _ _ #
            # _ _ # #
            # _ # _ #
            # # _ _ #
            _ # # # _
            _ _ _ _ _
        }
        49 { 
            _ _ # _ _
            _ # # _ _
            _ _ # _ _
            _ _ # _ _
            _ _ # _ _
            _ # # # _
            _ _ _ _ _
        }

    >>
    /BuildChar {
        %100 0 0 0 50 70 setcachedevice
        100 0 setcharwidth
        -1 1 scale
        exch begin
            charprocs exch
            2 copy known not{pop/.notdef}if
            get exec
            5 7 8 FontMatrix {} image
        end
    }
>> definefont pop

100 100 moveto
/bitfont 20 selectfont
(0 1 0 1 ?) show

showpage

[toc] | [prev] | [next] | [standalone]


#1718

Fromluser- -droog <mijoryx@yahoo.com>
Date2013-10-29 02:50 -0700
Message-ID<5e373ab9-8519-4533-aac0-b81610e577b7@googlegroups.com>
In reply to#1243
On Friday, February 1, 2013 1:54:42 AM UTC-6, luser- -droog wrote:
> On Thursday, January 31, 2013 5:01:59 PM UTC-6, Eli the Bearded wrote:
> 
> > In comp.lang.postscript, luser- -droog  <mijoryx@yahoo.com> wrote:
> 
> > > But you could easily do sthg like
> 
> > > /_ (\0) def
> > > /# (\377) def
> > > _ _ _ # 
> > > _ _ # _ 
> > > _ # _ _ 
> > > # _ _ _ 
> > > 4 4 8 
> > > [.1 0 0 .1 0 0]{}image
> 
> > > Now PS art is as easy as ASCII art. Have fun!
> 
> > It's like xpm images in postscript! I like this. If you changed your matrix
> > to flip the image side-to-side, though, so the ASCII art matches the
> > orientation of the output, it would be easier to use: 
> 
> 
> >   [-.1 0 0 .1 0 0] 
> 
> 
> Yes. That's much better. But I'm now thinking there's no
> advantage in leaving stuff on the stack and passing an 
> empty procedure (except perhaps in Level-1 interpreters).
> The image data might just as well be *in* the procedure.

Again, my comment here is wrong. But also,
the matrix needs to add an x-offset now, since 
it maps right-to-left. Otherwise it places the 
image with the origin at the bottom right corner.

    [-.1 0 0 .1 .1 0]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web