📄 webimgview.cpp
字号:
}
GifList.Add(PMyGifAnimation);
CurrentFrameItem=GifList.Size();
}//END if (hdib)
break;
case -50://if p = -50 then Dll is passing a comment
{
//No comment handling processed here. Is easy though
//pComment is just an array of char's *char
//and each -50 call is a new comment
}
break;
case -80://p = -80 Dll is passing the fully updated dib
if (hdib)
{
TMyGifAnimation *PG = (TMyGifAnimation*) GifList[1];
if (hdib != PG->HDib)
{
PMyGifAnimation = new TMyGifAnimation;
PMyGifAnimation->HDib = CopyDIB(hdib);
PMyGifAnimation->hPAL = CreateDIBPalette(hdib);
if (GifHeader)
{
PMyGifAnimation->ScreenWidth = ((MYHEADER*)(GifHeader))->ScreenWidth;
PMyGifAnimation->ScreenHeight = ((MYHEADER*)(GifHeader))->ScreenHeight;
PMyGifAnimation->GlobalColorTableSize = ((MYHEADER*)(GifHeader))->GlobalColorTableSize;
PMyGifAnimation->GlobalColorTableFlag = ((MYHEADER*)(GifHeader))->GlobalColorTableFlag;
PMyGifAnimation->BackGroundColor = ((MYHEADER*)(GifHeader))->BackGroundColor;
//BYTE SortFlag;
//BYTE ColorResolution;
}
if (ImgDesc)
{
PMyGifAnimation->Left = ((MYIMAGEDESC*)(ImgDesc))->Left;
PMyGifAnimation->Top = ((MYIMAGEDESC*)(ImgDesc))->Top;
PMyGifAnimation->Width = ((MYIMAGEDESC*)(ImgDesc))->Width;
PMyGifAnimation->Height = ((MYIMAGEDESC*)(ImgDesc))->Height;
PMyGifAnimation->InterlaceFlag = ((MYIMAGEDESC*)(ImgDesc))->InterlaceFlag;
PMyGifAnimation->LocalColorTableFlag = ((MYIMAGEDESC*)(ImgDesc))->LocalColorTableFlag;
PMyGifAnimation->LocalColorTableSize = ((MYIMAGEDESC*)(ImgDesc))->LocalColorTableSize;
//BYTE SortFlag;
}
if (GraphCtrl)
{
PMyGifAnimation->DisposalMethod = ((MYGRAPHICALCONTROL*)(GraphCtrl))->DisposalMethod;
PMyGifAnimation->TransparentColorFlag = ((MYGRAPHICALCONTROL*)(GraphCtrl))->TransparentColorFlag;
PMyGifAnimation->TransparentColorIndex = ((MYGRAPHICALCONTROL*)(GraphCtrl))->ColorIndex;
PMyGifAnimation->DelayTime = ((MYGRAPHICALCONTROL*)(GraphCtrl))->DelayTime;
PMyGifAnimation->NetLoops = NetLoop;
//BYTE BlockSize;
//BYTE UserInputFlag;
}
GifList.Last();
GifList.Add(PMyGifAnimation);
GlobalFree(hdib);
hdib=0;
}
else
{
PG->HDib = CopyDIB(hdib);
GlobalFree(hdib);
hdib=0;
}
CurrentFrameItem=GifList.Size()-1;
}//END if (hdib)
break;
default:
result = CancelLoadImage;
}//END switch (p)
//We start the animation during load only at the 2nd frame
//because the first frame is allready displayed
if ((p == -80) && (CurrentFrameItem >1))
{
//Set the timer to animate during loading when not set yet.
if (!LoadTimerSet)
{
SetTimer(IDLoadTimer,5 ,NULL);
LoadTimerSet = true;
}
//Force a repaint while loading
//
DrawFrame(CurrentFrameItem);
//Wait according the delaytime of the gif.
while (!TimerAnimate)
{
PumpMessages();
}
TimerAnimate=false;
return result;
}
//call this when P > 0
//if p >0 then Dll is passing progress
DrawFrame(CurrentFrameItem);
PumpMessages();
return result;
}
/////////////////////////////////////////////////////////////////////////////
//This event is called when loading an animated gif
/////////////////////////////////////////////////////////////////////////////
short CWebImgView::SaveCallEvent (HANDLE* hdib, //Pass handle to dib to save
WORD * cLeft, //Left of the frame
WORD * cTop, //Top of the frame
WORD * cWidth, //Width of the frame
WORD * cHeigth,//Height of the frame
BYTE * cLocalColorTableFlag, //Frame has its own palette. If 0 it will use the colortable of frame 1
BYTE * cInterlaceFlag, //Save frame interlaced (Only one frame 1)
BYTE * cSortFlag,//Not used (Set to 0)
//If bitdepth = 1 then cLocalColorTableSize = 1
//If bitdepth = 4 then cLocalColorTableSize = 15
//If bitdepth = 8 then cLocalColorTableSize = 255
BYTE * cLocalColorTableSize,
BYTE * cBlockSize,//Not used (Set to 0)
BYTE * cDisposalMethod,//Disposal method.
BYTE * cUserInputFlag,//Not used (Set to 1)
BYTE * cTransparentColorFlag,//Specifiy if frame has a transparant color
WORD * cDelayTime,//Delay time in Micro Seconds
BYTE * cTransparentColorIndex,//Index to paletteEntry to show background
char * cpComment,//Add a comment to this frame
short frame,//This is passed by the dll to let you know which frame to save
short p)//Proggress and indicator//
//-50 dll wants a comment
//-100 dll wants all but not comment
//>-1 Progress
{
short result = 1;
if (ExitingApp) return 0;
PMyGifAnimation = new TMyGifAnimation;
TMyGifAnimation *PMyGifAnimation = (TMyGifAnimation*) GifList[frame];
if (((SaveCurrentFrame == true) && (CurrentFrameItem ==frame)) ||(SaveCurrentFrame == false))
{
switch (p)
{
case -100:
if (hdib)
{
if (GetDIBBitPerPixel(PMyGifAnimation->HDib) >8) // Change DIB, if resolution is > 8
{
IsFileSaving = true;
if(My_ReduceDib)
{
short Resolution = 8;
HANDLE CopyPictureDIB = CopyDIB(PMyGifAnimation->HDib);
void * P = GlobalLock(CopyPictureDIB);
My_ReduceDib(P,
Resolution,
0,
0,
NULL,
1,
(long) this,
UpdateProgressCallBack);
IsFileSaving = false;
CopyPictureDIB = GlobalHandle(P);
GlobalUnlock (P);
PMyGifAnimation->HDib = CopyPictureDIB;
}
}
*hdib = PMyGifAnimation->HDib;
*cLeft = PMyGifAnimation->Left;
*cTop = PMyGifAnimation->Top;
*cWidth = PMyGifAnimation->Width;
*cHeigth = PMyGifAnimation->Height;
*cLocalColorTableFlag = PMyGifAnimation->LocalColorTableFlag;
*cInterlaceFlag = PMyGifAnimation->InterlaceFlag;
*cSortFlag = 0;
*cLocalColorTableSize= PMyGifAnimation->LocalColorTableSize;
*cBlockSize =0;
*cDisposalMethod =PMyGifAnimation->DisposalMethod;
*cUserInputFlag =1;
*cTransparentColorFlag =PMyGifAnimation->TransparentColorFlag;
*cDelayTime =PMyGifAnimation->DelayTime;
*cTransparentColorIndex = PMyGifAnimation->TransparentColorIndex;
cpComment ="SkyLine Tools";
}
break;
case - 50:
if (hdib)
{
cpComment ="SkyLine Tools";
}
break;
}
}
return result;
}
/////////////////////////////////////////////////////////////////////////////
//This event is called when loading png, jpg
/////////////////////////////////////////////////////////////////////////////
short CWebImgView::ProgressEvent (short Progress)
{
short result = 1;
if (ExitingApp) return 0;
if (IsFileSaving == false)
{
if (!LoadTimerSet)
{
SetTimer(IDLoadTimer,5 ,NULL);
LoadTimerSet = true;
}
//Force a repaint while loading
DrawFrame(CurrentFrameItem);
//Wait according the delaytime of the gif.
while (!TimerAnimate)
{
PumpMessages();
}
TimerAnimate=false;
DrawFrame(CurrentFrameItem);
PumpMessages();
}
return result;
}
/////////////////////////////////////////////////////////////////////////////
//This event is called when loading png, jpg
/////////////////////////////////////////////////////////////////////////////
short CWebImgView::DibUpdateEvent(HANDLE hdib)
{
short result = 1;
if (ExitingApp) return 0;
PictureDIB = hdib;
PMyGifAnimation = new TMyGifAnimation;
PMyGifAnimation->hPAL = CreateDIBPalette(PictureDIB);
PMyGifAnimation->HDib = PictureDIB;
PMyGifAnimation->Left = 0;
PMyGifAnimation->Top = 0;
PMyGifAnimation->Width = GetDIBWidth(PictureDIB);
PMyGifAnimation->Height = GetDIBHeight(PictureDIB);
PMyGifAnimation->TransparentColorFlag = false;
PMyGifAnimation->ScreenWidth=GetDIBWidth(PictureDIB);
PMyGifAnimation->ScreenHeight=GetDIBHeight(PictureDIB);
PMyGifAnimation->BackGroundColor = 0;
PMyGifAnimation->NetLoops = 10;
PMyGifAnimation->LocalColorTableSize =0;
PMyGifAnimation->DisposalMethod = 1;
PMyGifAnimation->DelayTime=100;
PMyGifAnimation->TransparentColorIndex = 0;
PMyGifAnimation->LocalColorTableFlag =0;
PMyGifAnimation->InterlaceFlag =0;
GifList.Add(PMyGifAnimation);
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Get the position and size of a frame
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
LPRECT CWebImgView::GetFrameRect(int Frame)
{
if (ExitingApp) return NULL;
if ((CurrentFrameItem <=GifList.Size()) && (CurrentFrameItem >0))
{
TMyGifAnimation *PMyGif = (TMyGifAnimation*) GifList[CurrentFrameItem];
if (PMyGif)
{
RECT *R;
R = new(RECT);
R->left=PMyGif->Left;
R->top=PMyGif->Top;
R->right=PMyGif->Left+PMyGif->Width;
R->bottom=PMyGif->Top+PMyGif->Height;
return R;
}
}
return NULL;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Draws a particular frame
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CWebImgView::DrawFrame(int Frame)
{
if (!CanAnimate) return;
if (ExitingApp) return;
HBITMAP hbm = 0;
HBITMAP hbm2 = 0;
HANDLE rethandle = NULL;
HDC MemDC, MemDC2;
RECT CurrentRectangle;
if ((Frame <=GifList.Size()) && (Frame >0))
{
TMyGifAnimation *PG = (TMyGifAnimation*) GifList[Frame];
if (PG)
{
//PictureDIB = PG->HDib;
if (PG->TransparentColorFlag) // If Image have transparent color flag
{
// Clear Previous Image
if (Frame > 0)
{
// Get frame size
CurrentRectangle = *GetFrameRect(Frame-1);
// If previous frame coordinates are changed, restore background picture
// Example for moving gifs
if((PreviousFrameRect.left!=CurrentRectangle.left) ||
(PreviousFrameRect.top!=CurrentRectangle.top) ||
(PreviousFrameRect.right!=CurrentRectangle.right)||
(PreviousFrameRect.bottom!=CurrentRectangle.bottom))
{
StretchBlt(GetDC()->m_hDC,
PreviousFrameRect.left = 0,
PreviousFrameRect.top =0,
PreviousFrameRect.right,
PreviousFrameRect.bottom,
BufferDC,
PreviousFrameRect.left= 0,
PreviousFrameRect.top = 0,
PreviousFrameRect.right,
PreviousFrameRect.bottom,
SRCCOPY);
PreviousFrameRect = CurrentRectangle;
}
}
// Create compitable DC
MemDC = CreateCompatibleDC(GetDC()->m_hDC);
hbm = CreateCompatibleBitmap(GetDC()->m_hDC, PG->Width,PG->Height);
MemDC2 = CreateCompatibleDC(GetDC()->m_hDC);
hbm2 = CreateCompatibleBitmap(GetDC()->m_hDC, PG->Width,PG->Height);
SelectObject(MemDC, hbm);
SelectObject(MemDC2, hbm2);
// Copy Background Image to MemDC with SRCCOPY mode
StretchBlt(MemDC2,0,0,PG->Width,PG->Height,BufferDC,PG->Left,PG->Top,PG->Width,PG->Height,SRCCOPY);
// Create Image Mask && Copy to MemDC with SRCAND mode
HANDLE MaskDib = MakeMaskDib(PG->HDib,PG->Width,PG->Height,PG->TransparentColorIndex);
HPALETTE MaskPal = CreateDIBPalette(MaskDib);
// Copy MaskDIB and Original Image to MemDC
StretchDIBMode(MemDC, MaskDib, MaskPal,0,0,PG->Width,PG->Height, SRCCOPY);
StretchDIBMode(MemDC,PG->HDib,PG->hPAL,0,0,PG->Width,PG->Height, SRCERASE);
StretchDIBMode(MemDC2, MaskDib, MaskPal,0,0,PG->Width,PG->Height, SRCAND);
StretchBlt (MemDC2,0,0,PG->Width,PG->Height,MemDC,0,0,PG->Width,PG->Height,SRCINVERT);
GlobalFree(MaskDib);
DeleteObject(MaskPal);
// Copy Image from MemDC to Screen with SRCCOPY mode
StretchBlt(GetDC()->m_hDC,PG->Left,PG->Top,PG->Width,PG->Height,MemDC2,0,0,PG->Width,PG->Height,SRCCOPY);
DeleteDC(MemDC);
DeleteObject(hbm);
DeleteDC(MemDC2);
DeleteObject(hbm2);
}
else
DrawDIB(GetDC()->m_hDC,PG->HDib,PG->hPAL,PG->Left,PG->Top);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CWebImgView::OnTimer(UINT nIDEvent)
{
if (ExitingApp) return;
switch (nIDEvent)
{
case IDLoadTimer:
{ //Timer used when loading the image
TimerAnimate = true;
}
break;
case IDAnimateTimer:
{ //Timer used for the animation progress
if (InTimer) return;
InTimer = true;
if (CurrentFrameItem <=GifList.Size())
CurrentFrameItem++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -