/* Copyright (C) 1989, 1992 Aladdin Enterprises. All rights reserved.
Distributed by Free Software Foundation, Inc.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
/* Device-related operators for GhostScript */
/* copy for devices -- called from zcopy in zgeneric.c. */
zcopy_device(register os_ptr op
)
int code
= gs_copydevice(&new_dev
, op
->value
.pdevice
, alloc
);
if ( code
< 0 ) return code
;
make_tv(op
, t_device
, pdevice
, new_dev
);
zcopyscanlines(register os_ptr op
)
check_type(*op2
, t_device
);
dev
= op2
->value
.pdevice
;
check_type(*op1
, t_integer
);
if ( op1
->value
.intval
< 0 || op1
->value
.intval
> dev
->height
)
check_write_type(*op
, t_string
);
code
= gs_copyscanlines(dev
, (int)op1
->value
.intval
,
op
->value
.bytes
, r_size(op
), NULL
, &bytes_copied
);
if ( code
< 0 ) return e_typecheck
; /* not a memory device */
r_set_size(op2
, bytes_copied
);
zcurrentdevice(register os_ptr op
)
{ gx_device
*dev
= gs_currentdevice(igs
);
make_tv(op
, t_device
, pdevice
, dev
);
zdevicename(register os_ptr op
)
check_type(*op
, t_device
);
dname
= gs_devicename(op
->value
.pdevice
);
code
= string_to_ref(dname
, op
, "devicename");
if ( code
< 0 ) return code
;
/* deviceinitialmatrix */
zdeviceinitialmatrix(register os_ptr op
)
{ int code
= write_matrix(op
);
if ( code
< 0 ) return code
;
check_type(op
[-1], t_device
);
gs_deviceinitialmatrix(op
[-1].value
.pdevice
, (gs_matrix
*)op
->value
.refs
);
zflushpage(register os_ptr op
)
{ return gs_flushpage(igs
);
zgetdevice(register os_ptr op
)
check_type(*op
, t_integer
);
if ( op
->value
.intval
!= (int)(op
->value
.intval
) )
return e_rangecheck
; /* won't fit in an int */
dev
= gs_getdevice((int)(op
->value
.intval
));
if ( dev
== 0 ) return e_rangecheck
; /* index out of range */
make_tv(op
, t_device
, pdevice
, dev
);
zmakeimagedevice(register os_ptr op
)
check_type(op
[-2], t_integer
); /* width */
check_type(op
[-1], t_integer
); /* height */
if ( r_has_type(op
, t_null
) ) /* true color */
num_colors
= -24; /* 24-bit true color */
{ check_type(*op
, t_string
); /* palette */
if ( r_size(op
) > 3*256 ) return e_rangecheck
;
colors
= op
->value
.bytes
;
if ( (ulong
)(op
[-2].value
.intval
) > max_uint
>> 1 ||
(ulong
)(op
[-1].value
.intval
) > max_uint
>> 1
if ( (code
= read_matrix(op
- 3, &imat
)) < 0 ) return code
;
/* Everything OK, create device */
code
= gs_makeimagedevice(&new_dev
, &imat
,
(int)op
[-2].value
.intval
,
(int)op
[-1].value
.intval
,
colors
, num_colors
, alloc
);
{ make_tv(op
- 3, t_device
, pdevice
, new_dev
);
znulldevice(register os_ptr op
)
zoutputpage(register os_ptr op
)
check_type(op
[-1], t_integer
);
check_type(*op
, t_boolean
);
code
= gs_output_page(igs
, (int)op
[-1].value
.intval
, op
->value
.index
);
if ( code
< 0 ) return code
;
zsetdevice(register os_ptr op
)
check_type(*op
, t_device
);
code
= gs_setdevice(igs
, op
->value
.pdevice
);
/* ------ Initialization procedure ------ */
op_def zdevice_op_defs
[] = {
{"3copyscanlines", zcopyscanlines
},
{"0currentdevice", zcurrentdevice
},
{"2deviceinitialmatrix", zdeviceinitialmatrix
},
{"1devicename", zdevicename
},
{"0flushpage", zflushpage
},
{"1getdevice", zgetdevice
},
{"4makeimagedevice", zmakeimagedevice
},
{"0nulldevice", znulldevice
},
{"2.outputpage", zoutputpage
},
{"1setdevice", zsetdevice
},