Sophie

Sophie

distrib > Mageia > 5 > i586 > by-pkgid > 65f8aa69c4b85eb2463f24ce9ff49b95 > files > 310

cimg-devel-1.5.9-3.mga5.i586.rpm

\hypertarget{group__cimg__overview}{\section{C\+Img Library Overview}
\label{group__cimg__overview}\index{C\+Img Library Overview@{C\+Img Library Overview}}
}
The {\bfseries C\+Img Library} is an image processing library, designed for C++ programmers. It provides useful classes and functions to load/save, display and process various types of images.\hypertarget{group__cimg__overview_s1}{}\subsection{Library structure}\label{group__cimg__overview_s1}
The C\+Img Library consists in a single header file {\ttfamily C\+Img.\+h} providing a set of C++ template classes that can be used in your own sources, to load/save, process and display images or list of images. Very portable (Unix/\+X11,Windows, Mac\+O\+S X, Free\+B\+S\+D,..), efficient, simple to use, it's a pleasant toolkit for coding image processing stuffs in C++.

The header file {\ttfamily C\+Img.\+h} contains all the classes and functions that compose the library itself. This is one originality of the C\+Img Library. This particularly means that \+:
\begin{DoxyItemize}
\item No pre-\/compilation of the library is needed, since the compilation of the C\+Img functions is done at the same time as the compilation of your own C++ code.
\item No complex dependencies have to be handled \+: Just include the {\ttfamily C\+Img.\+h} file, and you get a working C++ image processing toolkit.
\item The compilation is done on the fly \+: only C\+Img functionalities really used by your program are compiled and appear in the compiled executable program. This leads to very compact code, without any unused stuffs.
\item Class members and functions are inlined, leading to better performance during the program execution.
\end{DoxyItemize}

The C\+Img Library is structured as follows \+:


