home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevmem.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  17.8 KB  |  582 lines

  1. /* Copyright (C) 1989, 1995, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevmem.c,v 1.2 2000/09/19 19:00:14 lpd Exp $ */
  20. /* Generic "memory" (stored bitmap) device */
  21. #include "memory_.h"
  22. #include "gx.h"
  23. #include "gserrors.h"
  24. #include "gsrect.h"
  25. #include "gsstruct.h"
  26. #include "gxarith.h"
  27. #include "gxdevice.h"
  28. #include "gxgetbit.h"
  29. #include "gxdevmem.h"        /* semi-public definitions */
  30. #include "gdevmem.h"        /* private definitions */
  31.  
  32. /* Structure descriptor */
  33. public_st_device_memory();
  34.  
  35. /* GC procedures */
  36. private 
  37. ENUM_PTRS_WITH(device_memory_enum_ptrs, gx_device_memory *mptr)
  38. {
  39.     return ENUM_USING(st_device_forward, vptr, sizeof(gx_device_forward), index - 3);
  40. }
  41. case 0: ENUM_RETURN((mptr->foreign_bits ? NULL : (void *)mptr->base));
  42. case 1: ENUM_RETURN((mptr->foreign_line_pointers ? NULL : (void *)mptr->line_ptrs));
  43. ENUM_STRING_PTR(2, gx_device_memory, palette);
  44. ENUM_PTRS_END
  45. private
  46. RELOC_PTRS_WITH(device_memory_reloc_ptrs, gx_device_memory *mptr)
  47. {
  48.     if (!mptr->foreign_bits) {
  49.     byte *base_old = mptr->base;
  50.     long reloc;
  51.     int y;
  52.  
  53.     RELOC_PTR(gx_device_memory, base);
  54.     reloc = base_old - mptr->base;
  55.     for (y = 0; y < mptr->height; y++)
  56.         mptr->line_ptrs[y] -= reloc;
  57.     /* Relocate line_ptrs, which also points into the data area. */
  58.     mptr->line_ptrs = (byte **) ((byte *) mptr->line_ptrs - reloc);
  59.     } else if (!mptr->foreign_line_pointers) {
  60.     RELOC_PTR(gx_device_memory, line_ptrs);
  61.     }
  62.     RELOC_CONST_STRING_PTR(gx_device_memory, palette);
  63.     RELOC_USING(st_device_forward, vptr, sizeof(gx_device_forward));
  64. }
  65. RELOC_PTRS_END
  66.  
  67. /* Define the palettes for monobit devices. */
  68. private const byte b_w_palette_string[6] = {
  69.     0xff, 0xff, 0xff, 0, 0, 0
  70. };
  71. const gs_const_string mem_mono_b_w_palette = {
  72.     b_w_palette_string, 6
  73. };
  74. private const byte w_b_palette_string[6] = {
  75.     0, 0, 0, 0xff, 0xff, 0xff
  76. };
  77. const gs_const_string mem_mono_w_b_palette = {
  78.     w_b_palette_string, 6
  79. };
  80.  
  81. /* ------ Generic code ------ */
  82.  
  83. /* Return the appropriate memory device for a given */
  84. /* number of bits per pixel (0 if none suitable). */
  85. private const gx_device_memory *const mem_devices[33] = {
  86.     0, &mem_mono_device, &mem_mapped2_device, 0, &mem_mapped4_device,
  87.     0, 0, 0, &mem_mapped8_device,
  88.     0, 0, 0, 0, 0, 0, 0, &mem_true16_device,
  89.     0, 0, 0, 0, 0, 0, 0, &mem_true24_device,
  90.     0, 0, 0, 0, 0, 0, 0, &mem_true32_device
  91. };
  92. const gx_device_memory *
  93. gdev_mem_device_for_bits(int bits_per_pixel)
  94. {
  95.     return ((uint)bits_per_pixel > 32 ? (const gx_device_memory *)0 :
  96.         mem_devices[bits_per_pixel]);
  97. }
  98. /* Do the same for a word-oriented device. */
  99. private const gx_device_memory *const mem_word_devices[33] = {
  100.     0, &mem_mono_device, &mem_mapped2_word_device, 0, &mem_mapped4_word_device,
  101.     0, 0, 0, &mem_mapped8_word_device,
  102.     0, 0, 0, 0, 0, 0, 0, 0 /*no 16-bit word device*/,
  103.     0, 0, 0, 0, 0, 0, 0, &mem_true24_word_device,
  104.     0, 0, 0, 0, 0, 0, 0, &mem_true32_word_device
  105. };
  106. const gx_device_memory *
  107. gdev_mem_word_device_for_bits(int bits_per_pixel)
  108. {
  109.     return ((uint)bits_per_pixel > 32 ? (const gx_device_memory *)0 :
  110.         mem_word_devices[bits_per_pixel]);
  111. }
  112.  
  113. /* Test whether a device is a memory device */
  114. bool
  115. gs_device_is_memory(const gx_device * dev)
  116. {
  117.     /*
  118.      * We use the draw_thin_line procedure to mark memory devices.
  119.      * See gdevmem.h.
  120.      */
  121.     int bits_per_pixel = dev->color_info.depth;
  122.     const gx_device_memory *mdproto;
  123.  
  124.     if ((uint)bits_per_pixel > 32)
  125.     return false;
  126.     mdproto = mem_devices[bits_per_pixel];
  127.     if (mdproto != 0 && dev_proc(dev, draw_thin_line) == dev_proc(mdproto, draw_thin_line))
  128.     return true;
  129.     mdproto = mem_word_devices[bits_per_pixel];
  130.     return (mdproto != 0 && dev_proc(dev, draw_thin_line) == dev_proc(mdproto, draw_thin_line));
  131. }
  132.  
  133. /* Make a memory device. */
  134. /* Note that the default for monobit devices is white = 0, black = 1. */
  135. void
  136. gs_make_mem_device(gx_device_memory * dev, const gx_device_memory * mdproto,
  137.            gs_memory_t * mem, int page_device, gx_device * target)
  138. {
  139.     gx_device_init((gx_device *) dev, (const gx_device *)mdproto,
  140.            mem, true);
  141.     dev->stype = &st_device_memory;
  142.     switch (page_device) {
  143.     case -1:
  144.         set_dev_proc(dev, get_page_device, gx_default_get_page_device);
  145.         break;
  146.     case 1:
  147.         set_dev_proc(dev, get_page_device, gx_page_device_get_page_device);
  148.         break;
  149.     }
  150.     /* Preload the black and white cache. */
  151.     if (target == 0) {
  152.     if (dev->color_info.depth == 1) {
  153.         /* The default for black-and-white devices is inverted. */
  154.         dev->cached_colors.black = 1;
  155.         dev->cached_colors.white = 0;
  156.     } else {
  157.         dev->cached_colors.black = 0;
  158.         dev->cached_colors.white = (1 << dev->color_info.depth) - 1;
  159.     }
  160.     } else {
  161.     gx_device_set_target((gx_device_forward *)dev, target);
  162.     /* Forward the color mapping operations to the target. */
  163.     gx_device_forward_color_procs((gx_device_forward *) dev);
  164.     gx_device_copy_color_procs((gx_device *)dev, target);
  165.     dev->cached_colors = target->cached_colors;
  166.     }
  167.     if (dev->color_info.depth == 1)
  168.     gdev_mem_mono_set_inverted(dev,
  169.                    (target == 0 ||
  170.                     (*dev_proc(target, map_rgb_color))
  171.                 (target, (gx_color_value) 0, (gx_color_value) 0,
  172.                  (gx_color_value) 0) != 0));
  173. }
  174. /* Make a monobit memory device.  This is never a page device. */
  175. /* Note that white=0, black=1. */
  176. void
  177. gs_make_mem_mono_device(gx_device_memory * dev, gs_memory_t * mem,
  178.             gx_device * target)
  179. {
  180.     gx_device_init((gx_device *)dev, (const gx_device *)&mem_mono_device,
  181.            mem, true);
  182.     set_dev_proc(dev, get_page_device, gx_default_get_page_device);
  183.     gx_device_set_target((gx_device_forward *)dev, target);
  184.     gdev_mem_mono_set_inverted(dev, true);
  185. }
  186.  
  187. /* Define whether a monobit memory device is inverted (black=1). */
  188. void
  189. gdev_mem_mono_set_inverted(gx_device_memory * dev, bool black_is_1)
  190. {
  191.     if (black_is_1)
  192.     dev->palette = mem_mono_b_w_palette;
  193.     else
  194.     dev->palette = mem_mono_w_b_palette;
  195. }
  196.  
  197. /*
  198.  * Compute the size of the bitmap storage, including the space for the scan
  199.  * line pointer table.  Note that scan lines are padded to a multiple of
  200.  * align_bitmap_mod bytes, and additional padding may be needed if the
  201.  * pointer table must be aligned to an even larger modulus.
  202.  *
  203.  * The computation for planar devices is a little messier.  Each plane
  204.  * must pad its scan lines, and then we must pad again for the pointer
  205.  * tables (one table per plane).
  206.  */
  207. ulong
  208. gdev_mem_bits_size(const gx_device_memory * dev, int width, int height)
  209. {
  210.     int num_planes = dev->num_planes;
  211.     gx_render_plane_t plane1;
  212.     const gx_render_plane_t *planes;
  213.     ulong size;
  214.     int pi;
  215.  
  216.     if (num_planes)
  217.     planes = dev->planes;
  218.     else
  219.     planes = &plane1, plane1.depth = dev->color_info.depth, num_planes = 1;
  220.     for (size = 0, pi = 0; pi < num_planes; ++pi)
  221.     size += bitmap_raster(width * planes[pi].depth);
  222.     return ROUND_UP(size * height, ARCH_ALIGN_PTR_MOD);
  223. }
  224. ulong
  225. gdev_mem_line_ptrs_size(const gx_device_memory * dev, int width, int height)
  226. {
  227.     return (ulong)height * sizeof(byte *) * max(dev->num_planes, 1);
  228. }
  229. ulong
  230. gdev_mem_data_size(const gx_device_memory * dev, int width, int height)
  231. {
  232.     return gdev_mem_bits_size(dev, width, height) +
  233.     gdev_mem_line_ptrs_size(dev, width, height);
  234. }
  235. /*
  236.  * Do the inverse computation: given a width (in pixels) and a buffer size,
  237.  * compute the maximum height.
  238.  */
  239. int
  240. gdev_mem_max_height(const gx_device_memory * dev, int width, ulong size)
  241. {
  242.     ulong max_height = size /
  243.     (bitmap_raster(width * dev->color_info.depth) +
  244.      sizeof(byte *) * max(dev->num_planes, 1));
  245.     int height = (int)min(max_height, max_int);
  246.  
  247.     /*
  248.      * Because of alignment rounding, the just-computed height might
  249.      * be too large by a small amount.  Adjust it the easy way.
  250.      */
  251.     while (gdev_mem_data_size(dev, width, height) > size)
  252.     --height;
  253.     return height;
  254. }
  255.  
  256. /* Open a memory device, allocating the data area if appropriate, */
  257. /* and create the scan line table. */
  258. int
  259. mem_open(gx_device * dev)
  260. {
  261.     gx_device_memory *const mdev = (gx_device_memory *)dev;
  262.  
  263.     /* Check that we aren't trying to open a planar device as chunky. */
  264.     if (mdev->num_planes)
  265.     return_error(gs_error_rangecheck);
  266.     return gdev_mem_open_scan_lines(mdev, dev->height);
  267. }
  268. int
  269. gdev_mem_open_scan_lines(gx_device_memory *mdev, int setup_height)
  270. {
  271.     bool line_pointers_adjacent = true;
  272.  
  273.     if (setup_height < 0 || setup_height > mdev->height)
  274.     return_error(gs_error_rangecheck);
  275.     if (mdev->bitmap_memory != 0) {
  276.     /* Allocate the data now. */
  277.     ulong size = gdev_mem_bitmap_size(mdev);
  278.  
  279.     if ((uint) size != size)
  280.         return_error(gs_error_limitcheck);
  281.     mdev->base = gs_alloc_bytes(mdev->bitmap_memory, (uint)size,
  282.                     "mem_open");
  283.     if (mdev->base == 0)
  284.         return_error(gs_error_VMerror);
  285.     mdev->foreign_bits = false;
  286.     } else if (mdev->line_pointer_memory != 0) {
  287.     /* Allocate the line pointers now. */
  288.  
  289.     mdev->line_ptrs = (byte **)
  290.         gs_alloc_byte_array(mdev->line_pointer_memory, mdev->height,
  291.                 sizeof(byte *) * max(mdev->num_planes, 1),
  292.                 "gdev_mem_open_scan_lines");
  293.     if (mdev->line_ptrs == 0)
  294.         return_error(gs_error_VMerror);
  295.     mdev->foreign_line_pointers = false;
  296.     line_pointers_adjacent = false;
  297.     }
  298.     if (line_pointers_adjacent)
  299.     mdev->line_ptrs = (byte **)
  300.         (mdev->base + gdev_mem_bits_size(mdev, mdev->width, mdev->height));
  301.     mdev->raster = gdev_mem_raster(mdev);
  302.     return gdev_mem_set_line_ptrs(mdev, NULL, 0, NULL, setup_height);
  303. }
  304. /*
  305.  * Set up the scan line pointers of a memory device.
  306.  * See gxdevmem.h for the detailed specification.
  307.  * Sets or uses line_ptrs, base, raster; uses width, color_info.depth,
  308.  * num_planes, plane_depths, plane_depth.
  309.  */
  310. int
  311. gdev_mem_set_line_ptrs(gx_device_memory * mdev, byte * base, int raster,
  312.                byte **line_ptrs, int setup_height)
  313. {
  314.     int num_planes = mdev->num_planes;
  315.     gx_render_plane_t plane1;
  316.     const gx_render_plane_t *planes;
  317.     byte **pline =
  318.     (line_ptrs ? (mdev->line_ptrs = line_ptrs) : mdev->line_ptrs);
  319.     byte *data =
  320.     (base ? (mdev->raster = raster, mdev->base = base) :
  321.      (raster = mdev->raster, mdev->base));
  322.     int pi;
  323.  
  324.     if (num_planes) {
  325.     if (base && !mdev->plane_depth)
  326.         return_error(gs_error_rangecheck);
  327.     planes = mdev->planes;
  328.     } else {
  329.     planes = &plane1;
  330.     plane1.depth = mdev->color_info.depth;
  331.     num_planes = 1;
  332.     }
  333.  
  334.     for (pi = 0; pi < num_planes; ++pi) {
  335.     int raster = bitmap_raster(mdev->width * planes[pi].depth);
  336.     byte **pptr = pline;
  337.     byte **pend = pptr + setup_height;
  338.     byte *scan_line = data;
  339.  
  340.     while (pptr < pend) {
  341.         *pptr++ = scan_line;
  342.         scan_line += raster;
  343.     }
  344.     data += raster * mdev->height;
  345.     pline += setup_height;    /* not mdev->height, see gxdevmem.h */
  346.     }
  347.  
  348.     return 0;
  349. }
  350.  
  351. /* Return the initial transformation matrix */
  352. void
  353. mem_get_initial_matrix(gx_device * dev, gs_matrix * pmat)
  354. {
  355.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  356.  
  357.     pmat->xx = mdev->initial_matrix.xx;
  358.     pmat->xy = mdev->initial_matrix.xy;
  359.     pmat->yx = mdev->initial_matrix.yx;
  360.     pmat->yy = mdev->initial_matrix.yy;
  361.     pmat->tx = mdev->initial_matrix.tx;
  362.     pmat->ty = mdev->initial_matrix.ty;
  363. }
  364.  
  365. /* Close a memory device, freeing the data area if appropriate. */
  366. int
  367. mem_close(gx_device * dev)
  368. {
  369.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  370.  
  371.     if (mdev->bitmap_memory != 0) {
  372.     gs_free_object(mdev->bitmap_memory, mdev->base, "mem_close");
  373.     /*
  374.      * The following assignment is strictly for the benefit of one
  375.      * client that is sloppy about using is_open properly.
  376.      */
  377.     mdev->base = 0;
  378.     } else if (mdev->line_pointer_memory != 0) {
  379.     gs_free_object(mdev->line_pointer_memory, mdev->line_ptrs,
  380.                "mem_close");
  381.     mdev->line_ptrs = 0;    /* ibid. */
  382.     }
  383.     return 0;
  384. }
  385.  
  386. /* Copy bits to a client. */
  387. #undef chunk
  388. #define chunk byte
  389. int
  390. mem_get_bits_rectangle(gx_device * dev, const gs_int_rect * prect,
  391.                gs_get_bits_params_t * params, gs_int_rect ** unread)
  392. {
  393.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  394.     gs_get_bits_options_t options = params->options;
  395.     int x = prect->p.x, w = prect->q.x - x, y = prect->p.y, h = prect->q.y - y;
  396.  
  397.     if (options == 0) {
  398.     params->options =
  399.         (GB_ALIGN_STANDARD | GB_ALIGN_ANY) |
  400.         (GB_RETURN_COPY | GB_RETURN_POINTER) |
  401.         (GB_OFFSET_0 | GB_OFFSET_SPECIFIED | GB_OFFSET_ANY) |
  402.         (GB_RASTER_STANDARD | GB_RASTER_SPECIFIED | GB_RASTER_ANY) |
  403.         GB_PACKING_CHUNKY | GB_COLORS_NATIVE | GB_ALPHA_NONE;
  404.     return_error(gs_error_rangecheck);
  405.     }
  406.     if ((w <= 0) | (h <= 0)) {
  407.     if ((w | h) < 0)
  408.         return_error(gs_error_rangecheck);
  409.     return 0;
  410.     }
  411.     if (x < 0 || w > dev->width - x ||
  412.     y < 0 || h > dev->height - y
  413.     )
  414.     return_error(gs_error_rangecheck);
  415.     {
  416.     gs_get_bits_params_t copy_params;
  417.     byte *base = scan_line_base(mdev, y);
  418.     int code;
  419.  
  420.     copy_params.options =
  421.         GB_COLORS_NATIVE | GB_PACKING_CHUNKY | GB_ALPHA_NONE |
  422.         (mdev->raster ==
  423.          bitmap_raster(mdev->width * mdev->color_info.depth) ?
  424.          GB_RASTER_STANDARD : GB_RASTER_SPECIFIED);
  425.     copy_params.raster = mdev->raster;
  426.     code = gx_get_bits_return_pointer(dev, x, h, params,
  427.                       ©_params, base);
  428.     if (code >= 0)
  429.         return code;
  430.     return gx_get_bits_copy(dev, x, w, h, params, ©_params, base,
  431.                 gx_device_raster(dev, true));
  432.     }
  433. }
  434.  
  435. #if !arch_is_big_endian
  436.  
  437. /*
  438.  * Swap byte order in a rectangular subset of a bitmap.  If store = true,
  439.  * assume the rectangle will be overwritten, so don't swap any bytes where
  440.  * it doesn't matter.  The caller has already done a fit_fill or fit_copy.
  441.  * Note that the coordinates are specified in bits, not in terms of the
  442.  * actual device depth.
  443.  */
  444. void
  445. mem_swap_byte_rect(byte * base, uint raster, int x, int w, int h, bool store)
  446. {
  447.     int xbit = x & 31;
  448.  
  449.     if (store) {
  450.     if (xbit + w > 64) {    /* Operation spans multiple words. */
  451.         /* Just swap the words at the left and right edges. */
  452.         if (xbit != 0)
  453.         mem_swap_byte_rect(base, raster, x, 1, h, false);
  454.         x += w - 1;
  455.         xbit = x & 31;
  456.         if (xbit == 31)
  457.         return;
  458.         w = 1;
  459.     }
  460.     }
  461.     /* Swap the entire rectangle (or what's left of it). */
  462.     {
  463.     byte *row = base + ((x >> 5) << 2);
  464.     int nw = (xbit + w + 31) >> 5;
  465.     int ny;
  466.  
  467.     for (ny = h; ny > 0; row += raster, --ny) {
  468.         int nx = nw;
  469.         bits32 *pw = (bits32 *) row;
  470.  
  471.         do {
  472.         bits32 w = *pw;
  473.  
  474.         *pw++ = (w >> 24) + ((w >> 8) & 0xff00) +
  475.             ((w & 0xff00) << 8) + (w << 24);
  476.         }
  477.         while (--nx);
  478.     }
  479.     }
  480. }
  481.  
  482. /* Copy a word-oriented rectangle to the client, swapping bytes as needed. */
  483. int
  484. mem_word_get_bits_rectangle(gx_device * dev, const gs_int_rect * prect,
  485.                gs_get_bits_params_t * params, gs_int_rect ** unread)
  486. {
  487.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  488.     byte *src;
  489.     uint dev_raster = gx_device_raster(dev, 1);
  490.     int x = prect->p.x;
  491.     int w = prect->q.x - x;
  492.     int y = prect->p.y;
  493.     int h = prect->q.y - y;
  494.     int bit_x, bit_w;
  495.     int code;
  496.  
  497.     fit_fill_xywh(dev, x, y, w, h);
  498.     if (w <= 0 || h <= 0) {
  499.     /*
  500.      * It's easiest to just keep going with an empty rectangle.
  501.      * We pass the original rectangle to mem_get_bits_rectangle,
  502.      * so unread will be filled in correctly.
  503.      */
  504.     x = y = w = h = 0;
  505.     }
  506.     bit_x = x * dev->color_info.depth;
  507.     bit_w = w * dev->color_info.depth;
  508.     src = scan_line_base(mdev, y);
  509.     mem_swap_byte_rect(src, dev_raster, bit_x, bit_w, h, false);
  510.     code = mem_get_bits_rectangle(dev, prect, params, unread);
  511.     mem_swap_byte_rect(src, dev_raster, bit_x, bit_w, h, false);
  512.     return code;
  513. }
  514.  
  515. #endif /* !arch_is_big_endian */
  516.  
  517. /* Map a r-g-b color to a color index for a mapped color memory device */
  518. /* (2, 4, or 8 bits per pixel.) */
  519. /* This requires searching the palette. */
  520. gx_color_index
  521. mem_mapped_map_rgb_color(gx_device * dev, gx_color_value r, gx_color_value g,
  522.              gx_color_value b)
  523. {
  524.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  525.     byte br = gx_color_value_to_byte(r);
  526.     byte bg = gx_color_value_to_byte(g);
  527.     byte bb = gx_color_value_to_byte(b);
  528.     register const byte *pptr = mdev->palette.data;
  529.     int cnt = mdev->palette.size;
  530.     const byte *which = 0;    /* initialized only to pacify gcc */
  531.     int best = 256 * 3;
  532.  
  533.     while ((cnt -= 3) >= 0) {
  534.     register int diff = *pptr - br;
  535.  
  536.     if (diff < 0)
  537.         diff = -diff;
  538.     if (diff < best) {    /* quick rejection */
  539.         int dg = pptr[1] - bg;
  540.  
  541.         if (dg < 0)
  542.         dg = -dg;
  543.         if ((diff += dg) < best) {    /* quick rejection */
  544.         int db = pptr[2] - bb;
  545.  
  546.         if (db < 0)
  547.             db = -db;
  548.         if ((diff += db) < best)
  549.             which = pptr, best = diff;
  550.         }
  551.     }
  552.     pptr += 3;
  553.     }
  554.     return (gx_color_index) ((which - mdev->palette.data) / 3);
  555. }
  556.  
  557. /* Map a color index to a r-g-b color for a mapped color memory device. */
  558. int
  559. mem_mapped_map_color_rgb(gx_device * dev, gx_color_index color,
  560.              gx_color_value prgb[3])
  561. {
  562.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  563.     const byte *pptr = mdev->palette.data + (int)color * 3;
  564.  
  565.     prgb[0] = gx_color_value_from_byte(pptr[0]);
  566.     prgb[1] = gx_color_value_from_byte(pptr[1]);
  567.     prgb[2] = gx_color_value_from_byte(pptr[2]);
  568.     return 0;
  569. }
  570.  
  571. /*
  572.  * Implement draw_thin_line using a distinguished procedure that serves
  573.  * as the common marker for all memory devices.
  574.  */
  575. int
  576. mem_draw_thin_line(gx_device *dev, fixed fx0, fixed fy0, fixed fx1, fixed fy1,
  577.            const gx_drawing_color *pdcolor,
  578.            gs_logical_operation_t lop)
  579. {
  580.     return gx_default_draw_thin_line(dev, fx0, fy0, fx1, fy1, pdcolor, lop);
  581. }
  582.