📄 cimg.h
字号:
correctly defined. Generally, this exception is thrown when one tries to process \a empty images. The example
below will throw a \a CImgInstanceException.
\code
CImg<float> img; // Construct an empty image.
img.blur(10); // Try to blur the image.
\endcode
- \b CImgArgumentException : Thrown when one of the arguments given to the called %CImg function is not correct.
Generally, this exception is thrown when arguments passed to the function are outside an admissible range of values.
The example below will throw a \a CImgArgumentException.
\code
CImg<float> img(100,100,1,3); // Define a 100x100 color image with float pixels.
img = NULL; // Try to fill pixels from the NULL pointer (invalid argument to operator=() ).
\endcode
- \b CImgIOException : Thrown when an error occured when trying to load or save image files.
The example below will throw a \a CImgIOException.
\code
CImg<float> img("file_doesnt_exist.jpg"); // Try to load a file that doesn't exist.
\endcode
- \b CImgDisplayException : Thrown when an error occured when trying to display an image in a window.
This exception is thrown when image display request cannot be satisfied.
The parent class CImgException may be thrown itself when errors that cannot be classified in one of
the above type occur. It is recommended not to throw CImgExceptions yourself, since there are normally
reserved to %CImg Library functions.
\b CImgInstanceException, \b CImgArgumentException, \b CImgIOException and \b CImgDisplayException are simple
subclasses of CImgException and are thus not detailled more in this reference documentation.
\section ex2 Exception handling
When an error occurs, the %CImg Library first displays the error in a modal window.
Then, it throws an instance of the corresponding exception class, generally leading the program to stop
(this is the default behavior).
You can bypass this default behavior by handling the exceptions yourself,
using a code block <tt>try { ... } catch() { ... }</tt>.
In this case, you can avoid the apparition of the modal window, by
defining the environment variable <tt>cimg_debug</tt> to 0 before including the %CImg header file.
The example below shows how to cleanly handle %CImg Library exceptions :
\code
#define cimg_debug 0 // Disable modal window in CImg exceptions.
#define "CImg.h"
int main() {
try {
...; // Here, do what you want.
}
catch (CImgInstanceException &e) {
std::fprintf(stderr,"CImg Library Error : %s",e.message); // Display your own error message
... // Do what you want now.
}
}
\endcode
**/
struct CImgException {
char message[1024]; //!< Message associated with the error that thrown the exception.
CImgException() { message[0]='\0'; }
CImgException(const char *format,...) { cimg_exception_err("CImgException",true); }
};
// The \ref CImgInstanceException class is used to throw an exception related
// to a non suitable instance encountered in a library function call.
struct CImgInstanceException : CImgException {
CImgInstanceException(const char *format,...) { cimg_exception_err("CImgInstanceException",true); }
};
// The \ref CImgArgumentException class is used to throw an exception related
// to invalid arguments encountered in a library function call.
struct CImgArgumentException : CImgException {
CImgArgumentException(const char *format,...) { cimg_exception_err("CImgArgumentException",true); }
};
// The \ref CImgIOException class is used to throw an exception related
// to Input/Output file problems encountered in a library function call.
struct CImgIOException : CImgException {
CImgIOException(const char *format,...) { cimg_exception_err("CImgIOException",true); }
};
// The CImgDisplayException class is used to throw an exception related to display problems
// encountered in a library function call.
struct CImgDisplayException : CImgException {
CImgDisplayException(const char *format,...) { cimg_exception_err("CImgDisplayException",false); }
};
/*
#-------------------------------------
#
#
# Definition of the namespace 'cimg'
#
#
#-------------------------------------
*/
//! Namespace that encompasses \a low-level functions and variables of the %CImg Library.
/**
Most of the functions and variables within this namespace are used by the library for low-level processing.
Nevertheless, documented variables and functions of this namespace may be used safely in your own source code.
\warning Never write <tt>using namespace cimg_library::cimg;</tt> in your source code, since a lot of functions of the
<tt>cimg::</tt> namespace have prototypes similar to standard C functions defined in the global namespace <tt>::</tt>.
**/
namespace cimg {
// Define the trait that will be used to determine the best data type to work with.
template<typename T,typename t> struct largest { typedef t type; };
template<> struct largest<unsigned char,bool> { typedef unsigned char type; };
template<> struct largest<unsigned char,char> { typedef short type; };
template<> struct largest<char,bool> { typedef char type; };
template<> struct largest<char,unsigned char> { typedef short type; };
template<> struct largest<char,unsigned short> { typedef int type; };
template<> struct largest<char,unsigned int> { typedef float type; };
template<> struct largest<char,unsigned long> { typedef float type; };
template<> struct largest<unsigned short,bool> { typedef unsigned short type; };
template<> struct largest<unsigned short,unsigned char> { typedef unsigned short type; };
template<> struct largest<unsigned short,char> { typedef short type; };
template<> struct largest<unsigned short,short> { typedef int type; };
template<> struct largest<short,bool> { typedef short type; };
template<> struct largest<short,unsigned char> { typedef short type; };
template<> struct largest<short,char> { typedef short type; };
template<> struct largest<short,unsigned short> { typedef int type; };
template<> struct largest<short,unsigned int> { typedef float type; };
template<> struct largest<short,unsigned long> { typedef float type; };
template<> struct largest<unsigned int,bool> { typedef unsigned int type; };
template<> struct largest<unsigned int,unsigned char> { typedef unsigned int type; };
template<> struct largest<unsigned int,char> { typedef unsigned int type; };
template<> struct largest<unsigned int,unsigned short> { typedef unsigned int type; };
template<> struct largest<unsigned int,short> { typedef float type; };
template<> struct largest<unsigned int,int> { typedef float type; };
template<> struct largest<int,bool> { typedef int type; };
template<> struct largest<int,unsigned char> { typedef int type; };
template<> struct largest<int,char> { typedef int type; };
template<> struct largest<int,unsigned short> { typedef int type; };
template<> struct largest<int,short> { typedef int type; };
template<> struct largest<int,unsigned int> { typedef float type; };
template<> struct largest<int,unsigned long> { typedef float type; };
template<> struct largest<float,bool> { typedef float type; };
template<> struct largest<float,unsigned char> { typedef float type; };
template<> struct largest<float,char> { typedef float type; };
template<> struct largest<float,unsigned short> { typedef float type; };
template<> struct largest<float,short> { typedef float type; };
template<> struct largest<float,unsigned int> { typedef float type; };
template<> struct largest<float,int> { typedef float type; };
template<> struct largest<float,unsigned long> { typedef float type; };
template<> struct largest<float,long> { typedef float type; };
template<> struct largest<double,bool> { typedef double type; };
template<> struct largest<double,unsigned char> { typedef double type; };
template<> struct largest<double,char> { typedef double type; };
template<> struct largest<double,unsigned short> { typedef double type; };
template<> struct largest<double,short> { typedef double type; };
template<> struct largest<double,unsigned int> { typedef double type; };
template<> struct largest<double,int> { typedef double type; };
template<> struct largest<double,unsigned long> { typedef double type; };
template<> struct largest<double,long> { typedef double type; };
template<> struct largest<double,float> { typedef double type; };
// Define internal library variables.
#if cimg_display_type==1
struct X11info {
pthread_mutex_t* mutex;
pthread_t* event_thread;
CImgDisplay* wins[1024];
Display* display;
unsigned int nb_wins;
bool thread_finished;
unsigned int nb_bits;
GC* gc;
bool blue_first;
bool byte_order;
bool shm_enabled;
X11info():mutex(NULL),event_thread(NULL),display(NULL),nb_wins(0),
thread_finished(false),nb_bits(0),gc(NULL),blue_first(false),byte_order(false),shm_enabled(false) {};
};
#if defined(cimg_module)
X11info& X11attr();
#elif defined(cimg_main)
X11info& X11attr() { static X11info val; return val; }
#else
inline X11info& X11attr() { static X11info val; return val; }
#endif
#endif
#ifdef cimg_color_terminal
const char t_normal[9] = {0x1b,'[','0',';','0',';','0','m','\0'};
const char t_red[11] = {0x1b,'[','4',';','3','1',';','5','9','m','\0'};
const char t_bold[5] = {0x1b,'[','1','m','\0'};
const char t_purple[11] = {0x1b,'[','0',';','3','5',';','5','9','m','\0'};
#else
const char t_normal[1] = {'\0'};
const char *const t_red = cimg::t_normal, *const t_bold = cimg::t_normal, *const t_purple = cimg::t_normal;
#endif
#if cimg_display_type==1
// Keycodes for X11-based graphical systems
const unsigned int keyESC = XK_Escape;
const unsigned int keyF1 = XK_F1;
const unsigned int keyF2 = XK_F2;
const unsigned int keyF3 = XK_F3;
const unsigned int keyF4 = XK_F4;
const unsigned int keyF5 = XK_F5;
const unsigned int keyF6 = XK_F6;
const unsigned int keyF7 = XK_F7;
const unsigned int keyF8 = XK_F8;
const unsigned int keyF9 = XK_F9;
const unsigned int keyF10 = XK_F10;
const unsigned int keyF11 = XK_F11;
const unsigned int keyF12 = XK_F12;
const unsigned int keyPAUSE = XK_Pause;
const unsigned int key1 = XK_1;
const unsigned int key2 = XK_2;
const unsigned int key3 = XK_3;
const unsigned int key4 = XK_4;
const unsigned int key5 = XK_5;
const unsigned int key6 = XK_6;
const unsigned int key7 = XK_7;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -