// WebImgView.cpp : implementation of the CWebImgView class
//
#include "stdafx.h"
#include "MainFrm.h"
#include "WebImg.h"
#include "Wlink.h"
#include "WebImgDoc.h"
#include "WebImgView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//*****************************************************************************************
//Pointer to Dll Calls
an_wtgiffiledib My_an_wtgiffiledib = NULL;
an_rdgiffiledib My_an_rdgiffiledib = NULL;
rdpngfiledibprog My_rdpngfiledibprog = NULL;
wrpngfiledib My_wrpngfiledib = NULL;
rdjpgfiledibprog My_rdjpgfiledibprog = NULL;
wrjpgfiledib My_wrjpgfiledib = NULL;
rdbmpfiledib My_rdbmpfiledib = NULL;
wrbmpfiledib My_wrbmpfiledib = NULL;
ilcompressfile My_ilcompressfile = NULL;
ildecompressfile My_ildecompressfile = NULL;
ilcompressbuf My_ilcompressbuf = NULL;
ildecompressbuf My_ildecompressbuf = NULL;
ReduceDib My_ReduceDib = NULL;
InitDll My_InitDll = NULL;
DdbtoDib My_DdbtoDib = NULL;
//*****************************************************************************************
//*****************************************************************************************
//Progress Call Back Function.
short __cdecl pfcallback(short prog, long calling_object_address)
{
short result =1;
return result;
}
//*****************************************************************************************
//Load Call Back Function of animated gif.This call is passed
//to the class using the variable v typecasted to the class
//*****************************************************************************************
short __cdecl pfcallapp(HANDLE hdib, // Handle for Dib
void *GifHeader, // Pointer to GIF Header (Structure)
void *ImgDesc, // Pointer to Image Descreptor (Structure)
void *GraphCtrl, // Pointer to Graphical Control Ext.(Strucure)
long NetLoop, // Number of Netscape loops
char *pComment, // Pointer to comment block
short p, // Progressive showing
long calling_object_address) // LongInt of this
{
if (calling_object_address != 0)
{
//Get the calling class
CWebImgView *pCWebImgView = (CWebImgView *)calling_object_address;
//Pass the call to the calling class
return pCWebImgView->CallEvent(hdib,
GifHeader,
ImgDesc,
GraphCtrl,
NetLoop,
pComment,
p);
} else return -1;
}
/*****************************************************************************************
Update callback Dispatch funtion which forward the callback to the apprporiate object
*****************************************************************************************/
short __cdecl savegifcallapp (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 colortable of frame 1
BYTE * cInterlaceFlag, //Save frame interlaced (only one frame 1)
BYTE * cSortFlag, // Not use (set to 0)
BYTE * cLocalColorTableSize,
BYTE * cBlockSize, //Not used (set to 0)
BYTE * cDisposalMethod, //Disposal method
BYTE * cUserInputFlag, // Not used (Set to 1)
BYTE * cTransparentColorFlag, //Specify if frame has a transparent color
WORD * cDelayTime, // Delay time in Micro seconds
BYTE * cTransparentColorIndex, // Index to paletteEntry to show background
char * cpComment, // Add comment to this frame
short frame, // This is passed by the dll to let You know which frame to save
short p, //Progress and indicator
long calling_object_address)
{
if (calling_object_address != 0)
{
//Get the calling class
CWebImgView *pCWebImgView = (CWebImgView *)calling_object_address;
//Pass the call to the calling class
return pCWebImgView->SaveCallEvent(hdib,
cLeft,
cTop,
cWidth,
cHeigth,
cLocalColorTableFlag,
cInterlaceFlag,
cSortFlag,
cLocalColorTableSize,
cBlockSize,
cDisposalMethod,
cUserInputFlag,
cTransparentColorFlag,
cDelayTime,
cTransparentColorIndex,
cpComment,
frame,
p);
} else return -1;
}
/*****************************************************************************************
Update callback Dispatch funtion which forward the callback to the apprporiate object
*****************************************************************************************/
short __cdecl DibUpdateCallBack (HANDLE hdib,
long calling_object_address)
{
if (calling_object_address != 0)
{
//Get the calling class
CWebImgView *pCWebImgView = (CWebImgView *)calling_object_address;
//Pass the call to the calling class
return pCWebImgView->DibUpdateEvent(hdib);
} else return -1;
}
/*****************************************************************************************
Update Progress callback Dispatch funtion which forward the callback to the apprporiate object
*****************************************************************************************/
short __cdecl UpdateProgressCallBack (short Progress,
long calling_object_address)
{
if (calling_object_address != 0)
{
//Get the calling class
CWebImgView *pCWebImgView = (CWebImgView *)calling_object_address;
//Pass the call to the calling class
return pCWebImgView->ProgressEvent(Progress);
} else return -1;
}
/********************************************************************/
/*** DDBtoDIB: ***/
/********************************************************************/
HANDLE CWebImgView::IDDBtoDIB(HBITMAP hDDB,
HPALETTE hPal,
UINT uBPP)
{
UINT uStyle = BI_RGB;
LPBITMAPINFOHEADER lpBI;
LPBITMAPINFO lpBMI;
BYTE *lpBits;
BITMAPINFOHEADER BI;
BITMAP BM;
HPALETTE hOldPal;
HANDLE hDIB;
HANDLE h;
HDC hDC;
DWORD dwSize;
UINT uLines;
if (!hDDB)
{
return NULL;
}
if (!hPal) hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
GetObject(hDDB, sizeof(BITMAP), (LPSTR) &BM);
if (uBPP == 0) uBPP = 1 * BM.bmBitsPixel;
BI.biSize = sizeof(BITMAPINFOHEADER);
BI.biWidth = BM.bmWidth;
BI.biHeight = BM.bmHeight;
BI.biPlanes = 1;
BI.biBitCount = uBPP;
BI.biCompression = uStyle;
BI.biSizeImage = 01;
BI.biXPelsPerMeter = 2953;
BI.biYPelsPerMeter = 2953;
BI.biClrUsed = 0;
BI.biClrUsed = DibNumColors(&BI);
BI.biClrImportant = 0;
dwSize = BI.biSize + BI.biClrUsed * sizeof(RGBQUAD);
hDIB = GlobalAlloc(GHND, dwSize);
if (!hDIB) return NULL;
lpBMI = (LPBITMAPINFO) GlobalLock(hDIB);
lpBI = (LPBITMAPINFOHEADER) lpBMI;
*lpBI = BI;
hDC = ::GetDC(NULL);
hOldPal = SelectPalette(hDC, hPal, FALSE);
RealizePalette(hDC);
GetDI