rem: FRAME cached_frame, cached_screen_frame;
add: FRAME cached_frame, cached_screen_frame = 0;
context: int flash_rect_func(void *data){#define NORMAL_STRENGTH 4#define NORMAL_F_STRENGTH 0#define CACHE_SIZE 10	DWORD TimeIn, WaitTime;	SIZE strength, fstrength, incr;	RECT cached_rect, framesize_rect;	FRAME cached_frame, cached_screen_frame;	Task task = (Task)data;	int cached[CACHE_SIZE];	STAMP cached_stamp[CACHE_SIZE];	int i;	for (i = 0; i < CACHE_SIZE; i++)	{		cached[i] = 0;		cached_stamp[i].frame = 0;	}	fstrength = NORMAL_F_STRENGTH;	incr = 1;	strength = NORMAL_STRENGTH;	TimeIn = GetTimeCounter ();	WaitTime = ONE_SECOND / 16;	while (!Task_ReadState(task, TASK_EXIT))	{		CONTEXT OldContext;		LockMutex (flash_mutex);		if (flash_changed)		{			cached_rect = flash_rect;			cached_frame = flash_frame;			cached_screen_frame = flash_screen_frame;			flash_changed = 0;			UnlockMutex (flash_mutex);			//  Wait for the  flash_screen_frame to get initialized			FlushGraphics ();			if (cached_frame)				GetFrameRect (cached_frame, &framesize_rect);			for (i = 0; i < CACHE_SIZE; i++)			{				cached[i] = 0;				if(cached_stamp[i].frame)					DestroyDrawable (ReleaseDrawable (cached_stamp[i].frame));				cached_stamp[i].frame = 0;			}		}		else			UnlockMutex (flash_mutex);				if (cached_rect.extent.width)		{			STAMP *pStamp;			if (cached_frame)			{#define MIN_F_STRENGTH -3#define MAX_F_STRENGTH 3				int num = 0, denom = 0;				if ((fstrength += incr) > MAX_F_STRENGTH)				{					fstrength = MAX_F_STRENGTH - 1;					incr = -1;				}				else if (fstrength < MIN_F_STRENGTH)				{					fstrength = MIN_F_STRENGTH + 1;					incr = 1;				}				if (cached[fstrength - MIN_F_STRENGTH])					pStamp = &cached_stamp[fstrength - MIN_F_STRENGTH];				else				{					RECT tmp_rect = framesize_rect;					pStamp = &cached_stamp[fstrength - MIN_F_STRENGTH];					cached[fstrength - MIN_F_STRENGTH] = 1;					pStamp->frame = CaptureDrawable (CreateDrawable (WANT_PIXMAP, 							framesize_rect.extent.width, framesize_rect.extent.height, 1));					pStamp->origin.x = framesize_rect.corner.x;					pStamp->origin.y = framesize_rect.corner.y;					tmp_rect.corner.x = 0;					tmp_rect.corner.y = 0;					if (fstrength != NORMAL_F_STRENGTH)					{						arith_frame_blit (cached_frame, &tmp_rect, pStamp->frame, NULL,								fstrength > 0 ? fstrength : -fstrength, 16);						if (fstrength < 0)						{							num = -8;							denom = 8;						}						else						{							num = 8;							denom = -8;						}					}					arith_frame_blit (cached_screen_frame, &framesize_rect, pStamp->frame, 							&tmp_rect, num, denom);				}			}			else			{#define MIN_STRENGTH 4#define MAX_STRENGTH 6				if ((strength += 2) > MAX_STRENGTH)					strength = MIN_STRENGTH;				if (cached[strength - MIN_STRENGTH])					pStamp = &cached_stamp[strength - MIN_STRENGTH];				else				{					RECT tmp_rect = cached_rect;					pStamp = &cached_stamp[strength - MIN_STRENGTH];					cached[strength - MIN_STRENGTH] = 1;					pStamp->frame = CaptureDrawable (CreateDrawable (WANT_PIXMAP, 							cached_rect.extent.width, cached_rect.extent.height, 1));					pStamp->origin.x = 0;					pStamp->origin.y = 0;					tmp_rect.corner.x = 0;					tmp_rect.corner.y = 0;					arith_frame_blit (cached_screen_frame, &tmp_rect, pStamp->frame, 							&tmp_rect, 4, 4);					if (strength != 4)						arith_frame_blit (cached_screen_frame, &tmp_rect, pStamp->frame, 								&tmp_rect, strength, 4);				}			}			SetSemaphore (GraphicsSem);			OldContext = SetContext (ScreenContext);			SetContextClipRect (&cached_rect);			DrawStamp (pStamp);			SetContextClipRect (NULL_PTR); // this will flush whatever			SetContext (OldContext);			ClearSemaphore (GraphicsSem);		}		FlushGraphics ();		SleepThreadUntil (TimeIn + WaitTime);		TimeIn = GetTimeCounter ();	}	flash_task = 0;	FinishTask (task);	return(0);}