diff options
Diffstat (limited to 'base/gdevmem.c')
-rw-r--r-- | base/gdevmem.c | 65 |
1 files changed, 43 insertions, 22 deletions
diff --git a/base/gdevmem.c b/base/gdevmem.c index 7b158a0e..95da5d6c 100644 --- a/base/gdevmem.c +++ b/base/gdevmem.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2019 Artifex Software, Inc. +/* Copyright (C) 2001-2020 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -83,8 +83,8 @@ const gs_const_string mem_mono_w_b_palette = { /* ------ Generic code ------ */ /* Return the appropriate memory device for a given */ -/* number of bits per pixel (0 if none suitable). - Greater than 64 occurs for the planar case +/* number of bits per pixel (0 if none suitable). + Greater than 64 occurs for the planar case which we will then return a mem_x_device */ static const gx_device_memory *const mem_devices[65] = { 0, &mem_mono_device, &mem_mapped2_device, 0, &mem_mapped4_device, @@ -161,7 +161,7 @@ gs_make_mem_device(gx_device_memory * dev, const gx_device_memory * mdproto, break; } /* Preload the black and white cache. */ - if (target == 0) { + if (target == NULL) { if (dev->color_info.depth == 1) { /* The default for black-and-white devices is inverted. */ dev->cached_colors.black = 1; @@ -192,7 +192,7 @@ gs_make_mem_device(gx_device_memory * dev, const gx_device_memory * mdproto, cv[k] = 0; } } - gdev_mem_mono_set_inverted(dev, (target == 0 || + gdev_mem_mono_set_inverted(dev, (target == NULL || (*dev_proc(dev, encode_color))((gx_device *)dev, cv) != 0)); } check_device_separable((gx_device *)dev); @@ -212,7 +212,7 @@ gs_make_mem_device_with_copydevice(gx_device_memory ** ppdev, int code; gx_device_memory *pdev; - if (mem == 0) + if (mem == NULL) return -1; code = gs_copydevice((gx_device **)&pdev, @@ -230,7 +230,7 @@ gs_make_mem_device_with_copydevice(gx_device_memory ** ppdev, break; } /* Preload the black and white cache. */ - if (target == 0) { + if (target == NULL) { if (pdev->color_info.depth == 1) { /* The default for black-and-white devices is inverted. */ pdev->cached_colors.black = 1; @@ -252,7 +252,7 @@ gs_make_mem_device_with_copydevice(gx_device_memory ** ppdev, gx_color_value cv[3]; cv[0] = cv[1] = cv[2] = 0; - gdev_mem_mono_set_inverted(pdev, (target == 0 || + gdev_mem_mono_set_inverted(pdev, (target == NULL || (*dev_proc(pdev, encode_color))((gx_device *)pdev, cv) != 0)); } check_device_separable((gx_device *)pdev); @@ -270,7 +270,7 @@ gs_make_mem_mono_device_with_copydevice(gx_device_memory ** ppdev, gs_memory_t * int code; gx_device_memory *pdev; - if (mem == 0) + if (mem == NULL) return -1; code = gs_copydevice((gx_device **)&pdev, @@ -436,12 +436,19 @@ mem_open(gx_device * dev) int gdev_mem_open_scan_lines(gx_device_memory *mdev, int setup_height) { + return gdev_mem_open_scan_lines_interleaved(mdev, setup_height, 0); +} +int +gdev_mem_open_scan_lines_interleaved(gx_device_memory *mdev, + int setup_height, + int interleaved) +{ bool line_pointers_adjacent = true; ulong size; if (setup_height < 0 || setup_height > mdev->height) return_error(gs_error_rangecheck); - if (mdev->bitmap_memory != 0) { + if (mdev->bitmap_memory != NULL) { int align; /* Allocate the data now. */ if (gdev_mem_bitmap_size(mdev, &size) < 0) @@ -451,7 +458,7 @@ gdev_mem_open_scan_lines(gx_device_memory *mdev, int setup_height) return_error(gs_error_limitcheck); mdev->base = gs_alloc_bytes(mdev->bitmap_memory, (uint)size, "mem_open"); - if (mdev->base == 0) + if (mdev->base == NULL) return_error(gs_error_VMerror); #ifdef PACIFY_VALGRIND /* If we end up writing the bitmap to the clist, we can get valgrind errors @@ -463,14 +470,14 @@ gdev_mem_open_scan_lines(gx_device_memory *mdev, int setup_height) align = 1<<mdev->log2_align_mod; mdev->base += (-(int)(intptr_t)mdev->base) & (align-1); mdev->foreign_bits = false; - } else if (mdev->line_pointer_memory != 0) { + } else if (mdev->line_pointer_memory != NULL) { /* Allocate the line pointers now. */ mdev->line_ptrs = (byte **) gs_alloc_byte_array(mdev->line_pointer_memory, mdev->height, sizeof(byte *) * (mdev->is_planar ? mdev->color_info.num_components : 1), "gdev_mem_open_scan_lines"); - if (mdev->line_ptrs == 0) + if (mdev->line_ptrs == NULL) return_error(gs_error_VMerror); mdev->foreign_line_pointers = false; line_pointers_adjacent = false; @@ -478,7 +485,7 @@ gdev_mem_open_scan_lines(gx_device_memory *mdev, int setup_height) if (line_pointers_adjacent) { int code; - if (mdev->base == 0) + if (mdev->base == NULL) return_error(gs_error_rangecheck); code = gdev_mem_bits_size(mdev, mdev->width, mdev->height, &size); @@ -488,7 +495,9 @@ gdev_mem_open_scan_lines(gx_device_memory *mdev, int setup_height) mdev->line_ptrs = (byte **)(mdev->base + size); } mdev->raster = gx_device_raster((gx_device *)mdev, 1); - return gdev_mem_set_line_ptrs(mdev, NULL, 0, NULL, setup_height); + return gdev_mem_set_line_ptrs_interleaved(mdev, NULL, 0, NULL, + setup_height, + interleaved); } /* * Set up the scan line pointers of a memory device. @@ -497,13 +506,21 @@ gdev_mem_open_scan_lines(gx_device_memory *mdev, int setup_height) * num_planes, plane_depths, plane_depth. */ int -gdev_mem_set_line_ptrs(gx_device_memory * mdev, byte * base, int raster, +gdev_mem_set_line_ptrs(gx_device_memory *mdev, byte *base, int raster, byte **line_ptrs, int setup_height) { + return gdev_mem_set_line_ptrs_interleaved(mdev, base, raster, line_ptrs, setup_height, 0); +} +int +gdev_mem_set_line_ptrs_interleaved(gx_device_memory * mdev, byte * base, + int raster, byte **line_ptrs, + int setup_height, int interleaved) +{ int num_planes = (mdev->is_planar ? mdev->color_info.num_components : 0); byte **pline; byte *data; int pi; + int plane_raster; /* If we are supplied with line_ptrs, then assume that we don't have * any already, and take them on. */ @@ -539,6 +556,10 @@ gdev_mem_set_line_ptrs(gx_device_memory * mdev, byte * base, int raster, num_planes = 1; } + if (interleaved) + plane_raster = raster, raster *= num_planes; + else + plane_raster = raster * mdev->height; for (pi = 0; pi < num_planes; ++pi) { byte **pptr = pline; byte **pend = pptr + setup_height; @@ -548,7 +569,7 @@ gdev_mem_set_line_ptrs(gx_device_memory * mdev, byte * base, int raster, *pptr++ = scan_line; scan_line += raster; } - data += raster * mdev->height; + data += plane_raster; pline += setup_height; /* not mdev->height, see gxdevmem.h */ } @@ -610,7 +631,7 @@ mem_get_bits_rectangle(gx_device * dev, const gs_int_rect * prect, GB_PACKING_CHUNKY | GB_COLORS_NATIVE | GB_ALPHA_NONE; return_error(gs_error_rangecheck); } - if (mdev->line_ptrs == 0x00) + if (mdev->line_ptrs == NULL) return_error(gs_error_rangecheck); if ((w <= 0) | (h <= 0)) { if ((w | h) < 0) @@ -678,10 +699,10 @@ mem_swap_byte_rect(byte * base, uint raster, int x, int w, int h, bool store) bits32 *pw = (bits32 *) row; do { - bits32 w = *pw; + bits32 v = *pw; - *pw++ = (w >> 24) + ((w >> 8) & 0xff00) + - ((w & 0xff00) << 8) + (w << 24); + *pw++ = (v >> 24) + ((v >> 8) & 0xff00) + + ((v & 0xff00) << 8) + (v << 24); } while (--nx); } @@ -715,7 +736,7 @@ mem_word_get_bits_rectangle(gx_device * dev, const gs_int_rect * prect, bit_x = x * dev->color_info.depth; bit_w = w * dev->color_info.depth; - if(mdev->line_ptrs == 0x00) + if(mdev->line_ptrs == NULL) return_error(gs_error_rangecheck); src = scan_line_base(mdev, y); |