home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxgd101.zip / RXGDUTIL.C < prev    next >
Text File  |  1995-09-19  |  40KB  |  1,102 lines

  1. /*----------------------------------------------------------------------
  2.  
  3.    Support Routines for RXgdUtil.DLL
  4.  
  5.         Written by Andy Wysocki, 9/95
  6.         Copyright 1995, AB Software
  7.         Permission granted to use this code in any fashion provided
  8.         that this notice is retained and any alterations are
  9.         labeled as such. It is requested, but not required, that
  10.         you share extensions to this module with me so that we
  11.         can incorporate them into new versions.
  12.  
  13.   ----------------------------------------------------------------------*/
  14. #define  INCL_VIO
  15. #define  INCL_DOS
  16. #define  INCL_ERRORS
  17. #define  INCL_REXXSAA
  18. #define  _DLL
  19. #include <os2.h>
  20. #include <rexxsaa.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <io.h>
  24.  
  25. #include "gd.h"
  26. #include "gdfontg.h"
  27. #include "gdfontl.h"
  28. #include "gdfontmb.h"
  29. #include "gdfonts.h"
  30. #include "gdfontt.h"
  31.  
  32. #define BUILDRXSTRING(t, s) { \
  33.   strcpy((t)->strptr,(s));\
  34.   (t)->strlength = strlen((s)); \
  35.   }
  36.  
  37. #define BUILDRXULONG(t, s) { \
  38.   sprintf((t)->strptr, "%u", (s));\
  39.   (t)->strlength = strlen((t)->strptr); \
  40.   }
  41.  
  42. #define BUILDRXLONG(t, s) { \
  43.   sprintf((t)->strptr, "%d", (s));\
  44.   (t)->strlength = strlen((t)->strptr); \
  45.   }
  46.  
  47. #define OK_CALL         0
  48. #define BAD_CALL        40
  49.  
  50. #define MAX_DIGITS      10
  51.  
  52.  
  53. static PSZ RxFuncTable[] =
  54.   {
  55.   "RxgdImageCreate",          "RxgdImageCreate",
  56.   "RxgdImageCreateFromGIF",   "RxgdImageCreateFromGIF",
  57.   "RxgdImageDestroy",         "RxgdImageDestroy",
  58.   "RxgdImageGIF",             "RxgdImageGIF",
  59.   "RxgdImageSetPixel",        "RxgdImageSetPixel",
  60.   "RxgdImageLine",            "RxgdImageLine",
  61.   "RxgdImagePolygon",         "RxgdImagePolygon",
  62.   "RxgdImageFilledPolygon",   "RxgdImagePolygon",
  63.   "RxgdImageRectangle",       "RxgdImageRectangle",
  64.   "RxgdImageFilledRectangle", "RxgdImageRectangle",
  65.   "RxgdImageArc",             "RxgdImageArc",
  66.   "RxgdImageFillToBorder",    "RxgdImageFillToBorder",
  67.   "RxgdImageFill",            "RxgdImageFill",
  68.   "RxgdImageColorAllocate",   "RxgdImageColorAllocate",
  69.   "RxgdImageColorClosest",    "RxgdImageColorAllocate",
  70.   "RxgdImageColorExact",      "RxgdImageColorAllocate",
  71.   "RxgdImageString",          "RxgdImageString",
  72.   "RxgdImageStringUp",        "RxgdImageString",
  73.   "RxgdImageSetBrush",        "RxgdImageSetBrush",
  74.   "RxgdImageSetTile",         "RxgdImageSetBrush",
  75.   "RxgdImageSetStyle",        "RxgdImageSetStyle",
  76.   "RxgdImageGetStyledBrushed","RxgdImageGetStyledBrushed",
  77.   "RxgdImageBlue",            "RxgdImageGetColor",
  78.   "RxgdImageRed",             "RxgdImageGetColor",
  79.   "RxgdImageGreen",           "RxgdImageGetColor",
  80.   "RxgdImageGetPixel",        "RxgdImageGetPixel",
  81.   "RxgdImageSX",              "RxgdImageSxy",
  82.   "RxgdImageSY",              "RxgdImageSxy",
  83.   "RxgdImageBoundsSafe",      "RxgdImageBoundsSafe",
  84.   "RxgdImageColorsTotal",     "RxgdImageGetTTI",
  85.   "RxgdImageGetInterlaced",   "RxgdImageGetTTI",
  86.   "RxgdImageGetTransparent",  "RxgdImageGetTTI",
  87.   "RxgdImageColorDeallocate", "RxgdImageColorDeallocate",
  88.   "RxgdImageColorTransparent","RxgdImageColorSet",
  89.   "RxgdImageInterlace",       "RxgdImageColorSet",
  90.   "RxgdImageCopy",            "RxgdImageCopy",
  91.   "RxgdImageCopyResized",     "RxgdImageCopyResized",
  92.   "RxgdImageSetColor",        "RxgdImageSetColor",
  93.   "RxgdUnloadFuncs",          "RxgdUnloadFuncs",
  94.   "RxgdLoadFuncs",            "RxgdLoadFuncs",
  95.   };
  96.  
  97. /*********************************************************************/
  98. /*  Declare all exported functions as REXX functions.                */
  99. /*********************************************************************/
  100. RexxFunctionHandler RxgdLoadFuncs;
  101. RexxFunctionHandler RxgdUnloadFuncs;
  102. RexxFunctionHandler RxgdImageCreate;
  103. RexxFunctionHandler RxgdImageCreateFromGIF;
  104. RexxFunctionHandler RxgdImageDestroy;
  105. RexxFunctionHandler RxgdImageGIF;
  106.  
  107. RexxFunctionHandler RxgdImageSetPixel;
  108. RexxFunctionHandler RxgdImageLine;
  109. RexxFunctionHandler RxgdImagePolygon;
  110. RexxFunctionHandler RxgdImageRectangle;
  111. RexxFunctionHandler RxgdImageArc;
  112. RexxFunctionHandler RxgdImageFillToBorder;
  113. RexxFunctionHandler RxgdImageFill;
  114.  
  115. RexxFunctionHandler RxgdImageColorAllocate;
  116. RexxFunctionHandler RxgdImageString;
  117. RexxFunctionHandler RxgdImageSetBrush;
  118. RexxFunctionHandler RxgdImageSetStyle;
  119. RexxFunctionHandler RxgdImageGetStyledBrushed;
  120.  
  121. RexxFunctionHandler RxgdImageGetColor;
  122. RexxFunctionHandler RxgdImageGetPixel;
  123. RexxFunctionHandler RxgdImageSxy;
  124. RexxFunctionHandler RxgdImageGetBoundsSafe;
  125. RexxFunctionHandler RxgdImageGetTTI;
  126. RexxFunctionHandler RxgdImageColorDeallocate;
  127. RexxFunctionHandler RxgdImageColorSet;
  128. RexxFunctionHandler RxgdImageCopy;
  129. RexxFunctionHandler RxgdImageCopyResized;
  130.  
  131. RexxFunctionHandler RxgdImageSetColor;
  132.  
  133. /*----------------------------------------------------------------------*/
  134. /* Debug routine - No use in normal code                                */
  135. /*----------------------------------------------------------------------*/
  136. #if 0
  137. MyLog(char *_Str)
  138. {
  139. FILE    *FP;
  140.  
  141.   FP = fopen("rxgdutil.dbg", "ab");
  142.  
  143.   if (!FP)
  144.     return;
  145.  
  146.   fwrite(_Str, 1, strlen(_Str), FP);
  147.   fwrite("\r\n", 1, 2, FP);
  148.  
  149.   fclose(FP);
  150.  
  151. }
  152. #endif
  153.  
  154. /*----------------------------------------------------------------------*/
  155. /* RXGDLOADFUNCS -                                                      */
  156. /*----------------------------------------------------------------------*/
  157. ULONG RxgdLoadFuncs(
  158.   PSZ           _Name,                  /* name of the function         */
  159.   ULONG         _Argc,                  /* number of args               */
  160.   RXSTRING      _Argv[],                /* list of argument strings     */
  161.   PSZ           _Queuename,             /* current queue name           */
  162.   PRXSTRING     _Retstr)                /* returned result string       */
  163. {
  164.  
  165. int     entries;
  166. int     index;
  167.  
  168.   _Retstr->strlength = 0;
  169.  
  170.   if (_Argc > 0)                        /* Bad call to function         */
  171.     return(BAD_CALL);                   /* Let REXX bomb                */
  172.  
  173.   entries = sizeof(RxFuncTable) / sizeof(PSZ);
  174.  
  175.   for (index = 0; index < entries; index+=2)
  176.     RexxRegisterFunctionDll(RxFuncTable[index],
  177.                             "RXGDUTIL",
  178.                             RxFuncTable[index+1]);
  179.  
  180. return(OK_CALL);
  181. }
  182.  
  183. /*----------------------------------------------------------------------*/
  184. /* RXGDUNLOADFUNCS -                                                    */
  185. /*----------------------------------------------------------------------*/
  186. ULONG RxgdUnloadFuncs(
  187.   PSZ           _Name,                  /* name of the function         */
  188.   ULONG         _Argc,                  /* number of args               */
  189.   RXSTRING      _Argv[],                /* list of argument strings     */
  190.   PSZ           _Queuename,             /* current queue name           */
  191.   PRXSTRING     _Retstr)                /* returned result string       */
  192. {
  193.  
  194. int     entries;
  195. int     index;
  196.  
  197.   _Retstr->strlength = 0;
  198.  
  199.   if (_Argc > 0)
  200.     return(BAD_CALL);
  201.  
  202.   entries = sizeof(RxFuncTable) / sizeof(PSZ);
  203.  
  204.   for (index = 0; index < entries; index+=2)
  205.     RexxDeregisterFunction(RxFuncTable[index]);
  206.  
  207. return(OK_CALL);
  208. }
  209.  
  210.  
  211. /*----------------------------------------------------------------------*/
  212. /*----------------------------------------------------------------------*/
  213. ULONG RxgdImageCreate(
  214.   PSZ           _Name,                  /* name of the function         */
  215.   ULONG         _Argc,                  /* number of args               */
  216.   RXSTRING      _Argv[],                /* list of argument strings     */
  217.   PSZ           _Queuename,             /* current queue name           */
  218.   PRXSTRING     _Retstr)                /* returned result string       */
  219. {
  220. gdImagePtr   im;
  221. ULONG   row, col;
  222.  
  223.   BUILDRXULONG(_Retstr, 0);             /* Not created                */
  224.                                         /* check arguments            */
  225.   if (_Argc != 2)                       /* wrong number?              */
  226.     return BAD_CALL;                    /* raise an error             */
  227.  
  228.   row = atol(_Argv[0].strptr);
  229.   col = atol(_Argv[1].strptr);
  230.  
  231.   im = gdImageCreate(row, col);
  232.  
  233.   BUILDRXULONG(_Retstr, (ULONG)im);
  234.  
  235.  
  236.   return(OK_CALL);                      /* no error on call           */
  237. }
  238.  
  239.  
  240. /*----------------------------------------------------------------------*/
  241. /*----------------------------------------------------------------------*/
  242. ULONG RxgdImageCreateFromGIF(
  243.   PSZ           _Name,                  /* name of the function         */
  244.   ULONG         _Argc,                  /* number of args               */
  245.   RXSTRING      _Argv[],                /* list of argument strings     */
  246.   PSZ           _Queuename,             /* current queue name           */
  247.   PRXSTRING     _Retstr)                /* returned result string       */
  248. {
  249. FILE            *FP;
  250. gdImagePtr      im;
  251. ULONG           rc;
  252.  
  253.   BUILDRXULONG(_Retstr, 0);             /* Not created                */
  254.                                         /* check arguments            */
  255.   if (_Argc != 1)                       /* wrong number?              */
  256.     return BAD_CALL;                    /* raise an error             */
  257.  
  258.   FP = fopen(_Argv[0].strptr, "rb");    /* Open the GIF file            */
  259.  
  260.   if (!FP)                              /* Return a bad RC to caller    */
  261.     {
  262.     BUILDRXULONG(_Retstr, 1);
  263.     return(OK_CALL);
  264.     }
  265.  
  266.   im = gdImageCreateFromGif(FP);        /* Create internal memory str   */
  267.  
  268.   fclose(FP);
  269.  
  270.   BUILDRXULONG(_Retstr, (ULONG)im);     /* Return handle to caller      */
  271.  
  272. return(OK_CALL);
  273. }
  274.  
  275.  
  276. /*----------------------------------------------------------------------*/
  277. /*----------------------------------------------------------------------*/
  278. ULONG RxgdImageDestroy(
  279.   PSZ           _Name,                  /* name of the function         */
  280.   ULONG         _Argc,                  /* number of args               */
  281.   RXSTRING      _Argv[],                /* list of argument strings     */
  282.   PSZ           _Queuename,             /* current queue name           */
  283.   PRXSTRING     _Retstr)                /* returned result string       */
  284. {
  285. gdImagePtr      im;
  286.  
  287.   BUILDRXULONG(_Retstr, 0);             /* Not created                */
  288.                                         /* check arguments            */
  289.   if (_Argc != 1)                       /* wrong number?              */
  290.     return BAD_CALL;                    /* raise an error             */
  291.  
  292.   im = (gdImagePtr)atol(_Argv[0].strptr);
  293.  
  294.   gdImageDestroy(im);                   /* free up memory               */
  295.  
  296. return(OK_CALL);
  297. }
  298.  
  299.  
  300. /*----------------------------------------------------------------------*/
  301. /*----------------------------------------------------------------------*/
  302. ULONG RxgdImageGIF(
  303.   PSZ           _Name,                  /* name of the function         */
  304.   ULONG         _Argc,                  /* number of args               */
  305.   RXSTRING      _Argv[],                /* list of argument strings     */
  306.   PSZ           _Queuename,             /* current queue name           */
  307.   PRXSTRING     _Retstr)                /* returned result string       */
  308. {
  309. FILE            *FP;
  310. gdImagePtr      im;
  311.  
  312.   BUILDRXULONG(_Retstr, 0);             /* Not created                */
  313.                                         /* check arguments            */
  314.   if (_Argc != 2)                       /* wrong number?              */
  315.     return BAD_CALL;                    /* raise an error             */
  316.  
  317.   im = (gdImagePtr)atol(_Argv[0].strptr);
  318.  
  319.   FP = fopen(_Argv[1].strptr, "wb");
  320.  
  321.   if (!FP)
  322.     {
  323.     BUILDRXULONG(_Retstr, 1);
  324.     return(OK_CALL);
  325.     }
  326.  
  327.   gdImageGif(im, FP);
  328.  
  329.   fclose(FP);
  330.  
  331. return(OK_CALL);
  332. }
  333.  
  334.  
  335. /*----------------------------------------------------------------------*/
  336. /*----------------------------------------------------------------------*/
  337. ULONG RxgdImageSetPixel(
  338.   PSZ           _Name,                  /* name of the function         */
  339.   ULONG         _Argc,                  /* number of args               */
  340.   RXSTRING      _Argv[],                /* list of argument strings     */
  341.   PSZ           _Queuename,             /* current queue name           */
  342.   PRXSTRING     _Retstr)                /* returned result string       */
  343. {
  344. gdImagePtr      im;
  345. int     x, y, color;
  346.  
  347.   BUILDRXULONG(_Retstr, 0);             /* Not created                */
  348.                                         /* check arguments            */
  349.   if (_Argc != 4)                       /* wrong number?              */
  350.     return BAD_CALL;                    /* raise an error             */
  351.  
  352.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  353.   x     = atol(_Argv[1].strptr);
  354.   y     = atol(_Argv[2].strptr);
  355.   color = atol(_Argv[3].strptr);
  356.  
  357.   gdImageSetPixel(im, x, y, color);
  358.  
  359. return(OK_CALL);
  360. }
  361.  
  362.  
  363.  
  364. /*----------------------------------------------------------------------*/
  365. /*----------------------------------------------------------------------*/
  366. ULONG RxgdImageLine(
  367.   PSZ           _Name,                  /* name of the function         */
  368.   ULONG         _Argc,                  /* number of args               */
  369.   RXSTRING      _Argv[],                /* list of argument strings     */
  370.   PSZ           _Queuename,             /* current queue name           */
  371.   PRXSTRING     _Retstr)                /* returned result string       */
  372. {
  373. gdImagePtr      im;
  374. int     x1, x2, y1, y2, color;
  375.  
  376.   BUILDRXULONG(_Retstr, 0);             /* Not created                */
  377.                                         /* check arguments            */
  378.   if (_Argc != 6)                       /* wrong number?              */
  379.     return BAD_CALL;                    /* raise an error             */
  380.  
  381.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  382.   x1    = atol(_Argv[1].strptr);
  383.   y1    = atol(_Argv[2].strptr);
  384.   x2    = atol(_Argv[3].strptr);
  385.   y2    = atol(_Argv[4].strptr);
  386.   color = atol(_Argv[5].strptr);
  387.  
  388.   gdImageLine(im, x1, y1, x2, y2, color);
  389.  
  390. return(OK_CALL);
  391. }
  392.  
  393.  
  394. /*----------------------------------------------------------------------*/
  395. /*----------------------------------------------------------------------*/
  396. ULONG RxgdImageRectangle(
  397.   PSZ           _Name,                  /* name of the function         */
  398.   ULONG         _Argc,                  /* number of args               */
  399.   RXSTRING      _Argv[],                /* list of argument strings     */
  400.   PSZ           _Queuename,             /* current queue name           */
  401.   PRXSTRING     _Retstr)                /* returned result string       */
  402. {
  403. gdImagePtr      im;
  404. int     x1, x2, y1, y2, color;
  405.  
  406.   BUILDRXULONG(_Retstr, 0);             /* Not created                */
  407.                                         /* check arguments            */
  408.   if (_Argc != 6)                       /* wrong number?              */
  409.     return BAD_CALL;                    /* raise an error             */
  410.  
  411.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  412.   x1    = atol(_Argv[1].strptr);
  413.   y1    = atol(_Argv[2].strptr);
  414.   x2    = atol(_Argv[3].strptr);
  415.   y2    = atol(_Argv[4].strptr);
  416.   color = atol(_Argv[5].strptr);
  417.  
  418.   if (_Name[9] == 'R')                  /* SO I cheat here, it easier        */
  419.                                         /* than making a function for each   */
  420.                                         /* RxgdImageRectangle                */
  421.     gdImageRectangle(im, x1, y1, x2, y2, color);
  422.   else                                  /* RxgdImageFilledRectangle          */
  423.     gdImageFilledRectangle(im, x1, y1, x2, y2, color);
  424.  
  425. return(OK_CALL);
  426. }
  427.  
  428.  
  429. /*----------------------------------------------------------------------*/
  430. /*----------------------------------------------------------------------*/
  431. ULONG RxgdImageArc(
  432.   PSZ           _Name,                  /* name of the function         */
  433.   ULONG         _Argc,                  /* number of args               */
  434.   RXSTRING      _Argv[],                /* list of argument strings     */
  435.   PSZ           _Queuename,             /* current queue name           */
  436.   PRXSTRING     _Retstr)                /* returned result string       */
  437. {
  438. gdImagePtr      im;
  439. int     cx, cy, w, h, s, e, color;
  440.  
  441.   BUILDRXULONG(_Retstr, 0);             /* Not created                */
  442.                                         /* check arguments            */
  443.   if (_Argc != 8)                       /* wrong number?              */
  444.     return BAD_CALL;                    /* raise an error             */
  445.  
  446.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  447.   cx    = atol(_Argv[1].strptr);
  448.   cy    = atol(_Argv[2].strptr);
  449.   w     = atol(_Argv[3].strptr);
  450.   h     = atol(_Argv[4].strptr);
  451.   s     = atol(_Argv[5].strptr);
  452.   e     = atol(_Argv[6].strptr);
  453.   color = atol(_Argv[7].strptr);
  454.  
  455.   gdImageArc(im, cx, cy, w, h, s, e, color);
  456.  
  457. return(OK_CALL);
  458. }
  459.  
  460.  
  461. /*----------------------------------------------------------------------*/
  462. /*----------------------------------------------------------------------*/
  463. ULONG RxgdImageFillToBorder(
  464.   PSZ           _Name,                  /* name of the function         */
  465.   ULONG         _Argc,                  /* number of args               */
  466.   RXSTRING      _Argv[],                /* list of argument strings     */
  467.   PSZ           _Queuename,             /* current queue name           */
  468.   PRXSTRING     _Retstr)                /* returned result string       */
  469. {
  470. gdImagePtr      im;
  471. int     x, y, border, color;
  472.  
  473.   BUILDRXULONG(_Retstr, 0);             /* Not created                */
  474.                                         /* check arguments            */
  475.   if (_Argc != 5)                       /* wrong number?              */
  476.     return BAD_CALL;                    /* raise an error             */
  477.  
  478.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  479.   x     = atol(_Argv[1].strptr);
  480.   y     = atol(_Argv[2].strptr);
  481.   border= atol(_Argv[3].strptr);
  482.   color = atol(_Argv[4].strptr);
  483.  
  484.   gdImageFillToBorder(im, x, y, border, color);
  485.  
  486. return(OK_CALL);
  487. }
  488.  
  489.  
  490. /*----------------------------------------------------------------------*/
  491. /*----------------------------------------------------------------------*/
  492. ULONG RxgdImageFill(
  493.   PSZ           _Name,                  /* name of the function         */
  494.   ULONG         _Argc,                  /* number of args               */
  495.   RXSTRING      _Argv[],                /* list of argument strings     */
  496.   PSZ           _Queuename,             /* current queue name           */
  497.   PRXSTRING     _Retstr)                /* returned result string       */
  498. {
  499. gdImagePtr      im;
  500. int     x, y, color;
  501.  
  502.   BUILDRXULONG(_Retstr, 0);             /* Not created                */
  503.                                         /* check arguments            */
  504.   if (_Argc != 4)                       /* wrong number?              */
  505.     return BAD_CALL;                    /* raise an error             */
  506.  
  507.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  508.   x     = atol(_Argv[1].strptr);
  509.   y     = atol(_Argv[2].strptr);
  510.   color = atol(_Argv[3].strptr);
  511.  
  512.   gdImageFill(im, x, y, color);
  513.  
  514. return(OK_CALL);
  515. }
  516.  
  517.  
  518. /*----------------------------------------------------------------------*/
  519. /*----------------------------------------------------------------------*/
  520. ULONG RxgdImageColorAllocate(
  521.   PSZ           _Name,                  /* name of the function         */
  522.   ULONG         _Argc,                  /* number of args               */
  523.   RXSTRING      _Argv[],                /* list of argument strings     */
  524.   PSZ           _Queuename,             /* current queue name           */
  525.   PRXSTRING     _Retstr)                /* returned result string       */
  526. {
  527. gdImagePtr      im;
  528. int     r, g, b;
  529. int     rc;
  530.  
  531.                                         /* check arguments            */
  532.   if (_Argc != 4)                       /* wrong number?              */
  533.     return (BAD_CALL);                  /* raise an error             */
  534.  
  535.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  536.   r     = atol(_Argv[1].strptr);
  537.   g     = atol(_Argv[2].strptr);
  538.   b     = atol(_Argv[3].strptr);
  539.  
  540.   switch(_Name[14])
  541.     {
  542.     case 'A':                           /* RxgdImageColorAllocate       */
  543.       rc = gdImageColorAllocate(im, r, g, b);
  544.       break;
  545.  
  546.     case 'C':                           /* RxgdImageColorClosest        */
  547.       rc = gdImageColorClosest(im, r, g, b);
  548.       break;
  549.  
  550.     case 'E':                           /* RxgdImageColorExact          */
  551.       rc = gdImageColorExact(im, r, g, b);
  552.       break;
  553.  
  554.     default:
  555.       return(BAD_CALL);
  556.     }
  557.  
  558.   BUILDRXLONG(_Retstr, rc);
  559.  
  560. return(OK_CALL);
  561. }
  562.  
  563. /*----------------------------------------------------------------------*/
  564. /* NOTE: GD.LIB does not have function like this,  I needed a way to    */
  565. /*      Change a specific color index, so I provide this function       */
  566. /*----------------------------------------------------------------------*/
  567. ULONG RxgdImageSetColor(
  568.   PSZ           _Name,                  /* name of the function         */
  569.   ULONG         _Argc,                  /* number of args               */
  570.   RXSTRING      _Argv[],                /* list of argument strings     */
  571.   PSZ           _Queuename,             /* current queue name           */
  572.   PRXSTRING     _Retstr)                /* returned result string       */
  573. {
  574. gdImagePtr      im;
  575. int     r, g, b, index;
  576. int     rc;
  577.  
  578.                                         /* check arguments            */
  579.   if (_Argc != 5)                       /* wrong number?              */
  580.     return (BAD_CALL);                  /* raise an error             */
  581.  
  582.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  583.   index = atol(_Argv[1].strptr);
  584.   r     = atol(_Argv[2].strptr);
  585.   g     = atol(_Argv[3].strptr);
  586.   b     = atol(_Argv[4].strptr);
  587.  
  588.   if (index > gdImageColorsTotal(im))
  589.     rc = -1;
  590.   else
  591.     {
  592.     ((im)->red[(index)])   = r;
  593.     ((im)->green[(index)]) = g;
  594.     ((im)->blue[(index)])  = b;
  595.     rc = 0;
  596.     }
  597.  
  598.   BUILDRXLONG(_Retstr, rc);
  599.  
  600. return(OK_CALL);
  601. }
  602.  
  603. /*----------------------------------------------------------------------*/
  604. /*----------------------------------------------------------------------*/
  605. ULONG RxgdImageString(
  606.   PSZ           _Name,                  /* name of the function         */
  607.   ULONG         _Argc,                  /* number of args               */
  608.   RXSTRING      _Argv[],                /* list of argument strings     */
  609.   PSZ           _Queuename,             /* current queue name           */
  610.   PRXSTRING     _Retstr)                /* returned result string       */
  611. {
  612. gdImagePtr      im;
  613. gdFontPtr       fnt;
  614. int     x, y, color;
  615. char    c;
  616.  
  617.                                         /* check arguments            */
  618.   if (_Argc != 6)                       /* wrong number?              */
  619.     return BAD_CALL;                    /* raise an error             */
  620.  
  621.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  622.   c     = _Argv[1].strptr[0];
  623.   x     = atol(_Argv[2].strptr);
  624.   y     = atol(_Argv[3].strptr);
  625.   color = atol(_Argv[5].strptr);
  626.  
  627.   switch (c)
  628.     {
  629.     case 't':
  630.     case 'T':
  631.       fnt = gdFontTiny;
  632.       break;
  633.     case 's':
  634.     case 'S':
  635.       fnt = gdFontSmall;
  636.       break;
  637.     case 'm':
  638.     case 'M':
  639.       fnt = gdFontMediumBold;
  640.       break;
  641.     case 'l':
  642.     case 'L':
  643.       fnt = gdFontLarge;
  644.       break;
  645.     case 'g':
  646.     case 'G':
  647.       fnt = gdFontGiant;
  648.       break;
  649.     default:
  650.       fnt = gdFontMediumBold;
  651.     }
  652.  
  653.   if (_Name[15] == 0)                   /* Just String                  */
  654.     gdImageString(im, fnt, x, y, _Argv[4].strptr, color);
  655.   else                                  /* StringUp call                */
  656.     gdImageStringUp(im, fnt, x, y, _Argv[4].strptr, color);
  657.  
  658.   BUILDRXULONG(_Retstr, 0);
  659.  
  660. return(OK_CALL);
  661. }
  662.  
  663.  
  664. /*----------------------------------------------------------------------*/
  665. /*----------------------------------------------------------------------*/
  666. ULONG RxgdImagePolygon(
  667.   PSZ           _Name,                  /* name of the function         */
  668.   ULONG         _Argc,                  /* number of args               */
  669.   RXSTRING      _Argv[],                /* list of argument strings     */
  670.   PSZ           _Queuename,             /* current queue name           */
  671.   PRXSTRING     _Retstr)                /* returned result string       */
  672. {
  673. gdImagePtr      im;
  674. int     p, pt, color;
  675. int     *points;
  676. int     index;
  677. LONG    rc;
  678. SHVBLOCK  shv;
  679. char    vname[256];
  680. char    vbuf[256];
  681.                                         /* check arguments            */
  682.   if (_Argc != 4)                       /* wrong number?              */
  683.     return BAD_CALL;                    /* raise an error             */
  684.  
  685.   im     = (gdImagePtr)atol(_Argv[0].strptr);
  686.  
  687.   p      = atol(_Argv[2].strptr);
  688.   pt     = p * 2;
  689.   points = (int *) malloc(sizeof(int) * pt);
  690.  
  691.   color   = atol(_Argv[3].strptr);
  692.  
  693.                                         /* Go get the STEM variable          */
  694.   for (index = 0; index < pt; index++ )
  695.     {
  696.     shv.shvnext  = 0;
  697.  
  698.     sprintf(vname, "%s.%d", _Argv[1].strptr, index);
  699.     MAKERXSTRING(shv.shvname, vname, strlen(vname));
  700.  
  701.     MAKERXSTRING(shv.shvvalue, vbuf, sizeof(vbuf));
  702.  
  703.     shv.shvnamelen = strlen(vname);
  704.     shv.shvvaluelen= sizeof(vbuf);
  705.     shv.shvcode = RXSHV_SYFET;
  706.     shv.shvret   = 0;
  707.     rc = RexxVariablePool(&shv);
  708.  
  709.     points[index] = atol(shv.shvvalue.strptr);
  710.     }
  711.  
  712.   if (_Name[9] == 'P')
  713.     gdImagePolygon(im, (gdPointPtr)points, p, color);
  714.   else
  715.     gdImageFilledPolygon(im, (gdPointPtr)points, p, color);
  716.  
  717.   free(points);
  718.  
  719.   BUILDRXULONG(_Retstr, 0);
  720.  
  721. return(OK_CALL);
  722. }
  723.  
  724. /*----------------------------------------------------------------------*/
  725. /*----------------------------------------------------------------------*/
  726. ULONG RxgdImageSetBrush(
  727.   PSZ           _Name,                  /* name of the function         */
  728.   ULONG         _Argc,                  /* number of args               */
  729.   RXSTRING      _Argv[],                /* list of argument strings     */
  730.   PSZ           _Queuename,             /* current queue name           */
  731.   PRXSTRING     _Retstr)                /* returned result string       */
  732. {
  733. gdImagePtr      im, br;
  734.  
  735.                                         /* check arguments            */
  736.   if (_Argc != 2)                       /* wrong number?              */
  737.     return BAD_CALL;                    /* raise an error             */
  738.  
  739.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  740.   br    = (gdImagePtr)atol(_Argv[1].strptr);
  741.  
  742.   if (_Name[12] == 'B')                 /* Shared function, check name  */
  743.     {
  744.     gdImageSetBrush(im, br);
  745.     BUILDRXULONG(_Retstr, gdBrushed);
  746.     }
  747.   else
  748.     {
  749.     gdImageSetTile(im, br);
  750.     BUILDRXULONG(_Retstr, gdTiled);
  751.     }
  752.  
  753. return(OK_CALL);
  754. }
  755.  
  756.  
  757. /*----------------------------------------------------------------------*/
  758. /*----------------------------------------------------------------------*/
  759. ULONG RxgdImageSetStyle(
  760.   PSZ           _Name,                  /* name of the function         */
  761.   ULONG         _Argc,                  /* number of args               */
  762.   RXSTRING      _Argv[],                /* list of argument strings     */
  763.   PSZ           _Queuename,             /* current queue name           */
  764.   PRXSTRING     _Retstr)                /* returned result string       */
  765. {
  766. gdImagePtr      im;
  767. int     s, sp;
  768. int     *style;
  769. int     index;
  770. SHVBLOCK  shv;
  771. char    vname[256];
  772. char    vbuf[256];
  773.                                         /* check arguments            */
  774.   if (_Argc != 3)                       /* wrong number?              */
  775.     return BAD_CALL;                    /* raise an error             */
  776.  
  777.   im     = (gdImagePtr)atol(_Argv[0].strptr);
  778.  
  779.   sp     = atol(_Argv[2].strptr);
  780.   style  = (int *) malloc(sizeof(int) * sp);
  781.  
  782.                                         /* Get the STEM Variable             */
  783.   for (index = 0; index < sp; index++ )
  784.     {
  785.     shv.shvnext  = 0;
  786.  
  787.     sprintf(vname, "%s.%d", _Argv[1].strptr, index);
  788.     MAKERXSTRING(shv.shvname, vname, strlen(vname));
  789.  
  790.     MAKERXSTRING(shv.shvvalue, vbuf, sizeof(vbuf));
  791.  
  792.     shv.shvnamelen = strlen(vname);
  793.     shv.shvvaluelen= sizeof(vbuf);
  794.     shv.shvcode = RXSHV_SYFET;
  795.     shv.shvret   = 0;
  796.     RexxVariablePool(&shv);
  797.  
  798.     style[index] = atol(shv.shvvalue.strptr);
  799.     }
  800.  
  801.   gdImageSetStyle(im, (int *)style, sp);
  802.  
  803.   free(style);
  804.  
  805.   BUILDRXULONG(_Retstr, gdStyled);
  806.  
  807. return(OK_CALL);
  808. }
  809.  
  810.  
  811. /*----------------------------------------------------------------------*/
  812. /*----------------------------------------------------------------------*/
  813. ULONG RxgdImageGetStyledBrushed(
  814.   PSZ           _Name,                  /* name of the function         */
  815.   ULONG         _Argc,                  /* number of args               */
  816.   RXSTRING      _Argv[],                /* list of argument strings     */
  817.   PSZ           _Queuename,             /* current queue name           */
  818.   PRXSTRING     _Retstr)                /* returned result string       */
  819. {
  820.  
  821.   BUILDRXULONG(_Retstr, gdStyledBrushed);
  822.  
  823. return(OK_CALL);
  824. }
  825.  
  826.  
  827. /*----------------------------------------------------------------------*/
  828. /*----------------------------------------------------------------------*/
  829. ULONG RxgdImageGetColor(
  830.   PSZ           _Name,                  /* name of the function         */
  831.   ULONG         _Argc,                  /* number of args               */
  832.   RXSTRING      _Argv[],                /* list of argument strings     */
  833.   PSZ           _Queuename,             /* current queue name           */
  834.   PRXSTRING     _Retstr)                /* returned result string       */
  835. {
  836. ULONG   color;
  837. gdImagePtr      im;
  838.                                         /* check arguments            */
  839.   if (_Argc != 2)                       /* wrong number?              */
  840.     return BAD_CALL;                    /* raise an error             */
  841.  
  842.   im     = (gdImagePtr)atol(_Argv[0].strptr);
  843.   color  = atol(_Argv[1].strptr);
  844.  
  845.   switch(_Name[9])
  846.     {
  847.     case 'G':
  848.       color = gdImageGreen(im, color);
  849.       break;
  850.     case 'R':
  851.       color = gdImageRed(im, color);
  852.       break;
  853.     case 'B':
  854.       color = gdImageBlue(im, color);
  855.       break;
  856.     }
  857.  
  858.   BUILDRXULONG(_Retstr, color);
  859.  
  860. return(OK_CALL);
  861. }
  862.  
  863.  
  864. /*----------------------------------------------------------------------*/
  865. /*----------------------------------------------------------------------*/
  866. ULONG RxgdImageGetPixel(
  867.   PSZ           _Name,                  /* name of the function         */
  868.   ULONG         _Argc,                  /* number of args               */
  869.   RXSTRING      _Argv[],                /* list of argument strings     */
  870.   PSZ           _Queuename,             /* current queue name           */
  871.   PRXSTRING     _Retstr)                /* returned result string       */
  872. {
  873. int     x, y, color;
  874. gdImagePtr      im;
  875.                                         /* check arguments            */
  876.   if (_Argc != 3)                       /* wrong number?              */
  877.     return BAD_CALL;                    /* raise an error             */
  878.  
  879.   im = (gdImagePtr)atol(_Argv[0].strptr);
  880.   x  = atol(_Argv[1].strptr);
  881.   y  = atol(_Argv[2].strptr);
  882.  
  883.  
  884.   BUILDRXULONG(_Retstr, gdImageGetPixel(im, x, y));
  885.  
  886. return(OK_CALL);
  887. }
  888.  
  889. /*----------------------------------------------------------------------*/
  890. /*----------------------------------------------------------------------*/
  891. ULONG RxgdImageSxy(
  892.   PSZ           _Name,                  /* name of the function         */
  893.   ULONG         _Argc,                  /* number of args               */
  894.   RXSTRING      _Argv[],                /* list of argument strings     */
  895.   PSZ           _Queuename,             /* current queue name           */
  896.   PRXSTRING     _Retstr)                /* returned result string       */
  897. {
  898. int     xy;
  899. gdImagePtr      im;
  900.                                         /* check arguments            */
  901.   if (_Argc != 1)                       /* wrong number?              */
  902.     return BAD_CALL;                    /* raise an error             */
  903.  
  904.   im = (gdImagePtr)atol(_Argv[0].strptr);
  905.  
  906.   if (_Name[10] == 'X')
  907.     xy = gdImageSX(im);
  908.   else
  909.     xy = gdImageSY(im);
  910.  
  911.   BUILDRXULONG(_Retstr, xy);
  912.  
  913. return(OK_CALL);
  914. }
  915.  
  916.  
  917. /*----------------------------------------------------------------------*/
  918. /*----------------------------------------------------------------------*/
  919. ULONG RxgdImageBoundsSafe(
  920.   PSZ           _Name,                  /* name of the function         */
  921.   ULONG         _Argc,                  /* number of args               */
  922.   RXSTRING      _Argv[],                /* list of argument strings     */
  923.   PSZ           _Queuename,             /* current queue name           */
  924.   PRXSTRING     _Retstr)                /* returned result string       */
  925. {
  926. int     x, y;
  927. gdImagePtr      im;
  928.                                         /* check arguments            */
  929.   if (_Argc != 3)                       /* wrong number?              */
  930.     return BAD_CALL;                    /* raise an error             */
  931.  
  932.   im = (gdImagePtr)atol(_Argv[0].strptr);
  933.   x  = atol(_Argv[1].strptr);
  934.   y  = atol(_Argv[2].strptr);
  935.  
  936.  
  937.   BUILDRXULONG(_Retstr, gdImageBoundsSafe(im, x, y));
  938.  
  939. return(OK_CALL);
  940. }
  941.  
  942.  
  943. /*----------------------------------------------------------------------*/
  944. /*----------------------------------------------------------------------*/
  945. ULONG RxgdImageGetTTI(
  946.   PSZ           _Name,                  /* name of the function         */
  947.   ULONG         _Argc,                  /* number of args               */
  948.   RXSTRING      _Argv[],                /* list of argument strings     */
  949.   PSZ           _Queuename,             /* current queue name           */
  950.   PRXSTRING     _Retstr)                /* returned result string       */
  951. {
  952. int     rc;
  953. gdImagePtr      im;
  954.                                         /* check arguments            */
  955.   if (_Argc != 1)                       /* wrong number?              */
  956.     return BAD_CALL;                    /* raise an error             */
  957.  
  958.   im = (gdImagePtr)atol(_Argv[0].strptr);
  959.  
  960.   switch (_Name[12])
  961.     {
  962.     case 'o':
  963.     case 'O':
  964.       rc = gdImageColorsTotal(im);
  965.       break;
  966.     case 'I':
  967.       rc = gdImageGetInterlaced(im);
  968.       break;
  969.     case 'T':
  970.       rc = gdImageGetTransparent(im);
  971.       break;
  972.     }
  973.  
  974.   BUILDRXLONG(_Retstr, rc);
  975.  
  976. return(OK_CALL);
  977. }
  978.  
  979.  
  980. /*----------------------------------------------------------------------*/
  981. /*----------------------------------------------------------------------*/
  982. ULONG RxgdImageColorDeallocate(
  983.   PSZ           _Name,                  /* name of the function         */
  984.   ULONG         _Argc,                  /* number of args               */
  985.   RXSTRING      _Argv[],                /* list of argument strings     */
  986.   PSZ           _Queuename,             /* current queue name           */
  987.   PRXSTRING     _Retstr)                /* returned result string       */
  988. {
  989. int     color;
  990. gdImagePtr      im;
  991.                                         /* check arguments            */
  992.   if (_Argc != 2)                       /* wrong number?              */
  993.     return BAD_CALL;                    /* raise an error             */
  994.  
  995.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  996.   color = atol(_Argv[1].strptr);
  997.  
  998.   gdImageColorDeallocate(im, color);
  999.  
  1000.   BUILDRXULONG(_Retstr, 0);
  1001.  
  1002. return(OK_CALL);
  1003. }
  1004.  
  1005. /*----------------------------------------------------------------------*/
  1006. /*----------------------------------------------------------------------*/
  1007. ULONG RxgdImageColorSet(
  1008.   PSZ           _Name,                  /* name of the function         */
  1009.   ULONG         _Argc,                  /* number of args               */
  1010.   RXSTRING      _Argv[],                /* list of argument strings     */
  1011.   PSZ           _Queuename,             /* current queue name           */
  1012.   PRXSTRING     _Retstr)                /* returned result string       */
  1013. {
  1014. int     color;
  1015. gdImagePtr      im;
  1016.                                         /* check arguments            */
  1017.   if (_Argc != 2)                       /* wrong number?              */
  1018.     return BAD_CALL;                    /* raise an error             */
  1019.  
  1020.   im    = (gdImagePtr)atol(_Argv[0].strptr);
  1021.   color = atol(_Argv[1].strptr);
  1022.  
  1023.   switch (_Name[9])
  1024.     {
  1025.     case 'C':
  1026.       gdImageColorTransparent(im, color);
  1027.       break;
  1028.     case 'I':
  1029.       gdImageInterlace(im, color);
  1030.       break;
  1031.     }
  1032.  
  1033.  
  1034.   BUILDRXULONG(_Retstr, 0);
  1035.  
  1036. return(OK_CALL);
  1037. }
  1038.  
  1039. /*----------------------------------------------------------------------*/
  1040. /*----------------------------------------------------------------------*/
  1041. ULONG RxgdImageCopy(
  1042.   PSZ           _Name,                  /* name of the function         */
  1043.   ULONG         _Argc,                  /* number of args               */
  1044.   RXSTRING      _Argv[],                /* list of argument strings     */
  1045.   PSZ           _Queuename,             /* current queue name           */
  1046.   PRXSTRING     _Retstr)                /* returned result string       */
  1047. {
  1048. int     dstX, dstY, srcX, srcY, w, h;
  1049. gdImagePtr      src, dst;
  1050.                                         /* check arguments            */
  1051.   if (_Argc != 8)                       /* wrong number?              */
  1052.     return BAD_CALL;                    /* raise an error             */
  1053.  
  1054.   dst   = (gdImagePtr)atol(_Argv[0].strptr);
  1055.   src   = (gdImagePtr)atol(_Argv[1].strptr);
  1056.   dstX  = atol(_Argv[2].strptr);
  1057.   dstY  = atol(_Argv[3].strptr);
  1058.   srcX  = atol(_Argv[4].strptr);
  1059.   srcY  = atol(_Argv[5].strptr);
  1060.   w     = atol(_Argv[6].strptr);
  1061.   h     = atol(_Argv[7].strptr);
  1062.  
  1063.   gdImageCopy(dst, src, dstX, dstY, srcX, srcY, w, h);
  1064.  
  1065.   BUILDRXULONG(_Retstr, 0);
  1066.  
  1067. return(OK_CALL);
  1068. }
  1069.  
  1070. /*----------------------------------------------------------------------*/
  1071. /*----------------------------------------------------------------------*/
  1072. ULONG RxgdImageCopyResized(
  1073.   PSZ           _Name,                  /* name of the function         */
  1074.   ULONG         _Argc,                  /* number of args               */
  1075.   RXSTRING      _Argv[],                /* list of argument strings     */
  1076.   PSZ           _Queuename,             /* current queue name           */
  1077.   PRXSTRING     _Retstr)                /* returned result string       */
  1078. {
  1079. int     dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH;
  1080. gdImagePtr      src, dst;
  1081.                                         /* check arguments            */
  1082.   if (_Argc != 10)                      /* wrong number?              */
  1083.     return BAD_CALL;                    /* raise an error             */
  1084.  
  1085.   dst   = (gdImagePtr)atol(_Argv[0].strptr);
  1086.   src   = (gdImagePtr)atol(_Argv[1].strptr);
  1087.   dstX  = atol(_Argv[2].strptr);
  1088.   dstY  = atol(_Argv[3].strptr);
  1089.   srcX  = atol(_Argv[4].strptr);
  1090.   srcY  = atol(_Argv[5].strptr);
  1091.   dstW  = atol(_Argv[6].strptr);
  1092.   dstH  = atol(_Argv[7].strptr);
  1093.   srcW  = atol(_Argv[8].strptr);
  1094.   srcH  = atol(_Argv[9].strptr);
  1095.  
  1096.   gdImageCopyResized(dst, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
  1097.  
  1098.   BUILDRXULONG(_Retstr, 0);
  1099.  
  1100. return(OK_CALL);
  1101. }
  1102.