📄 kdu_show.cpp
字号:
/******************************************************************************/// File: kdu_show.cpp [scope = APPS/SHOW]// Version: Kakadu, V2.2// Author: David Taubman// Last Revised: 20 June, 2001/******************************************************************************/// Copyright 2001, David Taubman, The University of New South Wales (UNSW)// The copyright owner is Unisearch Ltd, Australia (commercial arm of UNSW)// Neither this copyright statement, nor the licensing details below// may be removed from this file or dissociated from its contents./******************************************************************************/// Licensee: Book Owner// License number: 99999// The Licensee has been granted a NON-COMMERCIAL license to the contents of// this source file, said Licensee being the owner of a copy of the book,// "JPEG2000: Image Compression Fundamentals, Standards and Practice," by// Taubman and Marcellin (Kluwer Academic Publishers, 2001). A brief summary// of the license appears below. This summary is not to be relied upon in// preference to the full text of the license agreement, which was accepted// upon breaking the seal of the compact disc accompanying the above-mentioned// book.// 1. The Licensee has the right to Non-Commercial Use of the Kakadu software,// Version 2.2, including distribution of one or more Applications built// using the software, provided such distribution is not for financial// return.// 2. The Licensee has the right to personal use of the Kakadu software,// Version 2.2.// 3. The Licensee has the right to distribute Reusable Code (including// source code and dynamically or statically linked libraries) to a Third// Party, provided the Third Party possesses a license to use the Kakadu// software, Version 2.2, and provided such distribution is not for// financial return./*******************************************************************************Description: Implements the application object of the interactive JPEG2000 viewer,"kdu_show". Menu processing and idle-time decompressor processing are allcontrolled from here. The "kdu_show" application demonstrates some of thesupport offered by the Kakadu framework for interactive applications,including persistence and incremental region-based decompression.*******************************************************************************/#include <crtdbg.h>#include "stdafx.h"#include <math.h>#include <strstream>#include "kdu_show.h"#include "MainFrm.h"#include "kdu_messaging.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/* ========================================================================== *//* Process (Application) Globals *//* ========================================================================== */CKdu_showApp theApp; // There can only be one application object.std::ostrstream err_stream; // Object collects text of Kakadu error messagesstd::ostrstream warn_stream; // Object collects text of Kakadu warning messages/* ========================================================================== *//* Internal Functions *//* ========================================================================== *//******************************************************************************//* STATIC combine_regions *//******************************************************************************/static kdu_dims combine_regions(kdu_dims r1, kdu_dims r2) /* Returns the largest rectangular region which is completely contained in the union of regions `r1' and `r2'. */{ if (!r1) return r2; if (!r2) return r1; // First try joining the regions together. kdu_coords joined_min = r1.pos; kdu_coords joined_lim = r1.pos + r1.size; kdu_coords r2_min = r2.pos; kdu_coords r2_lim = r2.pos + r2.size; if (joined_lim.x == r2_min.x) { // Tack r2 onto the right joined_lim.x = r2_lim.x; if (r2_min.y > joined_min.y) joined_min.y = r2_min.y; if (r2_lim.y < joined_lim.y) joined_lim.y = r2_lim.y; if (joined_lim.y < joined_min.y) joined_lim.y = joined_min.y; // No area. } else if (joined_min.x == r2_lim.x) { // Tack r2 onto the left joined_min.x = r2_min.x; if (r2_min.y > joined_min.y) joined_min.y = r2_min.y; if (r2_lim.y < joined_lim.y) joined_lim.y = r2_lim.y; if (joined_lim.y < joined_min.y) joined_lim.y = joined_min.y; // No area. } else if (joined_lim.y == r2_min.y) { // Tack r2 onto the bottom joined_lim.y = r2_lim.y; if (r2_min.x > joined_min.x) joined_min.x = r2_min.x; if (r2_lim.x < joined_lim.x) joined_lim.x = r2_lim.x; if (joined_lim.x < joined_min.x) joined_lim.x = joined_min.x; // No area. } else if (joined_min.y == r2_lim.y) { // Tack r2 onto the top joined_min.y = r2_min.y; if (r2_min.x > joined_min.x) joined_min.x = r2_min.x; if (r2_lim.x < joined_lim.x) joined_lim.x = r2_lim.x; if (joined_lim.x < joined_min.x) joined_lim.x = joined_min.x; // No area. } // Now take the larger of `joined', `r1' and `r2' kdu_dims result; result.pos = joined_min; result.size = joined_lim-joined_min; if (r1.area() > result.area()) result = r1; if (r2.area() > result.area()) result = r2; return result;}/* ========================================================================== *//* Error and Warning Message Handlers *//* ========================================================================== *//******************************************************************************//* CLASS core_messages_dlg *//******************************************************************************/class core_messages_dlg : public CDialog{ public: core_messages_dlg(char *string, CWnd* pParent = NULL) : CDialog(core_messages_dlg::IDD, pParent) { this->string = string; }// Dialog Data //{{AFX_DATA(core_messages_dlg) enum { IDD = IDD_CORE_MESSAGES }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(core_messages_dlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUALprivate: CStatic *get_static() { return (CStatic *) GetDlgItem(IDC_MESSAGE); }private: char *string;protected: // Generated message map functions //{{AFX_MSG(core_messages_dlg) virtual BOOL OnInitDialog(); //}}AFX_MSG DECLARE_MESSAGE_MAP()};/******************************************************************************//* core_messages_dlg::DoDataExchange *//******************************************************************************/void core_messages_dlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(core_messages_dlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(core_messages_dlg, CDialog) //{{AFX_MSG_MAP(core_messages_dlg) //}}AFX_MSG_MAPEND_MESSAGE_MAP()/******************************************************************************//* core_messages_dlg::OnInitDialog *//******************************************************************************/BOOL core_messages_dlg::OnInitDialog() { CDialog::OnInitDialog(); while (*string == '\n') string++; // skip leading empty lines, if any. get_static()->SetWindowText(string); // Find the height of the displayed text int text_height = 0; SIZE text_size; CDC *dc = get_static()->GetDC(); while (*string != '\0') { char *sp = strchr(string,'\n'); if (sp == NULL) sp = string + strlen(string); if (string != sp) text_size = dc->GetTextExtent(string,sp-string); text_height += text_size.cy; string = (*sp != '\0')?sp+1:sp; } get_static()->ReleaseDC(dc); // Resize windows to fit the text height WINDOWPLACEMENT dialog_placement, static_placement; GetWindowPlacement(&dialog_placement); get_static()->GetWindowPlacement(&static_placement); int dialog_width = dialog_placement.rcNormalPosition.right - dialog_placement.rcNormalPosition.left; int static_width = static_placement.rcNormalPosition.right - static_placement.rcNormalPosition.left; int dialog_height = dialog_placement.rcNormalPosition.bottom - dialog_placement.rcNormalPosition.top; int static_height = static_placement.rcNormalPosition.bottom - static_placement.rcNormalPosition.top; get_static()->SetWindowPos(NULL,0,0,static_width,text_height, SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW); SetWindowPos(NULL,0,0,dialog_width,text_height+8+dialog_height-static_height, SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW); return TRUE;}/******************************************************************************//* STATIC kdu_error_callback *//******************************************************************************/static void kdu_error_callback(){ err_stream.put('\0'); // Make sure the buffer is long enough to hold NULL. char *string = err_stream.str(); core_messages_dlg messages(string,theApp.frame); messages.DoModal(); err_stream.rdbuf()->freeze(0); err_stream.seekp(0); // Reset the stream in preparation for further messages throw ((int) 0); // Error message generates integer exception.}/******************************************************************************//* STATIC kdu_warning_callback *//******************************************************************************/static void kdu_warning_callback(){ warn_stream.put('\0'); // Make sure the buffer is long enough to hold NULL. char *string = warn_stream.str(); core_messages_dlg messages(string,theApp.frame); messages.DoModal(); warn_stream.rdbuf()->freeze(0); warn_stream.seekp(0); // Reset the stream in preparation for further messages}/* ========================================================================== *//* CAboutDlg Class *//* ========================================================================== */class CAboutDlg : public CDialog{public: CAboutDlg();// Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL// Implementationprotected: //{{AFX_MSG(CAboutDlg) // No message handlers //}}AFX_MSG DECLARE_MESSAGE_MAP()};BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAPEND_MESSAGE_MAP()/******************************************************************************//* CAboutDlg::CAboutDlg *//******************************************************************************/CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD){ //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT}/******************************************************************************//* CAboutDlg::DoDataExchange *//******************************************************************************/void CAboutDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP}/* ========================================================================== *//* CPropertyHelpDlg *//* ========================================================================== */class CPropertyHelpDlg : public CDialog{// Constructionpublic: CPropertyHelpDlg(char *string, kdu_coords placement, CWnd* pParent = NULL);// Dialog Data //{{AFX_DATA(CPropertyHelpDlg) enum { IDD = IDD_PROPERTYHELP }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -