HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PXL_ConvertImpl.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: PXL_Convert.C
7  *
8  * COMMENTS:
9  * Conversion routines for converting a pixel to other pixel types.
10  */
11 #ifndef PXL_CONVERT_C
12 #define PXL_CONVERT_C
13 
14 #include "PXL_Convert.h"
15 
16 // Very simple, but works in only a few cases (with anything and float).
17 template<class ToType, int fast1, class FromType, int fast2>
18 inline void
20  const PXL_Pixel<FromType,fast2> &from)
21 {
22  to = ((float) from);
23 }
24 
25 // 8 bit conversions
26 template<>
27 inline void
29  const PXL_Pixel<unsigned char,0> &from)
30 {
31  if(to.getBlack() == from.getBlack() && to.getWhite() == from.getWhite())
32  to.assign((unsigned char) from.getValue());
33  else
34  {
35  // ranges do not match -- convert to int and back.
36  float f = (float) from;
37  to = f;
38  }
39 }
40 
41 template<>
42 inline void
44  const PXL_Pixel<unsigned char,0> &from)
45 {
46  if(to.getBlack() == from.getBlack() && to.getWhite() == from.getWhite())
47  to.assign((unsigned char) from.getValue());
48  else
49  {
50  // ranges do not match -- convert to int and back.
51  float f = (float) from;
52  to = f;
53  }
54 }
55 
56 template<>
57 inline void
59  const PXL_Pixel<unsigned char,1> &from)
60 {
61  if(to.getBlack() == from.getBlack() && to.getWhite() == from.getWhite())
62  to.assign((unsigned char) from.getValue());
63  else
64  {
65  // ranges do not match -- convert to int and back.
66  float f = (float) from;
67  to = f;
68  }
69 }
70 
71 template<>
72 inline void
74  const PXL_Pixel<unsigned char,1> &from)
75 {
76  to.assign((unsigned char) from.getValue());
77 }
78 
79 template<>
80 inline void
82  const PXL_Pixel<unsigned short,0> &from)
83 {
84  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
85  to.assign((unsigned char) from);
86  else
87  {
88  float f = (float) from;
89  to = f;
90  }
91 }
92 
93 template<>
94 inline void
96  const PXL_Pixel<unsigned short,1> &from)
97 {
98  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
99  to.assign((unsigned char) from);
100  else
101  {
102  float f = (float) from;
103  to = f;
104  }
105 }
106 
107 template<>
108 inline void
110  const PXL_Pixel<unsigned short,0> &from)
111 {
112  to.assign((unsigned char) from);
113 }
114 
115 template<>
116 inline void
118  const PXL_Pixel<unsigned short,1> &from)
119 {
120  to.assign((unsigned char) from);
121 }
122 
123 
124 template<>
125 inline void
127  const PXL_Pixel<unsigned int,0> &from)
128 {
129  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
130  to.assign((unsigned char) from);
131  else
132  to = (float) from;
133 }
134 
135 template<>
136 inline void
138  const PXL_Pixel<unsigned int,0> &from)
139 {
140  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
141  to.assign((unsigned char) from);
142  else
143  to = (float) from;
144 }
145 
146 template<>
147 inline void
149  const PXL_Pixel<unsigned int,1> &from)
150 {
151  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
152  to.assign((unsigned char) from);
153  else
154  to = (float) from;
155 }
156 
157 template<>
158 inline void
160  const PXL_Pixel<unsigned int,1> &from)
161 {
162  to.assign((unsigned char) from);
163 }
164 
165 template<>
166 inline void
168  const PXL_Pixel<float,0> &from)
169 {
170  to = (float) from;
171 }
172 
173 template<>
174 inline void
176  const PXL_Pixel<float,0> &from)
177 {
178  to = (float) from;
179 }
180 
181 template<>
182 inline void
184  const PXL_Pixel<float,1> &from)
185 {
186  to = (float) from;
187 }
188 
189 template<>
190 inline void
192  const PXL_Pixel<float,1> &from)
193 {
194  to = (float) from;
195 }
196 
197 // 16 bit conversions. ----------------------------------------------------
198 
199 template<>
200 inline void
202  const PXL_Pixel<unsigned char,0> &from)
203 {
204  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
205  to.assign((unsigned short) from);
206  else
207  {
208  float f = (float) from;
209  to = f;
210  }
211 }
212 
213 template<>
214 inline void
216  const PXL_Pixel<unsigned char,0> &from)
217 {
218  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
219  to.assign((unsigned short) from);
220  else
221  {
222  float f = (float) from;
223  to = f;
224  }
225 }
226 
227 template<>
228 inline void
230  const PXL_Pixel<unsigned char,1> &from)
231 {
232  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
233  to.assign((unsigned short) from);
234  else
235  {
236  float f = (float) from;
237  to = f;
238  }
239 }
240 
241 template<>
242 inline void
244  const PXL_Pixel<unsigned char,1> &from)
245 {
246  to.assign((unsigned short) from);
247 }
248 
249 template<>
250 inline void
252  const PXL_Pixel<unsigned short,0> &from)
253 {
254  if(to.getBlack() == from.getBlack() && to.getWhite() == from.getWhite())
255  to.assign(from.getValue());
256  else
257  {
258  // ranges do not match -- convert to int and back.
259  to = (float) from;
260  }
261 }
262 
263 template<>
264 inline void
266  const PXL_Pixel<unsigned short,0> &from)
267 {
268  if(to.getBlack() == from.getBlack() && to.getWhite() == from.getWhite())
269  to.assign(from.getValue());
270  else
271  {
272  // ranges do not match -- convert to int and back.
273  to = (float) from;
274  }
275 }
276 
277 template<>
278 inline void
280  const PXL_Pixel<unsigned short,1> &from)
281 {
282  if(to.getBlack() == from.getBlack() && to.getWhite() == from.getWhite())
283  to.assign(from.getValue());
284  else
285  {
286  // ranges do not match -- convert to int and back.
287  to = (float) from;
288  }
289 }
290 
291 template<>
292 inline void
294  const PXL_Pixel<unsigned short,1> &from)
295 {
296  to.assign(from.getValue());
297 }
298 
299 template<>
300 inline void
302  const PXL_Pixel<unsigned int,0> &from)
303 {
304  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
305  to.assign((unsigned short) from);
306  else
307  to = (float) from;
308 }
309 
310 template<>
311 inline void
313  const PXL_Pixel<unsigned int,0> &from)
314 {
315  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
316  to.assign((unsigned short) from);
317  else
318  to = (float) from;
319 }
320 
321 template<>
322 inline void
324  const PXL_Pixel<unsigned int,1> &from)
325 {
326  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
327  to.assign((unsigned short) from);
328  else
329  to = (float) from;
330 }
331 
332 template<>
333 inline void
335  const PXL_Pixel<unsigned int,1> &from)
336 {
337  to.assign((unsigned short) from);
338 }
339 
340 // 32 bit conversions. -----------------------------------------------------
341 template<>
342 inline void
344  const PXL_Pixel<unsigned char,0> &from)
345 {
346  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
347  to.assign((unsigned int) from);
348  else
349  to = (float) from;
350 }
351 
352 template<>
353 inline void
355  const PXL_Pixel<unsigned char,0> &from)
356 {
357  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
358  to.assign(from);
359  else
360  to = (float) from;
361 }
362 
363 template<>
364 inline void
366  const PXL_Pixel<unsigned char,1> &from)
367 {
368  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
369  to.assign((unsigned int) from);
370  else
371  to = ((float) from);
372 }
373 
374 template<>
375 inline void
377  const PXL_Pixel<unsigned char,1> &from)
378 {
379  to.assign((unsigned int) from);
380 }
381 
382 template<>
383 inline void
385  const PXL_Pixel<unsigned short,0> &from)
386 {
387  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
388  to.set((unsigned int) from);
389  else
390  to = ((float) from);
391 }
392 
393 template<>
394 inline void
396  const PXL_Pixel<unsigned short,0> &from)
397 {
398  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
399  to.set(from);
400  else
401  to = ((float) from);
402 }
403 
404 template<>
405 inline void
407  const PXL_Pixel<unsigned short,1> &from)
408 {
409  if(to.getBlack() == 0 && to.getWhite() == to.maxValue())
410  to.assign(from);
411  else
412  to = ((float) from);
413 }
414 
415 template<>
416 inline void
418  const PXL_Pixel<unsigned short,1> &from)
419 {
420  to = ((float) from);
421 }
422 
423 template<>
424 inline void
426  const PXL_Pixel<unsigned int,0> &from)
427 {
428  if(to.getBlack() == from.getBlack() && to.getWhite() == from.getWhite())
429  {
430  to.set(from.getValue());
431  }
432  else
433  {
434  // ranges do not match -- convert to int and back.
435  to = ((float) from);
436  }
437 }
438 
439 template<>
440 inline void
442  const PXL_Pixel<unsigned int,0> &from)
443 {
444  if(to.getBlack() == from.getBlack() && to.getWhite() == from.getWhite())
445  {
446  to.set(from.getValue());
447  }
448  else
449  {
450  // ranges do not match -- convert to int and back.
451  to = ((float) from);
452  }
453 }
454 
455 template<>
456 inline void
458  const PXL_Pixel<unsigned int,1> &from)
459 {
460  if(to.getBlack() == from.getBlack() && to.getWhite() == from.getWhite())
461  {
462  to.set(from.getValue());
463  }
464  else
465  {
466  // ranges do not match -- convert to int and back.
467  to = ((float) from);
468  }
469 }
470 
471 template<>
472 inline void
474  const PXL_Pixel<unsigned int,1> &from)
475 {
476  to.set(from.getValue());
477 }
478 
479 template<>
480 inline void
482  const PXL_Pixel<float,1> &from)
483 {
484  fpreal16 val = from.getValue();
485  to.set(val);
486 }
487 
488 template<>
489 inline void
491  const PXL_Pixel<float,1> &from)
492 {
493  fpreal16 val = from.getValue();
494  to.set(val);
495 }
496 
497 template<>
498 inline void
500  const PXL_Pixel<float,0> &from)
501 {
502  fpreal16 val = from.getValue();
503  to.set(val);
504 }
505 
506 template<>
507 inline void
509  const PXL_Pixel<float,0> &from)
510 {
511  fpreal16 val = from.getValue();
512  to.set(val);
513 }
514 
515 #endif
unsigned int getBlack() const
Definition: PXL_Pixel.h:79
GLfloat f
Definition: glcorearb.h:1925
unsigned int getWhite() const
Definition: PXL_Pixel.h:78
Type getValue() const
Definition: PXL_Pixel.h:80
Type assign(unsigned int)
Type maxValue() const
GLuint GLfloat * val
Definition: glcorearb.h:1607
Type set(Type)
static void convert(PXL_Pixel< ToType, fast1 > &, const PXL_Pixel< FromType, fast2 > &)