demodoc.cpp
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C++ 代码 · 共 1,895 行 · 第 1/5 页
CPP
1,895 行
AfxMessageBox(image->GetLastError());
delete image;
image = NULL;
return FALSE;
}
UpdateStatusBar();
UpdateAllViews(NULL,WM_USER_NEWIMAGE);
//multiple images (TIFF/ICO)
if (image->GetNumFrames()>1){
CString s;
s.Format("File with %d images. Read all?",image->GetNumFrames());
if (AfxMessageBox(s,MB_OKCANCEL)==IDOK){
int j; // points to the document name
for(j=strlen(filename)-1;j>=0;j--){
if (filename[j]=='\\'){ j++; break; }
}
// create the documents for the other images
for(int i=1;i<image->GetNumFrames();i++){
CDemoDoc *NewDoc=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDoc) {
CxImage *newImage = new CxImage();
newImage->SetFrame(i);
newImage->Load(filename,type);
NewDoc->image = newImage;
CString s;
s.Format("%s (%d)",filename.Mid(j),i+1);
NewDoc->SetTitle(s);
NewDoc->UpdateAllViews(NULL,WM_USER_NEWIMAGE);
}
}
}
}
// EXIF jpegs
if (image->GetType() == CXIMAGE_FORMAT_JPG){
FILE* hfile = fopen(filename,"rb");
m_exif.DecodeExif(hfile);
fclose(hfile);
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////
BOOL CDemoDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
CString filename(lpszPathName);
CString ext(FindExtension(filename));
ext.MakeLower();
if (ext == "") return FALSE;
int type = FindType(ext);
if (type == CXIMAGE_FORMAT_UNKNOWN) return FALSE;
if (type == CXIMAGE_FORMAT_GIF && image->GetBpp()>8){
AfxMessageBox("The image will be saved as a true color GIF!\nThis is ok for CxImage, but not for many other programs.\nFor better compatibility, please use DecreaseBpp to 8 bits or less.",MB_ICONINFORMATION);
}
bool retval;
Stopwatch(0);
retval = image->Save(filename, type);
Stopwatch(1);
UpdateStatusBar();
if (retval) return TRUE;
AfxMessageBox(image->GetLastError());
return FALSE;
}
//////////////////////////////////////////////////////////////////////////////
BOOL CDemoDoc::DoSave(LPCTSTR pszPathName, BOOL bReplace /*=TRUE*/)
{
if (!image) return FALSE;
CString newName = pszPathName;
BOOL bModified = IsModified();
BOOL bSaveAs = FALSE;
if (newName.IsEmpty()) bSaveAs = TRUE;
else if (!theApp.GetWritableType(image->GetType())) bSaveAs = TRUE;
if (bSaveAs){
newName = m_strPathName;
if (bReplace && newName.IsEmpty()){
newName = m_strTitle;
int iBad = newName.FindOneOf(_T("#%;/\\")); // dubious filename
if (iBad != -1) //newName.ReleaseBuffer(iBad);
newName = "UntitledImage";
// append the default suffix if there is one
if (image->GetType()) newName += theApp.GetExtFromType(image->GetType()).Mid(1,4);
}
int nDocType = image->GetType();
if (!theApp.PromptForFileName(newName,
bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY,
OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, &nDocType))
{
return FALSE; // don't even try to save
}
}
BeginWaitCursor();
if (!OnSaveDocument(newName)){
if (pszPathName == NULL){
// be sure to delete the file
TRY
{
CFile::Remove(newName);
}
CATCH_ALL(e)
{
TRACE0("Warning: failed to delete file after failed SaveAs\n");
}
END_CATCH_ALL
}
EndWaitCursor();
return FALSE;
}
EndWaitCursor();
if (bReplace) {
// Reset the title and change the document name
SetPathName(newName, TRUE);
ASSERT(m_strPathName == newName); // must be set
}
else // SaveCopyAs
{
SetModifiedFlag(bModified);
}
return TRUE; // success
}
//////////////////////////////////////////////////////////////////////////////
#define EPSILON (0.0000001)
int CDemoDoc::ComputePixel(float x, float y, float &x1, float &y1)
{
double r, nn;
if (x==0 && y==0) {
x1 = x;
y1 = y;
return 1;
}
nn = sqrt(x*x + y*y);
r = (fabs(x) > fabs(y)) ? fabs(nn/x): fabs(nn/y);
x1 = (float)(r*x);
y1 = (float)(r*y);
return 1;
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!(image==0 || hThread));
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateFileSave(CCmdUI* pCmdUI)
{
pCmdUI->Enable(0);
// pCmdUI->Enable((image != NULL)); //&& theApp.GetWritableType(image->GetType()));
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnStretchMode()
{
stretchMode = !stretchMode;
UpdateAllViews(NULL);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateStretchMode(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(stretchMode);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateCximageFlip(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageGrayscale(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageMirror(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageNegative(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageResample(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRotate(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRotater(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRotatel(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageDither(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageThreshold(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplityuv(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplitrgb(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplithsl(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplityiq(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplitxyz(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplitcmyk(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximagePseudocolors(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageFiltersColorize(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageLighten(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageDarken(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageContrast(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageEmboss(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageBlur(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageDilate(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageEdge(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageErode(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSharpen(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSoften(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCrop(CCmdUI* pCmdUI)
{ if(image==0 || hThread || !image->SelectionIsValid()) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRemovealphachannel(CCmdUI* pCmdUI)
{ if(image==0 || hThread || !image->AlphaIsValid()) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageInvetalpha(CCmdUI* pCmdUI)
{ if(image==0 || hThread || !image->AlphaIsValid()) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageAlphapalettetoggle(CCmdUI* pCmdUI)
{ if(image==0 || hThread || !image->AlphaPaletteIsValid()) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageAlphastrip(CCmdUI* pCmdUI)
{ if(image==0 || hThread || (!image->AlphaIsValid() && !image->AlphaPaletteIsValid())) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRemovetransparency(CCmdUI* pCmdUI)
{ if(image==0 || hThread || image->GetTransIndex()<0) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageGamma(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageMedian(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageAddnoise(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCombine(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageFft(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRepair(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageAlphachannelSplit(CCmdUI* pCmdUI)
{ if(image==0 || hThread || !image->AlphaIsValid()) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageFiltersLog(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageFiltersRoot(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageHistogramEqualize(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageHistogramNormalize(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageHistogramStretch(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageGaussian3x3(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageGaussian5x5(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageContour(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageLesscontrast(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageJitter(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateWindowDuplicate(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateFiltersMix(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCircletransformCylinder(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCircletransformPinch(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCircletransformPunch(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCircletransformSwirl(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCircletransformBathroom(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageHistogramStretch1(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageHistogramStretch2(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateFiltersNonlinearEdge(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSkew(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateJpegcompression(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateTransformEllipse(CCmdUI* pCmdUI)
{
if (image==NULL) pCmdUI->Enable(0);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnTransformEllipse()
{
SubmitUndo();
DWORD x, y;
float x1, y1; //***bd*** use float source with GetPixelColorInterpolated
float fx, fy, xmid, ymid, ar;
CxImage *image2 = new CxImage(*image,false,false,true);
xmid = (float) (image->GetWidth()/2.0);
ymid = (float) (image->GetHeight()/2.0);
ar = (float)(image->GetHeight())/(float)(image->GetWidth());
for (y=0; y<image->GetHeight(); y++) {
for (x=0; x<image->GetWidth(); x++) {
ComputePixel(ar*(x-xmid), y-ymid, fx, fy);
x1 = xmid+fx/ar;
y1 = ymid+fy;
//correct method to use would be GetAreaColorAveraged (but I guess there's not that much aliasing here)
image2->SetPixelColor(x, y, image->GetPixelColorInterpolated(x1, y1, CxImage::IM_BILINEAR, CxImage::OM_BACKGROUND));
//image2->SetPixelColor(x, y, image->GetPixelColor(x1, y1));
}
}
delete image;
image = image2;
UpdateAllViews(NULL);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnWindowDuplicate()
{
CDemoDoc *NewDoc=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDoc) {
CxImage *newImage = new CxImage(*image);
NewDoc->image = newImage;
CString s;
s.Format("Copy %d of %s",((CDemoApp*)AfxGetApp())->m_nDocCount++,GetTitle());
NewDoc->SetTitle(s);
NewDoc->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
if (image==NULL) pCmdUI->Enable(0);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnEditCopy()
{
HANDLE hDIB=image->CopyToHandle();
if (::OpenClipboard(AfxGetApp()->m_pMainWnd->GetSafeHwnd())) {
if(::EmptyClipboard()) {
if (::SetClipboardData(CF_DIB,hDIB) == NULL ) {
AfxMessageBox( "Unable to set Clipboard data" );
}
}
}
CloseClipboard();
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateEditUndo(CCmdUI* pCmdUI)
{
if(image==0 || hThread) pCmdUI->Enable(0);
else pCmdUI->Enable(m_UndoLevel>0);
CString s;
s.Format("Undo (%d)\tCtrl+Z",m_UndoLevel);
pCmdUI->SetText(s);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?