summaryrefslogtreecommitdiff
path: root/html/en/rep_guide.html
blob: 0dfd9391dbd63cc30646bf68a9e12e386f32e800 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!doctype HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Representation Guide</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>

<body>

<h1>Image Representation Guide</h1>
<h3 align="left"><a name="raw">Raw Data Buffer</a></h3>

  <p align="left">To create a raw image buffer you can simply use the utility function:</p>
  
    <div align="left">
      <pre>int width, height, color_mode, data_type;
int size = imImageDataSize(width, height, color_mode, data_type);
void* buffer = malloc(size);</pre>
    </div>
  
  <div align="left">
    <p align="left">So if the data type is <strong>IM_FLOAT</strong>, we could write:</div>
  <div align="left">
    
      <pre>float* idata = (float*)buffer;</pre>
    
  </div>
  <div align="left">
    <p align="left">Then to locate the pixel at line y, column x, component d simply write:
  </div>
  <div align="left">
    
      <pre>float value;
if (is_packed) 
value = idata[y*width*depth + x*depth + d]
else
value = idata[d*width*height + y*width + x]</pre>
    
  </div>
  <div align="left">
    <p align="left">But notice that this code will return values at different pixel locations for top down and bottom up 
    orientations.</div>

<div align="left">
  <h3 align="left"><a name="imImage">imImage</a></h3>
</div>

  <div align="left">
    <p align="left">To use the <b>imImage</b> structure you must include the &lt;im_image.h&gt; header.</div>
  <div align="left">
    <p align="left">To create an <b>imImage</b> structure you can do it in several ways:</div>

<div align="left">
  
    
      <pre>int width, height, color_space, data_type, palette_count;
long *palette;
void* buffer

imImage* image;

image = imImageCreate(width, height, color_space, data_type) 
image = imImageInit(width, height, color_space, data_type, buffer, palette, palette_count) 
image = imImageDuplicate(image) 
image = imImageClone(image) </pre>
    
    <p>The <b>imImageInit</b> function allow you to initialize an <b>imImage</b> structure with an user allocated 
    buffer. This is very useful if you use your own image structure and wants to temporally use the image processing 
    functions of the library.</p>
    <p>To destroy the <b>imImage</b> structure simply call <b>imImageDestroy(image)</b>. If you do &quot;<b>data[0] 
    = NULL</b>&quot; before calling the destroy function then the raw data buffer will not be destroyed.</p>
  
</div>

  <div align="left">
    <p align="left">The <b>imImage</b> data buffer is allocated like the raw data buffer.
  </div>
  <div align="left">
    <p align="left">The separated color components are arranged one after another, but we access the data through an 
    array of pointers each one starting at the beginning of each color component. So 
    <b>image-&gt;data[0]</b> 
    contains a pointer to all the data, and <b>image-&gt;data[1]</b> is a short cut to the second component and so 
    on. With this you can use <b>image-&gt;data[0]</b> as a starting point for all the data, or use it as the first 
    component.</div>

<div align="left">
  
    
      <pre>count = width*height;
unsigned char* idata = (unsigned char*)image-&gt;data[0];
for (int i = 0; i &lt; count; i++)
{
  idata[i] = 255;
}</pre>
    
    <p>or</p>
    
      <pre>for (int d = 0; d &lt; image-&gt;depth; d++)
{
  unsigned char* idata = (unsigned char*)image-&gt;data[d];

  for (int y = 0; y &lt; height; y++)
  {
    for (int x = 0; x &lt; width; x++)
    {
      int offset = y * width + x; 

      idata[offset] = 255;
    }
  }
}</pre>
    
  
</div>
<div align="left">
  
    <p align="left">The <b>imImage</b> structure contains all the image information obtained from a file, because it 
    also has support for alpha, attributes and the palette. The palette can be used for 
    <b>IM_MAP</b> images and 
    for pseudo color of <b>IM_GRAY</b> images.</p>
  
</div>

  <div align="left">
    <p align="left">An important subset of images is what we call a <b>Bitmap</b> image. It is an image that can be 
    directly used into the graphics display. For Bitmap images the color space must be 
    <b>IM_RGB</b>, <b>IM_MAP</b>,
    <b>IM_GRAY</b> or <b>IM_BINARY</b>, and the data type must be <b>IM_BYTE</b>.</div>
  <div align="left">
    <p align="left">The conversion between image data types, color spaces and the conversion to bitmap are defined only 
    for the <b>imImage</b> structure.</div>


</body>

</html>