home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / lib / PEXlib / pl_lut.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-27  |  30.7 KB  |  1,296 lines

  1. /* $XConsortium: pl_lut.c,v 1.8 92/10/27 15:43:42 mor Exp $ */
  2.  
  3. /******************************************************************************
  4. Copyright 1987,1991 by Digital Equipment Corporation, Maynard, Massachusetts
  5. Copyright 1992 by the Massachusetts Institute of Technology
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, distribute, and sell this software and its
  10. documentation for any purpose is hereby granted without fee, provided that
  11. the above copyright notice appear in all copies and that both that copyright
  12. notice and this permission notice appear in supporting documentation, and that
  13. the name of Digital or M.I.T. not be used in advertising or publicity
  14. pertaining to distribution of the software without specific, written prior
  15. permission.  Digital and M.I.T. make no representations about the suitability
  16. of this software for any purpose.  It is provided "as is" without express or
  17. implied warranty.
  18.  
  19. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  21. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  22. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  23. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  24. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  25. SOFTWARE.
  26. ******************************************************************************/
  27.  
  28. #include "PEXlib.h"
  29. #include "PEXlibint.h"
  30.  
  31. static PEXPointer _PEXRepackLUTEntries();
  32.  
  33. #define GetLUTEntryBuffer(_numEntries, _entryType, _buf) \
  34.     (_buf) = (char *) PEXAllocBuf ((_numEntries) * (sizeof (_entryType)));
  35.  
  36.  
  37. PEXLookupTable
  38. PEXCreateLookupTable (display, d, type)
  39.  
  40. INPUT Display    *display;
  41. INPUT Drawable    d;
  42. INPUT int    type;
  43.  
  44. {
  45.     PEXLookupTable        id;
  46.     pexCreateLookupTableReq    *req;
  47.  
  48.  
  49.     /*
  50.      * Get a lookup table resource id from X.
  51.      */
  52.  
  53.     id = XAllocID (display);
  54.  
  55.  
  56.     /*
  57.      * Lock around critical section, for multithreading.
  58.      */
  59.  
  60.     LockDisplay (display);
  61.  
  62.  
  63.     /*
  64.      * Put the request in the X request buffer.
  65.      */
  66.  
  67.     PEXGetReq (CreateLookupTable, req);
  68.     req->drawableExample = d;
  69.     req->lut = id;
  70.     req->tableType = type;
  71.  
  72.  
  73.     /*
  74.      * Done, so unlock and check for synchronous-ness.
  75.      */
  76.  
  77.     UnlockDisplay (display);
  78.     PEXSyncHandle (display);
  79.  
  80.     return (id);
  81. }
  82.  
  83.  
  84. void
  85. PEXFreeLookupTable (display, lut)
  86.  
  87. INPUT Display        *display;
  88. INPUT PEXLookupTable    lut;
  89.  
  90. {
  91.     pexFreeLookupTableReq     *req;
  92.  
  93.  
  94.     /*
  95.      * Lock around the critical section, for multithreading.
  96.      */
  97.  
  98.     LockDisplay (display);
  99.  
  100.  
  101.     /*
  102.      * Put the request in the X request buffer.
  103.      */
  104.  
  105.     PEXGetReq (FreeLookupTable, req);
  106.     req->id = lut;
  107.  
  108.  
  109.     /*
  110.      * Done, so unlock and check for synchronous-ness.
  111.      */
  112.  
  113.     UnlockDisplay (display);
  114.     PEXSyncHandle (display);
  115. }
  116.  
  117.  
  118. void
  119. PEXCopyLookupTable (display, srcLut, destLut)
  120.  
  121. INPUT Display        *display;
  122. INPUT PEXLookupTable    srcLut;
  123. INPUT PEXLookupTable    destLut;
  124.  
  125. {
  126.     pexCopyLookupTableReq     *req;
  127.  
  128.  
  129.     /*
  130.      * Lock around critical section, for multithreading.
  131.      */
  132.  
  133.     LockDisplay (display);
  134.  
  135.  
  136.     /*
  137.      * Put the request in the X request buffer.
  138.      */
  139.  
  140.     PEXGetReq (CopyLookupTable, req);
  141.     req->src = srcLut;
  142.     req->dst = destLut;
  143.  
  144.  
  145.     /*
  146.      * Done, so unlock and check for synchronous-ness.
  147.      */
  148.  
  149.     UnlockDisplay (display);
  150.     PEXSyncHandle (display);
  151. }
  152.  
  153.  
  154. Status
  155. PEXGetTableInfo (display, d, type, info)
  156.  
  157. INPUT Display        *display;
  158. INPUT Drawable        d;
  159. INPUT int        type;
  160. INPUT PEXTableInfo    *info;
  161.  
  162. {
  163.     pexGetTableInfoReq         *req;
  164.     pexGetTableInfoReply       rep;
  165.  
  166.  
  167.     /*
  168.      * Lock around critical section, for multithreading.
  169.      */
  170.  
  171.     LockDisplay (display);
  172.  
  173.  
  174.     /*
  175.      * Put the request in the X request buffer and get a reply.
  176.      */
  177.  
  178.     PEXGetReq (GetTableInfo, req);
  179.     req->drawableExample = d;
  180.     req->tableType = type;
  181.  
  182.     if (_XReply (display, &rep, 0, xTrue) == 0)
  183.     {
  184.     UnlockDisplay (display);
  185.     PEXSyncHandle (display);
  186.     return (0);            /* return an error */
  187.     }
  188.  
  189.     info->definable_entries = rep.definableEntries;
  190.     info->predefined_count = rep.numPredefined;
  191.     info->predefined_min = rep.predefinedMin;
  192.     info->predefined_max = rep.predefinedMax;
  193.  
  194.  
  195.     /*
  196.      * Done, so unlock and check for synchronous-ness.
  197.      */
  198.  
  199.     UnlockDisplay (display);
  200.     PEXSyncHandle (display);
  201.  
  202.     return (1);
  203. }
  204.  
  205.  
  206. Status
  207. PEXGetPredefinedEntries (display, d, type, start, count, entriesReturn)
  208.  
  209. INPUT Display        *display;
  210. INPUT Drawable        d;
  211. INPUT int        type;
  212. INPUT unsigned int    start;
  213. INPUT unsigned int    count;
  214. OUTPUT PEXPointer    *entriesReturn;
  215.  
  216. {
  217.     pexGetPredefinedEntriesReq        *req;
  218.     pexGetPredefinedEntriesReply    rep;
  219.     char                *pt;
  220.     int                    convertFP;
  221.  
  222.  
  223.     /*
  224.      * Lock around the critical section, for multithreading.
  225.      */
  226.  
  227.     LockDisplay (display);
  228.  
  229.  
  230.     /*
  231.      * Put the request in the X request buffer and get a reply.
  232.      */
  233.  
  234.     PEXGetFPReq (GetPredefinedEntries, req, convertFP);
  235.     req->drawableExample = d;
  236.     req->tableType = type;
  237.     req->start = start;
  238.     req->count = count;
  239.  
  240.     if (_XReply (display, &rep, 0, xFalse) == 0)
  241.     {
  242.     UnlockDisplay (display);
  243.     PEXSyncHandle (display);
  244.     *entriesReturn = NULL;
  245.     return (0);          /* return an error */
  246.     }
  247.  
  248.  
  249.     /*
  250.      * Read the reply into a scratch buffer, then repack the entries
  251.      * into a buffer allocated for the application.
  252.      */
  253.  
  254.     pt = (char *) _XAllocScratch (display, (unsigned long) (rep.length << 2));
  255.  
  256.     _XRead (display, (char *) pt, (long) (rep.length << 2));
  257.  
  258.     *entriesReturn = _PEXRepackLUTEntries (
  259.     (char *) pt, (int) rep.numEntries, type);
  260.  
  261.  
  262.     /*
  263.      * Done, so unlock and check for synchronous-ness.
  264.      */
  265.  
  266.     UnlockDisplay (display);
  267.     PEXSyncHandle (display);
  268.  
  269.     return (1);
  270. }
  271.  
  272.  
  273. Status
  274. PEXGetDefinedIndices (display, lut, numIndicesReturn, indicesReturn)
  275.  
  276. INPUT Display        *display;
  277. INPUT PEXLookupTable    lut;
  278. OUTPUT unsigned long    *numIndicesReturn;
  279. OUTPUT PEXTableIndex    **indicesReturn;
  280.  
  281. {
  282.     pexGetDefinedIndicesReq    *req;
  283.     pexGetDefinedIndicesReply    rep;
  284.  
  285.  
  286.     /*
  287.      * Lock around the critical section, for multithreading.
  288.      */
  289.  
  290.     LockDisplay (display);
  291.  
  292.  
  293.     /*
  294.      * Put the request in the X request buffer and get a reply.
  295.      */
  296.  
  297.     PEXGetReq (GetDefinedIndices, req);
  298.     req->id = lut;
  299.  
  300.     if (_XReply (display, &rep, 0, xFalse) == 0)
  301.     {
  302.     UnlockDisplay (display);
  303.     PEXSyncHandle (display);
  304.     *numIndicesReturn = 0;
  305.     *indicesReturn = NULL;
  306.     return (0);              /* return an error */
  307.     }
  308.  
  309.     *numIndicesReturn = rep.numIndices;
  310.  
  311.  
  312.     /*
  313.      * Allocate a buffer for the replies to pass back to the user.
  314.      */
  315.  
  316.     *indicesReturn = (PEXTableIndex *) PEXAllocBuf (
  317.     (unsigned) (rep.length << 2));
  318.  
  319.     _XRead (display, (char *) *indicesReturn, (long) (rep.length << 2));
  320.  
  321.  
  322.     /*
  323.      * Done, so unlock and check for synchronous-ness.
  324.      */
  325.  
  326.     UnlockDisplay (display);
  327.     PEXSyncHandle (display);
  328.  
  329.     return (1);
  330. }
  331.  
  332.  
  333. PEXPointer
  334. PEXGetTableEntry (display, lut, index, valueType,
  335.     statusReturn, table_type_return)
  336.  
  337. INPUT Display        *display;
  338. INPUT PEXLookupTable    lut;
  339. INPUT unsigned int    index;
  340. INPUT int        valueType;
  341. OUTPUT int        *statusReturn;
  342. OUTPUT int        *table_type_return;
  343.  
  344. {
  345.     pexGetTableEntryReq        *req;
  346.     pexGetTableEntryReply    rep;
  347.     char            *pt;
  348.     int                convertFP;
  349.     PEXPointer            entryReturn;
  350.  
  351.  
  352.     /*
  353.      * Lock around the critical section, for multithreading.
  354.      */
  355.  
  356.     LockDisplay (display);
  357.  
  358.  
  359.     /*
  360.      * Put the request in the X request buffer and get a reply.
  361.      */
  362.  
  363.     PEXGetFPReq (GetTableEntry, req, convertFP);
  364.     req->valueType = valueType;
  365.     req->lut = lut;
  366.     req->index = index;
  367.  
  368.     if (_XReply (display, &rep, 0, xFalse) == 0)
  369.     {
  370.     UnlockDisplay (display);
  371.     PEXSyncHandle (display);
  372.     return (NULL);               /* return an error */
  373.     }
  374.  
  375.     *statusReturn = rep.status;
  376.     *table_type_return = rep.tableType;
  377.  
  378.  
  379.     /*
  380.      * Read the reply into a scratch buffer, then repack the entries
  381.      * into a buffer allocated for the application.
  382.      */
  383.  
  384.     pt = (char *) _XAllocScratch (display, (unsigned long) (rep.length << 2));
  385.  
  386.     _XRead (display, (char *) pt, (long) (rep.length << 2));
  387.  
  388.     entryReturn = _PEXRepackLUTEntries ((char *) pt, 1, (int) rep.tableType);
  389.  
  390.  
  391.     /*
  392.      * Done, so unlock and check for synchronous-ness.
  393.      */
  394.  
  395.     UnlockDisplay (display);
  396.     PEXSyncHandle (display);
  397.  
  398.     return (entryReturn);
  399. }
  400.  
  401.  
  402. Status
  403. PEXGetTableEntries (display, lut, start, count, valueType,
  404.     table_type_return, entriesReturn)
  405.  
  406. INPUT Display        *display;
  407. INPUT PEXLookupTable    lut;
  408. INPUT unsigned int    start;
  409. INPUT unsigned int    count;
  410. INPUT int        valueType;
  411. OUTPUT int        *table_type_return;
  412. OUTPUT PEXPointer    *entriesReturn;
  413.  
  414. {
  415.     pexGetTableEntriesReq    *req;
  416.     pexGetTableEntriesReply    rep;
  417.     char            *pt;
  418.     int                convertFP;
  419.  
  420.  
  421.     /*
  422.      * Lock around the critical section, for multithreading.
  423.      */
  424.  
  425.     LockDisplay (display);
  426.  
  427.  
  428.     /*
  429.      * Put the request in the X request buffer and get a reply.
  430.      */
  431.  
  432.     PEXGetFPReq (GetTableEntries, req, convertFP);
  433.     req->valueType = valueType;
  434.     req->lut = lut;
  435.     req->start = start;
  436.     req->count = count;
  437.  
  438.     if (_XReply (display, &rep, 0, xFalse) == 0)
  439.     {
  440.     UnlockDisplay (display);
  441.     PEXSyncHandle (display);
  442.     *entriesReturn = NULL;
  443.     return (0);         /* return an error */
  444.     }
  445.  
  446.     *table_type_return = rep.tableType;
  447.  
  448.  
  449.     /*
  450.      * Read the reply into a scratch buffer, then repack the entries
  451.      * into a buffer allocated for the application.
  452.      */
  453.  
  454.     pt = (char *) _XAllocScratch (display, (unsigned long) (rep.length << 2));
  455.  
  456.     _XRead (display, (char *) pt, (long) (rep.length << 2));
  457.  
  458.     *entriesReturn = _PEXRepackLUTEntries ((char *) pt, (int) rep.numEntries,
  459.     (int) rep.tableType);
  460.  
  461.  
  462.     /*
  463.      * Done, so unlock and check for synchronous-ness.
  464.      */
  465.  
  466.     UnlockDisplay (display);
  467.     PEXSyncHandle (display);
  468.  
  469.     return (1);
  470. }
  471.  
  472.  
  473. void
  474. PEXSetTableEntries (display, lut, start, count, type, entries)
  475.  
  476. INPUT Display        *display;
  477. INPUT PEXLookupTable    lut;
  478. INPUT unsigned int    start;
  479. INPUT unsigned int    count;
  480. INPUT int        type;
  481. INPUT PEXPointer    entries;
  482.  
  483. {
  484.     pexSetTableEntriesReq    *req;
  485.     int                sizeColor, size, i;
  486.     int                convertFP;
  487.  
  488.  
  489.     /*
  490.      * Lock around the critical section, for multithreading.
  491.      */
  492.  
  493.     LockDisplay (display);
  494.  
  495.  
  496.     /*
  497.      * Put the request in the X request buffer.
  498.      */
  499.  
  500.     PEXGetFPReq (SetTableEntries, req, convertFP);
  501.     req->lut = lut;
  502.     req->start = start;
  503.     req->count = count;
  504.  
  505.     switch (type)
  506.     {
  507.     case PEXLUTLineBundle:
  508.     {
  509.     pexLineBundleEntry *dst, *dstStart;
  510.     PEXLineBundleEntry *src = (PEXLineBundleEntry *) entries;
  511.     
  512.     dstStart = dst = (pexLineBundleEntry *)
  513.         _XAllocScratch (display, count * sizeof (PEXLineBundleEntry));
  514.  
  515.     for (i = 0; i < count; i++, src++)
  516.     {
  517.         dst->lineType = src->type;
  518.         dst->polylineInterp = src->interp_method;
  519. #ifdef WORD64
  520. #else
  521.         dst->curveApprox = *(pexCurveApprox *) &(src->curve_approx);
  522. #endif
  523.         dst->lineWidth = src->width;
  524.         
  525.         PackColorSpecifier (&(src->color), &(dst->lineColor), sizeColor);
  526.  
  527.         dst = (pexLineBundleEntry *) ((char *) dst + 
  528.         sizeof (pexLineBundleEntry) + sizeColor);
  529.     }
  530.  
  531.     /* update the request length */
  532.     size = (char *) dst - (char *) dstStart;
  533.     req->length += (size + 3) >> 2;
  534.     
  535.     /* add the table entry data to the end of the X request */
  536.     Data (display, (char *) dstStart, size);
  537.  
  538.     break;
  539.     }
  540.  
  541.     case PEXLUTMarkerBundle:
  542.     {
  543.     pexMarkerBundleEntry *dst, *dstStart;
  544.     PEXMarkerBundleEntry *src = (PEXMarkerBundleEntry *) entries;
  545.  
  546.     dstStart = dst = (pexMarkerBundleEntry *) _XAllocScratch (
  547.         display, count * sizeof (PEXMarkerBundleEntry));
  548.  
  549.     for (i = 0; i < count; i++, src++)
  550.     {
  551.         dst->markerType = src->type;
  552.         dst->markerScale = src->scale;
  553.         
  554.         PackColorSpecifier (&(src->color), &(dst->markerColor), sizeColor);
  555.  
  556.         dst = (pexMarkerBundleEntry *) ((char *) dst + 
  557.         sizeof (pexMarkerBundleEntry) + sizeColor);
  558.     }
  559.  
  560.     /* update the request length */
  561.     size = (char *) dst - (char *) dstStart;
  562.     req->length += (size + 3) >> 2;
  563.     
  564.     /* add the table entry data to the end of the X request */
  565.     Data (display, (char *) dstStart, size);
  566.     
  567.     break;
  568.     }
  569.  
  570.     case PEXLUTTextBundle:
  571.     {
  572.     pexTextBundleEntry *dst, *dstStart;
  573.     PEXTextBundleEntry *src = (PEXTextBundleEntry *) entries;
  574.  
  575.     dstStart = dst = (pexTextBundleEntry *)
  576.         _XAllocScratch (display, count * sizeof (PEXTextBundleEntry));
  577.  
  578.     for (i = 0; i < count; i++, src++)
  579.     {
  580.         dst->textFontIndex = src->font_index;
  581.         dst->textPrecision = src->precision;
  582.         dst->charExpansion = src->char_expansion;
  583.         dst->charSpacing = src->char_spacing;
  584.         
  585.         PackColorSpecifier (&(src->color), &(dst->textColor), sizeColor);
  586.  
  587.         dst = (pexTextBundleEntry *) ((char *) dst + 
  588.         sizeof (pexTextBundleEntry) + sizeColor);
  589.     }
  590.  
  591.     /* update the request length */
  592.     size = (char *) dst - (char *) dstStart;
  593.     req->length += (size + 3) >> 2;
  594.  
  595.     /* add the table entry data to the end of the X request */
  596.     Data (display, (char *) dstStart, size);
  597.  
  598.     break;
  599.     }
  600.  
  601.     case PEXLUTInteriorBundle:
  602.     {
  603.     char *dst, *dstStart;
  604.     PEXInteriorBundleEntry *src = (PEXInteriorBundleEntry *) entries;
  605.  
  606.     dstStart = dst = (char *) _XAllocScratch (display,
  607.         count * sizeof (PEXInteriorBundleEntry));
  608.  
  609.     for (i = 0; i < count; i++, src++)
  610.     {
  611.         ((pexInteriorBundleEntry *) dst)->interiorStyle =
  612.         src->style;
  613.         ((pexInteriorBundleEntry *) dst)->interiorStyleIndex =
  614.         src->style_index;
  615.         ((pexInteriorBundleEntry *) dst)->reflectionModel =
  616.         src->reflection_model;
  617.         ((pexInteriorBundleEntry *) dst)->surfaceInterp =
  618.         src->interp_method;
  619.         ((pexInteriorBundleEntry *) dst)->bfInteriorStyle =
  620.         src->bf_style;
  621.         ((pexInteriorBundleEntry *) dst)->bfInteriorStyleIndex =
  622.         src->bf_style_index;
  623.         ((pexInteriorBundleEntry *) dst)->bfReflectionModel =
  624.         src->bf_reflection_model;
  625.         ((pexInteriorBundleEntry *) dst)->bfSurfaceInterp =
  626.         src->bf_interp_method;
  627. #ifdef WORD64
  628. #else
  629.         ((pexInteriorBundleEntry *) dst)->surfaceApprox =
  630.         *(pexSurfaceApprox *) &(src->surface_approx);
  631. #endif
  632.         dst += sizeof (pexInteriorBundleEntry);
  633.  
  634.         /* copy surfaceColor */
  635.         PackColorSpecifier (&(src->color), dst, sizeColor);
  636.         dst += sizeof (pexColorSpecifier) + sizeColor;
  637.  
  638.         /* copy reflectionAttr */
  639.         ((pexReflectionAttr *) dst)->ambient =
  640.         src->reflection_attr.ambient;
  641.         ((pexReflectionAttr *) dst)->diffuse = 
  642.         src->reflection_attr.diffuse;
  643.         ((pexReflectionAttr *) dst)->specular =
  644.         src->reflection_attr.specular;
  645.         ((pexReflectionAttr *) dst)->specularConc = 
  646.         src->reflection_attr.specular_conc;
  647.         ((pexReflectionAttr *) dst)->transmission = 
  648.         src->reflection_attr.transmission;
  649.         PackColorSpecifier ( 
  650.         &(src->reflection_attr.specular_color),
  651.         &(((pexReflectionAttr *) dst)->specularColor), sizeColor);
  652.         dst += sizeof (pexReflectionAttr) + sizeColor;
  653.  
  654.         /* copy bfSurfaceColor */
  655.         PackColorSpecifier (&(src->bf_color), dst, sizeColor);
  656.         dst += sizeof (pexColorSpecifier) + sizeColor;
  657.  
  658.         /* copy bfReflectionAttr */
  659.         ((pexReflectionAttr *) dst)->ambient =
  660.         src->bf_reflection_attr.ambient;
  661.         ((pexReflectionAttr *) dst)->diffuse =
  662.         src->bf_reflection_attr.diffuse;
  663.         ((pexReflectionAttr *) dst)->specular = 
  664.         src->bf_reflection_attr.specular;
  665.         ((pexReflectionAttr *) dst)->specularConc = 
  666.         src->bf_reflection_attr.specular_conc;
  667.         ((pexReflectionAttr *) dst)->transmission = 
  668.         src->bf_reflection_attr.transmission;
  669.         PackColorSpecifier ( 
  670.         &(src->bf_reflection_attr.specular_color),
  671.         &(((pexReflectionAttr *) dst)->specularColor), sizeColor);
  672.         dst += sizeof (pexReflectionAttr) + sizeColor;
  673.     }
  674.     
  675.     /* update the request length */
  676.     size = (char *) dst - (char *) dstStart;
  677.     req->length += (size + 3) >> 2;
  678.     
  679.     /* add the table entry data to the end of the X request */
  680.     Data (display, (char *) dstStart, size);
  681.  
  682.     break;
  683.     }
  684.  
  685.     case PEXLUTEdgeBundle:
  686.     {
  687.     pexEdgeBundleEntry *dst, *dstStart;
  688.     PEXEdgeBundleEntry *src = (PEXEdgeBundleEntry *) entries;
  689.  
  690.     dstStart = dst = (pexEdgeBundleEntry *)
  691.         _XAllocScratch (display, count * sizeof (PEXEdgeBundleEntry));
  692.  
  693.     for (i = 0; i < count; i++, src++)
  694.     {
  695.         dst->edges = src->edge_flag;
  696.         dst->edgeType = src->type;
  697.         dst->edgeWidth = src->width;
  698.         
  699.         PackColorSpecifier (&(src->color), &(dst->edgeColor), sizeColor);
  700.  
  701.         dst = (pexEdgeBundleEntry *) ((char *) dst + 
  702.         sizeof (pexEdgeBundleEntry) + sizeColor);
  703.     }
  704.  
  705.     /* update the request length */
  706.     size = (char *) dst - (char *) dstStart;
  707.     req->length += (size + 3) >> 2;
  708.     
  709.     /* add the table entry data to the end of the X request */
  710.     Data (display, (char *) dstStart, size);
  711.  
  712.     break;
  713.     }
  714.  
  715.     case PEXLUTPattern:
  716.     {
  717.     pexPatternEntry *dst, *dstStart;
  718.     PEXPatternEntry *src = (PEXPatternEntry *)entries;
  719.  
  720.     size = count * sizeof (pexPatternEntry);
  721.     for (i = 0; i < count; i++)
  722.     {
  723.         size += (src[i].col_count *
  724.         src[i].row_count * sizeof (PEXColor));
  725.     }
  726.  
  727.     dstStart = dst = (pexPatternEntry *)
  728.         _XAllocScratch (display, (unsigned long) size);
  729.  
  730.     for (i = 0; i < count; i++, src++)
  731.     {
  732.         dst->colorType = src->color_type;
  733.         dst->numx = src->col_count;
  734.         dst->numy = src->row_count;
  735.  
  736.         sizeColor = GetColorSize (src->color_type);
  737.         sizeColor *= (src->col_count * src->row_count);
  738.         COPY_AREA ((char *) src->colors.indexed, &dst[1], sizeColor);
  739.  
  740.         dst = (pexPatternEntry *) ((char *) dst + 
  741.         sizeof (pexPatternEntry) + sizeColor);
  742.     }
  743.  
  744.     /* update the request length */
  745.     size = (char *) dst - (char *) dstStart;
  746.     req->length += (size + 3) >> 2;
  747.  
  748.     /* add the table entry data to the end of the X request */
  749.     Data (display, (char *) dstStart, size);
  750.  
  751.     break;
  752.     }
  753.  
  754.     case PEXLUTTextFont:
  755.     {
  756.     pexTextFontEntry *dst, *dstStart;
  757.     PEXTextFontEntry *src = (PEXTextFontEntry *)entries;
  758.  
  759.     size = count * sizeof (pexTextFontEntry);
  760.     for (i = 0; i < count; i++)
  761.     {
  762.         size += src[i].count * sizeof (pexFont);
  763.     }
  764.  
  765.     dstStart = dst = (pexTextFontEntry *)
  766.         _XAllocScratch (display, (unsigned long) size);
  767.  
  768.     for (i = 0; i < count; i++, src++)
  769.     {
  770.         dst->numFonts = src->count;
  771.         
  772.         COPY_AREA (src->fonts, &dst[1], src->count * sizeof (pexFont));
  773.  
  774.         dst = (pexTextFontEntry *) ((char *) dst + 
  775.         sizeof (pexTextFontEntry) + (src->count * sizeof (pexFont)));
  776.     }
  777.  
  778.     /* update the request length */
  779.     size = (char *) dst - (char *) dstStart;
  780.     req->length += (size + 3) >> 2;
  781.  
  782.     /* add the table entry data to the end of the X request */
  783.     Data (display, (char *) dstStart, size);
  784.     
  785.     break;
  786.     }
  787.  
  788.     case PEXLUTColor:
  789.     {
  790.     pexColorSpecifier *dst, *dstStart;
  791.     PEXColorEntry *src = (PEXColorEntry *) entries;
  792.  
  793.     dstStart = dst = (pexColorSpecifier *)
  794.         _XAllocScratch (display, count * sizeof (PEXColorEntry));
  795.  
  796.     for (i = 0; i < count; i++, src++)
  797.     {
  798.         PackColorSpecifier (src, dst, sizeColor);
  799.         
  800.         dst = (pexColorSpecifier *) ((char *) dst + 
  801.         sizeof (pexColorSpecifier) + sizeColor);
  802.     }
  803.  
  804.     /* update the request length */
  805.     size = (char *) dst - (char *) dstStart;
  806.     req->length += (size + 3) >> 2;
  807.  
  808.     /* add the table entry data to the end of the X request */
  809.     Data (display, (char *) dstStart, size);
  810.  
  811.     break;
  812.     }
  813.  
  814.     case PEXLUTView:
  815.         size = count * sizeof (PEXViewEntry);
  816.  
  817.         /* update the request length */
  818.     req->length += (size + 3) >> 2;
  819.  
  820.     /* add the table entry data to the end of the X request */
  821.     Data (display, (char *) entries, size);
  822.  
  823.     break;
  824.  
  825.      case PEXLUTLight:
  826.      {
  827.      pexLightEntry *dst, *dstStart;
  828.      PEXLightEntry *src = (PEXLightEntry *) entries;
  829.  
  830.      dstStart = dst = (pexLightEntry *)
  831.          _XAllocScratch (display, count * sizeof (PEXLightEntry));
  832.  
  833.      for (i = 0; i < count; i++, src++)
  834.      {
  835.          dst->lightType = src->type;
  836. #ifdef WORD64
  837. #else
  838.          dst->direction = *(pexVector3D *) &(src->direction);
  839.          dst->point = *(pexCoord3D *) &(src->point);
  840. #endif
  841.          dst->concentration = src->concentration;
  842.          dst->spreadAngle = src->spread_angle;
  843.          dst->attenuation1 = src->attenuation1;
  844.          dst->attenuation2 = src->attenuation2;
  845.         
  846.          PackColorSpecifier (&(src->color), &(dst->lightColor), sizeColor);
  847.  
  848.          dst = (pexLightEntry *) ((char *) dst + 
  849.          sizeof (pexLightEntry) + sizeColor);
  850.      }
  851.  
  852.      /* update the request length */
  853.      size = (char *) dst - (char *) dstStart;
  854.      req->length += (size + 3) >> 2;
  855.  
  856.      /* add the table entry data to the end of the X request */
  857.      Data (display, (char *) dstStart, size);
  858.      
  859.      break;
  860.      }
  861.  
  862.      case PEXLUTDepthCue:
  863.      {
  864.      pexDepthCueEntry *dst, *dstStart;
  865.      PEXDepthCueEntry *src = (PEXDepthCueEntry *) entries;
  866.  
  867.      dstStart = dst = (pexDepthCueEntry *)
  868.          _XAllocScratch (display, count * sizeof (PEXDepthCueEntry));
  869.  
  870.      for (i = 0; i < count; i++, src++)
  871.      {
  872.          dst->mode = src->mode;
  873.          dst->frontPlane = src->front_plane;
  874.          dst->backPlane = src->back_plane;
  875.          dst->frontScaling = src->front_scaling;
  876.          dst->backScaling = src->back_scaling;
  877.          
  878.          PackColorSpecifier (&(src->color), &(dst->depthCueColor), 
  879.          sizeColor);
  880.  
  881.          dst = (pexDepthCueEntry *) ((char *) dst + 
  882.          sizeof (pexDepthCueEntry) + sizeColor);
  883.      }
  884.  
  885.      /* update the request length */
  886.      size = (char *) dst - (char *) dstStart;
  887.      req->length += (size + 3) >> 2;
  888.      
  889.      /* add the table entry data to the end of the X request */
  890.      Data (display, (char *) dstStart, size);
  891.  
  892.      break;
  893.      }
  894.  
  895.      case PEXLUTColorApprox:
  896.     size = count * sizeof (PEXColorApproxEntry);
  897.  
  898.     /* update the request length */
  899.     req->length += (size + 3) >> 2;
  900.  
  901.     /* add the table entry data to the end of the X request */
  902.     Data (display, (char *) entries, size);
  903.     break;
  904.     }
  905.  
  906.  
  907.     /*
  908.      * Done, so unlock and check for synchronous-ness.
  909.      */
  910.  
  911.     UnlockDisplay (display);
  912.     PEXSyncHandle (display);
  913. }
  914.  
  915.  
  916. void
  917. PEXDeleteTableEntries (display, lut, start, count)
  918.  
  919. INPUT Display        *display;
  920. INPUT PEXLookupTable    lut;
  921. INPUT unsigned int    start;
  922. INPUT unsigned int    count;
  923.  
  924. {
  925.     pexDeleteTableEntriesReq    *req;
  926.  
  927.  
  928.     /*
  929.      * Lock around the critical section, for multithreading.
  930.      */
  931.  
  932.     LockDisplay (display);
  933.  
  934.  
  935.     /*
  936.      * Put the request in the X request buffer.
  937.      */
  938.  
  939.     PEXGetReq (DeleteTableEntries, req);
  940.     req->lut = lut;
  941.     req->start = start;
  942.     req->count = count;
  943.  
  944.  
  945.     /*
  946.      * Done, so unlock and check for synchronous-ness.
  947.      */
  948.  
  949.     UnlockDisplay (display);
  950.     PEXSyncHandle (display);
  951. }
  952.  
  953.  
  954.  
  955. /* This routine repacks the lut entries returned by PEXGetTableEntry,
  956.  * PEXGetTableEntries, and PEXGetPredefinedEntries.  This is mostly to
  957.  * change the colors, which may be of different sizes, to a fixed size
  958.  * to make it easier for application programs.  This isn't the fastest
  959.  * way to process replies that have no colors, but it's not expected to
  960.  * be used a whole lot.
  961. */
  962.  
  963. static PEXPointer
  964. _PEXRepackLUTEntries (pt, numEntries, type)
  965.  
  966. INPUT  char        *pt;
  967. INPUT  int        numEntries;
  968. INPUT  int        type;
  969.  
  970. {
  971.     int            sizeColor, i;
  972.     char        *buf;
  973.  
  974.  
  975.     switch (type)
  976.     {
  977.     case PEXLUTLineBundle:
  978.     {
  979.     PEXLineBundleEntry *dst;
  980.     pexLineBundleEntry *src = (pexLineBundleEntry *) pt;
  981.  
  982.     GetLUTEntryBuffer (numEntries, PEXLineBundleEntry, buf);
  983.     dst = (PEXLineBundleEntry *) buf;
  984.  
  985.     for (i = 0; i < numEntries; i++, dst++)
  986.     {
  987.         dst->type = src->lineType;
  988.         dst->interp_method = src->polylineInterp;
  989. #ifdef WORD64
  990. #else
  991.         dst->curve_approx = *(PEXCurveApprox *) &(src->curveApprox);
  992. #endif
  993.         dst->width = src->lineWidth;
  994.  
  995.         PackColorSpecifier (&(src->lineColor), &(dst->color), sizeColor);
  996.  
  997.         src = (pexLineBundleEntry *) ((char *) src +
  998.         sizeof (pexLineBundleEntry) + sizeColor);
  999.     }
  1000.  
  1001.     break;
  1002.     }
  1003.  
  1004.     case PEXLUTMarkerBundle:
  1005.     {
  1006.     PEXMarkerBundleEntry *dst;
  1007.     pexMarkerBundleEntry *src = (pexMarkerBundleEntry *) pt;
  1008.  
  1009.     GetLUTEntryBuffer (numEntries, PEXMarkerBundleEntry, buf);
  1010.     dst = (PEXMarkerBundleEntry *) buf;
  1011.  
  1012.     for (i = 0; i < numEntries; i++, dst++)
  1013.     {
  1014.         dst->type = src->markerType;
  1015.         dst->scale = src->markerScale;
  1016.         
  1017.         PackColorSpecifier (&(src->markerColor), &(dst->color), sizeColor);
  1018.  
  1019.         src = (pexMarkerBundleEntry *) ((char *) src +
  1020.         sizeof (pexMarkerBundleEntry) + sizeColor);
  1021.     }
  1022.  
  1023.     break;
  1024.     }
  1025.  
  1026.     case PEXLUTTextBundle:
  1027.     {
  1028.     PEXTextBundleEntry *dst;
  1029.     pexTextBundleEntry *src = (pexTextBundleEntry *) pt;
  1030.         
  1031.     GetLUTEntryBuffer (numEntries, PEXTextBundleEntry, buf);
  1032.     dst = (PEXTextBundleEntry *) buf;
  1033.  
  1034.     for (i = 0; i < numEntries; i++, dst++)
  1035.     {
  1036.         dst->font_index = src->textFontIndex;
  1037.         dst->precision = src->textPrecision;
  1038.         dst->char_expansion = src->charExpansion;
  1039.         dst->char_spacing = src->charSpacing;
  1040.         
  1041.         PackColorSpecifier (&(src->textColor), &(dst->color), sizeColor);
  1042.  
  1043.         src = (pexTextBundleEntry *) ((char *) src +
  1044.         sizeof (pexTextBundleEntry) + sizeColor);
  1045.     }
  1046.  
  1047.     break;
  1048.     }
  1049.  
  1050.     case PEXLUTInteriorBundle:
  1051.     {
  1052.     PEXInteriorBundleEntry *dst;
  1053.     char *src = (char *) pt;
  1054.  
  1055.     GetLUTEntryBuffer (numEntries, PEXInteriorBundleEntry, buf);
  1056.     dst = (PEXInteriorBundleEntry *) buf;
  1057.  
  1058.     for (i = 0; i < numEntries; i++, dst++)
  1059.     {
  1060.         dst->style =
  1061.         ((pexInteriorBundleEntry *) src)->interiorStyle;
  1062.         dst->style_index =
  1063.         ((pexInteriorBundleEntry *) src)->interiorStyleIndex;
  1064.         dst->reflection_model =
  1065.         ((pexInteriorBundleEntry *) src)->reflectionModel;
  1066.         dst->interp_method =
  1067.         ((pexInteriorBundleEntry *) src)->surfaceInterp;
  1068.         dst->bf_style =
  1069.         ((pexInteriorBundleEntry *) src)->bfInteriorStyle;
  1070.         dst->bf_style_index =
  1071.         ((pexInteriorBundleEntry *) src)->bfInteriorStyleIndex;
  1072.         dst->bf_reflection_model =
  1073.         ((pexInteriorBundleEntry *) src)->bfReflectionModel;
  1074.         dst->bf_interp_method =
  1075.         ((pexInteriorBundleEntry *) src)->bfSurfaceInterp;
  1076. #ifdef WORD64
  1077. #else
  1078.         dst->surface_approx = *(PEXSurfaceApprox *)
  1079.         &(((pexInteriorBundleEntry *) src)->surfaceApprox);
  1080. #endif
  1081.         src += sizeof (pexInteriorBundleEntry);
  1082.  
  1083.         /* copy surfaceColor */
  1084.         PackColorSpecifier (src, &(dst->color), sizeColor);
  1085.         src += sizeof (pexColorSpecifier) + sizeColor;
  1086.  
  1087.         /* copy reflectionAttr */
  1088.         dst->reflection_attr.ambient = 
  1089.         ((pexReflectionAttr *) src)->ambient;
  1090.         dst->reflection_attr.diffuse =
  1091.         ((pexReflectionAttr *) src)->diffuse;
  1092.         dst->reflection_attr.specular =
  1093.         ((pexReflectionAttr *) src)->specular;
  1094.         dst->reflection_attr.specular_conc =
  1095.         ((pexReflectionAttr *) src)->specularConc;
  1096.         dst->reflection_attr.transmission =
  1097.         ((pexReflectionAttr *) src)->transmission;
  1098.         PackColorSpecifier (
  1099.                 &(((pexReflectionAttr *)src)->specularColor),
  1100.                 &(dst->reflection_attr.specular_color), sizeColor);
  1101.         src += sizeof (pexReflectionAttr) + sizeColor;
  1102.  
  1103.         /* copy bfSurfaceColor */
  1104.         PackColorSpecifier (src, &(dst->bf_color), sizeColor);
  1105.         src += sizeof (pexColorSpecifier) + sizeColor;
  1106.  
  1107.         /* copy bfReflectionAttr */
  1108.         dst->bf_reflection_attr.ambient =
  1109.         ((pexReflectionAttr *) src)->ambient;
  1110.         dst->bf_reflection_attr.diffuse =
  1111.         ((pexReflectionAttr *) src)->diffuse;
  1112.         dst->bf_reflection_attr.specular =
  1113.         ((pexReflectionAttr *) src)->specular;
  1114.         dst->bf_reflection_attr.specular_conc =
  1115.         ((pexReflectionAttr *) src)->specularConc;
  1116.         dst->bf_reflection_attr.transmission =
  1117.         ((pexReflectionAttr *) src)->transmission;
  1118.         PackColorSpecifier (
  1119.                 &(((pexReflectionAttr *) src)->specularColor),
  1120.                 &(dst->bf_reflection_attr.specular_color), sizeColor);
  1121.         src += sizeof (pexReflectionAttr) + sizeColor;
  1122.     }
  1123.  
  1124.     break;
  1125.     }
  1126.  
  1127.     case PEXLUTEdgeBundle:
  1128.     {
  1129.     PEXEdgeBundleEntry *dst;
  1130.     pexEdgeBundleEntry *src = (pexEdgeBundleEntry *) pt;
  1131.          
  1132.     GetLUTEntryBuffer (numEntries, PEXEdgeBundleEntry, buf);
  1133.     dst = (PEXEdgeBundleEntry *) buf;
  1134.  
  1135.     for (i = 0; i < numEntries; i++, dst++)
  1136.     {
  1137.         dst->edge_flag = src->edges;
  1138.         dst->type = src->edgeType;
  1139.         dst->width = src->edgeWidth;
  1140.  
  1141.         PackColorSpecifier (&(src->edgeColor), &(dst->color), sizeColor);
  1142.  
  1143.         src = (pexEdgeBundleEntry *) ((char *) src +
  1144.         sizeof (pexEdgeBundleEntry) + sizeColor);
  1145.     }
  1146.  
  1147.     break;
  1148.     }
  1149.  
  1150.     case PEXLUTPattern:
  1151.     {
  1152.     PEXPatternEntry *dst;
  1153.     pexPatternEntry *src = (pexPatternEntry *)pt;
  1154.     
  1155.     GetLUTEntryBuffer (numEntries, PEXPatternEntry, buf);
  1156.     dst = (PEXPatternEntry *) buf;
  1157.  
  1158.     for (i = 0; i < numEntries; i++, dst++)
  1159.     {
  1160.         dst->color_type = src->colorType;
  1161.         dst->col_count = src->numx;
  1162.         dst->row_count = src->numy;
  1163.  
  1164.         sizeColor = GetColorSize (src->colorType);
  1165.         sizeColor *= (src->numx * src->numy);
  1166.         dst->colors.indexed =
  1167.         (PEXColorIndexed *) PEXAllocBuf ((unsigned) sizeColor);
  1168.         COPY_AREA (&src[1], (char *) dst->colors.indexed, sizeColor);
  1169.  
  1170.         src = (pexPatternEntry *) ((char *) src +
  1171.         sizeof (pexPatternEntry) + sizeColor);
  1172.     }
  1173.     break;
  1174.     }
  1175.  
  1176.     case PEXLUTTextFont:
  1177.     {
  1178.     PEXTextFontEntry *dst;
  1179.     pexTextFontEntry *src = (pexTextFontEntry *) pt;
  1180.  
  1181.     GetLUTEntryBuffer (numEntries, PEXTextFontEntry, buf);
  1182.     dst = (PEXTextFontEntry *) buf;
  1183.  
  1184.     for (i = 0; i < numEntries; i++, dst++)
  1185.     {
  1186.         dst->count = src->numFonts;
  1187.         dst->fonts = (pexFont *)
  1188.         PEXAllocBuf (src->numFonts * sizeof (pexFont));
  1189.         
  1190.         COPY_AREA (&src[1], dst->fonts,
  1191.         src->numFonts * sizeof (pexFont));
  1192.  
  1193.         src = (pexTextFontEntry *) ((char *) src + 
  1194.         sizeof (pexTextFontEntry) +
  1195.         (src->numFonts * sizeof (pexFont)));
  1196.     }
  1197.     
  1198.     break;
  1199.     }
  1200.  
  1201.     case PEXLUTColor:
  1202.     {
  1203.     PEXColorEntry *dst;
  1204.     pexColorSpecifier *src = (pexColorSpecifier *) pt;
  1205.     
  1206.     GetLUTEntryBuffer (numEntries, PEXColorEntry, buf);
  1207.     dst = (PEXColorEntry *) buf;
  1208.  
  1209.     for (i = 0; i < numEntries; i++, dst++)
  1210.     {
  1211.         PackColorSpecifier (src, dst, sizeColor);
  1212.  
  1213.         src = (pexColorSpecifier *) ((char *) src +
  1214.         sizeof (pexColorSpecifier) + sizeColor);
  1215.     }
  1216.     
  1217.     break;
  1218.     }
  1219.  
  1220.     case PEXLUTView:
  1221.     GetLUTEntryBuffer (numEntries, PEXViewEntry, buf);
  1222.  
  1223.     COPY_AREA ((char *) pt, (char *) buf,
  1224.         numEntries * sizeof (pexViewEntry));
  1225.  
  1226.     break;
  1227.  
  1228.     case PEXLUTLight:
  1229.     {
  1230.     PEXLightEntry *dst;
  1231.     pexLightEntry *src = (pexLightEntry *) pt;
  1232.     
  1233.     GetLUTEntryBuffer (numEntries, PEXLightEntry, buf);
  1234.     dst = (PEXLightEntry *) buf;
  1235.  
  1236.     for (i = 0; i < numEntries; i++, dst++)
  1237.     {
  1238.         dst->type = src->lightType;
  1239. #ifdef WORD64
  1240. #else
  1241.         dst->direction = *(PEXVector *) &(src->direction);
  1242.         dst->point = *(PEXCoord *) &(src->point);
  1243. #endif
  1244.         dst->concentration = src->concentration;
  1245.         dst->spread_angle = src->spreadAngle;
  1246.         dst->attenuation1 = src->attenuation1;
  1247.         dst->attenuation2 = src->attenuation2;
  1248.         
  1249.         PackColorSpecifier (&(src->lightColor), &(dst->color), sizeColor);
  1250.  
  1251.         src = (pexLightEntry *) ((char *) src +
  1252.         sizeof (pexLightEntry) + sizeColor);
  1253.     }
  1254.  
  1255.     break;
  1256.     }
  1257.  
  1258.     case PEXLUTDepthCue:
  1259.     {
  1260.     PEXDepthCueEntry *dst;
  1261.     pexDepthCueEntry *src = (pexDepthCueEntry *) pt;
  1262.     
  1263.     GetLUTEntryBuffer (numEntries, PEXDepthCueEntry, buf);
  1264.     dst = (PEXDepthCueEntry *) buf;
  1265.     
  1266.     for (i = 0; i < numEntries; i++, dst++)
  1267.     {
  1268.         dst->mode = src->mode;
  1269.         dst->front_plane = src->frontPlane;
  1270.         dst->back_plane = src->backPlane;
  1271.         dst->front_scaling = src->frontScaling;
  1272.         dst->back_scaling = src->backScaling;
  1273.         
  1274.         PackColorSpecifier (&(src->depthCueColor), &(dst->color),
  1275.                 sizeColor);
  1276.  
  1277.         src = (pexDepthCueEntry *) ((char *) src +
  1278.         sizeof (pexDepthCueEntry) + sizeColor);
  1279.     }
  1280.  
  1281.     break;
  1282.     }
  1283.  
  1284.     case PEXLUTColorApprox:
  1285.     GetLUTEntryBuffer (numEntries, PEXColorApproxEntry, buf);
  1286.  
  1287.     COPY_AREA ((char *) pt, (char *) buf,
  1288.         numEntries * sizeof (pexColorApproxEntry));
  1289.  
  1290.         break;
  1291.     }
  1292.  
  1293.     return ((PEXPointer) buf);
  1294. }
  1295.  
  1296.