bmeps.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 886 行 · 第 1/2 页
C
886 行
fprintf(out, "/inputf\n currentfile\n");
if(bmeps_enc_a85) {
fprintf(out, " /ASCII85Decode filter\n");
} else {
fprintf(out, " /ASCIIHexDecode filter\n");
}
if(bmeps_enc_fl) {
fprintf(out, " /FlateDecode filter\n");
}
if(bmeps_enc_rl) {
fprintf(out, " /RunLengthDecode filter\n");
}
fprintf(out, "def\n");
}
if(show_dsc_comments) {
fprintf(out, "%%%%EndResource\n");
fprintf(out, "%%%%EndProlog\n");
fprintf(out, "%%%%BeginSetup\n");
fprintf(out, "%%%%EndSetup\n");
}
} else {
if(show_dsc_comments) {
fprintf(out, "%%%%BeginSetup\n");
}
if(bmeps_color) {
fprintf(out, "/DeviceRGB setcolorspace\n");
} else {
fprintf(out, "/DeviceGray setcolorspace\n");
}
if(show_dsc_comments) {
fprintf(out, "%%%%EndSetup\n");
}
}
if(show_dsc_comments) {
fprintf(out, "%%%%Page: Image%d 1\n", imageno++);
}
if(version_not_yet_printed) {
version_not_yet_printed = 0;
fprintf(out,
"%%\n%% created by bmp2eps %s \n%%\n",
the_version_number
);
}
fprintf(out, "gsave\n");
fprintf(out, "0 %lu translate\n", h);
fprintf(out, "%lu %lu scale\n", w, h);
if(use_trans && (bmeps_pslevel > 2)) {
fprintf(out, "<<\n");
fprintf(out, " /ImageType 3\n");
fprintf(out, " /DataDict\n <<\n");
fprintf(out, " /ImageType 1\n");
fprintf(out, " /Width %lu\n", w);
fprintf(out, " /Height %lu\n", h);
fprintf(out, " /ImageMatrix [%lu 0 0 -%lu 0 0]\n", w, h);
fprintf(out, " /MultipleDataSources false\n");
fprintf(out, " /DataSource\n currentfile");
if(bmeps_enc_a85) {
fprintf(out, "\n /ASCII85Decode filter");
} else {
fprintf(out, "\n /ASCIIHexDecode filter");
}
if(bmeps_enc_fl) {
fprintf(out, "\n /FlateDecode filter");
}
if(bmeps_enc_rl) {
fprintf(out, "\n /RunLengthDecode filter");
}
fprintf(out, "\n");
fprintf(out, " /BitsPerComponent 8\n");
if(bmeps_color) {
fprintf(out, " /Decode [ 0 1 0 1 0 1 ]\n");
} else {
fprintf(out, " /Decode [ 0 1 ]\n");
}
fprintf(out, " >>\n");
fprintf(out, " /MaskDict\n <<\n");
fprintf(out, " /ImageType 1\n");
fprintf(out, " /Width %lu\n", w);
fprintf(out, " /Height %lu\n", h);
fprintf(out, " /ImageMatrix [%lu 0 0 -%lu 0 0]\n", w, h);
fprintf(out, " /BitsPerComponent 8\n");
fprintf(out, " /Decode [ 0 1 ]\n");
fprintf(out, " >>\n");
fprintf(out, " /InterleaveType 1\n");
fprintf(out, ">>\nimage\n");
} else {
fprintf(out, "%lu %lu 8 [%lu 0 0 -%lu 0 0]\n",
w, h, w, h
);
if(bmeps_pslevel > 1) {
if(bmeps_color) {
fprintf(out, "{ inputf pstr readstring pop }\n");
fprintf(out, "false\n3\ncolorimage\n");
} else {
fprintf(out, "{ inputf pstr readstring pop }\n");
fprintf(out, "image\n");
}
} else {
fprintf(out, "{ currentfile pstr readhexstring pop }\n");
fprintf(out, "image\n");
}
}
{
int mode;
mode = 0;
if(bmeps_enc_a85) {
mode |= OE_ASC85;
}
if(bmeps_enc_rl) {
mode |= OE_RL;
}
oe_init(&bmepsoe, out, mode, 9, rlbuffer);
state = 1;
}
}
}
void bmeps_end_image(FILE *out)
{
if(out) {
if(state > 1) {
oe_byte_flush(&bmepsoe);
state = 0;
}
if(bmeps_pslevel > 1) {
if(bmeps_enc_a85) {
fprintf(out, "%s\n", "~>");
} else {
fprintf(out, "%s\n", ">");
}
}
fprintf(out, "grestore\n");
fprintf(out, "showpage\n");
}
}
void bmeps_draft(FILE *out, unsigned long w, unsigned long h)
{
if(show_dsc_comments) {
fprintf(out, "%%%%EndProlog\n");
fprintf(out, "%%%%Page: 1 1\n");
}
fprintf(out, "gsave\n");
fprintf(out, "0.75 setgray\n");
fprintf(out, "newpath\n");
fprintf(out, "0 0 moveto\n");
fprintf(out, "%lu 0 lineto\n", w);
fprintf(out, "%lu %lu lineto\n", w, h);
fprintf(out, "0 %lu lineto\n", h);
fprintf(out, "closepath\n");
fprintf(out, "fill\n");
fprintf(out, "1 setlinewidth\n");
fprintf(out, "0 setgray\n");
fprintf(out, "newpath\n");
fprintf(out, "1 1 moveto\n");
fprintf(out, "%lu 1 lineto\n", (w - 1UL));
fprintf(out, "%lu %lu lineto\n", (w - 1UL), (h - 1UL));
fprintf(out, "1 %lu lineto\n", (h - 1UL));
fprintf(out, "closepath\n");
fprintf(out, "stroke\n");
fprintf(out, "newpath\n");
fprintf(out, "1 1 moveto\n");
fprintf(out, "%lu %lu lineto\n", (w - 1UL), (h - 1UL));
fprintf(out, "stroke\n");
fprintf(out, "newpath\n");
fprintf(out, "1 %lu moveto\n", (h - 1UL));
fprintf(out, "%lu 1 lineto\n", (w - 1UL));
fprintf(out, "stroke\n");
fprintf(out, "grestore\n");
fprintf(out, "showpage\n");
}
typedef int FCT(FILE *out, FILE *in, char *name);
typedef int FCTWH(FILE *in, unsigned long *w, unsigned long *h);
typedef struct {
char *suffix;
FCT *fctrun;
FCT *fctbb;
FCTWH *wh;
char *xsuffix; /* for version printing */
}
HANDLERENTRY;
HANDLERENTRY handlers[] = {
{ "bmp", bmeps_bmp, bmeps_bmp_bb, bmeps_bmp_wh , "BMP" },
#ifdef HAVE_PNG_H
{ "png", bmeps_png, bmeps_png_bb, bmeps_png_wh , "PNG" },
#endif
{ NULL, NULL, NULL, NULL },
};
static char *get_suffix(char *name)
{
char *back = NULL;
char *ptr;
if(name) {
ptr = name;
while(*ptr) {
switch(*ptr) {
case '.': back = ptr; break;
case '/': back = NULL; break;
case '\\': back = NULL; break;
}
ptr++;
}
}
if(back) { back++; }
return back;
}
#define STRCASECMP(a,b) stricmp(a,b)
FCT *get_run_handler(char *name)
{
FCT *back = NULL;
if(name) {
char *suffix;
suffix = get_suffix(name);
if(suffix) {
HANDLERENTRY *he;
he = handlers;
while((he->suffix) && (back == NULL)) {
if( STRCASECMP(suffix,(he->suffix)) == 0 ) {
back = he->fctrun;
}
he++;
}
}
}
return back;
}
FCT *get_bb_handler(char *name)
{
FCT *back = NULL;
if(name) {
char *suffix;
suffix = get_suffix(name);
if(suffix) {
HANDLERENTRY *he;
he = handlers;
while((he->suffix) && (back == NULL)) {
if( STRCASECMP(suffix,(he->suffix)) == 0 ) {
back = he->fctbb;
}
he++;
}
}
}
return back;
}
FCTWH *get_wh_handler(char *name)
{
FCTWH *back = NULL;
if(name) {
char *suffix;
suffix = get_suffix(name);
if(suffix) {
HANDLERENTRY *he;
he = handlers;
while((he->suffix) && (back == NULL)) {
if( STRCASECMP(suffix,(he->suffix)) == 0 ) {
back = he->wh;
}
he++;
}
}
}
return back;
}
int bmeps_run(FILE *out, FILE *in, char *name)
{
int back = 0;
FCT *fct;
bmeps_configure();
fct = get_run_handler(name);
if(fct) {
back = (*fct)(out, in, name);
}
return back;
}
int bmeps_can_handle(char *name)
{
int back = 0;
FCT *fct;
fct = get_run_handler(name);
if(fct) {
back = 1;
}
return back;
}
int bmeps_run_bb(FILE *out, FILE *in, char *name)
{
int back = 0;
FCT *fct;
fct = get_bb_handler(name);
if(fct) {
back = (*fct)(out, in, name);
}
return back;
}
int bmeps_wh(FILE *in, char *name, unsigned long *w, unsigned long *h)
{
int back = 0;
FCTWH *fct;
fct = get_wh_handler(name);
if(fct) {
back = (*fct)(in, w, h);
}
return back;
}
void bmeps_version(FILE *out)
{
HANDLERENTRY *he;
char c, *p;
int issecond;
if(out) {
fprintf(out,
"%% libbmeps\tEPS output and bitmap conversion library %s %s\n",
the_version_number,
"(SCCS=1.65)"
);
fprintf(out, "%%\t\t(");
he = handlers; issecond = 0;
while(he->suffix) {
if(he->xsuffix) {
if(issecond) {
fprintf(out, ", ");
} else {
issecond = 1;
}
p = he->xsuffix;
while(*p) {
c = *p;
fprintf(out, "%c", ((islower(c)) ? toupper(c) : c));
p++;
}
}
he++;
}
fprintf(out, ")\n");
}
}
void bmeps_get_cfg(BmepsConfiguration *bcp)
{
if(bcp) {
bcp->psl = bmeps_get_pslevel();
bcp->col = bmeps_get_colored();
bcp->a85 = bmeps_get_enc_a85();
bcp->rl = bmeps_get_enc_rl();
bcp->fl = bmeps_get_enc_fl();
bcp->alpha = bmeps_get_alpha();
bcp->trans = bmeps_get_trans();
bcp->altrig = bmeps_get_altrig();
bcp->mix = bmeps_get_mix();
bcp->specbg = bmeps_get_specbg();
bcp->bg_red = bmeps_get_bg_red();
bcp->bg_green = bmeps_get_bg_green();
bcp->bg_blue = bmeps_get_bg_blue();
bcp->dsc_show = show_dsc_comments;
}
}
void bmeps_set_cfg(BmepsConfiguration *bcp)
{
if(bcp) {
bmeps_setup(
bcp->psl,
bcp->col,
bcp->a85,
bcp->rl,
bcp->fl,
bcp->alpha,
bcp->trans,
bcp->altrig,
bcp->mix,
bcp->specbg,
bcp->bg_red,
bcp->bg_green,
bcp->bg_blue,
bcp->dsc_show
);
}
}
void bmeps_copy_cfg(BmepsConfiguration *d, BmepsConfiguration *s)
{
if(d && s) {
d->psl = s->psl;
d->col = s->col;
d->a85 = s->a85;
d->rl = s->rl;
d->fl = s->fl;
d->alpha = s->alpha;
d->trans = s->trans;
d->altrig = s->altrig;
d->mix = s->mix;
d->specbg = s->specbg;
d->bg_red = s->bg_red;
d->bg_green = s->bg_green;
d->bg_blue = s->bg_blue;
d->dsc_show = s->dsc_show;
}
}
char bmeps_getpid_tmpname[32];
char bmeps_default_tmpname[] = { "BMP2EPS.TMP" };
static int configured_tmpname = 0;
char *bmeps_tmpname(void)
{
char *back = NULL;
back = bmeps_default_tmpname;
if(!configured_tmpname) {
configured_tmpname = 1;
sprintf(bmeps_getpid_tmpname, "BMP2EPS.%lu.TMP", ((unsigned long)getpid()));
}
back = bmeps_getpid_tmpname;
return back;
}
void bmeps_delete(char *filename)
{
if(filename) {
unlink(filename);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?