home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / misc / imagefx_sdk / sas / examples / xdraw / sharp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  5.6 KB  |  264 lines

  1. /*
  2.  * A Sharpen Enhanced Drawing Mode for ImageFX 2.0
  3.  *
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <scan/modall.h>
  8. #include <scan/drawinfo.h>
  9.  
  10.  
  11. UBYTE __regargs do_sharp (UBYTE *pix, int brow)
  12. {
  13.    int val;
  14.    int a1, a2, a3, a4;
  15.  
  16.    a1 = (int)(*(pix-brow));
  17.    a2 = (int)(*(pix+brow));
  18.    a3 = (int)(*(pix-1));
  19.    a4 = (int)(*(pix+1));
  20.  
  21.    val = ( (int)(*(pix)) * 5 ) - a1 - a2 - a3 - a4;
  22. // val = ( (int)(*(pix)) * 3 ) - a1 - a2;
  23.  
  24. // kprintf("a1=%ld,a2=%ld,a3=%ld,a4=%ld,val=%ld\n", a1,a2,a3,a4,val);
  25.  
  26.    if (val < 0) val = 0;
  27.    else if (val > 255) val = 255;
  28.  
  29.    val = (val + *(pix)) >> 1;    /* soften it a bit */
  30.  
  31.    return((UBYTE)val);
  32. }
  33.  
  34. /**********************************************************************\
  35.  
  36.                                 Library Vectors
  37.  
  38. \**********************************************************************/
  39.  
  40. /*
  41.  * XDM_Attr:
  42.  *
  43.  * Return to ImageFX some information about the Drawing Mode (eg.
  44.  * whether Options are needed, whether we work on greyscale or
  45.  * color, etc.).  Called when ImageFX first scans the drawing
  46.  * mode directory.
  47.  *
  48.  */
  49. ULONG __saveds __asm XDM_Attr (register __a0 struct XDrawAttr *da)
  50. {
  51.    da->Flags      = XDMF_NoPen;
  52.    da->Priority   = 117;
  53.    da->HorizOffs  = 1;
  54.    da->VertOffs   = 1;
  55.    return(0);
  56. }
  57.  
  58. /*
  59.  * XDM_Init:
  60.  *
  61.  * Initialize the drawing mode.
  62.  *
  63.  */
  64. int __saveds __asm XDM_Init (void)
  65. {
  66.    return(1);
  67. }
  68.  
  69. /*
  70.  * XDM_Cleanup:
  71.  *
  72.  * Cleanup the drawing mode.
  73.  *
  74.  */
  75. void __saveds __asm XDM_Cleanup (void)
  76. {
  77. }
  78.  
  79. /*
  80.  * XDM_Begin:
  81.  *
  82.  * Prepare before a pixel affecting operation.
  83.  *
  84.  */
  85. int __saveds __asm XDM_Begin (register __a0 struct IDrawInfo *di)
  86. {
  87.    return(1);
  88. }
  89.  
  90. /*
  91.  * XDM_End:
  92.  *
  93.  * Cleanup after a pixel affecting operation.
  94.  *
  95.  */
  96. void __saveds __asm XDM_End (register __a0 struct IDrawInfo *di)
  97. {
  98. }
  99.  
  100. /*
  101.  * XDM_Affect:
  102.  *
  103.  * Affect a block of pixels.  We may also affect some of the
  104.  * parameters of the IDrawInfo structure, such as the X & Y
  105.  * location of the block of pixels.
  106.  *
  107.  */
  108. void __saveds __asm XDM_Affect (register __a0 struct IDrawInfo *di)
  109. {
  110. #ifdef USE_BUFFERS
  111.  
  112.    int i, j;
  113.    UBYTE *ored, *ogrn, *oblu;
  114.    UBYTE *ired, *igrn, *iblu;
  115.  
  116.    for (j = 0; j < di->Height; j++) {
  117.       GetBufLines(di->BBuf, &ired, &igrn, &iblu, j, 3);
  118.       ired += di->BufW + 1;
  119.       igrn += di->BufW + 1;
  120.       iblu += di->BufW + 1;
  121.       GetBufLine(di->BOut, &ored, &ogrn, &oblu, j);
  122.       for (i = 0; i < di->Width; i++) {
  123.  
  124.          *ored++ = do_sharp(ired, di->BufW);
  125.          *ogrn++ = do_sharp(igrn, di->BufW);
  126.          *oblu++ = do_sharp(iblu, di->BufW);
  127.  
  128.          ired++; igrn++; iblu++;
  129.       }
  130.       PutBufLine(di->BOut);
  131.    }
  132.  
  133. #else
  134.  
  135.    int i, j;
  136.    UBYTE *ored, *ogrn, *oblu;
  137.    UBYTE *ired, *igrn, *iblu;
  138.  
  139.    ored = di->OutR;
  140.    ogrn = di->OutG;
  141.    oblu = di->OutB;
  142.  
  143.    for (j = 0; j < di->Height; j++) {
  144.       ired = di->BufR + (j * di->BufW);
  145.       igrn = di->BufG + (j * di->BufW);
  146.       iblu = di->BufB + (j * di->BufW);
  147.       for (i = 0; i < di->Width; i++) {
  148.  
  149.          *ored++ = do_sharp(ired, di->BufW);
  150.          *ogrn++ = do_sharp(igrn, di->BufW);
  151.          *oblu++ = do_sharp(iblu, di->BufW);
  152.  
  153.          ired++; igrn++; iblu++;
  154.       }
  155.    }
  156.  
  157. #endif
  158.  
  159. }
  160.  
  161. /*
  162.  * XDM_Options:
  163.  *
  164.  * Present a window to the user allowing him to adjust drawing mode
  165.  * options.  Arguments may optionally be passed from an Arexx command.
  166.  * This function will only be called if the flag XDMF_AreOptions is
  167.  * returned from XDM_Attr().
  168.  *
  169.  */
  170. int __saveds __asm XDM_Options (register __a0 LONG *args)
  171. {
  172.    return(0);
  173. }
  174.  
  175. /*
  176.  * XDM_LoadPrefs:
  177.  *
  178.  * Set preferences according to information loaded from disk.
  179.  *
  180.  */
  181. int __saveds __asm XDM_LoadPrefs (register __a0 void *prefs)
  182. {
  183.    return(1);
  184. }
  185.  
  186. /*
  187.  * XDM_SavePrefs:
  188.  *
  189.  * Request preferences settings that are about to be saved to disk.
  190.  *
  191.  */
  192. int __saveds __asm XDM_SavePrefs (register __a0 void *prefs)
  193. {
  194.    return(1);
  195. }
  196.  
  197.  
  198. /**********************************************************************\
  199.  
  200.                          Library Initialization Stuff
  201.  
  202. \**********************************************************************/
  203.  
  204. /*
  205.  * This is the table of all the functions that can be called in this
  206.  * module.  The first four (Open, Close, Expunge, and Null) are reserved
  207.  * for system use and MUST be specified in the order shown.  The actual
  208.  * functions are in the standard module startup code.
  209.  */
  210. ULONG FuncTable[] = {
  211.    /* These four MUST be present in this order */
  212.    (ULONG) LibOpen,
  213.    (ULONG) LibClose,
  214.    (ULONG) LibExpunge,
  215.    (ULONG) LibNull,
  216.  
  217.    /* Specific to the module */
  218.    (ULONG) XDM_Attr,
  219.    (ULONG) XDM_Begin,
  220.    (ULONG) XDM_End,
  221.    (ULONG) XDM_Affect,
  222.    (ULONG) XDM_Options,
  223.    (ULONG) XDM_LoadPrefs,
  224.    (ULONG) XDM_SavePrefs,
  225.    (ULONG) 0,
  226.    (ULONG) 0,
  227.    (ULONG) XDM_Init,
  228.    (ULONG) XDM_Cleanup,
  229.  
  230.    /* End with -1L */
  231.    (ULONG) -1L
  232. };
  233.  
  234. /*
  235.  * These are used by the standard module startup code.
  236.  * LibraryName is the name of the library, and LibraryID is a short
  237.  * description of the library.  Both of these are largely irrelavent,
  238.  * but they are included just for completeness.
  239.  */
  240. UBYTE LibraryID[]    = "$VER: Sharpen Extended Drawing Mode 2.0.19 (15.2.95)";
  241. UBYTE LibraryType    = NT_XDRAWMODE;
  242.  
  243. /*
  244.  * This is called by the standard module startup code when Image Scan
  245.  * first opens the module.  Here we should fill in the NumGads,
  246.  * NewGad, Language, and LangCount fields of the provided ModuleBase
  247.  * structure if necessary.
  248.  */
  249. long  __asm UserOpen (register __a6 struct ModuleBase *modbase)
  250. {
  251.    return(TRUE);
  252. }
  253.  
  254. /*
  255.  * This is called by the standard module startup code when Image Scan
  256.  * closes the module.  It should cleanup anything allocated or obtained
  257.  * in the UserOpen() function.
  258.  */
  259. long  __asm UserClose (register __a6 struct ModuleBase *modbase)
  260. {
  261.    return(TRUE);
  262. }
  263.  
  264.