HDK
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
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
19
PXL_Convert<ToType,fast1, FromType, fast2>::convert
(
PXL_Pixel<ToType,fast1>
&to,
20
const
PXL_Pixel<FromType,fast2>
&from)
21
{
22
to = ((
float
) from);
23
}
24
25
// 8 bit conversions
26
template
<>
27
inline
void
28
PXL_Convert<unsigned char,0,unsigned char,0>::convert
(
PXL_Pixel<unsigned char,0>
&to,
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
43
PXL_Convert<unsigned char,1,unsigned char,0>::convert
(
PXL_Pixel<unsigned char,1>
&to,
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
58
PXL_Convert<unsigned char,0,unsigned char,1>::convert
(
PXL_Pixel<unsigned char,0>
&to,
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
73
PXL_Convert<unsigned char,1,unsigned char,1>::convert
(
PXL_Pixel<unsigned char,1>
&to,
74
const
PXL_Pixel<unsigned char,1>
&from)
75
{
76
to.
assign
((
unsigned
char
) from.
getValue
());
77
}
78
79
template
<>
80
inline
void
81
PXL_Convert<unsigned char,0,unsigned short,0>::convert
(
PXL_Pixel<unsigned char,0>
&to,
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
95
PXL_Convert<unsigned char,0,unsigned short,1>::convert
(
PXL_Pixel<unsigned char,0>
&to,
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
109
PXL_Convert<unsigned char,1,unsigned short,0>::convert
(
PXL_Pixel<unsigned char,1>
&to,
110
const
PXL_Pixel<unsigned short,0>
&from)
111
{
112
to.
assign
((
unsigned
char
) from);
113
}
114
115
template
<>
116
inline
void
117
PXL_Convert<unsigned char,1,unsigned short,1>::convert
(
PXL_Pixel<unsigned char,1>
&to,
118
const
PXL_Pixel<unsigned short,1>
&from)
119
{
120
to.
assign
((
unsigned
char
) from);
121
}
122
123
124
template
<>
125
inline
void
126
PXL_Convert<unsigned char,0,unsigned int,0>::convert
(
PXL_Pixel<unsigned char,0>
&to,
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
137
PXL_Convert<unsigned char,1,unsigned int,0>::convert
(
PXL_Pixel<unsigned char,1>
&to,
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
148
PXL_Convert<unsigned char,0,unsigned int,1>::convert
(
PXL_Pixel<unsigned char,0>
&to,
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
159
PXL_Convert<unsigned char,1,unsigned int,1>::convert
(
PXL_Pixel<unsigned char,1>
&to,
160
const
PXL_Pixel<unsigned int,1>
&from)
161
{
162
to.
assign
((
unsigned
char
) from);
163
}
164
165
template
<>
166
inline
void
167
PXL_Convert<unsigned char,0,float,0>::convert
(
PXL_Pixel<unsigned char,0>
&to,
168
const
PXL_Pixel<float,0>
&from)
169
{
170
to = (
float
) from;
171
}
172
173
template
<>
174
inline
void
175
PXL_Convert<unsigned char,1,float,0>::convert
(
PXL_Pixel<unsigned char,1>
&to,
176
const
PXL_Pixel<float,0>
&from)
177
{
178
to = (
float
) from;
179
}
180
181
template
<>
182
inline
void
183
PXL_Convert<unsigned char,0,float,1>::convert
(
PXL_Pixel<unsigned char,0>
&to,
184
const
PXL_Pixel<float,1>
&from)
185
{
186
to = (
float
) from;
187
}
188
189
template
<>
190
inline
void
191
PXL_Convert<unsigned char,1,float,1>::convert
(
PXL_Pixel<unsigned char,1>
&to,
192
const
PXL_Pixel<float,1>
&from)
193
{
194
to = (
float
) from;
195
}
196
197
// 16 bit conversions. ----------------------------------------------------
198
199
template
<>
200
inline
void
201
PXL_Convert<unsigned short,0,unsigned char,0>::convert
(
PXL_Pixel<unsigned short,0>
&to,
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
215
PXL_Convert<unsigned short,1,unsigned char,0>::convert
(
PXL_Pixel<unsigned short,1>
&to,
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
229
PXL_Convert<unsigned short,0,unsigned char,1>::convert
(
PXL_Pixel<unsigned short,0>
&to,
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
243
PXL_Convert<unsigned short,1,unsigned char,1>::convert
(
PXL_Pixel<unsigned short,1>
&to,
244
const
PXL_Pixel<unsigned char,1>
&from)
245
{
246
to.
assign
((
unsigned
short
) from);
247
}
248
249
template
<>
250
inline
void
251
PXL_Convert<unsigned short,0,unsigned short,0>::convert
(
PXL_Pixel<unsigned short,0>
&to,
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
265
PXL_Convert<unsigned short,1,unsigned short,0>::convert
(
PXL_Pixel<unsigned short,1>
&to,
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
279
PXL_Convert<unsigned short,0,unsigned short,1>::convert
(
PXL_Pixel<unsigned short,0>
&to,
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
293
PXL_Convert<unsigned short,1,unsigned short,1>::convert
(
PXL_Pixel<unsigned short,1>
&to,
294
const
PXL_Pixel<unsigned short,1>
&from)
295
{
296
to.
assign
(from.
getValue
());
297
}
298
299
template
<>
300
inline
void
301
PXL_Convert<unsigned short,0,unsigned int,0>::convert
(
PXL_Pixel<unsigned short,0>
&to,
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
312
PXL_Convert<unsigned short,1,unsigned int,0>::convert
(
PXL_Pixel<unsigned short,1>
&to,
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
323
PXL_Convert<unsigned short,0,unsigned int,1>::convert
(
PXL_Pixel<unsigned short,0>
&to,
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
334
PXL_Convert<unsigned short,1,unsigned int,1>::convert
(
PXL_Pixel<unsigned short,1>
&to,
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
343
PXL_Convert<unsigned int,0,unsigned char,0>::convert
(
PXL_Pixel<unsigned int,0>
&to,
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
354
PXL_Convert<unsigned int,1,unsigned char,0>::convert
(
PXL_Pixel<unsigned int,1>
&to,
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
365
PXL_Convert<unsigned int,0,unsigned char,1>::convert
(
PXL_Pixel<unsigned int,0>
&to,
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
376
PXL_Convert<unsigned int,1,unsigned char,1>::convert
(
PXL_Pixel<unsigned int,1>
&to,
377
const
PXL_Pixel<unsigned char,1>
&from)
378
{
379
to.
assign
((
unsigned
int
) from);
380
}
381
382
template
<>
383
inline
void
384
PXL_Convert<unsigned int,0,unsigned short,0>::convert
(
PXL_Pixel<unsigned int,0>
&to,
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
395
PXL_Convert<unsigned int,1,unsigned short,0>::convert
(
PXL_Pixel<unsigned int,1>
&to,
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
406
PXL_Convert<unsigned int,0,unsigned short,1>::convert
(
PXL_Pixel<unsigned int,0>
&to,
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
417
PXL_Convert<unsigned int,1,unsigned short,1>::convert
(
PXL_Pixel<unsigned int,1>
&to,
418
const
PXL_Pixel<unsigned short,1>
&from)
419
{
420
to = ((
float
) from);
421
}
422
423
template
<>
424
inline
void
425
PXL_Convert<unsigned int,0,unsigned int,0>::convert
(
PXL_Pixel<unsigned int,0>
&to,
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
441
PXL_Convert<unsigned int,1,unsigned int,0>::convert
(
PXL_Pixel<unsigned int,1>
&to,
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
457
PXL_Convert<unsigned int,0,unsigned int,1>::convert
(
PXL_Pixel<unsigned int,0>
&to,
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
473
PXL_Convert<unsigned int,1,unsigned int,1>::convert
(
PXL_Pixel<unsigned int,1>
&to,
474
const
PXL_Pixel<unsigned int,1>
&from)
475
{
476
to.
set
(from.
getValue
());
477
}
478
479
template
<>
480
inline
void
481
PXL_Convert<fpreal16,1,float,1>::convert
(
PXL_Pixel<fpreal16,1>
&to,
482
const
PXL_Pixel<float,1>
&from)
483
{
484
fpreal16
val
= from.
getValue
();
485
to.
set
(val);
486
}
487
488
template
<>
489
inline
void
490
PXL_Convert<fpreal16,0,float,1>::convert
(
PXL_Pixel<fpreal16,0>
&to,
491
const
PXL_Pixel<float,1>
&from)
492
{
493
fpreal16
val
= from.
getValue
();
494
to.
set
(val);
495
}
496
497
template
<>
498
inline
void
499
PXL_Convert<fpreal16,0,float,0>::convert
(
PXL_Pixel<fpreal16,0>
&to,
500
const
PXL_Pixel<float,0>
&from)
501
{
502
fpreal16
val
= from.
getValue
();
503
to.
set
(val);
504
}
505
506
template
<>
507
inline
void
508
PXL_Convert<fpreal16,1,float,0>::convert
(
PXL_Pixel<fpreal16,1>
&to,
509
const
PXL_Pixel<float,0>
&from)
510
{
511
fpreal16
val
= from.
getValue
();
512
to.
set
(val);
513
}
514
515
#endif
PXL_Pixel
Definition:
PXL_Pixel.h:20
fpreal16
Definition:
fpreal16.h:99
PXL_Pixel::getBlack
unsigned int getBlack() const
Definition:
PXL_Pixel.h:79
f
GLfloat f
Definition:
glcorearb.h:1926
float
IMATH_NAMESPACE::V2f float
Definition:
ImfStandardAttributes.h:706
PXL_Pixel::getWhite
unsigned int getWhite() const
Definition:
PXL_Pixel.h:78
PXL_Pixel::getValue
Type getValue() const
Definition:
PXL_Pixel.h:80
PXL_Pixel::assign
Type assign(unsigned int)
Definition:
PXL_PixelImpl.h:1959
PXL_Pixel::maxValue
Type maxValue() const
PXL_Convert.h
val
GLuint GLfloat * val
Definition:
glcorearb.h:1608
PXL_Pixel::set
Type set(Type)
Definition:
PXL_PixelImpl.h:1972
PXL_Convert::convert
static void convert(PXL_Pixel< ToType, fast1 > &, const PXL_Pixel< FromType, fast2 > &)
Definition:
PXL_ConvertImpl.h:19
PXL
PXL_ConvertImpl.h
Generated on Fri Nov 8 2024 03:40:05 for HDK by
1.8.6