summaryrefslogtreecommitdiff
path: root/base/gsdevice.c
Commit message (Collapse)AuthorAgeFilesLines
* Bug 705217: Fix bad length in gx_device_delete_output_file.Robin Watts2022-06-011-3/+3
| | | | | We were failing to allow for the terminator in a gs_snprintf call. Thanks to Ken for the analysis and fix.
* Move base files away from gs_sprintf to gs_snprintf.Robin Watts2022-02-161-8/+10
|
* Add psdcmyktags and psdcmyktags16 devicesMichael Vhrel2022-01-111-6/+2
| | | | | | | | | | | | | | | | Add example tags devn devices, both 8 and 16 bit. The tags plane is always placed as the last plane in the data (i.e it follows any spots that get added). Changes were made to remove tags conditionals in the planar memory device code, since it really should not care what the extra planes are used for and it should not add components to the device based upon the tags support. The target device should handle any of this sort of setup. There were also some changes needed in the pdf14 code, as the tags information was not getting properly communicated when we had knockout objects and devn colors. Also, fix various whitespace issues.
* Runtime safety of non threadsafe devices and rework globals.Robin Watts2021-11-051-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some devices within Ghostscript (currently the x11 devices, uniprint and opvp/oprp) use non const static variables, so cannot be run in multiple instances at a time. We now maintain a core "count" of how many non-threadsafe devices are being used at any time. This value can be atomically adjusted by calls to gs_lib_ctx_nts_adjust. Non threadsafe devices now call gx_init_non_threadsafe_device either as or as part of their initialise_device proc. This function attempts to increment the non-threadsafe count and fails to init if there is already a non-threadsafe device running. On success, the device finalize method is modified so that it will decrement the count at the end. The known non-threadsafe devices are updated to call this. In order to have somewhere safe to store this count, we introduce a gs_globals structure, shared between instances. Setting this up without race conditions requires some new gp_ functions that can make use of platform specific threading primitives. We have these implemented for both windows and pthread based platforms. On other platforms, we drop back to the old unsafe mechanism for counting instances. While we do this work, we take the opportunity to push the gs_memory_t pointer used for non-threadsafe debug printing into thread local storage. This enables us to remove the remaining GS_THREADSAFE guarded compilation from the source code. What is left is broadly down to allowing debugging collection for statistics, and these are now controlled by specific COLLECT_STATS_XXX defines. It is assumed that anyone wanting to collect such stats is smart enough to not try to do so while using Ghostscript in a multi-instance environment.
* Bug697978: Replace tiffsep1 to support object type specific halftoning.Ray Johnston2021-08-221-6/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation rendered contone (as tiffsep does) then used threshold array based halftoning on the entire image, which used more memory (or a greater number of bands). This version renders to 1-bit planes which allows object type specific halftones to be supported as well as allowing PDF or PS to change halftones any number of times on a page, as is allowed for by the language (although defined as "implementation dependent"). This version is much more useful as a RIP for generating plates and fixes some problems raised by customer 162. Also add a #define PPM_COMBINED_OUTPUT to allow comparison to pkmraw output (disabled by default). Development discovered several places that assumed that DeviceN devices would be 8 or more bits per component, and gdev_mem_set_planar_interleaved planar setup needs to avoid using the mem_planar_put_image proc. NB: Transparency is necessarily performed in contone buffers, so any object type specific halftone is lost -- the transparency page will be halftoned during 'put_image' using the default halftone in effect when the put_image occurs. Thus, changing the halftone while constructing the page only works for pages without transparency. A future enhancement would be to use the tags when the page uses transparency, then use those tags in a custom "put_image" procedure (the normal default 'put_image' method that creates a typed image does not deal with the tags plane. Possible enhancements for performance optimization are: 1. Implement alternative halftone color routines for planar devices so we don't need to construct chunky multi-component (e.g. CMYK) tiles, only to then extract and pack the bits from the tile for writing the planes. 2. Implement a mem_planar_put_image for halftoned devices that uses the optimized threshold based method similar to the monochrome image code (which uses CAL if available).
* Fix SEGV seen with ps3cet/09-59.PS and the ijs deviceRay Johnston2021-08-201-1/+1
| | | | | The ijs device initialize_device proc allocates memory, thus the dev->memory must be set up prior to this call in gx_device_init.
* Remove "unread" param from get_bits_rectangle.Robin Watts2021-07-011-1/+1
| | | | No one sets it. No one reads it. It's pointless, so excise it.
* Rename opmode to opmsupported, and tweak operation.Robin Watts2021-05-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | First off, we rename 'opmode' to 'opmsupported'. opmode does NOT mean the same as OPM in PDF, but rather indicates whether OPM can be supported on a given device or not. Renaming should solve this confusion. On creation of a device dev->color_info.opmsupported is set to GX_CINFO_OPMSUPPORTED_UNKNOWN. The idea is that this UNKNOWN value should be resolved to either 0 or 1 (OPMSUPPORTED_NOT or OPMSUPPORTED) before it is used. This requires code to check for it being unknown, and if it is, call a function to resolve it. We have found at least one place in the code where this fails to happen properly. To protect against this happening elsewhere, we introduce a gx_get_opmode function that performs this "Is it unknown? If so resolve. Read value." dance for us. By insisting that we always call this rather than accessing directly, we harden ourselves against missing cases. This produces a far few diffs, all of which look like progressions to me.
* Remove get_bits in favour of get_bits_rectangle.Robin Watts2021-05-031-2/+20
|
* Split initialize device proc into two.Robin Watts2021-04-261-7/+10
| | | | | | | | | | | | | | | | | The device initialize function currently performs 2 jobs. Firstly, it fills out the device_procs. Secondly, it performs any minimal initialization required by the device (typically none). At various points in the code we want to be able to copy procs from one 'prototype' device to another, so we call initialize for that. This populates the device procs, but does other work that typically requires a 'derived device' structure rather than a vanilla gx_device to work in. Accordingly, we split the job into two; initialize_device_procs (the first part) and initialize_device (the second part). The initialize_device_procs function will set up the initialize_device function pointer along with the rest if required.
* Remove obsolete get_xfont_{procs,device} device proc.Robin Watts2021-04-201-1/+1
|
* Remove obsolete pattern_manage dev proc.Robin Watts2021-04-201-1/+0
|
* Further rationalisation of device init.Robin Watts2021-04-201-8/+4
| | | | | | | | | | Move the initialize procedure out of the device procs table, and into a bare function pointer at the start of the device proc. Devices just initialise this, and the rest should fall into place. This means changes to the device instantion macros (and all the uses thereof), but makes the code nicer overall. In particular, this removes the vestigial 'static_procs' structure.
* Move devices away from static init of procs.Robin Watts2021-04-201-10/+25
|
* Remove gx_device_set_procs.Robin Watts2021-04-201-12/+4
| | | | | Move this to be done in gs_copydevice2 inline. None of the other calls ever achieve anything, so remove them.
* Rename finish_copydevice to initialize, and remove second param.Robin Watts2021-04-201-10/+8
| | | | | | | | | | | It used to be that finish_copydevice(dev, const old_dev) would be used to copy stuff from a prototype to a new instance of a device. Now, no copying is ever done. Also, it's a confusing name. Rename it to be 'initialize', which is clearer. Also, it should become even more appropriate in future, if we have this function be the one that is responsible for filling out the procs.
* Update copyright to 2021Chris Liddell2021-03-151-1/+1
|
* NupControl improvements to prevent save/restore problems.Ray Johnston2021-03-031-0/+4
| | | | | | | | | | | | | The NupControl string needs to be a reference counted to work with save/ restore, and when the parameter is changed the new value needs to be propagated to children devices. The structure containing the string is adpated (simplified slightly) from the PageList implementation. Note that the parents and children references must be included in the ref_count when the NupControl structure is updated (example if 'epo' is installed, when it uninstalls itself, cannot free the the structure when it does rc_decrement). Minor comment change to devices/gdevbit.c to change NupList to NupControl.
* Fix hang condition detected on Windows release build.Ray Johnston2021-02-111-1/+1
| | | | | | The NupControl commit changed 'gx_device_set_hwsize_from_media' to call the dev_spec_op of the parent device, but the body of the while loop to find the uppermost parent could hang.
* Implement Nup subclass device to support nesting images on a page.Ray Johnston2021-01-261-10/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By using a subclassing device to intercept a few of the device procs (get_initial_matrix, output_page, fillpage, put_params, close_device, and dev_spec_op) pages can be placed on to a page that is eventually output. This initial implementation scales the pages on the 'nest' as defined by -sNupControl parameter that is a string of the form "HxV" where H and V are integers controlling nesting across (H) and down (V) the page. All pages on the nest are the same size/orientation as the first page of the nest, and if a different PageSize is encountered, any pages on the current nest will be output before starting a new nest. In gx_device_set_hwsize_from_media dev_spec_op is used to prevent changing the device width and height (HWSize) for PageSize or .MediaSize params. This requires that the graphics library should not assume that HWSize is derived from PageSize and HWResolution, but it allows the intial clip_path for the nested pages to be set from the MediaSize, Margins, and HWMargins in gx_default_clip_box. There are a few files that have differences with the 'psdcmyk' devices when tested with -sNupControl=1x1: Bug688584.ps: Page 6 missing graphics,related to SeparationOrder usage. (a bug will be opened for this once this is committed). Bug692517.ps: subclass device barely switches to clist mode for 72.0 (don't care, page mode still works for larger MaxBitmap), tests_private/pdf/PDFIA1.7_SUBSET/CATX2975.pdf.ppmraw.300.0..gs (seems to be a progression on page 9)
* Improve memory device bitmap size calculation in tagged planar cases.Robin Watts2021-01-141-1/+4
| | | | | The planar calculations for memory device sizes were failing to take the presence of tags into account. Fix those calculations here.
* Fix compiler warningKen Sharp2020-11-271-1/+1
| | | | Explicitly cast gx_device_null pointer to a gx_device pointer.
* Ensure the nulldevice has a proper set of device methodsKen Sharp2020-11-261-0/+1
| | | | | | | | | | | gs_make_null_device uses the gs_null_device structure to create an instance of the nulldevice, but it did not call gx_device_fill_in_procs to set the device methods which are left as NULL in the declaration. Since all device methods (except fill_rectangle) are expected to be real functions, not NULL, many places in the code do not check that the device method is not NULL before calling it. This could (and in pdfi did) lead to us attempting to execute 0x00 causing seg faults.
* Fix pdfwrite "%d" mode with file permissionsChris Liddell2020-08-201-1/+1
| | | | | | | | | | | | | | | Firstly, in gx_device_delete_output_file the iodev pointer was being passed to the delete_method incorrectly (passing a pointer to that pointer). Thus when we attempted to use that to confirm permission to delete the file, it crashed. Credit to Ken for finding that. Secondly, due to the way pdfwrite works, when running with an output file per page, it creates the current output file immediately it has completed writing the previous one. Thus, it has to delete that partial file on exit. Previously, the output file was not added to the "control" permission list, so an attempt to delete it would result in an error. So add the output file to the "control" as well as "write" list.
* Ensure we can call dev_spec_op as soon as device is createdChris Liddell2020-07-291-0/+5
| | | | | | Since we can legitimately want to interrogate a device for its capabilities and preferences right from its creation, ensure the dev_spec_op is valid as soon as the device is created.
* Refactor gdev_space_params slightly.Robin Watts2020-06-251-0/+24
| | | | | | | | | | | | | | The gdev_space_params structure is also known as gdev_prn_space_params, which is slightly misleading as there is nothing prn specific about it. Rename all uses of gdev_prn_space_params within the code to be gdev_space_params. Leave gdev_prn_space_params defined as a typedef so that any customer code will not be affected. Rename compare_gdev_prn_space_params to be gdev_space_params_cmp to better reflect its non-prn-specific nature. Make it non-static and move it to gsdevice.c.
* Rework display device "DisplayHandle" passing.Robin Watts2020-06-251-0/+6
| | | | | | | | | | | | | | | | | | | | | Add gsapi_{,de}register_callout API. This allows integrators to register handlers for "callouts" from gs devices. The first example of such a callout is the display device. Previously, this has relied on the gsapi_set_display_callback API to pass a pointer to a structure into the core, from where it was hackily poked into the display device structure. Instead, we now have the display device "callout" to registered handlers to get the structure and the handle to use. The legacy API is maintained by the API level implementing a handler to return the display callback in response to the devices callout. The code to do the 'poking' of the display device has therefore been removed, and replaced by code that checks to see if an opened device needs reopening after init, if so, opens/closes it.
* Update copyright to 2020Chris Liddell2020-04-101-1/+1
|
* Squashed commit fill-stroke3 branchMichael Vrhel2020-01-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | This branch had several contributors including Robin Watts, Ken Sharp and Ray Johnston. The intent was to add a "fill and stroke" path device method to ensure we get proper rendering when doing fill/stroke methods with overprint and transparency. In addition, adding the method made it possible for pdfwrite to match the original pdf source file if it also had fill/stroke methods. The interaction with overprint and transparency led to significant changes in parts of the code related to those sections. In particular, overprint was reworked to ensure that the overprint compositor and the transparency compositor were aware if it was to be using the overprint drawn_comps for stroke or for fill. The code was rewritten so that the overprint compositor actions only occurred when an actual operation occurred (e.g. fill, stroke, image, text) as opposed to every time that the overprint graphic state values changed. When there is a fill-stroke operation with transparency, depending upon the graphic state values, a non-isolated knockout group may be pushed. From this, an issue with knockout groups within knockout groups was revealed, which was related to the backdrop selection. The backdrop selection code was simplified.
* Remove spurious call to gp_validate_path_len()...Chris Liddell2019-09-241-4/+1
| | | | | | | | | | | | ...in gx_device_open_output_file() There is no need to validate the path in gx_device_open_output_file() as it will be done at a lower level (gp_fopen) for paths that require it (we only validate *after* the Postscript style %device% paths have been expanded into 'real' paths). This also interacts badly with the revised handling of formatted string file names, hence remove it.
* Add gsapi call to introduce new 'Filing Systems' to gs.Robin Watts2019-07-021-1/+1
| | | | Still to do - Example?
* Move FILE * operations behind new gp_file * API.Robin Watts2019-05-291-5/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (squash of commits from filesec branch) Most of this commit is donkeywork conversions of calls from FILE * -> gp_file *, fwrite -> gp_fwrite etc. Pretty much every device is touched, along with the clist and parsing code. The more interesting changes are within gp.h (where the actual new API is defined), gpmisc.c (where the basic implementations live), and the platform specific levels (gp_mswin.c, gp_unifs.c etc where the platform specific implementations have been tweaked/renamed). File opening path validation All file opening routines now call a central routine for path validation. This then consults new entries in gs_lib_ctx to see if validation is enabled or not. If so, it validates the paths by seeing if they match. Simple C level functions for adding/removing/clearing paths, exposed through the gsapi level. Add 2 postscript operators for path control. <name> <string> .addcontrolpath - Add the given <string> (path) to the list of paths for controlset <name>, where <name> can be: /PermitFileReading /PermitFileWriting /PermitFileControl (Anything else -> rangecheck) - .activatepathcontrol - Enable path control. At this point PS cannot make any more changes, and all file access is checked.
* Update source/header file copyright notice to 2019Chris Liddell2019-01-161-1/+1
|
* Bug 697545 : Prevent SEGV when no graphic state is saved.Shailesh Mistry2019-01-111-3/+5
| | | | | | | Prevent SEGV if memory allocation fails leading to pgs->saved being NULL. Error created using :- MEMENTO_FAILAT=351 ./membin/gpcl6 -sDEVICE=pbmraw -dMaxBitmap=2000 -o /dev/null ./tests_private/pcl/pcl5cfts/fts.0270
* Fix for bug 692652: Prevent derefence of NULL if parsed.iodev == NULLRay Johnston2019-01-071-3/+3
| | | | Robin's suggestion seems reasonable to me.
* Commit of gpdl-shared-device branch.Chris Liddell2018-12-071-1/+1
| | | | | | | | | This commit is a squashed version of the gpdl-shared-device branch. Essentially this is a first version of the new language switching mechanism. This does not build as part as "all", but rather as "experimental" or "gpdl".
* Bug 699740: Better handle failing to set the nulldeviceChris Liddell2018-10-191-4/+15
| | | | | | | | | | When pushing the nulldevice, if gs_setdevice_no_erase() failed, that *could* mean we end up freeing the device referenced in the graphics state. If that happens, search back through the saved gstates to find the initial graphics state, and pull the initial device from there. This allows us to return a Fatal error code, and exit cleanly.
* Close a device before any other 'finalize' actionsChris Liddell2018-10-101-3/+5
| | | | | | | | | Previously, when a device object was being finalized, we were calling the device's own finalize method, and (possibly) freeing the reference counted icc data before calling gs_closedevice() to ensure the device is genuinely closed. Reorder the operations so closing the device is the *first* thing we do.
* Bug 697545 : Prevent SEGV in gs_setdevice_no_erase.Shailesh Mistry2018-10-031-2/+5
| | | | | | | Prevent SEGV if gsicc_init_iccmanager fails. Error created using :- MEMENTO_FAILAT=350 ./membin/gpcl6 -sDEVICE=pbmraw -dMaxBitmap=2000 -o /dev/null ./tests_private/pcl/pcl5cfts/fts.0070
* Bug 699654(2): preserve LockSafetyParams in the nulldeviceChris Liddell2018-08-251-1/+4
| | | | | | | | | | | | | | | The nulldevice does not necessarily use the normal setpagedevice machinery, but can be set using the nulldevice operator. In which case, we don't preserve the settings from the original device (in the way setpagedevice does). Since nulldevice does nothing, this is not generally a problem, but in the case of LockSafetyParams it *is* important when we restore back to the original device, when LockSafetyParams not being set is "preserved" into the post- restore configuration. We have to initialise the value to false because the nulldevice is used during initialisation (before any other device exists), and *must* be writable for that.
* Bug #699153 - fix cppcheck warningKen Sharp2018-03-261-2/+2
| | | | Also fix two tab whitespaces, convert to spaces.
* Remove unused variableKen Sharp2018-02-031-2/+0
| | | | another scanbuild warning
* remove some unused code - scanbuild warnings....Ken Sharp2018-02-021-17/+0
|
* Update copyright notice with new head office address.Ken Sharp2018-01-301-3/+3
| | | | | | | | | Also update copyright dates. Remove gs_cmdl.ps as we no longer use it, and remove its entry from psfiles.htm. Remove xfonts.htm as this feature (xfont support) is long, long gone.
* Bug 697545 : Fix memory leak in gs_copydevice2.Shailesh Mistry2018-01-231-1/+3
| | | | | | | Fix memory leak for allocation event number 673. Error created using :- MEMENTO_FAILAT=674 ./membin/gpcl6 -sDEVICE=ppmraw -o /dev/null ./pcl/examples/owl.pcl
* Bug 697545 : Fix memory leak in gs_nulldevice.Shailesh Mistry2018-01-211-3/+6
| | | | | | | Fix memory leak for allocation event number 355. Error created using :- MEMENTO_FAILAT=356 ./membin/gpcl6 -sDEVICE=ppmraw -o /dev/null ./pcl/examples/owl.pcl
* Device method repair - use accessors throughoutKen Sharp2017-11-161-3/+3
| | | | | A lot of places accessed device methods directly, instead of using the accessor macros. Update all the code to use the accessors.
* Repair the device API - device methods should never be NULLKen Sharp2017-11-161-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original intention of the device API was that device methods (with the odd exception of fill_rectangle) must not be NULL. That appears to have been broken with the introduction of the transparency compositor, with the result that the code now: 1) has to check for methods being NULL sometimes, because that causes crashes. 2) Uses a device method being NULL to determine code paths. We want to return the device method design, because having to check for NULL methods before calling is wasteful. In this commit: define default methods for all the methods that previously did not have one. Modify gx_device_fill_in_procs to include those defaults in the device methods which it checks for NULL and replaces. Finding all the places where the code path differs if a device method is NULL, alter to check against the default method instead. Remove NULL checks where they are no longer required. Device whose 'procs' get copied directly (clist) must have defaults for all methods. Fix gx_copy_device_procs so that we only special case (don't replace the method) for those few methods where it matters that the subclassing device must have the default method if the subclassed device does. Long term we should change the code not to rely on this! Remove a couple of macros that were not required or plain dumb.
* More fixes for tag plane problems.Ray Johnston2017-04-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | tests_private/comparefiles/Altona_Technical_v20_x4.pdf Page 7 had a problem in blending when nos_knockout was true that ignored the tag. This also showed up cases where the alt_dev_color was not updated with the tag (e.g. tests_private/comparefiles/0000728-simpleNG.pdf). Another difference that tests_private/comparefiles/Bug689761.pdf shows is that "gsave fill grestore stroke" reverts the dev_color with grestore, but doesn't change the dev->graphics_type_tag. Keep the tag in the dev_color structure so that we know if the dev_color needs unset. Fix the ensure_tag_is_set inline function to make sure BOTH the device's graphics_type_tag AND the dev_color.tag are set correctly. We need to write and read the pattern tag plane for raster patterns with transparency. Seen with tests_private/comparefiles/Bug689422.pdf Lastly, the ensure_tag_is_set in gs_shfill needs to happen before the remap_color (since it may unset the dev_color if the tag was different).
* Remove MarginsHWResolution non-standard device parameterRay Johnston2016-12-021-3/+2
|