我们已经具备了使用postscript解释器xpost作为库的基本功能。我想征求社区对API设置的一些反馈。这个名为xpost_client.c的示例程序演示了将一个小的EPS光栅化为792x612BGR缓冲区的API,然后将其作为ASCII文件转储到一个文件中(因此您可以使用文本编辑器检查它)。
/*
This is a simple example of a client calling xpost as a library
with a postscript program, desiring the raster data of the
generated image.
TODO:
define buffer interchange type
*/
#include <stdlib.h>
#include <stdio.h>
#include "xpost.h"
#include "xpost_memory.h"
#include "xpost_object.h"
#include "xpost_context.h"
#include "xpost_interpreter.h"
char *prog =
"%%BoundingBox: 200 300 400 500\n"
"300 400 100 0 360 arc\n"
"fill\n"
"showpage\n";
int main() {
void *buffer_type_object;
xpost_init();
xpost_create("bgr",
XPOST_OUTPUT_BUFFEROUT,
&buffer_type_object,
XPOST_SHOWPAGE_RETURN,
1);
xpost_run(XPOST_INPUT_STRING, prog);
{
unsigned char *buffer = buffer_type_object;
int i,j;
FILE *fp = fopen("xpost_client_out.ppm", "w");
fprintf(fp, "P3\n612 792\n255\n");
for (i=0; i<792; i++) {
for (j=0; j<612; j++) {
unsigned int red, green, blue;
red = *buffer++;
green = *buffer++;
blue = *buffer++;
++buffer;
fprintf(fp, "%d ", red);
fprintf(fp, "%d ", green);
fprintf(fp, "%d ", blue);
if ((j%20)==0)
fprintf(fp, "\n");
}
fprintf(fp, "\n");
}
fclose(fp);
}
xpost_destroy();
free(buffer_type_object);
xpost_quit();
return 0;
} 目前只有bgr设备提供OUTPUT_BUFFEROUT选项。C代码假设PS程序包含一个showpage来触发缓冲区的复制。没有展示::你的缓冲区是个垃圾指针,伙计。
我确实计划将辅助头扫描到一个"xpost.h"头文件中。但这是你目前需要的最高层的完整列表。
一个明显的缺陷是目前无法设置几何图形或分辨率。它是每像素1点,就是这样。它目前也是硬编码的字母尺寸,(对不起,世界其他地方)。有没有人想过在高层最好的接口方式?
库用户可能需要的其他选项吗?缓冲区类型的struct需要比高度、宽度和步幅更高的东西吗?stride应该计数单词还是字节?
在unixes,Cygwin和mingw中,你可以
hg clone https://luser.droog@code.google.com/p/xpost/ 然后阅读安装内容,但快速版本是
./configure
make
sudo make install 然后你就可以跑了
xpost_client 在xpost_client_out.ppm中生成一个填充圆的(buggy)渲染,在Gimp中为我加载ok。
该程序还可以在线浏览:
http://code.google.com/p/xpost/source/browse/src/bin/xpost_client.c
http://code.google.com/p/xpost/source/browse/src/lib/xpost.h
http://code.google.com/p/xpost/source/browse/src/lib/xpost_memory.h
http://code.google.com/p/xpost/source/browse/src/lib/xpost_object.hhttp://code.google.com/p/xpost/source/browse/src/lib/xpost_context.h
http://code.google.com/p/xpost/source/browse/src/lib/xpost_interpreter.h
注意:我还将此代码发布到comp.lang.postscript,以进行更多的讨论式讨论。
还要注意:解释器在名为gmemXXXXXX lmemXXXXXX xdumpXXXXXX的当前目录中生成临时文件(其中XXXXXX是系统生成的唯一文件名序列),这可能不必要地积累磁盘空间。它们必须定期手动移除。而且要小心代码,这些代码可能会对堆栈进行无限的推送,lmemXXXXXX可能会变得非常大,以容纳一个巨大的堆栈。
发布于 2014-10-08 07:37:54
基于这两行…
xpost_create("bgr",XPOST_OUTPUT_BUFFEROUT,&buffer_type_object,XPOST_SHOWPAGE_RETURN,1);xpost_run(XPOST_INPUT_STRING,prog);
我对xpost_create()和xpost_run()之间的相互作用感到困惑。是否可以同时创建和使用多个xpost上下文?如果是这样的话,xpost_create()不应该返回某种将作为参数传递给xpost_run()的句柄吗?或者,如果没有,那么我为什么要调用xpost_create()和xpost_destroy()呢?
我希望库的行为更像打印机,因为它会为每个showpage命令生成一个图像。实现该工作的一种方法是注册一个回调,每当遇到showpage时都会调用该回调。也许它可以将有关边界框的一些信息作为参数传递给回调,因为必须猜测或硬编码这些信息是不合理的。
奇怪的是,颜色模型被称为"bgr",但像素值在输出缓冲区中按相反的顺序排列(红色、绿色、蓝色)。我还会考虑将缓冲区作为
typedef {
int red;
int green;
int blue;
} struct pixel;…而不是单独的red、green和blue整数。
您的示例客户端似乎没有显示任何错误处理能力。例如,如果PostScript解释器有堆栈下流,会发生什么情况?
https://codereview.stackexchange.com/questions/65061
复制相似问题