summaryrefslogtreecommitdiff
path: root/gs/base/gdevmem.c
diff options
context:
space:
mode:
authorHenry Stiles <henry.stiles@artifex.com>2009-08-10 23:29:24 +0000
committerHenry Stiles <henry.stiles@artifex.com>2009-08-10 23:29:24 +0000
commita488444271954b4f93a3978154c0a30294249ca5 (patch)
tree244a34926f959b37e6e7e3f4f994406cac40cb72 /gs/base/gdevmem.c
parentcab73292739afaf9768b7c0af9bf7556c92c20da (diff)
Adds a new memory device constructor
(gs_make_mem_device_with_copydevice) to replace gs_make_mem_device and fixes several device reference counting problems (leaks) which affected all the the client languages. No expected visual differences. git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@9968 a1074d23-0009-0410-80fe-cf8c14f379e6
Diffstat (limited to 'gs/base/gdevmem.c')
-rw-r--r--gs/base/gdevmem.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/gs/base/gdevmem.c b/gs/base/gdevmem.c
index 34caa98d3..e2fa76207 100644
--- a/gs/base/gdevmem.c
+++ b/gs/base/gdevmem.c
@@ -180,6 +180,67 @@ gs_make_mem_device(gx_device_memory * dev, const gx_device_memory * mdproto,
dev->band_y = 0;
}
+/* Make a memory device using copydevice, this should replace gs_make_mem_device. */
+/* Note that the default for monobit devices is white = 0, black = 1. */
+int
+gs_make_mem_device_with_copydevice(gx_device_memory ** ppdev,
+ const gx_device_memory * mdproto,
+ gs_memory_t * mem,
+ int page_device,
+ gx_device * target)
+{
+ int code;
+ gx_device_memory *pdev;
+
+ if (mem == 0)
+ return -1;
+
+ code = gs_copydevice((gx_device **)&pdev,
+ (const gx_device *)mdproto,
+ mem);
+ if (code < 0)
+ return code;
+
+ switch (page_device) {
+ case -1:
+ set_dev_proc(pdev, get_page_device, gx_default_get_page_device);
+ break;
+ case 1:
+ set_dev_proc(pdev, get_page_device, gx_page_device_get_page_device);
+ break;
+ }
+ /* Preload the black and white cache. */
+ if (target == 0) {
+ if (pdev->color_info.depth == 1) {
+ /* The default for black-and-white devices is inverted. */
+ pdev->cached_colors.black = 1;
+ pdev->cached_colors.white = 0;
+ } else {
+ pdev->cached_colors.black = 0;
+ pdev->cached_colors.white = (1 << pdev->color_info.depth) - 1;
+ }
+ } else {
+ gx_device_set_target((gx_device_forward *)pdev, target);
+ /* Forward the color mapping operations to the target. */
+ gx_device_forward_color_procs((gx_device_forward *) pdev);
+ gx_device_copy_color_procs((gx_device *)pdev, target);
+ pdev->cached_colors = target->cached_colors;
+ }
+ if (pdev->color_info.depth == 1) {
+ gx_color_value cv[3];
+
+ cv[0] = cv[1] = cv[2] = 0;
+ gdev_mem_mono_set_inverted(pdev, (target == 0 ||
+ (*dev_proc(pdev, map_rgb_color))((gx_device *)pdev, cv) != 0));
+ }
+ check_device_separable((gx_device *)pdev);
+ gx_device_fill_in_procs((gx_device *)pdev);
+ pdev->band_y = 0;
+ *ppdev = pdev;
+ return 0;
+}
+
+
/* Make a monobit memory device using copydevice */
int
gs_make_mem_mono_device_with_copydevice(gx_device_memory ** ppdev, gs_memory_t * mem,