home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ImageManager / Examples / Filter.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  3KB  |  122 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <proto/exec.h>
  5. #include <proto/imagemanager.h>
  6. #include <proto/intuition.h>
  7.  
  8. #ifndef REG
  9. #define REG(x) register __ ## x
  10. #endif
  11.  
  12. extern "C" kprintf (STRPTR, ...);
  13.  
  14. struct Library *ImageManagerBase;
  15.  
  16. struct InstanceData { ULONG Height; ULONG *Buffer; };
  17.  
  18. ULONG Dispatcher (REG(a0) struct IClass *cl, REG(a2) Object *obj, REG(a1) Msg msg)
  19. {
  20.     ULONG result = FALSE;
  21.     struct InstanceData *data = (InstanceData *)INST_DATA(cl, obj);
  22.  
  23.     switch(msg->MethodID)
  24.     {
  25.         case IMM_NewFrame:
  26.         {
  27.             if(result = DoSuperMethodA(cl, obj, msg))
  28.                 data->Height = ((IMP_NewFrame *)msg)->Height;
  29.         }
  30.         break;
  31.  
  32.         case IMM_ReceiveData:
  33.         {
  34.             struct IMP_ReceiveData *rmsg = (IMP_ReceiveData *)msg;
  35.  
  36.             ULONG width = rmsg->Pixels.Width;
  37.             DOUBLE y_intensity = sin(((DOUBLE)rmsg->Pixels.Y) * PI / ((DOUBLE)data->Height));
  38.             UBYTE *rgba, *dst = rgba = (UBYTE *)rmsg->Pixels.RGBA;
  39.  
  40.             if(rmsg->Pixels.Flags & IMF_ReceiveData_KeepIntact)
  41.             {
  42.                 if(!data->Buffer)
  43.                     data->Buffer = new ULONG [width];
  44.                 if(!(dst = (UBYTE *)(rmsg->Pixels.RGBA = data->Buffer)))
  45.                     break;
  46.             }
  47.  
  48.             for(UWORD i = 0; i < width; i++)
  49.             {
  50.                 DOUBLE intensity = y_intensity * sin(((DOUBLE)i) * PI / ((DOUBLE)width));
  51.                 dst[4*i+0] = intensity * rgba[4*i+0];
  52.                 dst[4*i+1] = intensity * rgba[4*i+1];
  53.                 dst[4*i+2] = intensity * rgba[4*i+2];
  54.             }
  55.  
  56.             result = DoSuperMethodA(cl, obj, msg);
  57.         }
  58.         break;
  59.  
  60.         case OM_DISPOSE:
  61.         {
  62.             delete data->Buffer;
  63.             result = DoSuperMethodA(cl, obj, msg);
  64.         }
  65.         break;
  66.  
  67.         default:
  68.             result = DoSuperMethodA(cl, obj, msg);
  69.         break;
  70.     }
  71.     return result;
  72. }
  73.  
  74. int main (int argc, char **argv)
  75. {
  76.     if(ImageManagerBase = OpenLibrary("ImageManager.library", 1))
  77.     {
  78.         struct IClass *myclass, *superclass = IM_GetClass("Link");
  79.         if(superclass && (myclass = MakeClass(NULL, NULL, superclass, sizeof(InstanceData), 0L)))
  80.         {
  81.             myclass->cl_Dispatcher.h_Entry = (HOOKFUNC)Dispatcher;
  82.             struct Window *win = OpenWindowTags(NULL, WA_Activate, TRUE, WA_IDCMP, IDCMP_CLOSEWINDOW, WA_CloseGadget, TRUE, WA_DragBar, TRUE, WA_DepthGadget, TRUE, TAG_DONE);
  83.  
  84.             Object **objects = IM_CreateChain(0L,
  85.  
  86.                 IMC_NewObject, "File",
  87.                     TAG_DONE,
  88.  
  89.                 IMC_NewObject, "Decoder",
  90.                     TAG_DONE,
  91.  
  92.                 IMC_CustomObject, myclass,
  93.                     TAG_DONE,
  94.  
  95.                 IMC_NewObject, "Container",
  96.                     IMA_Container_Screen, win->WScreen,
  97.                     TAG_DONE,
  98.  
  99.                 IMC_NewObject, "Raster",
  100.                     IMA_Raster_RastPort, win->RPort,
  101.                     IMA_Raster_Left, win->BorderLeft,
  102.                     IMA_Raster_Top, win->BorderTop,
  103.                     TAG_DONE,
  104.  
  105.                 IMC_EndChain);
  106.  
  107.             if(objects)
  108.             {
  109.                 DoMethod(objects[0], IMM_File_Load, argc == 2 ? argv[1] : "Download:/«99.03.02»/001_ScrollBarGrab.PNG");
  110.                 WaitPort(win->UserPort);
  111.                 IM_DeleteChain(objects);
  112.             }
  113.  
  114.             CloseWindow(win);
  115.             FreeClass(myclass);
  116.         }
  117.         IM_FreeClass(superclass);
  118.         CloseLibrary(ImageManagerBase);
  119.     }
  120.     return 0;
  121. }
  122.