PTdecode/CImg-1.3.0/html/reference/group__cimg__storage.html

Mon, 03 Aug 2009 14:09:20 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Mon, 03 Aug 2009 14:09:20 +0100
changeset 5
1204ebf9340d
permissions
-rwxr-xr-x

added P-touch decoder source

     1  xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
     2 <head>
     3 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
     4 <title>The CImg Library - C++ Template Image Processing Toolkit</title>
     5 <meta content="David Tschumperle" name="author"></meta>
     6 <link rel="shortcut icon" type="image/x-icon" href="http://cimg.sourceforge.net/favicon.ico"></link>
     7 <link rel="icon" type="image/png" href="favicon.png"></link>
     8 <link href="doxygen.css" rel="stylesheet" type="text/css">
     9 <link href="tabs.css" rel="stylesheet" type="text/css">
    10 <style type="text/css">
    11 <!--
    12 body {background-color:white; font-family:sans-serif; }
    13 a:active{text-decoration:none; color:#303090}
    14 a:link{text-decoration:none; color:#303090}
    15 a:visited{text-decoration:none; color:#303090}
    16 a:hover{text-decoration:underline; color:#4E9F71}
    17 -->
    18 </style>
    19 <script language="JavaScript" type="text/javascript">
    20   <!-- Original:  Eric King (eric_andrew_king@hotmail.com) is used to display images in popup windows -->
    21   <!-- Web Site:  http://redrival.com/eak/ -->
    22   <!-- This script and many more are available free online at -->
    23   <!-- The JavaScript Source!! http://javascript.internet.com -->
    24   <!-- Begin
    25   function NewWindow(mypage, myname, w, h, scroll) {
    26   var winl = (screen.width - w) / 2;
    27   var wint = (screen.height - h) / 2;
    28   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
    29   win = window.open(mypage, myname, winprops)
    30   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
    31   }
    32   //  End -->
    33 </script>
    34 </head>
    35 <body>
    36  <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
    37   <tbody><tr><td>
    38    <hr noshade="noshade" size="1" width="90%"></hr>
    39    <center>
    40    <br/>
    41    <a href="http://cimg.sourceforge.net"><img src="http://cimg.sourceforge.net/img/CImgLogo.jpg" alt="" border="0"></img></a><br/>
    42    <br/>
    43    </center>
    44    <hr noshade="noshade" size="1" width="90%"></hr>
    45    <center>
    46    <table bgcolor="#EEEEFF" style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="3" cellspacing="0">
    47    <tbody><tr><td style="text-align: center; vertical-align: top;">
    48    <font color="#FFFFFF" face="Arial,Helvetica" size="-1">
    49    <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/index.shtml">Main</a> <b>]</b>
    50    <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/news.shtml">News</a><b>] </b>
    51    <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/download.shtml">Download</a> <b>]</b>
    52    <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/screenshots.shtml">Screenshots</a> <b>]</b>
    53    <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/reference/group__cimg__faq.html">FAQ</a> <b>]</b>
    54    <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/reference/group__cimg__tutorial.html">Tutorial</a> <b>]</b>
    55    <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/reference/index.html">Documentation</a> <b>]</b>
    56    <b>[</b> <a target="_parent" href="http://sourceforge.net/forum/forum.php?forum_id=334630">Forum</a> <b>]</b>
    57    <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/chat.shtml">Chat</a> <b>]</b>
    58    <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/links.shtml">Links</a> <b>]</b>
    59    </font>
    60    </td></tr></tbody>
    61    </table>
    62    </center>
    63    <hr noshade="noshade" size="1" width="90%"></hr>
    64   </td></tr></tbody>
    65 </table>
    66 <!-- Generated by Doxygen 1.5.7.1 -->
    67 <script type="text/javascript">
    68 <!--
    69 function changeDisplayState (e){
    70   var num=this.id.replace(/[^[0-9]/g,'');
    71   var button=this.firstChild;
    72   var sectionDiv=document.getElementById('dynsection'+num);
    73   if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
    74     sectionDiv.style.display='block';
    75     button.src='open.gif';
    76   }else{
    77     sectionDiv.style.display='none';
    78     button.src='closed.gif';
    79   }
    80 }
    81 function initDynSections(){
    82   var divs=document.getElementsByTagName('div');
    83   var sectionCounter=1;
    84   for(var i=0;i<divs.length-1;i++){
    85     if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
    86       var header=divs[i];
    87       var section=divs[i+1];
    88       var button=header.firstChild;
    89       if (button!='IMG'){
    90         divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
    91         button=document.createElement('img');
    92         divs[i].insertBefore(button,divs[i].firstChild);
    93       }
    94       header.style.cursor='pointer';
    95       header.onclick=changeDisplayState;
    96       header.id='dynheader'+sectionCounter;
    97       button.src='closed.gif';
    98       section.id='dynsection'+sectionCounter;
    99       section.style.display='none';
   100       section.style.marginLeft='14px';
   101       sectionCounter++;
   102     }
   103   }
   104 }
   105 window.onload = initDynSections;
   106 -->
   107 </script>
   108 <div class="navigation" id="top">
   109   <div class="tabs">
   110     <ul>
   111       <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
   112       <li><a href="modules.html"><span>Modules</span></a></li>
   113       <li><a href="namespaces.html"><span>Namespaces</span></a></li>
   114       <li><a href="annotated.html"><span>Classes</span></a></li>
   115     </ul>
   116   </div>
   117 </div>
   118 <div class="contents">
   119 <h1>How pixel data are stored with CImg.</h1><table border="0" cellpadding="0" cellspacing="0">
   120 <tr><td></td></tr>
   121 </table>
   122 First, CImg&lt;T&gt; are *very* basic structures, which means that there are no memory tricks, weird memory alignments or disk caches used to store pixel data of images. When an image is instanced, all its pixel values are stored in memory at the same time (yes, you should avoid working with huge images when dealing with CImg, if you have only 64kb of RAM).<p>
   123 A CImg&lt;T&gt; is basically a 4th-dimensional array (width,height,depth,dim), and its pixel data are stored linearly in a single memory buffer of general size (width*height*depth*dim). Nothing more, nothing less. The address of this memory buffer can be retrieved by the function CImg&lt;T&gt;::ptr(). As each image value is stored as a type T (T being known by the programmer of course), this pointer is a 'T*', or a 'const T*' if your image is 'const'. so, 'T *ptr = img.ptr()' gives you the pointer to the first value of the image 'img'. The overall size of the used memory for one instance image (in bytes) is then 'width*height*depth*dim*sizeof(T)'.<p>
   124 Now, the ordering of the pixel values in this buffer follows these rules : The values are *not* interleaved, and are ordered first along the X,Y,Z and V axis respectively (corresponding to the width,height,depth,dim dimensions), starting from the upper-left pixel to the bottom-right pixel of the instane image, with a classical scanline run.<p>
   125 So, a color image with dim=3 and depth=1, will be stored in memory as :<p>
   126 R1R2R3R4R5R6......G1G2G3G4G5G6.......B1B2B3B4B5B6.... (i.e following a 'planar' structure)<p>
   127 and *not* as R1G1B1R2G2B2R3G3B3... (interleaved channels), where R1 = img(0,0,0,0) is the first upper-left pixel of the red component of the image, R2 is img(1,0,0,0), G1 = img(0,0,0,1), G2 = img(1,0,0,1), B1 = img(0,0,0,2), and so on...<p>
   128 Another example, a (1x5x1x1) CImg&lt;T&gt; (column vector A) will be stored as : A1A2A3A4A5 where A1 = img(0,0), A2 = img(0,1), ... , A5 = img(0,4).<p>
   129 As you see, it is *very* simple and intuitive : no interleaving, no padding, just simple. This is cool not only because it is simple, but this has in fact a number of interesting properties. For instance, a 2D color image is stored in memory exactly as a 3D scalar image having a depth=3, meaning that when you are dealing with 2D color images, you can write 'img(x,y,k)' instead of 'img(x,y,0,k)' to access the kth channel of the (x,y) pixel. More generally, if you have one dimension that is 1 in your image, you can just skip it in the call to the operator(). Similarly, values of a column vector stored as an image with width=depth=dim=1 can be accessed by 'img(y)' instead of 'img(0,y)'. This is very convenient.<p>
   130 Another cool thing is that it allows you to work easily with 'shared' images. A shared image is a CImg&lt;T&gt; instance that shares its memory with another one (the 'base' image). Destroying a shared image does nothing in fact. Shared images is a convenient way of modifying only *portions* (consecutive in memory) of an image. For instance, if 'img' is a 2D color image, you can write :<p>
   131 img.get_shared_channel(0).blur(2); img.get_shared_channels(1,2).mirror('x');<p>
   132 which just blur the red channel of the image, and mirror the two others along the X-axis. This is possible since channels of an image are not interleaved but are stored as different consecutive planes in memory, so you see that constructing a shared image is possible (and trivial). </div>
   133 <hr noshade="noshade" size="1" width="100%">
   134 <a href="http://sourceforge.net">
   135 <img src="http://sourceforge.net/sflogo.php?group_id=96492&amp;type=3" border="0" height="37" width="125"></img>
   136 </a>
   137 <!-- Start of StatCounter Code -->
   138 <script type="text/javascript" language="javascript">
   139 <!--
   140 var sc_project=895001;
   141 var sc_invisible=1;
   142 var sc_partition=7;
   143 var sc_security="5ea85181";
   144 //-->
   145 </script>
   146 <script type="text/javascript" language="javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript><a href="http://www.statcounter.com/" target="_blank"><img  src="http://c8.statcounter.com/counter.php?sc_project=895001&amp;java=0&amp;security=5ea85181&amp;invisible=1" alt="counter stats" border="0"></a> </noscript>
   147 <!-- End of StatCounter Code -->
   148 </body>
   149 </html>