\begin{DoxyItemize}
\item All library classes and functions are defined in the namespace \hyperlink{namespacecimg__library}{cimg\+\_\+library}. This namespace encapsulates the library functionalities and avoid any class name collision that could happen with other includes. Generally, one uses this namespace as a default namespace \+: 
\begin{DoxyCode}
\textcolor{preprocessor}{#include "CImg.h"}
\textcolor{keyword}{using namespace }\hyperlink{namespacecimg__library}{cimg\_library};
...
\end{DoxyCode}

\item The namespace \hyperlink{namespacecimg__library_1_1cimg}{cimg\+\_\+library\+::cimg} defines a set of {\itshape low-\/level} functions and variables used by the library. Documented functions in this namespace can be safely used in your own program. But, {\bfseries never} use the \hyperlink{namespacecimg__library_1_1cimg}{cimg\+\_\+library\+::cimg} namespace as a default namespace, since it contains functions whose names are already defined in the standard C/\+C++ library.
\item The class \hyperlink{structcimg__library_1_1CImg}{cimg\+\_\+library\+::\+C\+Img} represents images up to 4-\/dimensions wide, containing pixels of type {\ttfamily T} (template parameter). This is actually the main class of the library.
\item The class \hyperlink{structcimg__library_1_1CImgList}{cimg\+\_\+library\+::\+C\+Img\+List} represents lists of cimg\+\_\+library\+::\+C\+Img$<$\+T$>$ images. It can be used for instance to store different frames of an image sequence.
\item The class \hyperlink{structcimg__library_1_1CImgDisplay}{cimg\+\_\+library\+::\+C\+Img\+Display} is able to display images or image lists into graphical display windows. As you may guess, the code of this class is highly system-\/dependent but this is transparent for the programmer, as environment variables are automatically set by the C\+Img library (see also \hyperlink{group__cimg__environment}{Setting Environment Variables}).
\item The class \hyperlink{structcimg__library_1_1CImgException}{cimg\+\_\+library\+::\+C\+Img\+Exception} (and its subclasses) are used by the library to throw exceptions when errors occur. Those exceptions can be catched with a bloc {\ttfamily try \{ ..\} catch (C\+Img\+Exception) \{ .. \}}. Subclasses define precisely the type of encountered errors.
\end{DoxyItemize}

Knowing these four classes is {\bfseries enough} to get benefit of the C\+Img Library functionalities.\hypertarget{group__cimg__overview_s2}{}\subsection{C\+Img version of \char`\"{}\+Hello world\char`\"{}.}\label{group__cimg__overview_s2}
Below is a very simple code that creates a \char`\"{}\+Hello World\char`\"{} image. This shows you basically how a C\+Img program looks like.


\begin{DoxyCode}
\textcolor{preprocessor}{#include "CImg.h"}
\textcolor{keyword}{using namespace }\hyperlink{namespacecimg__library}{cimg\_library};

\textcolor{keywordtype}{int} main() \{
  \hyperlink{structcimg__library_1_1CImg}{CImg<unsigned char>} img(640,400,1,3);        \textcolor{comment}{// Define a 640x400 color image with 8
       bits per color component.}
  img.fill(0);                                 \textcolor{comment}{// Set pixel values to 0 (color : black)}
  \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} purple[] = \{ 255,0,255 \};      \textcolor{comment}{// Define a purple color}
  img.draw\_text(100,100,\textcolor{stringliteral}{"Hello World"},purple); \textcolor{comment}{// Draw a purple "Hello world" at coordinates (100,100).}
  img.display(\textcolor{stringliteral}{"My first CImg code"});           \textcolor{comment}{// Display the image in a display window.}
  \textcolor{keywordflow}{return} 0;
\}
\end{DoxyCode}


Which can be also written in a more compact way as \+:


\begin{DoxyCode}
\textcolor{preprocessor}{#include "CImg.h"}
\textcolor{keyword}{using namespace }\hyperlink{namespacecimg__library}{cimg\_library};

\textcolor{keywordtype}{int} main() \{
  \textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} purple[] = \{ 255,0,255 \};
  \hyperlink{structcimg__library_1_1CImg}{CImg<unsigned char>}(640,400,1,3,0).draw\_text(100,100,\textcolor{stringliteral}{"Hello World"},purple).
      \hyperlink{structcimg__library_1_1CImg_aea0592215c6068e617a975a1fe5b7b7b}{display}(\textcolor{stringliteral}{"My first CImg code"});
  \textcolor{keywordflow}{return} 0;
\}
\end{DoxyCode}


Generally, you can write very small code that performs complex image processing tasks. The C\+Img Library is very simple to use and provide a lot of interesting algorithms for image manipulation.\hypertarget{group__cimg__overview_s3}{}\subsection{How to compile ?}\label{group__cimg__overview_s3}
The C\+Img library is a very light and user-\/friendly library \+: only standard system libraries are used. It avoid to handle complex dependancies and problems with library compatibility. The only thing you need is a (quite modern) C++ compiler \+:


\begin{DoxyItemize}
\item {\bfseries Microsoft Visual C++ 6.\+0, Visual Studio.\+N\+E\+T and Visual Express Edition} \+: Use project files and solution files provided in the C\+Img Library package (directory 'compilation/') to see how it works.
\item {\bfseries Intel I\+C\+L compiler} \+: Use the following command to compile a C\+Img-\/based program with I\+C\+L \+: 
\begin{DoxyCode}
icl /Ox hello\_world.cpp user32.lib gdi32.lib
\end{DoxyCode}

\item {\bfseries g++ (Ming\+W windows version)} \+: Use the following command to compile a C\+Img-\/based program with g++, on Windows \+: 
\begin{DoxyCode}
g++ -o hello\_word.exe hello\_word.cpp -O2 -lgdi32
\end{DoxyCode}

\item {\bfseries g++ (Linux version)} \+: Use the following command to compile a C\+Img-\/based program with g++, on Linux \+: 
\begin{DoxyCode}
g++ -o hello\_word.exe hello\_world.cpp -O2 -L/usr/X11R6/lib -lm -lpthread -lX11
\end{DoxyCode}

\item {\bfseries g++ (Solaris version)} \+: Use the following command to compile a C\+Img-\/based program with g++, on Solaris \+: 
\begin{DoxyCode}
g++ -o hello\_word.exe hello\_world.cpp -O2 -lm -lpthread -R/usr/X11R6/lib -lrt -lnsl -lsocket
\end{DoxyCode}

\item {\bfseries g++ (Mac O\+S X version)} \+: Use the following command to compile a C\+Img-\/based program with g++, on Mac O\+S X \+: 
\begin{DoxyCode}
g++ -o hello\_word.exe hello\_world.cpp -O2 -lm -lpthread -I/usr/X11R6/include -L/usr/X11R6/lib -lm -lpthread
       -lX11
\end{DoxyCode}

\item {\bfseries Dev-\/\+Cpp} \+: Use the project file provided in the C\+Img library package to see how it works.
\end{DoxyItemize}

If you are using another compilers and encounter problems, please \href{http://www.greyc.ensicaen.fr/~dtschump}{\tt write me} since maintaining compatibility is one of the priority of the C\+Img Library. Nevertheless, old compilers that does not respect the C++ norm will not support the C\+Img Library.\hypertarget{group__cimg__overview_s4}{}\subsection{What's next ?}\label{group__cimg__overview_s4}
If you are ready to get more, and to start writing more serious programs with C\+Img, you are invited to go to the \hyperlink{group__cimg__tutorial}{Tutorial \+: Getting Started.} section.