📄 webimgview.cpp
字号:
// 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);
GetDIBits(hDC, hDDB, 0, (UINT) BI.biHeight, NULL, lpBMI, DIB_RGB_COLORS);
BI = *lpBI;
GlobalUnlock(hDIB);
if (!BI.biSizeImage)
{
BI.biSizeImage = ((BI.biWidth * uBPP + 31) / 32) * 4 * BI.biHeight;
if (uStyle != BI_RGB)
{
if (hOldPal) SelectPalette(hDC, hOldPal, FALSE);
::ReleaseDC(NULL, hDC);
GlobalFree(hDIB);
return NULL;
}
}
BI.biClrUsed = DibNumColors(&BI);
dwSize = BI.biSize + BI.biClrUsed * sizeof(RGBQUAD) + BI.biSizeImage;
h = GlobalReAlloc(hDIB, dwSize, GHND);
if (!h)
{
if (hOldPal) SelectPalette(hDC, hOldPal, FALSE);
::ReleaseDC(NULL, hDC);
GlobalFree(hDIB);
return NULL;
}
else
hDIB = h;
lpBMI = (LPBITMAPINFO) GlobalLock(hDIB);
lpBI = (LPBITMAPINFOHEADER) lpBMI;
*lpBI = BI;
lpBits = (BYTE *) &(lpBMI->bmiColors[DibNumColors(lpBI)]);
uLines = GetDIBits(hDC, hDDB, 0, (UINT) BI.biHeight, lpBits, lpBMI,DIB_RGB_COLORS);
GlobalUnlock(hDIB);
if (hOldPal) SelectPalette(hDC, hOldPal, FALSE);
::ReleaseDC(NULL, hDC);
if (uLines == 0)
{
GlobalFree(hDIB);
return NULL;
}
return hDIB;
}
/********************************************************************/
/*** Creates a dib, image_type = 2,4,8 or 24 bit ***/
/********************************************************************/
HANDLE CWebImgView::CreateNewDib(long new_width,
long new_height,
short image_type)
{
LPBITMAPINFOHEADER lpBI;
LPBITMAPINFO lpBMI;
HANDLE hDIB;
DWORD dwIncr;
UINT uColors;
DWORD dwWidth;
DWORD dwHeight;
DWORD dwSize;
DWORD AlSize;
DWORD ClrImportant;
if (ExitingApp) return NULL;
dwWidth = new_width;
dwHeight = new_height;
switch (image_type)
{
case 2:
dwIncr = ((dwWidth + 31) / 32) * 4;
dwSize = dwIncr * dwHeight;
AlSize = sizeof(BITMAPINFOHEADER) + 2 * sizeof(RGBQUAD) + dwSize;
uColors=2;
ClrImportant=2;
image_type = 1;
break;
case 4: // 4-bit resolution
dwIncr = ((dwWidth *4 + 31) / 32) * 4;
dwSize = dwIncr * dwHeight;
AlSize = sizeof(BITMAPINFOHEADER) + 16 * sizeof(RGBQUAD) + dwSize;
uColors=16;
ClrImportant=16;
break;
case 8:
dwIncr = ((dwWidth * 8 + 31) / 32) * 4;
dwSize = dwIncr * dwHeight;
AlSize = (sizeof(BITMAPINFOHEADER) + (1 << 8) * sizeof(RGBQUAD) + dwSize);
uColors=256;
ClrImportant=256;
break;
case 24:
dwIncr = ((dwWidth * 24 + 31) / 32) * 4;
dwSize = dwIncr * dwHeight;
AlSize = (sizeof(BITMAPINFOHEADER) + dwSize);
uColors=0;
ClrImportant=0;
break;
default:
return NULL;
break;
}
hDIB = GlobalAlloc(GHND, AlSize);
if (!hDIB)
{
return NULL; //ERROR
}
lpBMI = (LPBITMAPINFO) GlobalLock(hDIB);
lpBI = (LPBITMAPINFOHEADER) lpBMI;
lpBI->biSize = sizeof(BITMAPINFOHEADER);
lpBI->biWidth = dwWidth;
lpBI->biHeight = dwHeight;
lpBI->biPlanes = 1;
lpBI->biBitCount = image_type;
lpBI->biCompression = BI_RGB;
lpBI->biSizeImage = dwSize;
lpBI->biXPelsPerMeter = 2953;
lpBI->biYPelsPerMeter = 2953;
lpBI->biClrUsed = uColors;
lpBI->biClrImportant = ClrImportant;
GlobalUnlock(hDIB);
return hDIB;
}
/********************************************************************/
/*** copies a dib ***/
/********************************************************************/
HANDLE CWebImgView::CopyDIB(HANDLE hsDIB)
{
HANDLE hNewDIB;
BYTE * lpOldDIB;
BYTE * lpNewDIB;
long dwSize;
if (ExitingApp) return NULL;
if (hsDIB == NULL) return NULL;
dwSize = GlobalSize(hsDIB);
hNewDIB = GlobalAlloc(GHND, dwSize);
if (hNewDIB <0) return NULL;
lpOldDIB = (BYTE *) GlobalLock(hsDIB);
lpNewDIB = (BYTE *) GlobalLock(hNewDIB);
memcpy(lpNewDIB, lpOldDIB, dwSize);
GlobalUnlock(hsDIB);
GlobalUnlock(hNewDIB);
return hNewDIB;
}
/********************************************************************/
/*** copies a 1 bit dib and inverts it ***/
/********************************************************************/
HANDLE CWebImgView::CopyAndInvert1BitDIB(HANDLE hsDIB)
{
HANDLE hNewDIB;
BYTE * lpOldDIB;
BYTE * lpNewDIB;
long dwSize;
LPBITMAPINFOHEADER lpBI;
LPBITMAPINFO lpBMI;
int dividor;
if (ExitingApp) return NULL;
if (hsDIB == NULL) return NULL;
dwSize = GlobalSize(hsDIB);
hNewDIB = GlobalAlloc(GHND, dwSize);
if (hNewDIB <0) return NULL;
lpOldDIB = (BYTE *) GlobalLock(hsDIB);
lpNewDIB = (BYTE *) GlobalLock(hNewDIB);
memcpy(lpNewDIB, lpOldDIB, dwSize);
GlobalUnlock(hsDIB);
GlobalUnlock(hNewDIB);
UINT uWidth = GetDIBWidth(hNewDIB);
UINT uHeight = GetDIBHeight(hNewDIB);
lpBMI = (LPBITMAPINFO) GlobalLock(hNewDIB);
lpBI = (LPBITMAPINFOHEADER) lpBMI;
BYTE *CByte = GetDIBBits(lpBI);
switch (GetDIBBitPerPixel(hNewDIB))
{
case 1: dividor=1; break;
case 4: return hNewDIB; break; //not suported here
case 8: return hNewDIB; break; //not suported here
}
int iLen = ((uWidth + 31) / 32) * 4;
iLen = iLen * uHeight;
for (int i=0; i< iLen;i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -