home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 6
/
AACD06.ISO
/
AACD
/
Programming
/
ImageManager
/
Examples
/
Filter.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-27
|
3KB
|
122 lines
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <proto/exec.h>
#include <proto/imagemanager.h>
#include <proto/intuition.h>
#ifndef REG
#define REG(x) register __ ## x
#endif
extern "C" kprintf (STRPTR, ...);
struct Library *ImageManagerBase;
struct InstanceData { ULONG Height; ULONG *Buffer; };
ULONG Dispatcher (REG(a0) struct IClass *cl, REG(a2) Object *obj, REG(a1) Msg msg)
{
ULONG result = FALSE;
struct InstanceData *data = (InstanceData *)INST_DATA(cl, obj);
switch(msg->MethodID)
{
case IMM_NewFrame:
{
if(result = DoSuperMethodA(cl, obj, msg))
data->Height = ((IMP_NewFrame *)msg)->Height;
}
break;
case IMM_ReceiveData:
{
struct IMP_ReceiveData *rmsg = (IMP_ReceiveData *)msg;
ULONG width = rmsg->Pixels.Width;
DOUBLE y_intensity = sin(((DOUBLE)rmsg->Pixels.Y) * PI / ((DOUBLE)data->Height));
UBYTE *rgba, *dst = rgba = (UBYTE *)rmsg->Pixels.RGBA;
if(rmsg->Pixels.Flags & IMF_ReceiveData_KeepIntact)
{
if(!data->Buffer)
data->Buffer = new ULONG [width];
if(!(dst = (UBYTE *)(rmsg->Pixels.RGBA = data->Buffer)))
break;
}
for(UWORD i = 0; i < width; i++)
{
DOUBLE intensity = y_intensity * sin(((DOUBLE)i) * PI / ((DOUBLE)width));
dst[4*i+0] = intensity * rgba[4*i+0];
dst[4*i+1] = intensity * rgba[4*i+1];
dst[4*i+2] = intensity * rgba[4*i+2];
}
result = DoSuperMethodA(cl, obj, msg);
}
break;
case OM_DISPOSE:
{
delete data->Buffer;
result = DoSuperMethodA(cl, obj, msg);
}
break;
default:
result = DoSuperMethodA(cl, obj, msg);
break;
}
return result;
}
int main (int argc, char **argv)
{
if(ImageManagerBase = OpenLibrary("ImageManager.library", 1))
{
struct IClass *myclass, *superclass = IM_GetClass("Link");
if(superclass && (myclass = MakeClass(NULL, NULL, superclass, sizeof(InstanceData), 0L)))
{
myclass->cl_Dispatcher.h_Entry = (HOOKFUNC)Dispatcher;
struct Window *win = OpenWindowTags(NULL, WA_Activate, TRUE, WA_IDCMP, IDCMP_CLOSEWINDOW, WA_CloseGadget, TRUE, WA_DragBar, TRUE, WA_DepthGadget, TRUE, TAG_DONE);
Object **objects = IM_CreateChain(0L,
IMC_NewObject, "File",
TAG_DONE,
IMC_NewObject, "Decoder",
TAG_DONE,
IMC_CustomObject, myclass,
TAG_DONE,
IMC_NewObject, "Container",
IMA_Container_Screen, win->WScreen,
TAG_DONE,
IMC_NewObject, "Raster",
IMA_Raster_RastPort, win->RPort,
IMA_Raster_Left, win->BorderLeft,
IMA_Raster_Top, win->BorderTop,
TAG_DONE,
IMC_EndChain);
if(objects)
{
DoMethod(objects[0], IMM_File_Load, argc == 2 ? argv[1] : "Download:/«99.03.02»/001_ScrollBarGrab.PNG");
WaitPort(win->UserPort);
IM_DeleteChain(objects);
}
CloseWindow(win);
FreeClass(myclass);
}
IM_FreeClass(superclass);
CloseLibrary(ImageManagerBase);
}
return 0;
}