www.pudn.com > RSImageManger.rar > ImageMangerView.cpp
// ImageMangerView.cpp : implementation of the CImageMangerView class
//
#include "stdafx.h"
#include "ImageManger.h"
#include "MainFrm.h"
#include "ImageMangerDoc.h"
#include "ImageMangerView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "math.h"
#include "GeocodeDlg.h" //zrf
#include "Image.h"
#include "JpegFile.h"
#include "GIFFile.h"
#include "BMPDlg.h"
#include "BMPFile.h"
#include "QuantDlg.h"
#include "dl1quant.h"
#include "BATCONVERT1.h"
#include "MetaData_NameDlg.h"
#include "SYSCONFIG.h"
//zrf 9-26
#include "stdpch.h"
// define 'EXTENDED_TEST' to see CTiffDecoderEx and CTiffEncoderEx in action
#define EXTENDED_TEST 1
#include "WinBmp.h"
#include "anybmp.h"
#include "bmpdec.h"
#include "tiffdecex.h"
#include "tiffencex.h"
#ifdef EXTENDED_TEST
#include "filesrc.h"
#include "filesink.h"
#endif
/////////////////////////////////////////////////////////////////////////////
// CImageMangerView
IMPLEMENT_DYNCREATE(CImageMangerView, CScrollView)
BEGIN_MESSAGE_MAP(CImageMangerView, CScrollView)
//{{AFX_MSG_MAP(CImageMangerView)
ON_COMMAND(ID_DECOMEINFOUR, OnDecomeinfour)
ON_COMMAND(ID_FILE_GETDIMENSIONSJPG, OnFileGetdimensionsjpg)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
ON_COMMAND(ID_FILE_SAVECOLORMAPPEDBMP, OnFileSavecolormappedbmp)
ON_COMMAND(ID_FILE_SAVEGRAYAS, OnFileSavegrayas)
ON_COMMAND(ID_IMAGE_BATCOMPRESS, OnImageBatcompress)
ON_COMMAND(ID_IMAGE_NOVIEW, OnImageNoview)
ON_COMMAND(ID_MOSAIC_LOCATE, OnMosaicLocate)
ON_COMMAND(ID_OPENINDEX, OnOpenindex)
ON_COMMAND(ID_OUTPUTBMP, OnOutputbmp)
ON_COMMAND(ID_VIEWINBOX, OnViewinbox)
ON_COMMAND(ID_VIEWINGRID, OnViewingrid)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_OPENBIGBMP, OnOpenbigbmp)
ON_COMMAND(ID_IMAGE_RESAMPLE, OnImageResample)
ON_COMMAND(ID_WALKVIEW, OnWalkview)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_PUTDMFILE, OnPutdmfile)
ON_COMMAND(ID_CONFIG, OnConfig)
ON_COMMAND(ID_IMAGE_TIFF, OnImageTiff)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CImageMangerView construction/destruction
CImageMangerView::CImageMangerView()
{
// TODO: add construction code here
SetScrollSizes(MM_TEXT, CSize(0, 0));//注意映射模式的改变有可能导致拉框选择的不正确
m_buf=NULL;
m_width=0;
m_height=0;
m_widthDW=0;
m_SelectMenu=0; //没有选择菜单
m_GetFlag=0;
m_bImageReady=0;
screenX0=10;
screenY0=10;
m_pImage=NULL;
m_Dragging=0;
ViewFlag=0;
hpal=NULL;
ImgBatFlag=0;
m_FileName="";
SlicerNum=0;//用来表示要将图象分成几块
PushNumb=0;
m_ZoomScale=0;
m_checkstatus=1;
m_Dlgdm=100;
m_jpegratio=75;
m_ColorFlag=-1;
m_color=-1;
}
CImageMangerView::~CImageMangerView()
{
// clean up
if (m_buf!=NULL) {
delete [] m_buf;
m_buf=NULL;
}
if(m_pImage!=NULL)
{
delete m_pImage;
m_pImage=NULL;
}
}
BOOL CImageMangerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
m_HCur1=(HCURSOR)::LoadImage(cs.hInstance,MAKEINTRESOURCE(IDC_CURSOR1),// IDC_SIZEALL);
IMAGE_CURSOR,32,32,
LR_CREATEDIBSECTION);
m_HCross=AfxGetApp()->LoadStandardCursor(IDC_ARROW);
::SetCursor(m_HCross);
//把背景刷子置为NULL
/*
ASSERT(cs.style & WS_CHILD);
if (cs.lpszClass == NULL)
cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS);
*/
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CImageMangerView drawing
void CImageMangerView::OnDraw(CDC* pDC)
{
CImageMangerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(ImgBatFlag!=0)
{
ViewFlag=1; //当进行批处理时,都可看成是非可视化处理
return;
}
if(m_SelectMenu==5)
DrawBMP(pDC);
else if(m_SelectMenu==2||m_SelectMenu==3)
//DrawBmp4(pDC,100,100,300,200,"e:\image8bit.bmp",1);
DrawAllView( pDC);
else if(m_pImage!=NULL)
{
//add for 24 draw
/*
if(m_pImage->m_bitcount==8)
{
DrawBmp(pDC,10,10,m_pImage->datawidth,m_pImage->dataheight,2);
}
else if(m_pImage->m_bitcount==24)
Paint(pDC);
else
{
return;
}
*/
Paint(pDC);
}
ReleaseDC(pDC);
}
void CImageMangerView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
////////
if (m_buf!=NULL)
SetScrollSizes(MM_TEXT,
CSize(m_width,m_height));
else if(m_bImageReady)
{
CSize sizeTotal;
sizeTotal.cx =m_pImage->m_imagewidth;
sizeTotal.cy =m_pImage->m_imageheight;
SetScrollSizes(MM_TEXT, sizeTotal);
}
////////no use?
else
{
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
}
/////////////////////////////////////////////////////////////////////////////
// CImageMangerView printing
BOOL CImageMangerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CImageMangerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CImageMangerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CImageMangerView diagnostics
#ifdef _DEBUG
void CImageMangerView::AssertValid() const
{
CScrollView::AssertValid();
}
void CImageMangerView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CImageMangerDoc* CImageMangerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageMangerDoc)));
return (CImageMangerDoc*)m_pDocument;
}
#endif //_DEBUG
////////////////////////////////////////////////////////////////////////////
//
// shoot the global image to the screen
void CImageMangerView::DrawBMP(CDC* pDC)
{
// if we don't have an image, get out of here
if (m_ntmp==NULL) return;
CRect clientRect;
GetClientRect(clientRect);
SetScrollSizes(MM_TEXT,
CSize(m_width,m_height));
// Center It
/*
UINT left = (clientRect.Width() - m_width) / 2;
UINT top = (clientRect.Height() - m_height) / 2;
*/
// set up a DIB
LPBITMAPINFO lpbi=new BITMAPINFO;
lpbi->bmiHeader.biWidth=m_width;
lpbi->bmiHeader.biHeight=m_height;
lpbi->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
lpbi->bmiHeader.biPlanes=1;
lpbi->bmiHeader.biBitCount=24;
lpbi->bmiHeader.biCompression=BI_RGB;
lpbi->bmiHeader.biSizeImage=0;
lpbi->bmiHeader.biXPelsPerMeter=0;
lpbi->bmiHeader.biYPelsPerMeter=0;
lpbi->bmiHeader.biClrUsed=0;
lpbi->bmiHeader.biClrImportant=0;
SetDIBitsToDevice(*pDC,/*left,top,*/10,10,m_width+10,m_height+10,
0,0,0,m_height,m_ntmp,/*(LPBITMAPINFO)&bmiHeader*/lpbi,DIB_RGB_COLORS);//DIB_PAL_COLORS); //DIB_RGB_COLORS
//delete [] tmp;
/* //像素大小的显示应放在下面
CString info;
info.Format("(%d x %d)", m_width, m_height);
theDC->SetBkMode(TRANSPARENT);
theDC->SetTextColor(RGB(0,0,0));
theDC->TextOut(10,5, info);
*/
/////////
if(SlicerNum==4)
{
CPen pen2(PS_SOLID,100,RGB(255,255,0));
CPen * oldpen=pDC->SelectObject(&pen2);
pDC->MoveTo(m_width/2,0);
pDC->LineTo(m_width/2,m_height);
pDC->MoveTo(0,m_height/2);
pDC->LineTo(m_width,m_height/2);
pen2.DeleteObject();
pDC->SelectObject(oldpen);
/////////////
}
delete lpbi;
//ReleaseDC(pDC);//?
//}
}
void CImageMangerView::OnFileOpen()
{
////
if(m_pImage!=NULL)
{
UnmapViewOfFile(m_pImage->pMapFile1);
CloseHandle(m_pImage->hFile1);
CloseHandle(m_pImage->hFile);
delete m_pImage;
m_pImage=NULL;
}
m_SelectMenu=5;
m_bImageReady=0;
SlicerNum=0;
m_color=-1;
////
CString fileName;
CString filt="BMP File(*.BMP)|*.BMP|索引文件 (*.IMG)|*.IMG|JPG (*.JPG)|*.JPG|All files (*.*)|*.*||";
// OPENFILENAME - so i can get to its Help page easily
CFileDialog fileDlg(TRUE,"*.BMP","*.BMP",NULL,filt,this);
fileDlg.m_ofn.Flags|=OFN_FILEMUSTEXIST;
fileDlg.m_ofn.lpstrTitle="打开图像";
if (fileDlg.DoModal()==IDOK) {
AfxGetApp()->DoWaitCursor(1);//zrf
fileName=fileDlg.GetPathName();
m_FileName=fileName;
CString ext=fileName.Right(4);
//CWaitCursor wait;
if (!ext.CompareNoCase(".JPG"))
LoadJPG(fileName);
if (!ext.CompareNoCase(".GIF"))
LoadGIF(fileName);
if (!ext.CompareNoCase(".BMP"))
LoadBMP(fileName);
if (!ext.CompareNoCase(".IMG"))
{
if (m_buf!=NULL)
{
delete [] m_buf;
m_buf=NULL;
}
if(m_pImage!=NULL)
{
UnmapViewOfFile(m_pImage->pMapFile1);
CloseHandle(m_pImage->hFile1);
CloseHandle(m_pImage->hFile);
delete m_pImage;
m_pImage=NULL;
}
m_pImage = new CImageDe;
m_pImage->m_CurFileName=fileName;
// CString Filename=fileName.Left(fileName.GetLength()-4)+".img";
//if(m_pImage->IsReplace(Filename)) //替换存在的文件,注意这两个文件是否在同一目录下
m_pImage->GetImageInfo();
m_pImage->GetAllImageData() ;
m_width=m_pImage->m_imagewidth;
m_height=m_pImage->m_imageheight;
m_SelectMenu=2;
m_bImageReady = 1;
m_ZoomScale=0;
Invalidate( );
return;
}
// wait.Restore( );
AfxGetApp()->DoWaitCursor(-1);
}
// DWORD-align for display
m_ntmp = JpegFile::MakeDwordAlignedBuf(m_buf,
m_width,
m_height,
&m_widthDW);
// force a redraw
Invalidate(TRUE);
}
////////////////////////////////////////////////////////////////////////////
// Save As dialog handler
//
void CImageMangerView::OnFileSaveAs()
{
CString fileName;
CString filt="JPG File (*.JPG)|*.JPG|BMP (*.BMP)|*.BMP|All files (*.*)|*.*||";
// OPENFILENAME - so i can get to its Help page easily
CFileDialog fileDlg(FALSE,"*.JPG","*.JPG",NULL,filt,this);
fileDlg.m_ofn.Flags|=OFN_FILEMUSTEXIST;
fileDlg.m_ofn.lpstrTitle="保存文件,请选择格式";
if (fileDlg.DoModal()==IDOK) {
AfxGetApp()->DoWaitCursor(1);
fileName=fileDlg.GetPathName();
CString ext=fileName.Right(4);
if(m_pImage!=NULL)
{
if(m_pImage->m_bitcount==24) m_ColorFlag=1;
else if(m_pImage->m_bitcount==8) m_ColorFlag=0;
else AfxMessageBox("不能处理该格式图象!");
}
if (!ext.CompareNoCase(".JPG"))
{
if(m_color==0)
SaveJPG(fileName,FALSE);
else
SaveJPG(fileName,TRUE);
}
if (!ext.CompareNoCase(".BMP"))//if 8bit or 24 bit
{
if (m_buf==NULL&&m_pImage==NULL)
{
AfxMessageBox("No Image!");
return;
}
//if(m_pImage->m_bitcount==8||m_pImage->m_bitcount==4||m_pImage->m_bitcount==16)
if(m_ColorFlag==0)//||m_color==0
OnFileSavecolormappedbmp(fileName);
else if(m_ColorFlag==1)//||m_color==1
SaveBMP24(fileName);
else
AfxMessageBox("sorry,不能保存这种图象格式!");
}
AfxGetApp()->DoWaitCursor(-1);
}
}
////////////////////////////////////////////////////////////////////////////
// read a JPG to our global buffer
//
void CImageMangerView::LoadJPG(CString fileName)
{
// m_buf is the global buffer
if (m_buf!=NULL) {
delete [] m_buf;
m_buf=NULL;
}
// read to buffer tmp
m_buf=JpegFile::JpegFileToRGB(fileName, &m_width, &m_height,&m_color);
//////////////////////
// set up for display
// do this before DWORD-alignment!!!
// this works on packed (not DWORD-aligned) buffers
// swap red and blue for display
JpegFile::BGRFromRGB(m_buf, m_width, m_height);
// vertical flip for display
JpegFile::VertFlipBuf(m_buf, m_width * 3, m_height);
}
////////////////////////////////////////////////////////////////////////////
// read a BMP to our global buffer
//
void CImageMangerView::LoadBMP(CString fileName)
{
if (m_buf!=NULL)
{
delete [] m_buf;
m_buf=NULL;
}
//判断文件大小,以决定是否建立索引
/*
CFile filebmp;
filebmp.Open(fileName,CFile::modeRead ,NULL);
DWORD filelength=filebmp. GetLength();
filebmp.Close;
*/
FILE* fpbmp;
int openflag;
openflag=0;
BITMAPFILEHEADER *bmfhr; //memory dump
BITMAPINFOHEADER *bmihr;
bmfhr=new BITMAPFILEHEADER;
bmihr=new BITMAPINFOHEADER;
fpbmp=fopen(fileName,"rb");
fread(bmfhr,sizeof(BITMAPFILEHEADER),1,fpbmp);
fread(bmihr,sizeof(BITMAPINFOHEADER),1,fpbmp);
long width=bmihr->biWidth;
long height=bmihr->biHeight;
if(width*height>500000)//1000*100*1000*5 5MB左右
openflag=1;
fclose(fpbmp);
if(bmihr->biBitCount==8)
m_ColorFlag=0;
else if(bmihr->biBitCount==24)
m_ColorFlag=1;
else
{
AfxMessageBox("只处理8位或24位的BMP!");
return;
}
if(openflag==1)
{
if(m_pImage!=NULL)
{
UnmapViewOfFile(m_pImage->pMapFile1);
CloseHandle(m_pImage->hFile1);
CloseHandle(m_pImage->hFile);
delete m_pImage;
m_pImage=NULL;
}
m_pImage = new CImageDe;
m_pImage->m_CurFileName=fileName;
CString strIMG =fileName.Left(fileName.GetLength()-3)+"img";
if(!m_pImage->IsReplace(strIMG))
{
m_pImage->GetImageInfo();
m_pImage->GetAllImageData();
m_ZoomScale=0;
}
else
{
m_pImage->m_outdexdm=m_Dlgdm;
m_pImage->OutPutIMG(fileName );
m_pImage->GetImageInfo();
m_pImage->GetAllImageData();
m_ZoomScale=0;
}
m_SelectMenu=2;
m_bImageReady = TRUE;
m_width=m_pImage->m_imagewidth;
m_height=m_pImage->m_imageheight;
Invalidate( );
return;
}
BMPFile theBmpFile;
m_buf=theBmpFile.LoadBMP(fileName, &m_width, &m_height);
if ((m_buf==NULL) || (theBmpFile.m_errorText!="OK")) {
AfxMessageBox(theBmpFile.m_errorText);
m_buf=NULL;//zrf
//m_buf==NULL;
return;
}
//////////////////////
// set up for display
// do this before DWORD-alignment!!!
// this works on packed (not DWORD-aligned) buffers
// swap red and blue for display
JpegFile::BGRFromRGB(m_buf, m_width, m_height);
// vertical flip for display
JpegFile::VertFlipBuf(m_buf, m_width * 3, m_height);
}
////////////////////////////////////////////////////////////////////////////
//
// read a GIF to our global buffer
void CImageMangerView::LoadGIF(CString filename)
{
if (m_buf!=NULL) {
delete [] m_buf;
m_buf=NULL;
}
GIFFile theGifThing;
// read the GIF to a packed buffer of RGB bytes
m_buf=theGifThing.GIFReadFileToRGB(filename,
&m_width,
&m_height);
if (m_buf==NULL) {
AfxMessageBox(theGifThing.m_GIFErrorText);
return;
}
//////////////////////
// set up for display
// do this before DWORD-alignment!!!
// swap red and blue for display
JpegFile::BGRFromRGB(m_buf, m_width, m_height);
// flip for display
JpegFile::VertFlipBuf(m_buf, m_width * 3, m_height);
}
////////////////////////////////////////////////////////////////////////////
// save functions are generally more complex than reading functions.
// there are many more decisions to be made for writing than for reading.
////////////////////////////////////////////////////////////////////////////
// save a JPG
void CImageMangerView::SaveJPG(CString fileName, BOOL color)
{
// note, because i'm lazy, most image data in this app
// is handled as 24-bit images. this makes the DIB
// conversion easier. 1,4,8, 15/16 and 32 bit DIBs are
// significantly more difficult to handle.
if (m_buf==NULL&&m_pImage==NULL) {
AfxMessageBox("No Image!");
return;
}
BOOL ok;
// we vertical flip for display. undo that.
if(m_buf!=NULL)
{
JpegFile::VertFlipBuf(m_buf, m_width * 3, m_height);
// we swap red and blue for display, undo that.
JpegFile::BGRFromRGB(m_buf, m_width, m_height);
// save RGB packed buffer to JPG
ok=JpegFile::RGBToJpegFile(fileName,
m_buf,
m_width,
m_height,
color,
m_jpegratio); // quality value 1-100.
}
else if(m_pImage!=NULL)
{
if(m_pImage->m_bitcount==24||m_pImage->m_bitcount==8)//注意在拉框显示时一律用24位,所以不用区分8与24位了
{
JpegFile::VertFlipBuf(m_pImage->mBoxImage,UINT(m_pImage->datawidth) * 3,UINT( m_pImage->dataheight));
// we swap red and blue for display, undo that.
JpegFile::BGRFromRGB(m_pImage->mBoxImage, UINT(m_pImage->datawidth) ,UINT(m_pImage->dataheight));
// save RGB packed buffer to JPG
ok=JpegFile::RGBToJpegFile(fileName,
m_pImage->mBoxImage,
UINT(m_pImage->datawidth),
UINT(m_pImage->dataheight),
color,
m_jpegratio); // quality value 1-100.
JpegFile::BGRFromRGB(m_pImage->mBoxImage, UINT(m_pImage->datawidth) ,UINT(m_pImage->dataheight));
// vertical flip for display
JpegFile::VertFlipBuf(m_pImage->mBoxImage,UINT(m_pImage->datawidth) * 3,UINT( m_pImage->dataheight));
}
/*
else if(m_pImage->m_bitcount==8)
{
//********处理
int RowByteNum=((m_pImage->datawidth*8)+31)/32*4;
int RowByteNum24=((m_pImage->datawidth*24)+31)/32*4;
unsigned char *tempimage = NULL; //store the bytes of the image
long jj= (long)m_pImage->dataheight*(long)RowByteNum;
long jj24= (long)m_pImage->dataheight*(long)RowByteNum24;
//bmpimage=new unsigned char[jj];
tempimage=new unsigned char[jj24];
int mi,mj,k,jj1;
k=0;
for(mi=0;midataheight; mi++)
for(mj=0;mjdatawidth; mj++)
{
jj1=mi*RowByteNum+mj;//RowByteNum//imagewidth
tempimage[k]=m_pImage->m_rgbquad[m_pImage->mBoxImage[jj1]].rgbBlue;
tempimage[k+1]=m_pImage->m_rgbquad[m_pImage->mBoxImage[jj1]].rgbGreen;
tempimage[k+2]=m_pImage->m_rgbquad[m_pImage->mBoxImage[jj1]].rgbRed;
k=k+3;
}
JpegFile::VertFlipBuf(tempimage,UINT(m_pImage->datawidth) * 3,UINT( m_pImage->dataheight));
// we swap red and blue for display, undo that.
JpegFile::BGRFromRGB(tempimage, UINT(m_pImage->datawidth) ,UINT(m_pImage->dataheight));
// save RGB packed buffer to JPG
ok=JpegFile::RGBToJpegFile(fileName,
tempimage,
UINT(m_pImage->datawidth),
UINT(m_pImage->dataheight),
color,
75); // quality value 1-100.
}
*/
//保存定位信息,注意必须有相应的原始BMP文件存在
double resolvx,resolvy,east, west, north, south;
if(!m_pImage->ReadDOMFile(m_pImage->m_CurFileName, resolvx, resolvy, //读控制点文件
east, west, north, south))
{
AfxMessageBox("读DOM文件失败,无法保存影象的定位信息");
//return FALSE;
}
double BoxPointy=west/*Xr原点*/+m_pImage->m_BoxI*resolvy;//m_resolvy;//作为新图象的原点坐标
double BoxPointx=north/*Yc*/-m_pImage->m_BoxJ*resolvx;//m_resolvx;
m_pImage->WriteDOMFile(fileName, resolvx, resolvy,
0,0,BoxPointy, BoxPointx);//BoxPointy指距North(X)的距离
}
if (!ok)
{
AfxMessageBox("Write Error");
}
else
{
// load what we just saved
LoadJPG(fileName);
Invalidate(TRUE);
}
}
////////////////////////////////////////////////////////////////////////////
//
// save an 8-bit GIF from our 24-bit global buffer. this requires color
// quantization of some kind.
void CImageMangerView::SaveGIF(CString filename)
{
// note, because i'm lazy, most image data in this app
// is handled as 24-bit images. this makes the DIB
// conversion easier. 1,4,8, 15/16 and 32 bit DIBs are
// significantly more difficult to handle.
if (m_buf==NULL) {
AfxMessageBox("No Image!");
return;
}
// get quantization params
CQuantDlg theDlg;
if (theDlg.DoModal()!=IDOK) {
return;
}
// convert from DIB orientation
JpegFile::VertFlipBuf(m_buf, m_width * 3, m_height);
// swap red and blue
JpegFile::BGRFromRGB(m_buf, m_width, m_height);
///////////////////////////////////////////////////////////////
// color quantization section - make an 8-bit image that looks like
// our 24-bit image...
// the palette
RGBQUAD RGBpal[256];
BYTE *colormappedBuffer;
// color or gray?
if (theDlg.m_color) {
// color !
// allocate a buffer to colormap to
colormappedBuffer = (BYTE *) new BYTE[m_width* m_height];
if (colormappedBuffer==NULL) {
AfxMessageBox("Alloc error in SaveGIF!");
return ;
}
BYTE tmpPal[3][256];
// colormap it
if (!dl1quant(m_buf, // input
colormappedBuffer, // output
m_width,
m_height,
theDlg.m_quantColors,
TRUE,
tmpPal)) {
AfxMessageBox("Quantization error");
delete [] colormappedBuffer;
return;
}
// copy our palette
for (UINT col=0;col<256;col++) {
if (col>theDlg.m_quantColors) {
RGBpal[col].rgbRed=0;
RGBpal[col].rgbBlue=0;
RGBpal[col].rgbGreen=0;
} else {
RGBpal[col].rgbRed=tmpPal[0][col];
RGBpal[col].rgbGreen=tmpPal[1][col];
RGBpal[col].rgbBlue=tmpPal[2][col];
}
}
} else {
// convert to 8-bit grayscale
colormappedBuffer = MakeColormappedGrayscale(m_buf, // RGB
(UINT)m_width, // pixels
(UINT)m_height,
(UINT)m_width * 3, // bytes
(UINT)256, // colors
RGBpal); // palette
}
if (colormappedBuffer==NULL) {
AfxMessageBox("Failed to make 256 color image");
return;
}
// figure out the palette entries
int red[256], blue[256], green[256];
for (int i=0;i<256;i++) {
red[i] = RGBpal[i].rgbRed;
green[i]= RGBpal[i].rgbGreen;
blue[i] = RGBpal[i].rgbBlue;
}
// write it
GIFFile theGifThing;
if (!theGifThing.GIFWriteFileFrom256Color(colormappedBuffer,
filename,
m_width,
m_height,
0, // background color
red, green, blue)) {
AfxMessageBox(theGifThing.m_GIFErrorText);
} else {
// load what we just saved
LoadGIF(filename);
Invalidate(TRUE);
}
if (colormappedBuffer!=NULL)
delete [] colormappedBuffer;
}
////////////////////////////////////////////////////////////////////////////
//
// use the BMPFile class to write a 24-bit BMP file
//
void CImageMangerView::SaveBMP24(CString filename)
{
// note, because i'm lazy, most image data in this app
// is handled as 24-bit images. this makes the DIB
// conversion easier. 1,4,8, 15/16 and 32 bit DIBs are
// significantly more difficult to handle.
if (m_buf==NULL&&m_pImage==NULL) {
AfxMessageBox("No Image!");
return;
}
if(m_pImage!=NULL)
{
m_pImage->OutPutImageInBmp(filename);
return;
}
// image in m_buf is already BGR and vertically flipped, so we don't need
// to do that for this function.
// i really should make an RGB to BMP fn.
BMPFile theBmpFile;
theBmpFile.SaveBMP(filename,
m_buf,
m_width,
m_height);
if (theBmpFile.m_errorText!="OK")
AfxMessageBox(theBmpFile.m_errorText, MB_ICONSTOP);
/*
else {
// load what we just saved
LoadBMP(filename);
Invalidate(TRUE);
}
*/
}
////////////////////////////////////////////////////////////////////////////
//
// save a grayscaled image
void CImageMangerView::OnFileSavegrayas()
{
// note, because i'm lazy, most image data in this app
// is handled as 24-bit images. this makes the DIB
// conversion easier. 1,4,8, 15/16 and 32 bit DIBs are
// significantly more difficult to handle.
CString fileName;
CString filt="JPG File (*.JPG)|*.JPG|All files (*.*)|*.*||";
// OPENFILENAME - so i can get to its Help page easily
CFileDialog fileDlg(FALSE,"*.JPG","*.JPG",NULL,filt,this);
fileDlg.m_ofn.Flags|=OFN_FILEMUSTEXIST;
fileDlg.m_ofn.lpstrTitle="File to save as grayscale";
if (fileDlg.DoModal()==IDOK) {
fileName=fileDlg.GetPathName();
AfxGetApp()->DoWaitCursor(1);
CString ext;
ext=fileName.Right(4);
if (!ext.CompareNoCase(".JPG"))
SaveJPG(fileName,FALSE);
AfxGetApp()->DoWaitCursor(-1);
}
}
////////////////////////////////////////////////////////////////////////////
//
// get JPG dimensions
void CImageMangerView::OnFileGetdimensionsjpg()
{
CString fileName;
CString filt="JPG File (*.JPG)|*.JPG|All files (*.*)|*.*||";
// OPENFILENAME - so i can get to its Help page easily
CFileDialog fileDlg(TRUE,"*.JPG","*.JPG",NULL,filt,this);
fileDlg.m_ofn.Flags|=OFN_FILEMUSTEXIST;
fileDlg.m_ofn.lpstrTitle="查询JPG图象大小信息";
if (fileDlg.DoModal()==IDOK) {
fileName=fileDlg.GetPathName();
UINT width, height;
if (JpegFile::GetJPGDimensions(fileName,
&width,
&height)) {
char buf[200];
sprintf(buf,"%d %d",width,height);
AfxMessageBox(buf);
} else
AfxMessageBox("JPEG Error");
}
}
////////////////////////////////////////////////////////////////////////////
//
// save 1,4,8 bit BMP from our 24-bit global buffer
//
// if the user chooses 8-bits per pixel, we provide the option of using
// the color quantizer.
void CImageMangerView::OnFileSavecolormappedbmp(CString fileName)
{
if (m_buf==NULL&&m_pImage==NULL) {
AfxMessageBox("请先打开图象!");
return;
}
BMPFile theBmpFile;
//BYTE *buf;
UINT width;
UINT height;
//buf=NULL;
CBMPDlg theDlg;
RGBQUAD colormap[256];
int bitsperpixel =8;
int colors = (int)pow(2,bitsperpixel);
BYTE *colorMappedBuffer = NULL;
BYTE tmpPal[3][256];
if(m_pImage!=NULL)
{
// m_pImage->OutPutImageInBmp(fileName);
if(m_pImage->mBoxImage==NULL)
{
AfxMessageBox("请先拉框选择,若要转换整幅图象,可使用批处理功能!");
return;
}
width=m_pImage->datawidth;
height=m_pImage->dataheight;
///////////
//JpegFile::BGRFromRGB(m_pImage->mBoxImage, width, height);
// vertical flip for display
//JpegFile::VertFlipBuf(m_pImage->mBoxImage, width * 3, height);
// allocate a buffer to colormap to
colorMappedBuffer = (BYTE *) new BYTE[width* height];
if (colorMappedBuffer==NULL)
{
AfxMessageBox("Memory Error in OnSaveColormappedbmp!");
return ;
}
// colormap it
// generates an 8-bit color-mapped image into colorMappedBuffer
if (!dl1quant(m_pImage->mBoxImage,
colorMappedBuffer, // buffers
width,
height,
64,//theDlg.m_quantColors,
TRUE,
tmpPal))
{ // palette
AfxMessageBox("Quantization error");
delete [] colorMappedBuffer;
return ;
}
// copy our palette
for (UINT col=0;col<256;col++)
{
if (col>64)
{
colormap[col].rgbRed=0;
colormap[col].rgbBlue=0;
colormap[col].rgbGreen=0;
}
else
{
colormap[col].rgbRed=tmpPal[0][col];
colormap[col].rgbGreen=tmpPal[1][col];
colormap[col].rgbBlue=tmpPal[2][col];
}
}
// finally, save the thing
if (colorMappedBuffer!=NULL)
{
// write the BMP using our colormapped image (one byte per pixel, packed),
// number of bits, number of total colors and a colormap
// pixel values must be in the range [0...colors-1]
BMPFile theDesBmpFile;
theDesBmpFile.SaveBMP(fileName, // path
colorMappedBuffer, // image
width, // pixels
height,
bitsperpixel, // 1,4,8
colors, // num colors
colormap); // palette
// toss our buffer...
delete [] colorMappedBuffer;
}
//生成定位信息
double resolvx,resolvy,east, west, north, south;
if(!m_pImage->ReadDOMFile(m_pImage->m_CurFileName, resolvx, resolvy, //读控制点文件
east, west, north, south))
{
AfxMessageBox("读DOM文件失败,无法保存影象的定位信息");
return ;
}
double BoxPointy=west/*Xr原点*/+m_pImage->m_BoxI*resolvy;//m_resolvy;//作为新图象的原点坐标
double BoxPointx=north/*Yc*/-m_pImage->m_BoxJ*resolvx;//m_resolvx;
m_pImage->WriteDOMFile(fileName, resolvx, resolvy,
0,0,BoxPointy, BoxPointx);//BoxPointy指距North(X)的距离
///////////
return;
}
else if(m_buf!=NULL)
{
///////////
// JpegFile::BGRFromRGB(m_pImage->mBoxImage, width, height);
// vertical flip for display
// JpegFile::VertFlipBuf(m_pImage->mBoxImage, width * 3, height);
// allocate a buffer to colormap to
colorMappedBuffer = (BYTE *) new BYTE[m_width* m_height];
if (colorMappedBuffer==NULL)
{
AfxMessageBox("Memory Error in OnSaveColormappedbmp!");
return ;
}
// colormap it
// generates an 8-bit color-mapped image into colorMappedBuffer
if (!dl1quant(m_buf,
colorMappedBuffer, // buffers
m_width,
m_height,
64,//theDlg.m_quantColors,
TRUE,
tmpPal))
{ // palette
AfxMessageBox("Quantization error");
delete [] colorMappedBuffer;
return ;
}
// copy our palette
for (UINT col=0;col<256;col++)
{
if (col>64)
{
colormap[col].rgbRed=0;
colormap[col].rgbBlue=0;
colormap[col].rgbGreen=0;
}
else
{
colormap[col].rgbRed=tmpPal[0][col];
colormap[col].rgbGreen=tmpPal[1][col];
colormap[col].rgbBlue=tmpPal[2][col];
}
}
// finally, save the thing
if (colorMappedBuffer!=NULL)
{
// write the BMP using our colormapped image (one byte per pixel, packed),
// number of bits, number of total colors and a colormap
// pixel values must be in the range [0...colors-1]
BMPFile theDesBmpFile;
theDesBmpFile.SaveBMP(fileName, // path
colorMappedBuffer, // image
m_width, // pixels
m_height,
bitsperpixel, // 1,4,8
colors, // num colors
colormap); // palette
// toss our buffer...
delete [] colorMappedBuffer;
}
}
}
////////////////////////////////////////////////////////////////////////
// instead of creating a good palette for the colormapped images
// this just graymaps them.
//
BYTE * CImageMangerView::MakeColormappedGrayscale(BYTE *inBuf,
UINT inWidth,
UINT inHeight,
UINT inWidthBytes,
UINT colors,
RGBQUAD* colormap)
{
////////////////////////////////////////////////////////////////////////
// allocate a buffer to colormap
BYTE *tmp = (BYTE *) new BYTE[inWidth * inHeight];
if (tmp==NULL)
return NULL;
// force our image to use a stupid gray scale
UINT color;
for (color = 0;color < colors; color++) {
colormap[color].rgbRed = color * 256 / colors;
colormap[color].rgbGreen = color * 256 / colors;
colormap[color].rgbBlue = color * 256 / colors;
}
UINT col, row;
for (row =0; row < inHeight; row++) {
for (col=0;col WriteDOMFile(dlg.m_filename,dlg.m_resolutionx,dlg.m_resolutiony,dlg.m_I,dlg.m_J,dlg.m_Y,dlg.m_X);
}
}
void CImageMangerView::OnOutputbmp()
{
// TODO: Add your command handler code here
if(!m_bImageReady) return;
//m_pImage->OutPutImageInBmp(DesImageFileName) ;
}
void CImageMangerView::OnViewinbox()
{
// TODO: Add your command handler code here
if(!m_bImageReady) return;
m_SelectMenu=1;
/*
if(m_pImage->mBoxImage)
{
delete m_pImage->mBoxImage;
m_pImage->mBoxImage=NULL;
}
*/
}
//zrf modify 8-9
void CImageMangerView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect clientRect;
GetClientRect(clientRect);
MetaData_Name RegionName;
//int P1x, P1y, P2x, P2y;
if(!m_bImageReady||m_SelectMenu==0) return;
if(m_SelectMenu==1||m_SelectMenu==9)
{
CRectTracker RectTracker;
if (RectTracker.TrackRubberBand(this, point))
{
CWaitCursor wait;
//m_bHaveSelectionRect = TRUE;
CImageMangerDoc* pDoc = GetDocument();
//ensure the rectangle is the right way up
if (RectTracker.m_rect.left > RectTracker.m_rect.right)
{
int t = RectTracker.m_rect.left;
RectTracker.m_rect.left = RectTracker.m_rect.right;
RectTracker.m_rect.right = t;
}
//ensure the rectangle is the right way up
if (RectTracker.m_rect.top > RectTracker.m_rect.bottom)
{
int t = RectTracker.m_rect.top;
RectTracker.m_rect.top = RectTracker.m_rect.bottom;
RectTracker.m_rect.bottom = t;
}
}
//clip the selection to the maximum size of the window
if(m_ZoomScale==0)
{
if (RectTracker.m_rect.left < screenX0)//假定原点是10,10
RectTracker.m_rect.left = screenX0;
if (RectTracker.m_rect.top < screenY0)
RectTracker.m_rect.top = screenY0;
if (RectTracker.m_rect.right > m_pImage->n_Allwidth+screenX0||RectTracker.m_rect.right<0)
RectTracker.m_rect.right = m_pImage->n_Allwidth+screenX0;
if (RectTracker.m_rect.bottom >m_pImage->n_Allheight+screenY0||RectTracker.m_rect.bottom<0 )
RectTracker.m_rect.bottom = m_pImage->n_Allheight+screenY0;
}
else
{
if (RectTracker.m_rect.left < screenX0)//假定原点是10,10
RectTracker.m_rect.left = screenX0;
if (RectTracker.m_rect.top < screenY0)
RectTracker.m_rect.top = screenY0;
if (RectTracker.m_rect.right > m_pImage->datawidth+screenX0||RectTracker.m_rect.right<0)
RectTracker.m_rect.right = m_pImage->datawidth+screenX0;
if (RectTracker.m_rect.bottom >m_pImage->dataheight+screenY0||RectTracker.m_rect.bottom<0 )
RectTracker.m_rect.bottom = m_pImage->dataheight+screenY0;
}
m_lastwide=m_pImage->datawidth;
m_lastheight=m_pImage->dataheight;
CRectWorkingArea(RectTracker.m_rect);
if(m_SelectMenu==9)
{
MetaData_NameDlg FormatDlg;
CString diming;
if(FormatDlg.DoModal()==IDOK)
{
diming=FormatDlg.m_RegionName;
RegionName.m_NameRect=m_Rect;
RegionName.m_sProName=diming;
RegionNameArray.Add(RegionName);
m_SelectMenu=3;
m_ZoomScale=0;//出现在输入地名后不能放大的现象
Invalidate();
return;
}
}
m_GetFlag=1;
if(m_ZoomScale!=0)
if(m_pImage->m_RealWidth==m_pImage->datawidth||m_pImage->m_RealHeight==m_pImage->dataheight)
{
AfxMessageBox("图象已是1:1比例显示,不能再放大");
return;
}
m_pImage->GetImage(m_Rect, screenX0, screenY0,clientRect,0) ;
m_ZoomScale++;
Invalidate( );
}
else if(m_SelectMenu==8)//漫游
{
if(m_GetFlag!=1)
{
MessageBeep(0);
AfxMessageBox("请先拉框选择,再进行漫游");
return ;
}
if(PushNumb==0)
{
mPointOrign=point;
//mPointOld=point;
PushNumb++;
//SetCapture();
}
}
CScrollView::OnLButtonDown(nFlags, point);
}
///////////////////////
//function:返回当前图象区域坐标值,以实际图象大小为尺度
void CImageMangerView::CRectWorkingArea(CRect rect)
{
double blx,bly;
// int newwide,newheight;
//long lostnum=100000;
if(m_ZoomScale!=0)
{
blx=(double)m_pImage->m_RealWidth/(double)m_pImage->datawidth;//实际图象宽与抽点后图象宽的比
bly=(double)m_pImage->m_RealHeight/(double)m_pImage->dataheight;
//newwide=(rect.right-rect.left)*blx;//下一新图象实际宽度注意由于分块的原因,输入图象
//的大小与实际输出图象的大小并不一致
//newheight=(rect.bottom-rect.top)*bly;
//计算新图象左上点、右下点在原始图象中的行列数
//由于数据是一块一块的取
m_Rect.top=(rect.top-screenY0)*bly+m_pImage->m_lasttop;//+200;//m_lastlet,m_lasttop上一幅图左上角点在原始图象中的行列数
m_Rect.left=(rect.left-screenX0)*blx+m_pImage->m_lastleft;//+m_pImage->m_dm;//200;//+200;
m_Rect.bottom=(rect.bottom-screenY0)*bly+m_pImage->m_lasttop;//m_Rect.top+newheight;//+m_pImage->m_dm;//200;
m_Rect.right=(rect.right-screenX0)*blx+m_pImage->m_lastleft;//m_Rect.left+newwide;//+m_pImage->m_dm;//200;
}
else
{
blx=(double)m_pImage->m_TotalWidth/(double)m_pImage->n_Allwidth;
bly=(double)m_pImage->m_TotalHeight/(double)m_pImage->n_Allheight;
m_Rect.left=blx*(rect.left-screenX0);//+200;
m_Rect.top=bly*(rect.top-screenX0);
m_Rect.right=blx*(rect.right-screenX0);//+200;
m_Rect.bottom=bly*(rect.bottom-screenX0);//+200;
}
}
//*******DrawMode 用来控制显示方式 1--原样显示,2--按给定大小放缩显示,纵横方向放缩比例相等
//******* 3-- 将位图按给定的大小放缩显示,充满给定的区域
//StretchBlt函数在显示时出现画面闪烁现象
void CImageMangerView::DrawBmp(CDC* pDC,int x,int y,int wide,int high,int DrawMode)
{
if(m_pImage->mBoxImage==0)return;
CDC pDC1;
int wide1,high1;
if(m_pImage->m_bitcount==8)nPalate=256;
else nPalate=0;
bhm_ddb=0;
CBitmap* pOldMap;
if(hpal==0&&nPalate>0)
{
LPLOGPALETTE cp=(LPLOGPALETTE)GlobalAlloc(GHND,sizeof(LOGPALETTE)+
nPalate*sizeof(PALETTEENTRY));
if(cp!=NULL)
{
cp->palVersion=0x0300;
cp->palNumEntries=nPalate; //设置调色板入口
//将调色板信息装入RGBQUAD结构,注意颜色的顺序变化
for(int i=0;ipalPalEntry[i].peRed = (BYTE)m_pImage->m_rgbquad[i].rgbRed;
cp->palPalEntry[i].peGreen = (BYTE)m_pImage->m_rgbquad[i].rgbGreen;
cp->palPalEntry[i].peBlue = (BYTE)m_pImage->m_rgbquad[i].rgbBlue;
}
hpal=CreatePalette(cp);//创建逻辑调色板
GlobalFree(cp);
}
}
HDC m_hdc;
m_hdc=pDC->GetSafeHdc();
HPALETTE hpalold=NULL;
if(hpal)
{
hpalold=SelectPalette(m_hdc,hpal,FALSE);
RealizePalette(m_hdc);
}
if(DrawMode==1)
{
wide1=m_pImage->datawidth;
high1=m_pImage->dataheight;
}
else if(DrawMode==2)
{
float bl1=(float)wide/m_pImage->datawidth;
float bl2=(float)high/m_pImage->dataheight;
if(bl1>bl2)
{
high1=high;
wide1=(int)(bl2*wide);
}
else
{
wide1=wide;
high1=(int)(bl1*high);
}
}
else if (DrawMode==3)
{
wide1=wide;
high1=high;
}
SetScrollSizes(MM_TEXT,
CSize(wide1,high1));
LPSTR lpbit;
lpbit=new char[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
BITMAPINFO* lpbitmap;
lpbitmap=(LPBITMAPINFO)lpbit;
lpbitmap->bmiHeader.biWidth=m_pImage->datawidth;
lpbitmap->bmiHeader.biHeight=m_pImage->dataheight;
lpbitmap->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
lpbitmap->bmiHeader.biPlanes=1;
lpbitmap->bmiHeader.biBitCount=m_pImage->m_bitcount;
lpbitmap->bmiHeader.biCompression=0;
lpbitmap->bmiHeader.biSizeImage=0;
lpbitmap->bmiHeader.biXPelsPerMeter=0;
lpbitmap->bmiHeader.biYPelsPerMeter=0;
lpbitmap->bmiHeader.biClrUsed=0;
lpbitmap->bmiHeader.biClrImportant=0;
if(hpal)memcpy(lpbit+sizeof(BITMAPINFOHEADER),m_pImage->m_rgbquad,256*sizeof(RGBQUAD));
// DIB to DDB
bhm_ddb=CreateDIBitmap(m_hdc,(LPBITMAPINFOHEADER)lpbit,CBM_INIT,m_pImage->mBoxImage,(LPBITMAPINFO)lpbit,DIB_RGB_COLORS);
if(hpalold)
{
SelectPalette(m_hdc,hpalold,FALSE);
hpal=0;
}
if(bhm_ddb!=0)
{
pDC1.CreateCompatibleDC(pDC);
pOldMap=pDC1.SelectObject(CBitmap::FromHandle(bhm_ddb));
//将内存设备描述对象中的图象映射到屏幕中的显示区域
pDC->StretchBlt(x,y,wide1,high1,&pDC1,0,0,m_pImage->datawidth,m_pImage->dataheight,SRCCOPY);
pDC1.SelectObject(pOldMap);
}
delete lpbit;
return ;
}
////////////////
//绘出重采样之全图
void CImageMangerView::DrawAllView(CDC* pDC)
{
if(m_pImage->m_pData!=NULL)
{
// SetScrollSizes(MM_TEXT,
//CSize(m_pImage->n_Allwidth+20,m_pImage->n_Allheight+20));
LPBITMAPINFO lpbi=new BITMAPINFO;
lpbi->bmiHeader.biWidth=m_pImage->n_Allwidth;
lpbi->bmiHeader.biHeight=m_pImage->n_Allheight;
lpbi->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
lpbi->bmiHeader.biPlanes=1;
lpbi->bmiHeader.biBitCount=24;
lpbi->bmiHeader.biCompression=BI_RGB;
lpbi->bmiHeader.biSizeImage=0;
lpbi->bmiHeader.biXPelsPerMeter=0;
lpbi->bmiHeader.biYPelsPerMeter=0;
lpbi->bmiHeader.biClrUsed=0;
lpbi->bmiHeader.biClrImportant=0;
SetDIBitsToDevice(*pDC,screenX0,screenY0,m_pImage->n_Allwidth,m_pImage->n_Allheight,0,0,0,m_pImage->n_Allheight,m_pImage->m_pData,lpbi,DIB_RGB_COLORS);//DIB_PAL_COLORS); //DIB_RGB_COLORS
delete lpbi;
}
}
//////////////////
void CImageMangerView::Paint(CDC* pDC)
{
if(m_pImage->mBoxImage!=NULL)
{
// if(m_SelectMenu!=8)
//{
//SetScrollSizes(MM_TEXT,
//CSize(m_pImage->datawidth+10,m_pImage->dataheight+10));
//}
LPBITMAPINFO lpbi=new BITMAPINFO;
lpbi->bmiHeader.biWidth=m_pImage->datawidth;
lpbi->bmiHeader.biHeight=m_pImage->dataheight;
lpbi->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
lpbi->bmiHeader.biPlanes=1;
lpbi->bmiHeader.biBitCount=24;//m_pImage->m_bitcount;
lpbi->bmiHeader.biCompression=BI_RGB;
lpbi->bmiHeader.biSizeImage=0;
lpbi->bmiHeader.biXPelsPerMeter=0;
lpbi->bmiHeader.biYPelsPerMeter=0;
lpbi->bmiHeader.biClrUsed=0;
lpbi->bmiHeader.biClrImportant=0;
SetDIBitsToDevice(*pDC,screenX0,screenY0,m_pImage->datawidth+10,m_pImage->dataheight+10,0,0,0,m_pImage->dataheight,m_pImage->mBoxImage,lpbi,DIB_RGB_COLORS);//DIB_PAL_COLORS); //DIB_RGB_COLORS
delete lpbi;
}
}
/*
void CImageMangerView::OnImageopen()
{
// TODO: Add your command handler code here
CFileDialog dlg(TRUE,".bmp",_T("*.bmp"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
"BMP File(*.bmp)|*.bmp||",NULL);
if(dlg.DoModal() != IDOK) return;
if(m_pImage) delete m_pImage;
m_pImage = new CImageDe;
CString fliename = dlg.GetPathName();
if(!m_pImage->OnReadBMP(fliename ))
return;
m_bImageReady = TRUE;
}*/
void CImageMangerView::OnMouseMove(UINT nFlags, CPoint point)
{
int m_arrow;//漫游方向 0--缺省值 1--上 2--下 3--向左 4--右
int mousedx,mousedy;
int pan;//为零则表示不进行漫游.为其他值表示漫游的抽样间隔,以上一幅拉框图的采样间隔进行漫游
double blx,bly;//必须为double型,否则不精确
BOOL limit;
CRect clientRect,limitRect;
GetClientRect(clientRect);
clientRect.NormalizeRect();
/*
if(!clientRect.PtInRect(point))//影响速度
{
m_HCross=AfxGetApp()->LoadStandardCursor(IDC_ARROW);
::SetCursor(m_HCross);
return;
}
*/
if(m_checkstatus==1)
if(!ShowStatusBar(point)) return;
limit=FALSE;
if(!m_bImageReady||m_SelectMenu==0||m_pImage==NULL) return;//Is right?
// TODO: Add your message handler code here and/or call default
if(m_SelectMenu==1)
{
m_HCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS);
::SetCursor(m_HCross);
}
else if(m_SelectMenu==8)
{
::SetCursor(m_HCur1);
limitRect=m_Rect;
pan=m_pImage->m_Interval;
blx=(double)m_pImage->m_RealWidth/(double)m_pImage->datawidth;//实际图象宽与抽点后图象宽的比
bly=(double)m_pImage->m_RealHeight/(double)m_pImage->dataheight;
if(PushNumb==1) //注意一次只显示一屏,固定大小
{
//漫游方向 0--缺省值 1--上 2--下 3--向左 4--右
//判断前一幅图象是否到顶了
mousedx=point.x-mPointOrign.x;
mousedy=point.y-mPointOrign.y;
if(mousedx>0&&fabs(mousedx)>fabs(mousedy))
{
m_arrow=3;//Left 第二个点在右边,显示左边的图象,并保留前一幅的1/3 向右移
if(m_Rect.left<=0)
{
limit=1;
}
m_Rect.right=m_Rect.left+SCREENW*blx/3;
m_Rect.left=m_Rect.right-SCREENW*blx;
m_Rect.top=m_Rect.top;
m_Rect.bottom=m_Rect.bottom;
if((m_Rect.right-m_Rect.left)/blx<(clientRect.right-clientRect.left))
m_Rect.right=(clientRect.right-clientRect.left)*blx+m_Rect.left;
}
else if(mousedx<0&&fabs(mousedx)>fabs(mousedy))
{
m_arrow=4;//Right
if(m_Rect.right>=m_pImage->m_TotalWidth)
{
limit=1;
}
m_Rect.left=m_Rect.right-SCREENW*blx/3;
m_Rect.top=m_Rect.top;
m_Rect.right=m_Rect.left+SCREENW*blx;
m_Rect.bottom=m_Rect.bottom;
if((m_Rect.right-m_Rect.left)/blx<(clientRect.right-clientRect.left))
m_Rect.right=(clientRect.right-clientRect.left)*blx+m_Rect.left;
}
else if(mousedy<0&&fabs(mousedy)>fabs(mousedx))
{
m_arrow=1;//below
if((m_Rect.bottom-m_Rect.top)>=m_pImage->m_TotalHeight)
{
limit=1;
}
m_Rect.left=m_Rect.left;
m_Rect.top=m_Rect.bottom-SCREENH*bly/3;
m_Rect.right=m_Rect.right;
m_Rect.bottom=m_Rect.top+SCREENH*bly;
if((m_Rect.bottom-m_Rect.top)/bly<(clientRect.bottom-clientRect.top))
m_Rect.bottom=(clientRect.bottom-clientRect.top)*bly+m_Rect.top;
else
m_Rect.top=m_Rect.top+(clientRect.bottom-clientRect.top)/4;
}
else
{
m_arrow=2;//above
if(m_Rect.top==0)
{
limit=1;
}
m_Rect.left=m_Rect.left;
m_Rect.bottom=m_Rect.top+SCREENH*bly/3;
m_Rect.top=m_Rect.bottom-SCREENH*bly;
m_Rect.right=m_Rect.right;
if((m_Rect.bottom-m_Rect.top)/bly<(clientRect.bottom-clientRect.top))
m_Rect.bottom=(clientRect.bottom-clientRect.top)*bly+m_Rect.top;
}
if(m_Rect.left<0)m_Rect.left=0;
if(m_Rect.right>m_pImage->m_TotalWidth+10)m_Rect.right=m_pImage->m_TotalWidth;
if(m_Rect.top<0)m_Rect.top=0;
if(m_Rect.bottom>m_pImage->m_TotalHeight+10)m_Rect.bottom=m_pImage->m_TotalHeight;
//m_GetFlag=1;
if(!limit)
{
m_arrow=0;
m_pImage->GetImage(m_Rect, screenX0, screenY0,clientRect,pan) ;
}
else
{
m_arrow=0;
m_Rect=limitRect;
m_pImage->GetImage( m_Rect, screenX0, screenY0,clientRect,pan) ;
}
PushNumb=0;
Invalidate( );
}
}
CScrollView::OnMouseMove(nFlags, point);
}
//生成索引,不显示
void CImageMangerView::OnImageNoview()
{
// TODO: Add your command handler code here
ViewFlag=1;
CFileDialog dlg(TRUE,".bmp",_T("*.bmp"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
"BMP File(*.bmp)|*.bmp||",NULL);
if(dlg.DoModal() != IDOK) return;
if(m_pImage) delete m_pImage;
m_pImage = new CImageDe;
CString fliename = dlg.GetPathName();
m_pImage->m_outdexdm=m_Dlgdm;
if(!m_pImage->OutPutIMG(fliename ))
return;
}
///////////////////////////////////////////////////////////////////////////////
//Function : 以格网的形式显示全图大小
//参数:
// m_ZoomX,m_ZoomY缩放比例
//
//////////////////////////////////////////////////////////////////////////////
void CImageMangerView::drawAllMap(CDC *pDC)
{
if(!m_bImageReady||m_pImage==NULL) return;
POINT pt[4];
CPen pen(0,0,RGB(255,0,0));
CPen * oldpen=pDC->SelectObject(&pen);
CBrush brush(RGB(0,0,255));
CBrush * oldbrush=pDC->SelectObject(&brush);
m_ZoomX=INT((m_pImage->m_imagewidth+screenX0)/400);
m_ZoomY=INT((m_pImage->m_imageheight+screenY0)/400);
if(m_ZoomX==0)m_ZoomX=1;
if(m_ZoomY==0)m_ZoomY=1;
screenX1=INT((m_pImage->m_imagewidth+screenX0)/m_ZoomX)+1;
screenY1=INT((m_pImage->m_imageheight+screenY0)/m_ZoomY)+1;
pt[0].x=(int) screenX0;
pt[0].y=(int) screenY0;
pt[1].x=(int) screenX1;
pt[1].y=(int) screenY0;
pt[2].x=(int) screenX1;
pt[2].y=(int) screenY1;
pt[3].x=(int) screenX0;//boxofRoad1.x;
pt[3].y=(int) screenY1;//boxofRoad2.y;
pDC->Polygon(pt,4);
pDC->SelectObject(oldpen);
pen.DeleteObject();
pDC->SelectObject(oldbrush);
brush.DeleteObject();
//.....
CPen pen2(PS_SOLID,0,RGB(255,255,0));
oldpen=pDC->SelectObject(&pen2);
double xx,yy,x0,y0;
int dx=INT(100/m_ZoomX);//dm=100
int dy=INT(100/m_ZoomY);
y0 = screenY0+dy;
x0 = screenX0 ;
xx = screenX1 ;
do
{
pDC->MoveTo((int) x0,(int) y0);
pDC->LineTo((int) xx,(int) y0);
y0 = y0 + dy;
}while( y0 <= screenY1 );
x0 = screenX0 +dx;
y0 = screenY0 ;
yy = screenY1;
do
{
pDC->MoveTo((int) x0,(int) y0);
pDC->LineTo((int) x0,(int) yy);
x0 = x0 + dx ;
}while( x0 <= screenX1 );
pen2.DeleteObject();
pDC->SelectObject(oldpen);
pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
pDC->SetBkMode(TRANSPARENT );//OPAQUE);
pDC->TextOut(200,screenY1+20,"影 象 分 解 全 局 图 ");
}
void CImageMangerView::OnOpenindex()
{
// TODO: Add your command handler code here
if (m_buf!=NULL)
{
delete [] m_buf;
m_buf=NULL;
}
CFileDialog dlg(TRUE,".img",_T("*.img"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
"DEX File(*.img)|*.img||",NULL);
if(dlg.DoModal() != IDOK) return;
if(m_pImage!=NULL)
{
UnmapViewOfFile(m_pImage->pMapFile1);
CloseHandle(m_pImage->hFile1);
CloseHandle(m_pImage->hFile);
delete m_pImage;
m_pImage=NULL;
}
m_pImage = new CImageDe;
CString filename = dlg.GetPathName();
m_pImage->m_CurFileName=filename;
CString Filename=filename.Left(filename.GetLength()-4)+"all.bmp";
if(m_pImage->IsReplace(Filename)) //替换存在的文件,注意这两个文件是否在同一目录下
{
m_pImage->ReSample(filename);
}
else
{
if(!m_pImage->ReadSampleFile(Filename))
return;
}
m_pImage->GetImageInfo(); //待改
m_width=m_pImage->m_imagewidth;
m_height=m_pImage->m_imageheight;
m_SelectMenu=2;
m_bImageReady = TRUE;
m_ZoomScale=0;
Invalidate( );
return;
}
/*
void CImageMangerView::OnOpenindexmenu()
{
// TODO: Add your command handler code here //OFN_ALLOWMULTISELECT
// TODO: Add your command handler code here
CFileDialog dlg(TRUE,".img",_T("*.img"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
"DEX File(*.img)|*.img||",NULL);
if(dlg.DoModal() != IDOK) return;
m_SelectMenu=2;
m_bImageReady = TRUE;
if(m_pImage)
{
UnmapViewOfFile(m_pImage->pMapFile1);
CloseHandle(m_pImage->hFile1);
CloseHandle(m_pImage->hFile);
delete m_pImage;
}
m_pImage = new CImageDe;
CString fliename = dlg.GetPathName();
m_pImage->m_CurFileName=fliename;
m_pImage->GetImageInfo();
Invalidate( );
return;
}
*/
/*
void CImageMangerView::OnViewimage()
{
// TODO: Add your command handler code here
if(!m_bImageReady||m_pImage==NULL) return;
m_SelectMenu=4;
CPoint ImageP1,ImageP2;
ImageP1.x=m_pImage->imageX0/m_pImage->m_resolvx;
ImageP2.x=m_pImage->imageX1/m_pImage->m_resolvx;
ImageP1.y=m_pImage->imageY0/m_pImage->m_resolvy;
ImageP2.y=m_pImage->imageY1/m_pImage->m_resolvy;
long t;
if(ImageP1.x>ImageP2.x)
{
t=ImageP1.x;
ImageP1.x=ImageP2.x;
ImageP2.x=t;
}
if(ImageP1.y>ImageP2.y)
{
t=ImageP1.y;
ImageP1.y=ImageP2.y;
ImageP2.y=t;
}
m_pImage->GetImageFromBox(ImageP1, ImageP2,screenX0,screenY0);
Invalidate( );
}
*/
//全图显示
void CImageMangerView::OnViewingrid()
{
// TODO: Add your command handler code here
if(!m_bImageReady) return;
m_SelectMenu=3;
m_ZoomScale=0;//比例尺最小
if(m_pImage!=NULL)
{
m_pImage->datawidth=m_pImage->n_Allwidth;
m_pImage->dataheight=m_pImage->n_Allheight;
m_pImage->m_lastleft=0;
m_pImage->m_lasttop=0;//zrf 8-21 -1 or -2
}
Invalidate( );
}
void CImageMangerView::OnImageBatcompress()
{
// TODO: Add your command handler code here
ImgBatFlag=1;
BATCONVERT FormatDlg;
int BatWay=0;
FormatDlg.m_BatWay=BatWay;
if(FormatDlg.DoModal()==IDOK)
{
BatWay=FormatDlg.m_BatWay;
switch(BatWay)
{
case 0:
CBmptojpg();
break;
case 1:
CBmptoimg();
break;
case 2:
CJpgtobmp();
break;
case 3:
CBmp8to24();
break;
case 4:
CBmp24to256();
break;
case 5:
BmpToTiff();
break;
case 6:
TiffToBmp();
break;
}
}
ImgBatFlag=0;
return;
}
//批处理转换BMP到JPG
BOOL CImageMangerView::CBmptojpg()
{
ImgBatFlag=1;
CFileDialog dlg(TRUE,".bmp",_T("*.bmp"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT,
"BMP TO JPEG File(*.bmp)|*.bmp||",NULL);
if(dlg.DoModal() != IDOK) return FALSE;
CString filename=dlg.GetPathName();
CString fullfilename=dlg.GetFileName();
CString destfilename,sourcefilename;
BYTE *buf;
UINT width;
UINT height;
buf=NULL;
POSITION pos;
pos=dlg.GetStartPosition( );
CWaitCursor wait;
do
{
//retrieve the position of the first file pathname in the list,
CString datafilename=dlg.GetNextPathName(pos) ;
int j;
j=datafilename.GetLength();
datafilename=datafilename.Left(j-4);
destfilename=datafilename+".jpg";
sourcefilename=datafilename+".bmp";
/////////save BMP TO JPEG
if (buf!=NULL)
{
delete [] buf;
buf=NULL;
}
BMPFile theBmpFile;
buf=theBmpFile.LoadBMP(sourcefilename, &width, &height);
if ((buf==NULL) || (theBmpFile.m_errorText!="OK")) {
AfxMessageBox(theBmpFile.m_errorText);
buf=NULL;
return FALSE;
}
JpegFile::BGRFromRGB(buf, width, height);
// vertical flip for display
JpegFile::VertFlipBuf(buf,width * 3, height);
JpegFile::VertFlipBuf(buf, width * 3, height);
// we swap red and blue for display, undo that.
JpegFile::BGRFromRGB(buf, width, height);
// save RGB packed buffer to JPG
BOOL ok=JpegFile::RGBToJpegFile(destfilename,
buf,
width,
height,
true,// color
m_jpegratio); // quality value 1-100.
if (!ok)
{
AfxMessageBox("Write Error");
return FALSE;
}
if (buf!=NULL)
{
delete [] buf;
buf=NULL;
}
}while(pos!=NULL);
return TRUE;
}
BOOL CImageMangerView::CJpgtobmp()
{
ImgBatFlag=3;
CFileDialog dlg(TRUE,".jpg",_T("*.jpg"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT,
"JPEG TO BMP File(*.jpg)|*.jpg||",NULL);
if(dlg.DoModal() != IDOK) return FALSE;
CString filename=dlg.GetPathName();
CString fullfilename=dlg.GetFileName();
CString destfilename,sourcefilename;
BYTE *buf;
UINT width;
UINT height;
buf=NULL;
int color;//1---RGB ,0--Grayscale ,-1...Default
POSITION pos;
pos=dlg.GetStartPosition( );
CWaitCursor wait;
do
{
//retrieve the position of the first file pathname in the list,
CString datafilename=dlg.GetNextPathName(pos) ;
int j;
j=datafilename.GetLength();
datafilename=datafilename.Left(j-4);
destfilename=datafilename+".bmp";
sourcefilename=datafilename+".jpg";
/////////save BMP TO JPEG
if (buf!=NULL)
{
delete [] buf;
buf=NULL;
}
//////////////
buf=JpegFile::JpegFileToRGB(sourcefilename, &width, &height,&color); //待改
JpegFile::BGRFromRGB(buf,width,height);
// vertical flip for display
JpegFile::VertFlipBuf(buf,width * 3,height);
if (buf==NULL)
{
return FALSE;
}
BMPFile theBmpFile;
theBmpFile.SaveBMP(destfilename,
buf,
width,
height);
if (theBmpFile.m_errorText!="OK")
return FALSE;
//////////
if (buf!=NULL)
{
delete [] buf;
buf=NULL;
}
}while(pos!=NULL);
return TRUE;
}
BOOL CImageMangerView::CBmptoimg()
{
ImgBatFlag=2;
CFileDialog dlg(TRUE,".bmp",_T("*.bmp"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT,
"BMP TO IMG File(*.bmp)|*.bmp||",NULL);
if(dlg.DoModal() != IDOK) return FALSE;
CString filename=dlg.GetPathName();
CString fullfilename=dlg.GetFileName();
CImageDe* m_pImage;
m_pImage=NULL;
POSITION pos;
pos=dlg.GetStartPosition( );
CWaitCursor wait;
do
{
//retrieve the position of the first file pathname in the list,
CString datafilename=dlg.GetNextPathName(pos) ;
//if(m_pImage!=NULL) delete m_pImage;
m_pImage=NULL;
m_pImage = new CImageDe;
m_pImage->m_outdexdm=m_Dlgdm;
if(m_pImage->OutPutIMG(datafilename ))
{
if(m_pImage!=NULL) delete m_pImage;
}
else
{
if(m_pImage!=NULL) delete m_pImage;
return FALSE;
}
} while(pos!=NULL);
return TRUE;
}
BOOL CImageMangerView::CBmp8to24()
{
ImgBatFlag=4;
CFileDialog dlg(TRUE,".bmp",_T("*.bmp"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT,
"BMP TO IMG File(*.bmp)|*.bmp||",NULL);
if(dlg.DoModal() != IDOK) return FALSE;
CString filename=dlg.GetPathName();
CString fullfilename=dlg.GetFileName();
CImageDe* pImage;
pImage=NULL;
POSITION pos;
pos=dlg.GetStartPosition( );
CWaitCursor wait;
do
{
//retrieve the position of the first file pathname in the list,
CString datafilename=dlg.GetNextPathName(pos) ;
pImage=NULL;
pImage = new CImageDe;
if(pImage->Change256To24(datafilename ))
{
if(pImage!=NULL) delete pImage;
}
else
{
if(pImage!=NULL) delete pImage;
return FALSE;
}
} while(pos!=NULL);
return TRUE;
}
BOOL CImageMangerView::CBmp24to256()
//功能:把24位的BMP转换成256色
{
ImgBatFlag=5;
CFileDialog dlg(TRUE,".bmp",_T("*.bmp"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT,
"BMP 真彩色 到 256 色(*.bmp)|*.bmp||",NULL);
if(dlg.DoModal() != IDOK) return FALSE;
CString filename=dlg.GetPathName();
CString fullfilename=dlg.GetFileName();
CString DesImageFileName,datafilename;
//
BMPFile theBmpFile;
BYTE *buf;
UINT width;
UINT height;
buf=NULL;
CBMPDlg theDlg;
RGBQUAD colormap[256];
int bitsperpixel =8;// theDlg.m_bits;
AfxGetApp()->DoWaitCursor(1);
int colors = (int)pow(2,bitsperpixel);
BYTE *colorMappedBuffer = NULL;
POSITION pos;
pos=dlg.GetStartPosition( );
CWaitCursor wait;
do
{
//retrieve the position of the first file pathname in the list,
datafilename=dlg.GetNextPathName(pos) ;
DesImageFileName = datafilename.Left(datafilename.GetLength()-4)+"bmp256.bmp";
if (buf!=NULL)
{
delete [] buf;
buf=NULL;
}
buf=theBmpFile.LoadBMP(datafilename, &width, &height);
if ((buf==NULL) || (theBmpFile.m_errorText!="OK"))
{
AfxMessageBox(theBmpFile.m_errorText);
buf=NULL;
return FALSE ;
}
JpegFile::BGRFromRGB(buf, width, height);
// vertical flip for display
JpegFile::VertFlipBuf(buf, width * 3, height);
// allocate a buffer to colormap to
colorMappedBuffer = (BYTE *) new BYTE[width* height];
if (colorMappedBuffer==NULL)
{
AfxMessageBox("Memory Error in OnSaveColormappedbmp!");
return FALSE;
}
BYTE tmpPal[3][256];
// colormap it
// generates an 8-bit color-mapped image into colorMappedBuffer
if (!dl1quant(buf,
colorMappedBuffer, // buffers
width,
height,
64,//theDlg.m_quantColors,
TRUE,
tmpPal))
{ // palette
AfxMessageBox("Quantization error");
delete [] colorMappedBuffer;
return FALSE;
}
// copy our palette
for (UINT col=0;col<256;col++)
{
if (col>64)
{
colormap[col].rgbRed=0;
colormap[col].rgbBlue=0;
colormap[col].rgbGreen=0;
}
else
{
colormap[col].rgbRed=tmpPal[0][col];
colormap[col].rgbGreen=tmpPal[1][col];
colormap[col].rgbBlue=tmpPal[2][col];
}
}
// finally, save the thing
if (colorMappedBuffer!=NULL)
{
// write the BMP using our colormapped image (one byte per pixel, packed),
// number of bits, number of total colors and a colormap
// pixel values must be in the range [0...colors-1]
BMPFile theDesBmpFile;
theDesBmpFile.SaveBMP(DesImageFileName, // path
colorMappedBuffer, // image
width, // pixels
height,
bitsperpixel, // 1,4,8
colors, // num colors
colormap); // palette
// toss our buffer...
delete [] colorMappedBuffer;
}
if (buf!=NULL)
{
delete [] buf;
buf=NULL;
}
//
} while(pos!=NULL);
AfxGetApp()->DoWaitCursor(-1);
return TRUE;
}
///////将图象分成四幅
void CImageMangerView::OnDecomeinfour()
{
// TODO: Add your command handler code here
if (m_buf==NULL&&m_pImage==NULL) {
AfxMessageBox("No Image!");
return;
}
SlicerNum=4;
Invalidate();
CString filename;
filename=m_FileName;
if(m_pImage!=NULL)
{
m_pImage->OutPutImageInBmp(filename);
return;
}
int width,width1;
int height,height1;
int RowByteNum=((m_width*24)+31)/32*4;
long jj= (long)m_height*(long)RowByteNum;
int BmpNum;
BmpNum=2;
width1=m_width/BmpNum;
if(INT(m_width/BmpNum)==0)
width=m_width/BmpNum;
else width=m_width/BmpNum+INT(m_width/BmpNum);
height1=m_height/BmpNum;
if(INT(m_height/BmpNum)==0)
height=m_height/BmpNum;
else height=m_height/BmpNum+INT(m_height/BmpNum);
int dmh,dmw;
dmh=m_height/BmpNum;
dmw=m_width/BmpNum;
int num=dmw*3*dmh;
BYTE *temp=new BYTE[num];
int k,jj1,i,j;
k=0;
BMPFile theBmpFile;
CString MultiFile;
MultiFile=filename;
CString ext;
ext="bmp";
//The First
k=0;
for(i=0;ijj)continue;
temp[k]=m_buf[jj1];
temp[k+1]=m_buf[jj1+1];
temp[k+2]=m_buf[jj1+2];
k=k+3;
}
MultiFile=MultiFile.Left(MultiFile.GetLength()-4)+"1"+".bmp";
theBmpFile.SaveBMP(MultiFile,
temp,
dmw,
dmh);
if(temp!=NULL)
{
delete []temp;
temp=NULL;
}
temp=new BYTE[dmh*(m_width-dmw)*3];
if (theBmpFile.m_errorText!="OK")
AfxMessageBox(theBmpFile.m_errorText, MB_ICONSTOP);
//The Second
k=0;
for(i=0;ijj)continue;
temp[k]=m_buf[jj1];
temp[k+1]=m_buf[jj1+1];
temp[k+2]=m_buf[jj1+2];
k=k+3;
}
MultiFile=MultiFile.Left(MultiFile.GetLength()-5)+"2"+".bmp";
theBmpFile.SaveBMP(MultiFile,
temp,
dmw,
dmh);
if(temp!=NULL)
{
delete []temp;
temp=NULL;
}
temp=new BYTE[dmw*(m_height-dmh)*3];
if (theBmpFile.m_errorText!="OK")
AfxMessageBox(theBmpFile.m_errorText, MB_ICONSTOP);
//The Third
k=0;
for(i=dmh;ijj)continue;
temp[k]=m_buf[jj1];
temp[k+1]=m_buf[jj1+1];
temp[k+2]=m_buf[jj1+2];
k=k+3;
}
MultiFile=MultiFile.Left(MultiFile.GetLength()-5)+"3"+".bmp";
theBmpFile.SaveBMP(MultiFile,
temp,
dmw,
dmh);
if(temp!=NULL)
{
delete []temp;
temp=NULL;
}
temp=new BYTE[(m_height-dmh)*(m_width-dmw)*3];
if (theBmpFile.m_errorText!="OK")
AfxMessageBox(theBmpFile.m_errorText, MB_ICONSTOP);
//The Fourth
k=0;
for(i=dmh;ijj)continue;
temp[k]=m_buf[jj1];
temp[k+1]=m_buf[jj1+1];
temp[k+2]=m_buf[jj1+2];
k=k+3;
}
MultiFile=MultiFile.Left(MultiFile.GetLength()-5)+"4"+".bmp";
theBmpFile.SaveBMP(MultiFile,
temp,
dmw,
dmh);
if(temp!=NULL)
{
delete []temp;
temp=NULL;
}
if (theBmpFile.m_errorText!="OK")
AfxMessageBox(theBmpFile.m_errorText, MB_ICONSTOP);
}
void CImageMangerView::OnOpenbigbmp()
{
// TODO: Add your command handler code here //重采样待加 参数设置和打开IMG一样
if (m_buf!=NULL)
{
delete [] m_buf;
m_buf=NULL;
}
CFileDialog dlg(TRUE,".bmp",_T("*.bmp"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
"打开大幅BMP影象(*.bmp)|*.bmp||",NULL);
if(dlg.DoModal() != IDOK) return;
if(m_pImage!=NULL)
{
UnmapViewOfFile(m_pImage->pMapFile1);
CloseHandle(m_pImage->hFile1);
CloseHandle(m_pImage->hFile);
delete m_pImage;
m_pImage=NULL;
}
m_pImage = new CImageDe;
CString filename = dlg.GetPathName();
m_pImage->m_CurFileName=filename;
CString Filename=filename.Left(filename.GetLength()-4)+".img";
if(m_pImage->IsReplace(Filename)) //替换存在的文件,注意这两个文件是否在同一目录下
{
m_pImage->m_outdexdm=m_Dlgdm;
m_pImage->OutPutIMG(filename );
}
else
{
//m_pImage->GetImageInfo();
if(m_pImage->GetAllImageData())
return;;
//if(m_pImage->GetAllImage(filename))
//return;
}
m_pImage->GetImageInfo();
m_SelectMenu=2;
m_bImageReady = TRUE;
m_width=m_pImage->m_imagewidth;
m_height=m_pImage->m_imageheight;
Invalidate( );
return;
//...
}
void CImageMangerView::OnImageResample()
{
// TODO: Add your command handler code here
if (m_buf!=NULL)
{
delete [] m_buf;
m_buf=NULL;
}
CFileDialog dlg(TRUE,".bmp",_T("*.bmp"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
"BMP File(*.bmp)|*.bmp||",NULL);
if(dlg.DoModal() != IDOK) return;
if(m_pImage!=NULL)
{
UnmapViewOfFile(m_pImage->pMapFile1);
CloseHandle(m_pImage->hFile1);
CloseHandle(m_pImage->hFile);
delete m_pImage;
m_pImage=NULL;
}
m_pImage = new CImageDe;
CString fliename = dlg.GetPathName();
m_pImage->m_CurFileName=fliename;
m_pImage->ReSample(fliename );
//pImage->OutPutIMG(fliename );
//m_pImage->GetImageInfo();
m_SelectMenu=2;
m_bImageReady = TRUE;
m_width=m_pImage->m_imagewidth;
m_height=m_pImage->m_imageheight;
Invalidate( );
return;
//...
}
//漫游函数
void CImageMangerView::OnWalkview()
{
// TODO: Add your command handler code here
if(!m_bImageReady) return;
m_SelectMenu=8;
PushNumb=0;
//保留前面一幅图的值
if(m_pImage->mBoxImage)
{
delete m_pImage->mBoxImage;
m_pImage->mBoxImage=NULL;
}
}
void CImageMangerView::OnRButtonDown(UINT nFlags, CPoint point) //释放鼠标
{
// TODO: Add your message handler code here and/or call default
if(m_SelectMenu==1||m_SelectMenu==8)//如果图象在拉框显示或漫游
{
ReleaseCapture();
PushNumb=0;
m_SelectMenu=0;
}
CScrollView::OnRButtonDown(nFlags, point);
}
/*
BOOL CImageMangerView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CBrush br;
br.CreateHatchBrush(HS_DIAGCROSS, RGB(0, 0, 0));
FillOutsideRect(pDC, &br);
//return CScrollView::OnEraseBkgnd(pDC);
return TRUE;
}
*/
void CImageMangerView::make_palette()
{
//if(hpal!=0)DeletePalette(hpal);
if(hpal==0&&nPalate>0)
{
LPLOGPALETTE cp=(LPLOGPALETTE)GlobalAlloc(GHND,sizeof(LOGPALETTE)+
nPalate*sizeof(PALETTEENTRY));
if(cp!=NULL)
{
cp->palVersion=0x0300;
cp->palNumEntries=nPalate; //设置调色板入口
//将调色板信息装入RGBQUAD结构,注意颜色的顺序变化
for(int i=0;ipalPalEntry[i].peRed = (BYTE)m_pImage->m_rgbquad[i].rgbRed;
cp->palPalEntry[i].peGreen = (BYTE)m_pImage->m_rgbquad[i].rgbGreen;
cp->palPalEntry[i].peBlue = (BYTE)m_pImage->m_rgbquad[i].rgbBlue;
}
hpal=CreatePalette(cp);//创建逻辑调色板
GlobalFree(cp);
}
}
}
void CImageMangerView::DrawBmp3(CDC* pDC,int x,int y,int wide,int high,int DrawMode)
{
if(m_pImage->mBoxImage==0)return;
CDC pDC1;
int wide1,high1;
bhm_ddb=0;
CBitmap* pOldMap;
if(DrawMode==1)
{
wide1=m_pImage->datawidth;
high1=m_pImage->dataheight;
}
else if(DrawMode==2)
{
float bl1=(float)wide/m_pImage->datawidth;
float bl2=(float)high/m_pImage->dataheight;
if(bl1>bl2)
{
high1=high;
wide1=(int)(bl2*wide);
}
else
{
wide1=wide;
high1=(int)(bl1*high);
}
}
else if (DrawMode==3)
{
wide1=wide;
high1=high;
}
SetScrollSizes(MM_TEXT,
CSize(wide1,high1));
DIBtoDDB(pDC->GetSafeHdc());
if(bhm_ddb!=0)
{
pDC1.CreateCompatibleDC(pDC);
pOldMap=pDC1.SelectObject(CBitmap::FromHandle(bhm_ddb));
//将内存设备描述对象中的图象映射到屏幕中的显示区域
//SetDIBitsToDevice(*pDC,screenX0,screenY0,m_pImage->datawidth+10,m_pImage->dataheight+10,0,0,0,m_pImage->dataheight,m_pImage->mBoxImage,lpbi,DIB_PAL_COLORS); //DIB_RGB_COLORS
// pDC->BitBlt(0,0,m_pImage->datawidth,m_pImage->dataheight,&pDC1,0,0,SRCCOPY);
pDC->StretchBlt(x,y,wide1,high1,&pDC1,0,0,m_pImage->datawidth,m_pImage->dataheight,SRCCOPY);
pDC1.SelectObject(pOldMap);
}
return ;
}
void CImageMangerView::DIBtoDDB(HDC hdc)
{
HPALETTE hpalold=NULL;
if(hpal)
{
hpalold=SelectPalette(hdc,hpal,FALSE);
RealizePalette(hdc);
}
LPSTR lpbit;
lpbit=new char[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
BITMAPINFO* lpbitmap;
lpbitmap=(LPBITMAPINFO)lpbit;
lpbitmap->bmiHeader.biWidth=m_pImage->datawidth;
lpbitmap->bmiHeader.biHeight=m_pImage->dataheight;
lpbitmap->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
lpbitmap->bmiHeader.biPlanes=1;
lpbitmap->bmiHeader.biBitCount=m_pImage->m_bitcount;
lpbitmap->bmiHeader.biCompression=0;
lpbitmap->bmiHeader.biSizeImage=0;
lpbitmap->bmiHeader.biXPelsPerMeter=0;
lpbitmap->bmiHeader.biYPelsPerMeter=0;
lpbitmap->bmiHeader.biClrUsed=0;
lpbitmap->bmiHeader.biClrImportant=0;
if(hpal)memcpy(lpbit+sizeof(BITMAPINFOHEADER),m_pImage->m_rgbquad,256*sizeof(RGBQUAD));
// DIB to DDB
bhm_ddb=CreateDIBitmap(hdc,(LPBITMAPINFOHEADER)lpbit,CBM_INIT,m_pImage->mBoxImage,(LPBITMAPINFO)lpbit,DIB_RGB_COLORS);
if(hpalold)
{
SelectPalette(hdc,hpalold,FALSE);
hpal=0;
}
delete lpbit;
}
void CImageMangerView::DrawBmp4(CDC* pDC,int x,int y,int wide,int high,char *fName,int DrawMode)
{
char p1[80];
CRect r;
BITMAPFILEHEADER fileh; //定义一个文件标题结构
BITMAPINFOHEADER fileh1; //定义一个信息标题结构
CBitmap Bitmap,*pOldMap; //定义一个位图对象
CDC pDC1; //定义一个设备描述表
unsigned char *BmpChar;
int minx,miny,maxx,maxy,BmpStartX,BmpStartY,BmpEndX,BmpEndY;
int i,j,xh,i1,j1,c1,c2,c3,nPalate;
int IsCompress,bicount,bytes_per_line,wide1,high1;
long filecd,boff,boxmfile1;
float pbX,pbY;
CPalette palatte,*pOldPalatte; //定义一个调色板结构
LOGPALETTE* cp; //定义一个逻辑调色板结构
RGBQUAD bmicolors[256]; //
CFile FileBmp;
BOOL YN=FileBmp.Open("E://image8bit.bmp"/*fName*/,CFile::typeBinary|CFile::modeRead);
if(YN==0) //如果文件打开错误,给出出错信息
{
strcpy(p1,"位图文件"); strcpy(p1,fName);
strcat(p1,"不存在");
AfxMessageBox(p1);
return;
}
FileBmp.Read((unsigned char *)&fileh,sizeof(fileh));
if(fileh.bfType!=19778) //判断是否是一个位图文件,19778是"BM"的数值
{
FileBmp.Close();
strcpy(p1,"文件"); strcat(p1,fName);
strcat(p1,"不是一个位图文件");
AfxMessageBox(p1);
return;
}
boff=fileh.bfOffBits; //文件头的长度,文件从开始到实际位图起点的字节偏移量
filecd=fileh.bfSize; //位图文件的大小
FileBmp.Read((unsigned char *)&fileh1,sizeof(fileh1));//读入信息标题
GetClientRect(&r);
if(DrawMode==1) //原样大小显示
{
wide1=fileh1.biWidth;
high1=fileh1.biHeight;
}
else if(DrawMode==2)//按参数给定的区域显示,纵横伸缩比例一样
{
float pbX=(float)wide/fileh1.biWidth;
float pbY=(float)high/fileh1.biHeight;
if(pbX>pbY)
{
high1=high;
wide1=(int)(pbY*wide);
}
else
{
wide1=wide;
high1=(int)(pbX*high);
}
}
else if(DrawMode==3) //严格按参数给定的区域显示
{
wide1=wide;
high1=high;
}
bicount=fileh1.biBitCount; //位图的位面数
IsCompress=fileh1.biCompression; //是否进行压缩
filecd=fileh1.biSizeImage; //图像尺寸大小
bytes_per_line=((long)fileh1.biWidth*bicount+31L)/32*4;
if(fileh1.biClrUsed==0) //如果颜色索引数等于0
{
if(bicount!=24) //如果不是24位位图
nPalate=(int)(pow(2,bicount)); //得到调色板颜色数
else
nPalate=0; //如果是24位位图,调色板颜色数为0
}
else //如果颜色索引数不等于0
{
if(bicount!=24)
nPalate=fileh1.biClrUsed;//直接得到调色版数量
else
nPalate=0;
}
if(nPalate>0)//如果调色板颜色数量大于0
{
for(i=0;ipalNumEntries=nPalate; //设置调色板入口
cp->palVersion=0x0300;
for(i=0;ipalPalEntry[i].peRed=bmicolors[i].rgbRed;
cp->palPalEntry[i].peGreen=bmicolors[i].rgbGreen;
cp->palPalEntry[i].peBlue=bmicolors[i].rgbBlue;
}
palatte.CreatePalette(cp); //创建逻辑调色板
pOldPalatte=pDC1.SelectPalette(&palatte,FALSE);
pDC1.RealizePalette();//从当前的调色板影射入口到系统调色板
}
//分配一个用来读入位图一行位图数据的字符串
BmpChar=new unsigned char[bytes_per_line];
if(IsCompress!=0)
{
//如果位图是采用压缩方式的,我们不进行处理退出
strcpy(p1,"不处理压缩格式的位图文件");
AfxMessageBox(p1);
FileBmp.Close();
delete BmpChar;
return ;
}
if(y+high1r.bottom||x+wide1r.right)
{
FileBmp.Close();
delete BmpChar;
return ;
}
//得到在客户区上实际图像绘制区域的大小
minx=max(x,r.left); //右上角横坐标
maxx=min(x+wide1,r.right);
miny=max(y,r.top);
maxy=min(y+high1,r.bottom);//右下角纵坐标
BmpStartX=(int)((float)fileh1.biWidth*(float)(minx-x)/(float)wide1); //每行起点
BmpEndX=fileh1.biWidth-1-(int)((float)fileh1.biWidth*(float)(x+wide1-maxx)/(float)wide1);//终点
BmpEndY=fileh1.biHeight-1-(int)(((float)fileh1.biHeight*(y+high1-maxy)/(float)high1));//起始行
BmpStartY=(int)((float)fileh1.biHeight*(miny-y)/(float)high1); //终止行
pbX=(float)fileh1.biWidth/wide1; //得到水平方向图像像素与要显示像素的比例
pbY=(float)fileh1.biHeight/high1; //竖直方向
if(pbX>1.5) //如果比例较大
{
BmpStartX=minx; //将屏幕上图像显示区的起点作为起点
BmpEndX=maxx-1; //终点作为终点
}
if(pbY>1.5) //如果竖直方向比例较大
{
BmpStartY=miny; //起始行
BmpEndY=maxy-1; //结束行
}
//建立一个空白位图
Bitmap.CreateCompatibleBitmap(pDC,BmpEndX-BmpStartX+1,BmpEndY-BmpStartY+1);
pDC1.CreateCompatibleDC(pDC);//建立一个与当前设备兼容的内存设备描述对象
pOldMap=pDC1.SelectObject(&Bitmap); //将空白位图选入内存设备描述对象
for(i=BmpEndY;i>=BmpStartY;i--)
{
if(pbY>1.5) //如果图像纵向压缩比例较大
i1=(int)(pbY*(i-y)); //得到图像文件中实际起始行
else
i1=i;
//以下得到实际起始行在文件中的位置,将这一行信息读入BmpChar中
boxmfile1=boff+(long)bytes_per_line*(fileh1.biHeight-1-i1);
FileBmp.Seek(boxmfile1,0);
FileBmp.Read((unsigned char *)BmpChar,bytes_per_line);
for(j=BmpStartX;j<=BmpEndX;j++) //对一行中所有要显示的像素循环
{
if(pbX>1.5) //如果横向压缩较大,得到像素点在一行中的实际位置
i1=(int)(pbX*(j-x));
else //否则,j的位置就是像素点在一行中的实际位置
i1=j;
if(bicount==1) //如果是1位面位图
{
j1=i1/8;
xh=*(BmpChar+j1);
j1=(int)(fmod(j,8));
j1=(int)(pow(2,7-j1));
//在内存描述对象中写入点
if(xh&j1)
pDC1.SetPixel(j-BmpStartX,i-BmpStartY,RGB(bmicolors[1].rgbRed,
bmicolors[1].rgbGreen,bmicolors[1].rgbBlue));
else
pDC1.SetPixel(j-BmpStartX,i-BmpStartY,RGB(bmicolors[0].rgbRed,
bmicolors[0].rgbGreen,bmicolors[0].rgbBlue));
}
else if(bicount==4)//如果是4位面位图
{
//以下得到像素的实际值
j1=i1/2;
xh=*(BmpChar+j1);
if(j1*2!=j)
j1=xh-xh/16*16;
else
j1=xh/16;
pDC1.SetPixel(j-BmpStartX,i-BmpStartY,RGB(bmicolors[j1].rgbRed,
bmicolors[j1].rgbGreen,bmicolors[j1].rgbBlue));
}
else if(bicount==8) //如果是8位面位图
{
j1=*(BmpChar+i1);
pDC1.SetPixel(j-BmpStartX,i-BmpStartY,RGB(bmicolors[j1].rgbRed,
bmicolors[j1].rgbGreen,bmicolors[j1].rgbBlue));
}
else if(bicount==24)
{
c1=*(BmpChar+3*(int)i1);
c2=*(BmpChar+3*(int)i1+1);
c3=*(BmpChar+3*(int)i1+2);
pDC1.SetPixel(j-BmpStartX,i-BmpStartY,RGB(c3,c2,c1));
}
}
}
pDC->StretchBlt(minx,miny,maxx-minx,maxy-miny,
&pDC1,0,0,BmpEndX-BmpStartX+1,BmpEndY-BmpStartY+1,SRCCOPY);
pDC1.SelectObject(pOldMap);
Bitmap.DeleteObject(); //删除位图
delete BmpChar; //释放字符串空间
FileBmp.Close(); //关闭文件
if(nPalate>0) //如果调色板颜色数量大于0
{
free(cp);
pDC1.SelectPalette(pOldPalatte,0);
}
return ;
}
/*
void CImageMangerView::OnDrawTest()
{
// TODO: Add your command handler code here
//m_SelectMenu=9;
// CClientDC ht(this);
// DrawBmp4(&ht,100,100,300,200,"e:\\image8bit.bmp",1);
}
*/
BOOL CImageMangerView::ShowStatusBar(CPoint showpoint)
{
LPCTSTR lpszNewText;
LPCTSTR lpszRegName;
CString RegionName;
CPoint NamePoint;
lpszNewText="";
if(m_bImageReady==0||m_pImage==NULL)return FALSE;
//lpszRegName=RegionName;
int test=m_bImageReady;
char buf[256];
char buf1[80];
double OriginX,OriginY;
double blx,bly;
///
blx=(double)m_pImage->m_RealWidth/(double)m_pImage->datawidth;//实际图象宽与抽点后图象宽的比
bly=(double)m_pImage->m_RealHeight/(double)m_pImage->dataheight;
OriginX=(showpoint.x-screenX0)*blx+m_pImage->m_lastleft; //以左上点为原点的分块后图象坐标系
OriginY=(showpoint.y-screenY0)*bly+m_pImage->m_lasttop;
NamePoint.x= OriginX;
NamePoint.y=OriginY;
if(!ShowName(NamePoint,RegionName))
RegionName="";
///如含有定位信息,可将图象坐标转换成大地坐标,以左下点为原点
if(m_pImage->IsDomTrue==1)
{
OriginX=OriginX*m_pImage->m_resolvx+m_pImage->m_OriginX;
OriginY=m_pImage->m_TotalHeight-OriginY;//距左下角点的原始像素个数
OriginY=OriginY*m_pImage->m_resolvy+m_pImage->m_OriginY;
//OriginY=(m_pImage->m_Row*m_pImage->m_dm-OriginY)*m_pImage->m_resolvy+m_pImage->m_OriginY;
}
sprintf( buf, "坐标显示:East %.2f,North %.2f ", OriginX,OriginY);
sprintf( buf1, "地名:%s ",RegionName);
lpszNewText=buf;
lpszRegName=buf1;
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
if(!pFrame) return 0;
pFrame->m_wndStatusBar.SetPaneText(5,lpszRegName , TRUE );
if(pFrame->m_wndStatusBar.SetPaneText(4, lpszNewText, TRUE )==0)
{
TRACE0("Failed to create status bar\n");
return FALSE ;
}
return TRUE;
}
void CImageMangerView::OnPutdmfile()
{
// TODO: Add your command handler code here
m_SelectMenu=9;
AfxMessageBox("请点鼠标左键拉框选择");
}
/*
void CImageMangerView::FWritedmfile()
{
}
*/
BOOL CImageMangerView::ShowName(CPoint point,CString &RegionName)
{
MetaData_Name Region;
// CString RegionName;
int selectIndex = -1;
if(RegionNameArray.GetSize() <= 0) return FALSE;
for(int i = 0; i < RegionNameArray.GetSize(); i ++)
{
if(RegionNameArray[i].m_NameRect.PtInRect(point))
{
selectIndex=i;
RegionName=RegionNameArray[i].m_sProName;
return TRUE;
}
}
return FALSE;
}
void CImageMangerView::OnConfig()
{
// TODO: Add your command handler code here
SYSCONFIG ConFigDlg;
ConFigDlg.m_checkstatus=m_checkstatus;
ConFigDlg.m_Dlgdm=m_Dlgdm;
ConFigDlg.m_jpegratio=m_jpegratio;
if(ConFigDlg.DoModal()==IDOK)
{
m_checkstatus=ConFigDlg.m_checkstatus;
m_Dlgdm=ConFigDlg.m_Dlgdm;
m_jpegratio=ConFigDlg.m_jpegratio;
return;
}
}
void CImageMangerView::OnImageTiff()
{
// TODO: Add your command handler code here
int argc;
char argv[120];
CFileDialog dlg(TRUE,".tif",_T("*.tif"),OFN_HIDEREADONLY,
"TIFF TO COMPRESSION File(*.tif)|*.tif||",NULL);
if(dlg.DoModal() != IDOK) return ;
CString FileName=dlg.GetFileName();
sprintf(argv, "%s ",FileName);
CAnyBmp bmp;
#ifndef EXTENDED_TEST
CTIFFDecoder td;
// decode image
td.MakeBmpFromFile( argv, &bmp );
#else // test tag reading capability
CTIFFDecoderEx myTD;
CFileSource myFS;
int rc = myFS.Open(argv);
if (rc)
{
//fprintf (stderr, "Error opening input file.\n");
return;// -1;
}
BOOL b = myTD.Associate( &myFS );
int i;
/*
uint32 w, h;
i = myTD.GetField(TIFFTAG_IMAGEWIDTH,&w);
i = myTD.GetField(TIFFTAG_IMAGELENGTH,&h);
i = myTD.GetField(TIFFTAG_MAKE,&cp);
i = myTD.GetField(TIFFTAG_MODEL,&cp);
*/
char* imgdsc = NULL;
char* author = NULL;
i = myTD.GetField(TIFFTAG_IMAGEDESCRIPTION,&imgdsc);
i = myTD.GetField(TIFFTAG_ARTIST,&author);
myTD.MakeBmp( &myFS, &bmp );
#endif
// ASSERT( bmp.GetBitsPerPixel() == 1 );
// build output file name
char outname[80];
char* cp = strrchr( argv, '.' );
strcpy( outname, argv );
if (cp)
{
int n = cp - argv;
strcpy( outname + n, "_bis" );
strcat( outname + n + 4, cp );
}
else
strcat( outname, "_bis" );
// now re-encode
#ifndef EXTENDED_TEST
CTIFFEncoder te;
te.MakeFileFromBmp( outname, &bmp );
#else // test tag writing capability
CTIFFEncoderEx tex;
uint32 ui32;
uint16 ui16;
CFileSink outfile;
outfile.Open( outname, bmp.GetMemUsed() + 4096 );
tex.Associate( &outfile );
// mandatory 'base_line' tags
tex.SetBaseTags( &bmp );
ui32 = bmp.GetHeight();
// one strip = the whole image (no strip, no tile)
tex.SetField( TIFFTAG_ROWSPERSTRIP, ui32 );
// select compression scheme
ui16 = bmp.GetBitsPerPixel() == 1 ?
COMPRESSION_CCITTFAX4 : COMPRESSION_PACKBITS;
tex.SetField( TIFFTAG_COMPRESSION, ui16 );
tex.SetField( TIFFTAG_DOCUMENTNAME, outname );
tex.SetField( TIFFTAG_SOFTWARE, "paintlib test encoder" );
// original artist or tired hacker ;-)
tex.SetField( TIFFTAG_ARTIST, author ? author : "bdelmee" );
if (imgdsc && *imgdsc)
tex.SetField( TIFFTAG_IMAGEDESCRIPTION, imgdsc );
tex.SaveBmp( &bmp, &outfile );
// only really needed if you encode several bitmaps
tex.Dissociate();
// also implicit in destructor
outfile.Close();
#endif
}
/*****************************************************************************************
BmpToTiff()
***************************************************************************************/
BOOL CImageMangerView::BmpToTiff()
{
ImgBatFlag=1;
CAnyBmp bmp;
int argc;
char argv[120];
CFileDialog dlg(TRUE,".bmp",_T("*.bmp"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT,
"BMP TO TIFF File(*.bmp)|*.bmp||",NULL);
if(dlg.DoModal() != IDOK) return FALSE;
POSITION pos;
pos=dlg.GetStartPosition( );
CWaitCursor wait;
do
{
//retrieve the position of the first file pathname in the list,
CString FileName=dlg.GetNextPathName(pos) ;
sprintf(argv, "%s ",FileName);
CBmpDecoder m_pBmpDec;
m_pBmpDec.MakeBmpFromFile(argv,&bmp);
char* imgdsc = NULL;
char* author = NULL;
char outname[80];
char* cp = strrchr( argv, '.' );
strcpy( outname, argv );
if (cp)
{
int n = cp - argv;
strcpy( outname + n, "_bis.tif" );
}
else
strcat( outname, "_bis" );
// now re-encode
#ifndef EXTENDED_TEST
CTIFFEncoder te;
te.MakeFileFromBmp( outname, &bmp );
#else // test tag writing capability
CTIFFEncoderEx tex;
uint32 ui32;
uint16 ui16;
CFileSink outfile;
outfile.Open( outname, bmp.GetMemUsed() + 4096 );
tex.Associate( &outfile );
// mandatory 'base_line' tags
tex.SetBaseTags( &bmp );
ui32 = bmp.GetHeight();
// one strip = the whole image (no strip, no tile)
tex.SetField( TIFFTAG_ROWSPERSTRIP, ui32 );
// select compression scheme
ui16 = bmp.GetBitsPerPixel() == 1 ?
COMPRESSION_CCITTFAX4 : COMPRESSION_PACKBITS;
tex.SetField( TIFFTAG_COMPRESSION, ui16 );
tex.SetField( TIFFTAG_DOCUMENTNAME, outname );
tex.SetField( TIFFTAG_SOFTWARE, "paintlib test encoder" );
// original artist or tired hacker ;-)
tex.SetField( TIFFTAG_ARTIST, author ? author : "bdelmee" );
if (imgdsc && *imgdsc)
tex.SetField( TIFFTAG_IMAGEDESCRIPTION, imgdsc );
tex.SaveBmp( &bmp, &outfile );
// only really needed if you encode several bitmaps
tex.Dissociate();
// also implicit in destructor
outfile.Close();
#endif
}while(pos!=NULL);
return TRUE;
}
BOOL CImageMangerView::TiffToBmp()
{
CWinBmp bmp;
int argc;
char argv[120];
char outname[80];
ImgBatFlag=1;
CFileDialog dlg(TRUE,".tif",_T("*.tif"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT,
"TIFF TO BMP File(*.tif)|*.tif||",NULL);
if(dlg.DoModal() != IDOK) return FALSE;
POSITION pos;
pos=dlg.GetStartPosition( );
CWaitCursor wait;
do
{
//retrieve the position of the first file pathname in the list,
CString FileName=dlg.GetNextPathName(pos) ;
sprintf(argv, "%s ",FileName);
CTIFFDecoder td;
// decode image
td.MakeBmpFromFile( argv, &bmp );
char* cp = strrchr( argv, '.' );
strcpy( outname, argv );
if (cp)
{
int n = cp - argv;
strcpy( outname + n, "_bis.bmp" );
}
else
strcat( outname, "_bis" );
bmp.SaveAsBmp (outname);
}while(pos!=NULL);
return TRUE;
}