.pbm文件图像渲染-[vhold] scanline-wiggles? [英] .pbm file image render - [vhold] scanline-wiggles?

查看:131
本文介绍了.pbm文件图像渲染-[vhold] scanline-wiggles?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试破解一个程序,以读取pbm,pgm或ppm文件,并使用 image 运算符将该图像渲染到Postscript输出设备中。只是测试 P4 输入(二进制可移植(1位)位图)路径,但我的输出却很麻烦。

I'm trying to hack-up a program to read a pbm, pgm, or ppm file and render the image to the postscript output device using the image operator. Just testing the P4 input (binary portable (1-bit) bitmap) path, but my output is all screwy.

%!
% cf. http://en.wikipedia.org/wiki/Netpbm_format
% cf. http://en.wikipedia.org/wiki/Computer_Graphics (origin of image)
% $ wget http://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Spacewar%21-PDP-1-20070512.jpg/320px-Spacewar%21-PDP-1-20070512.jpg
% $ convert 320px-Spacewar%21-PDP-1-20070512.jpg spacewar.pbm
% $ convert 320px-Spacewar%21-PDP-1-20070512.jpg spacewar.pgm
% $ convert 320px-Spacewar%21-PDP-1-20070512.jpg spacewar.ppm

/filename (spacewar.pbm) def
%/filename (spacewar.pgm) def
%/filename (spacewar.ppm) def

/infile filename (r) file def
/readscale false def

% Read magic number
infile token pop <<
    /P1 { /depth 1 def
        /readscale false def
        /filetype /ascii def }
    /P2 { /depth 8 def
        /readscale true def
        /filetype /ascii def }
    /P3 { /depth 24 def
        /readscale true def
        /filetype /ascii def }
    /P4 { /depth 1 def
        /readscale false def
        /filetype /binary def }
    /P5 { /depth 8 def
        /readscale true def
        /filetype /binary def }
    /P6 { /depth 24 def
        /readscale true def
        /filetype /binary def }
>> exch 2 copy known not{pop/default}if get exec

% Read header
/buf 256 string def
infile buf readline pop % line
(1:)print dup ==
(#) { % line (#)
    (2a:)print 1 index =
    search { % post (#) pre
        pop pop pop %
        infile buf readline pop % (#) next-line
        (#) % next-line (#)
        (2b pstack\n)print pstack()=
    }{ % line
        (2c:)print dup ==
        exit
    } ifelse
} loop % line
pstack()=
token pop /height exch def
token pop /width exch def
readscale {
    token pop /scale exch def
}{
    pop
}ifelse
/buf width
    depth mul
    8 div ceiling cvi
    string def
(bufsize: )print buf length =
/pad
    buf length 8 mul
    width sub def
(pad: )print pad =

/readdata <<
    /ascii { % file buf
        0 1 width 1 sub { % file buf i
            2 index token pop % file buf i
        } for
    }
    /binary { % file buf
        readstring pop
        %dup length 0 ne { 0 1 index length pad sub getinterval } if
        dup == flush
        %(bin)= flush
    }
>> filetype get def
%errordict/rangecheck{pstack dup length = quit}put

width
height
depth 
[ 1 0 0 -1 0 height ]
{
    infile buf readdata
} image

showpage

我很确定问题出在我对行的字节宽度和预期填充的计算:

I'm pretty sure the problem is my calculation of the byte-width of a row and the expected padding:

/buf width
    depth mul
    8 div ceiling cvi
    string def
(bufsize: )print buf length =
/pad
    buf length 8 mul
    width sub def
(pad: )print pad =

但这似乎是正确的,当我逐步执行它时。对于这个215位宽的位图,每行可获得27个字节。

But that seems, right, when I step through it. For this 215-bit-wide bitmap, I get 27-bytes per row.

编辑:删除 pad -chop很有帮助。也许我需要添加额外填充?

Removing the "pad"-chop helps. Perhaps I need to add extra padding?

问题在输出中得到了证明:

The problem is demonstrated in the output:

此答案的末尾可以找到类似但更简单的程序。

Where the similar, but simpler program from the end of this answer renders ok.

推荐答案

哦,亲爱的,这真是愚蠢。

Oh, dearie me, that was stupid.

我碰了两行:

 55 token pop /width exch def
 56 token pop /height exch def

在我键入的最后一次编辑期间所有这些都传给我:

It all came to me during that last edit where I typed:


对于这215位宽位图,我每行得到27个字节。

For this 215-bit-wide bitmap, I get 27-bytes per row.

然后我再次查看 identify 输出。当然,215是高度,而不是宽度。

And then I looked again at the identify output. Sure enough, 215 is the height, not the width.

这篇关于.pbm文件图像渲染-[vhold] scanline-wiggles?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