/src/dng_sdk/source/dng_reference.cpp
Line | Count | Source |
1 | | /*****************************************************************************/ |
2 | | // Copyright 2006-2009 Adobe Systems Incorporated |
3 | | // All Rights Reserved. |
4 | | // |
5 | | // NOTICE: Adobe permits you to use, modify, and distribute this file in |
6 | | // accordance with the terms of the Adobe license agreement accompanying it. |
7 | | /*****************************************************************************/ |
8 | | |
9 | | /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_reference.cpp#1 $ */ |
10 | | /* $DateTime: 2012/05/30 13:28:51 $ */ |
11 | | /* $Change: 832332 $ */ |
12 | | /* $Author: tknoll $ */ |
13 | | |
14 | | /*****************************************************************************/ |
15 | | |
16 | | #include "dng_reference.h" |
17 | | |
18 | | #include "dng_1d_table.h" |
19 | | #include "dng_hue_sat_map.h" |
20 | | #include "dng_matrix.h" |
21 | | #include "dng_resample.h" |
22 | | #include "dng_utils.h" |
23 | | |
24 | | /*****************************************************************************/ |
25 | | |
26 | | // This module contains routines that should be as fast as possible, even |
27 | | // at the expense of slight code size increases. |
28 | | |
29 | | #include "dng_fast_module.h" |
30 | | |
31 | | /*****************************************************************************/ |
32 | | |
33 | | void RefZeroBytes (void *dPtr, |
34 | | uint32 count) |
35 | 321k | { |
36 | | |
37 | 321k | memset (dPtr, 0, count); |
38 | | |
39 | 321k | } |
40 | | |
41 | | /*****************************************************************************/ |
42 | | |
43 | | void RefCopyBytes (const void *sPtr, |
44 | | void *dPtr, |
45 | | uint32 count) |
46 | 836M | { |
47 | | |
48 | 836M | memcpy (dPtr, sPtr, count); |
49 | | |
50 | 836M | } |
51 | | |
52 | | /*****************************************************************************/ |
53 | | |
54 | | void RefSwapBytes16 (uint16 *dPtr, |
55 | | uint32 count) |
56 | 0 | { |
57 | | |
58 | 0 | for (uint32 j = 0; j < count; j++) |
59 | 0 | { |
60 | | |
61 | 0 | dPtr [j] = SwapBytes16 (dPtr [j]); |
62 | | |
63 | 0 | } |
64 | | |
65 | 0 | } |
66 | | |
67 | | /*****************************************************************************/ |
68 | | |
69 | | void RefSwapBytes32 (uint32 *dPtr, |
70 | | uint32 count) |
71 | 0 | { |
72 | | |
73 | 0 | for (uint32 j = 0; j < count; j++) |
74 | 0 | { |
75 | | |
76 | 0 | dPtr [j] = SwapBytes32 (dPtr [j]); |
77 | | |
78 | 0 | } |
79 | | |
80 | 0 | } |
81 | | |
82 | | /*****************************************************************************/ |
83 | | |
84 | | void RefSetArea8 (uint8 *dPtr, |
85 | | uint8 value, |
86 | | uint32 rows, |
87 | | uint32 cols, |
88 | | uint32 planes, |
89 | | int32 rowStep, |
90 | | int32 colStep, |
91 | | int32 planeStep) |
92 | 14.5k | { |
93 | | |
94 | 275k | for (uint32 row = 0; row < rows; row++) |
95 | 261k | { |
96 | | |
97 | 261k | uint8 *dPtr1 = dPtr; |
98 | | |
99 | 2.07M | for (uint32 col = 0; col < cols; col++) |
100 | 1.81M | { |
101 | | |
102 | 1.81M | uint8 *dPtr2 = dPtr1; |
103 | | |
104 | 46.6M | for (uint32 plane = 0; plane < planes; plane++) |
105 | 44.8M | { |
106 | | |
107 | 44.8M | *dPtr2 = value; |
108 | | |
109 | 44.8M | dPtr2 += planeStep; |
110 | | |
111 | 44.8M | } |
112 | | |
113 | 1.81M | dPtr1 += colStep; |
114 | | |
115 | 1.81M | } |
116 | | |
117 | 261k | dPtr += rowStep; |
118 | | |
119 | 261k | } |
120 | | |
121 | 14.5k | } |
122 | | |
123 | | /*****************************************************************************/ |
124 | | |
125 | | void RefSetArea16 (uint16 *dPtr, |
126 | | uint16 value, |
127 | | uint32 rows, |
128 | | uint32 cols, |
129 | | uint32 planes, |
130 | | int32 rowStep, |
131 | | int32 colStep, |
132 | | int32 planeStep) |
133 | 46.7k | { |
134 | | |
135 | 1.40M | for (uint32 row = 0; row < rows; row++) |
136 | 1.35M | { |
137 | | |
138 | 1.35M | uint16 *dPtr1 = dPtr; |
139 | | |
140 | 25.4M | for (uint32 col = 0; col < cols; col++) |
141 | 24.0M | { |
142 | | |
143 | 24.0M | uint16 *dPtr2 = dPtr1; |
144 | | |
145 | 379M | for (uint32 plane = 0; plane < planes; plane++) |
146 | 355M | { |
147 | | |
148 | 355M | *dPtr2 = value; |
149 | | |
150 | 355M | dPtr2 += planeStep; |
151 | | |
152 | 355M | } |
153 | | |
154 | 24.0M | dPtr1 += colStep; |
155 | | |
156 | 24.0M | } |
157 | | |
158 | 1.35M | dPtr += rowStep; |
159 | | |
160 | 1.35M | } |
161 | | |
162 | 46.7k | } |
163 | | |
164 | | /*****************************************************************************/ |
165 | | |
166 | | void RefSetArea32 (uint32 *dPtr, |
167 | | uint32 value, |
168 | | uint32 rows, |
169 | | uint32 cols, |
170 | | uint32 planes, |
171 | | int32 rowStep, |
172 | | int32 colStep, |
173 | | int32 planeStep) |
174 | 15.1k | { |
175 | | |
176 | 446k | for (uint32 row = 0; row < rows; row++) |
177 | 431k | { |
178 | | |
179 | 431k | uint32 *dPtr1 = dPtr; |
180 | | |
181 | 3.64M | for (uint32 col = 0; col < cols; col++) |
182 | 3.21M | { |
183 | | |
184 | 3.21M | uint32 *dPtr2 = dPtr1; |
185 | | |
186 | 64.0M | for (uint32 plane = 0; plane < planes; plane++) |
187 | 60.8M | { |
188 | | |
189 | 60.8M | *dPtr2 = value; |
190 | | |
191 | 60.8M | dPtr2 += planeStep; |
192 | | |
193 | 60.8M | } |
194 | | |
195 | 3.21M | dPtr1 += colStep; |
196 | | |
197 | 3.21M | } |
198 | | |
199 | 431k | dPtr += rowStep; |
200 | | |
201 | 431k | } |
202 | | |
203 | 15.1k | } |
204 | | |
205 | | /*****************************************************************************/ |
206 | | |
207 | | void RefCopyArea8 (const uint8 *sPtr, |
208 | | uint8 *dPtr, |
209 | | uint32 rows, |
210 | | uint32 cols, |
211 | | uint32 planes, |
212 | | int32 sRowStep, |
213 | | int32 sColStep, |
214 | | int32 sPlaneStep, |
215 | | int32 dRowStep, |
216 | | int32 dColStep, |
217 | | int32 dPlaneStep) |
218 | 34.5k | { |
219 | | |
220 | 25.3M | for (uint32 row = 0; row < rows; row++) |
221 | 25.3M | { |
222 | | |
223 | 25.3M | const uint8 *sPtr1 = sPtr; |
224 | 25.3M | uint8 *dPtr1 = dPtr; |
225 | | |
226 | 260M | for (uint32 col = 0; col < cols; col++) |
227 | 235M | { |
228 | | |
229 | 235M | const uint8 *sPtr2 = sPtr1; |
230 | 235M | uint8 *dPtr2 = dPtr1; |
231 | | |
232 | 2.48G | for (uint32 plane = 0; plane < planes; plane++) |
233 | 2.24G | { |
234 | | |
235 | 2.24G | *dPtr2 = *sPtr2; |
236 | | |
237 | 2.24G | sPtr2 += sPlaneStep; |
238 | 2.24G | dPtr2 += dPlaneStep; |
239 | | |
240 | 2.24G | } |
241 | | |
242 | 235M | sPtr1 += sColStep; |
243 | 235M | dPtr1 += dColStep; |
244 | | |
245 | 235M | } |
246 | | |
247 | 25.3M | sPtr += sRowStep; |
248 | 25.3M | dPtr += dRowStep; |
249 | | |
250 | 25.3M | } |
251 | | |
252 | 34.5k | } |
253 | | |
254 | | /*****************************************************************************/ |
255 | | |
256 | | void RefCopyArea16 (const uint16 *sPtr, |
257 | | uint16 *dPtr, |
258 | | uint32 rows, |
259 | | uint32 cols, |
260 | | uint32 planes, |
261 | | int32 sRowStep, |
262 | | int32 sColStep, |
263 | | int32 sPlaneStep, |
264 | | int32 dRowStep, |
265 | | int32 dColStep, |
266 | | int32 dPlaneStep) |
267 | 928k | { |
268 | | |
269 | 5.81M | for (uint32 row = 0; row < rows; row++) |
270 | 4.88M | { |
271 | | |
272 | 4.88M | const uint16 *sPtr1 = sPtr; |
273 | 4.88M | uint16 *dPtr1 = dPtr; |
274 | | |
275 | 398M | for (uint32 col = 0; col < cols; col++) |
276 | 393M | { |
277 | | |
278 | 393M | const uint16 *sPtr2 = sPtr1; |
279 | 393M | uint16 *dPtr2 = dPtr1; |
280 | | |
281 | 9.79G | for (uint32 plane = 0; plane < planes; plane++) |
282 | 9.40G | { |
283 | | |
284 | 9.40G | *dPtr2 = *sPtr2; |
285 | | |
286 | 9.40G | sPtr2 += sPlaneStep; |
287 | 9.40G | dPtr2 += dPlaneStep; |
288 | | |
289 | 9.40G | } |
290 | | |
291 | 393M | sPtr1 += sColStep; |
292 | 393M | dPtr1 += dColStep; |
293 | | |
294 | 393M | } |
295 | | |
296 | 4.88M | sPtr += sRowStep; |
297 | 4.88M | dPtr += dRowStep; |
298 | | |
299 | 4.88M | } |
300 | | |
301 | 928k | } |
302 | | |
303 | | /*****************************************************************************/ |
304 | | |
305 | | void RefCopyArea32 (const uint32 *sPtr, |
306 | | uint32 *dPtr, |
307 | | uint32 rows, |
308 | | uint32 cols, |
309 | | uint32 planes, |
310 | | int32 sRowStep, |
311 | | int32 sColStep, |
312 | | int32 sPlaneStep, |
313 | | int32 dRowStep, |
314 | | int32 dColStep, |
315 | | int32 dPlaneStep) |
316 | 1.51M | { |
317 | | |
318 | 4.14M | for (uint32 row = 0; row < rows; row++) |
319 | 2.63M | { |
320 | | |
321 | 2.63M | const uint32 *sPtr1 = sPtr; |
322 | 2.63M | uint32 *dPtr1 = dPtr; |
323 | | |
324 | 174M | for (uint32 col = 0; col < cols; col++) |
325 | 172M | { |
326 | | |
327 | 172M | const uint32 *sPtr2 = sPtr1; |
328 | 172M | uint32 *dPtr2 = dPtr1; |
329 | | |
330 | 5.52G | for (uint32 plane = 0; plane < planes; plane++) |
331 | 5.34G | { |
332 | | |
333 | 5.34G | *dPtr2 = *sPtr2; |
334 | | |
335 | 5.34G | sPtr2 += sPlaneStep; |
336 | 5.34G | dPtr2 += dPlaneStep; |
337 | | |
338 | 5.34G | } |
339 | | |
340 | 172M | sPtr1 += sColStep; |
341 | 172M | dPtr1 += dColStep; |
342 | | |
343 | 172M | } |
344 | | |
345 | 2.63M | sPtr += sRowStep; |
346 | 2.63M | dPtr += dRowStep; |
347 | | |
348 | 2.63M | } |
349 | | |
350 | 1.51M | } |
351 | | |
352 | | /*****************************************************************************/ |
353 | | |
354 | | void RefCopyArea8_16 (const uint8 *sPtr, |
355 | | uint16 *dPtr, |
356 | | uint32 rows, |
357 | | uint32 cols, |
358 | | uint32 planes, |
359 | | int32 sRowStep, |
360 | | int32 sColStep, |
361 | | int32 sPlaneStep, |
362 | | int32 dRowStep, |
363 | | int32 dColStep, |
364 | | int32 dPlaneStep) |
365 | 13.2k | { |
366 | | |
367 | 26.4k | for (uint32 row = 0; row < rows; row++) |
368 | 13.2k | { |
369 | | |
370 | 13.2k | const uint8 *sPtr1 = sPtr; |
371 | 13.2k | uint16 *dPtr1 = dPtr; |
372 | | |
373 | 26.4k | for (uint32 col = 0; col < cols; col++) |
374 | 13.2k | { |
375 | | |
376 | 13.2k | const uint8 *sPtr2 = sPtr1; |
377 | 13.2k | uint16 *dPtr2 = dPtr1; |
378 | | |
379 | 129M | for (uint32 plane = 0; plane < planes; plane++) |
380 | 129M | { |
381 | | |
382 | 129M | *dPtr2 = *sPtr2; |
383 | | |
384 | 129M | sPtr2 += sPlaneStep; |
385 | 129M | dPtr2 += dPlaneStep; |
386 | | |
387 | 129M | } |
388 | | |
389 | 13.2k | sPtr1 += sColStep; |
390 | 13.2k | dPtr1 += dColStep; |
391 | | |
392 | 13.2k | } |
393 | | |
394 | 13.2k | sPtr += sRowStep; |
395 | 13.2k | dPtr += dRowStep; |
396 | | |
397 | 13.2k | } |
398 | | |
399 | 13.2k | } |
400 | | |
401 | | /*****************************************************************************/ |
402 | | |
403 | | void RefCopyArea8_S16 (const uint8 *sPtr, |
404 | | int16 *dPtr, |
405 | | uint32 rows, |
406 | | uint32 cols, |
407 | | uint32 planes, |
408 | | int32 sRowStep, |
409 | | int32 sColStep, |
410 | | int32 sPlaneStep, |
411 | | int32 dRowStep, |
412 | | int32 dColStep, |
413 | | int32 dPlaneStep) |
414 | 0 | { |
415 | | |
416 | 0 | for (uint32 row = 0; row < rows; row++) |
417 | 0 | { |
418 | | |
419 | 0 | const uint8 *sPtr1 = sPtr; |
420 | 0 | int16 *dPtr1 = dPtr; |
421 | | |
422 | 0 | for (uint32 col = 0; col < cols; col++) |
423 | 0 | { |
424 | | |
425 | 0 | const uint8 *sPtr2 = sPtr1; |
426 | 0 | int16 *dPtr2 = dPtr1; |
427 | | |
428 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
429 | 0 | { |
430 | | |
431 | 0 | int16 x = *sPtr; |
432 | | |
433 | 0 | *dPtr2 = x ^ 0x8000; |
434 | | |
435 | 0 | sPtr2 += sPlaneStep; |
436 | 0 | dPtr2 += dPlaneStep; |
437 | | |
438 | 0 | } |
439 | | |
440 | 0 | sPtr1 += sColStep; |
441 | 0 | dPtr1 += dColStep; |
442 | |
|
443 | 0 | } |
444 | | |
445 | 0 | sPtr += sRowStep; |
446 | 0 | dPtr += dRowStep; |
447 | | |
448 | 0 | } |
449 | | |
450 | 0 | } |
451 | | |
452 | | /*****************************************************************************/ |
453 | | |
454 | | void RefCopyArea8_32 (const uint8 *sPtr, |
455 | | uint32 *dPtr, |
456 | | uint32 rows, |
457 | | uint32 cols, |
458 | | uint32 planes, |
459 | | int32 sRowStep, |
460 | | int32 sColStep, |
461 | | int32 sPlaneStep, |
462 | | int32 dRowStep, |
463 | | int32 dColStep, |
464 | | int32 dPlaneStep) |
465 | 0 | { |
466 | | |
467 | 0 | for (uint32 row = 0; row < rows; row++) |
468 | 0 | { |
469 | | |
470 | 0 | const uint8 *sPtr1 = sPtr; |
471 | 0 | uint32 *dPtr1 = dPtr; |
472 | | |
473 | 0 | for (uint32 col = 0; col < cols; col++) |
474 | 0 | { |
475 | | |
476 | 0 | const uint8 *sPtr2 = sPtr1; |
477 | 0 | uint32 *dPtr2 = dPtr1; |
478 | | |
479 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
480 | 0 | { |
481 | | |
482 | 0 | *dPtr2 = *sPtr2; |
483 | | |
484 | 0 | sPtr2 += sPlaneStep; |
485 | 0 | dPtr2 += dPlaneStep; |
486 | | |
487 | 0 | } |
488 | | |
489 | 0 | sPtr1 += sColStep; |
490 | 0 | dPtr1 += dColStep; |
491 | |
|
492 | 0 | } |
493 | | |
494 | 0 | sPtr += sRowStep; |
495 | 0 | dPtr += dRowStep; |
496 | | |
497 | 0 | } |
498 | | |
499 | 0 | } |
500 | | |
501 | | /*****************************************************************************/ |
502 | | |
503 | | void RefCopyArea16_S16 (const uint16 *sPtr, |
504 | | int16 *dPtr, |
505 | | uint32 rows, |
506 | | uint32 cols, |
507 | | uint32 planes, |
508 | | int32 sRowStep, |
509 | | int32 sColStep, |
510 | | int32 sPlaneStep, |
511 | | int32 dRowStep, |
512 | | int32 dColStep, |
513 | | int32 dPlaneStep) |
514 | 0 | { |
515 | | |
516 | 0 | for (uint32 row = 0; row < rows; row++) |
517 | 0 | { |
518 | | |
519 | 0 | const uint16 *sPtr1 = sPtr; |
520 | 0 | int16 *dPtr1 = dPtr; |
521 | | |
522 | 0 | for (uint32 col = 0; col < cols; col++) |
523 | 0 | { |
524 | | |
525 | 0 | const uint16 *sPtr2 = sPtr1; |
526 | 0 | int16 *dPtr2 = dPtr1; |
527 | | |
528 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
529 | 0 | { |
530 | | |
531 | 0 | *dPtr2 = *sPtr2 ^ 0x8000; |
532 | | |
533 | 0 | sPtr2 += sPlaneStep; |
534 | 0 | dPtr2 += dPlaneStep; |
535 | | |
536 | 0 | } |
537 | | |
538 | 0 | sPtr1 += sColStep; |
539 | 0 | dPtr1 += dColStep; |
540 | |
|
541 | 0 | } |
542 | | |
543 | 0 | sPtr += sRowStep; |
544 | 0 | dPtr += dRowStep; |
545 | | |
546 | 0 | } |
547 | | |
548 | 0 | } |
549 | | |
550 | | /*****************************************************************************/ |
551 | | |
552 | | void RefCopyArea16_32 (const uint16 *sPtr, |
553 | | uint32 *dPtr, |
554 | | uint32 rows, |
555 | | uint32 cols, |
556 | | uint32 planes, |
557 | | int32 sRowStep, |
558 | | int32 sColStep, |
559 | | int32 sPlaneStep, |
560 | | int32 dRowStep, |
561 | | int32 dColStep, |
562 | | int32 dPlaneStep) |
563 | 0 | { |
564 | | |
565 | 0 | for (uint32 row = 0; row < rows; row++) |
566 | 0 | { |
567 | | |
568 | 0 | const uint16 *sPtr1 = sPtr; |
569 | 0 | uint32 *dPtr1 = dPtr; |
570 | | |
571 | 0 | for (uint32 col = 0; col < cols; col++) |
572 | 0 | { |
573 | | |
574 | 0 | const uint16 *sPtr2 = sPtr1; |
575 | 0 | uint32 *dPtr2 = dPtr1; |
576 | | |
577 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
578 | 0 | { |
579 | | |
580 | 0 | *dPtr2 = *sPtr2; |
581 | | |
582 | 0 | sPtr2 += sPlaneStep; |
583 | 0 | dPtr2 += dPlaneStep; |
584 | | |
585 | 0 | } |
586 | | |
587 | 0 | sPtr1 += sColStep; |
588 | 0 | dPtr1 += dColStep; |
589 | |
|
590 | 0 | } |
591 | | |
592 | 0 | sPtr += sRowStep; |
593 | 0 | dPtr += dRowStep; |
594 | | |
595 | 0 | } |
596 | | |
597 | 0 | } |
598 | | |
599 | | /*****************************************************************************/ |
600 | | |
601 | | void RefCopyArea8_R32 (const uint8 *sPtr, |
602 | | real32 *dPtr, |
603 | | uint32 rows, |
604 | | uint32 cols, |
605 | | uint32 planes, |
606 | | int32 sRowStep, |
607 | | int32 sColStep, |
608 | | int32 sPlaneStep, |
609 | | int32 dRowStep, |
610 | | int32 dColStep, |
611 | | int32 dPlaneStep, |
612 | | uint32 pixelRange) |
613 | 0 | { |
614 | | |
615 | 0 | real32 scale = 1.0f / (real32) pixelRange; |
616 | | |
617 | 0 | for (uint32 row = 0; row < rows; row++) |
618 | 0 | { |
619 | | |
620 | 0 | const uint8 *sPtr1 = sPtr; |
621 | 0 | real32 *dPtr1 = dPtr; |
622 | | |
623 | 0 | for (uint32 col = 0; col < cols; col++) |
624 | 0 | { |
625 | | |
626 | 0 | const uint8 *sPtr2 = sPtr1; |
627 | 0 | real32 *dPtr2 = dPtr1; |
628 | | |
629 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
630 | 0 | { |
631 | | |
632 | 0 | *dPtr2 = scale * (real32) *sPtr2; |
633 | | |
634 | 0 | sPtr2 += sPlaneStep; |
635 | 0 | dPtr2 += dPlaneStep; |
636 | | |
637 | 0 | } |
638 | | |
639 | 0 | sPtr1 += sColStep; |
640 | 0 | dPtr1 += dColStep; |
641 | |
|
642 | 0 | } |
643 | | |
644 | 0 | sPtr += sRowStep; |
645 | 0 | dPtr += dRowStep; |
646 | | |
647 | 0 | } |
648 | | |
649 | 0 | } |
650 | | |
651 | | /*****************************************************************************/ |
652 | | |
653 | | void RefCopyArea16_R32 (const uint16 *sPtr, |
654 | | real32 *dPtr, |
655 | | uint32 rows, |
656 | | uint32 cols, |
657 | | uint32 planes, |
658 | | int32 sRowStep, |
659 | | int32 sColStep, |
660 | | int32 sPlaneStep, |
661 | | int32 dRowStep, |
662 | | int32 dColStep, |
663 | | int32 dPlaneStep, |
664 | | uint32 pixelRange) |
665 | 366k | { |
666 | | |
667 | 366k | real32 scale = 1.0f / (real32) pixelRange; |
668 | | |
669 | 2.77M | for (uint32 row = 0; row < rows; row++) |
670 | 2.41M | { |
671 | | |
672 | 2.41M | const uint16 *sPtr1 = sPtr; |
673 | 2.41M | real32 *dPtr1 = dPtr; |
674 | | |
675 | 190M | for (uint32 col = 0; col < cols; col++) |
676 | 188M | { |
677 | | |
678 | 188M | const uint16 *sPtr2 = sPtr1; |
679 | 188M | real32 *dPtr2 = dPtr1; |
680 | | |
681 | 1.65G | for (uint32 plane = 0; plane < planes; plane++) |
682 | 1.46G | { |
683 | | |
684 | 1.46G | *dPtr2 = scale * (real32) *sPtr2; |
685 | | |
686 | 1.46G | sPtr2 += sPlaneStep; |
687 | 1.46G | dPtr2 += dPlaneStep; |
688 | | |
689 | 1.46G | } |
690 | | |
691 | 188M | sPtr1 += sColStep; |
692 | 188M | dPtr1 += dColStep; |
693 | | |
694 | 188M | } |
695 | | |
696 | 2.41M | sPtr += sRowStep; |
697 | 2.41M | dPtr += dRowStep; |
698 | | |
699 | 2.41M | } |
700 | | |
701 | 366k | } |
702 | | |
703 | | /*****************************************************************************/ |
704 | | |
705 | | void RefCopyAreaS16_R32 (const int16 *sPtr, |
706 | | real32 *dPtr, |
707 | | uint32 rows, |
708 | | uint32 cols, |
709 | | uint32 planes, |
710 | | int32 sRowStep, |
711 | | int32 sColStep, |
712 | | int32 sPlaneStep, |
713 | | int32 dRowStep, |
714 | | int32 dColStep, |
715 | | int32 dPlaneStep, |
716 | | uint32 pixelRange) |
717 | 0 | { |
718 | | |
719 | 0 | real32 scale = 1.0f / (real32) pixelRange; |
720 | | |
721 | 0 | for (uint32 row = 0; row < rows; row++) |
722 | 0 | { |
723 | | |
724 | 0 | const int16 *sPtr1 = sPtr; |
725 | 0 | real32 *dPtr1 = dPtr; |
726 | | |
727 | 0 | for (uint32 col = 0; col < cols; col++) |
728 | 0 | { |
729 | | |
730 | 0 | const int16 *sPtr2 = sPtr1; |
731 | 0 | real32 *dPtr2 = dPtr1; |
732 | | |
733 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
734 | 0 | { |
735 | | |
736 | 0 | int32 x = (*sPtr ^ 0x8000); |
737 | | |
738 | 0 | *dPtr2 = scale * (real32) x; |
739 | | |
740 | 0 | sPtr2 += sPlaneStep; |
741 | 0 | dPtr2 += dPlaneStep; |
742 | | |
743 | 0 | } |
744 | | |
745 | 0 | sPtr1 += sColStep; |
746 | 0 | dPtr1 += dColStep; |
747 | |
|
748 | 0 | } |
749 | | |
750 | 0 | sPtr += sRowStep; |
751 | 0 | dPtr += dRowStep; |
752 | | |
753 | 0 | } |
754 | | |
755 | 0 | } |
756 | | |
757 | | /*****************************************************************************/ |
758 | | |
759 | | void RefCopyAreaR32_8 (const real32 *sPtr, |
760 | | uint8 *dPtr, |
761 | | uint32 rows, |
762 | | uint32 cols, |
763 | | uint32 planes, |
764 | | int32 sRowStep, |
765 | | int32 sColStep, |
766 | | int32 sPlaneStep, |
767 | | int32 dRowStep, |
768 | | int32 dColStep, |
769 | | int32 dPlaneStep, |
770 | | uint32 pixelRange) |
771 | 841k | { |
772 | | |
773 | 841k | real32 scale = (real32) pixelRange; |
774 | | |
775 | 24.7M | for (uint32 row = 0; row < rows; row++) |
776 | 23.8M | { |
777 | | |
778 | 23.8M | const real32 *sPtr1 = sPtr; |
779 | 23.8M | uint8 *dPtr1 = dPtr; |
780 | | |
781 | 1.64G | for (uint32 col = 0; col < cols; col++) |
782 | 1.62G | { |
783 | | |
784 | 1.62G | const real32 *sPtr2 = sPtr1; |
785 | 1.62G | uint8 *dPtr2 = dPtr1; |
786 | | |
787 | 7.26G | for (uint32 plane = 0; plane < planes; plane++) |
788 | 5.64G | { |
789 | | |
790 | 5.64G | *dPtr2 = (uint8) (Pin_Overrange (*sPtr2) * scale + 0.5f); |
791 | | |
792 | 5.64G | sPtr2 += sPlaneStep; |
793 | 5.64G | dPtr2 += dPlaneStep; |
794 | | |
795 | 5.64G | } |
796 | | |
797 | 1.62G | sPtr1 += sColStep; |
798 | 1.62G | dPtr1 += dColStep; |
799 | | |
800 | 1.62G | } |
801 | | |
802 | 23.8M | sPtr += sRowStep; |
803 | 23.8M | dPtr += dRowStep; |
804 | | |
805 | 23.8M | } |
806 | | |
807 | 841k | } |
808 | | |
809 | | /*****************************************************************************/ |
810 | | |
811 | | void RefCopyAreaR32_16 (const real32 *sPtr, |
812 | | uint16 *dPtr, |
813 | | uint32 rows, |
814 | | uint32 cols, |
815 | | uint32 planes, |
816 | | int32 sRowStep, |
817 | | int32 sColStep, |
818 | | int32 sPlaneStep, |
819 | | int32 dRowStep, |
820 | | int32 dColStep, |
821 | | int32 dPlaneStep, |
822 | | uint32 pixelRange) |
823 | 68.0k | { |
824 | | |
825 | 68.0k | real32 scale = (real32) pixelRange; |
826 | | |
827 | 1.94M | for (uint32 row = 0; row < rows; row++) |
828 | 1.88M | { |
829 | | |
830 | 1.88M | const real32 *sPtr1 = sPtr; |
831 | 1.88M | uint16 *dPtr1 = dPtr; |
832 | | |
833 | 151M | for (uint32 col = 0; col < cols; col++) |
834 | 149M | { |
835 | | |
836 | 149M | const real32 *sPtr2 = sPtr1; |
837 | 149M | uint16 *dPtr2 = dPtr1; |
838 | | |
839 | 631M | for (uint32 plane = 0; plane < planes; plane++) |
840 | 481M | { |
841 | | |
842 | 481M | *dPtr2 = (uint16) (Pin_Overrange (*sPtr2) * scale + 0.5f); |
843 | | |
844 | 481M | sPtr2 += sPlaneStep; |
845 | 481M | dPtr2 += dPlaneStep; |
846 | | |
847 | 481M | } |
848 | | |
849 | 149M | sPtr1 += sColStep; |
850 | 149M | dPtr1 += dColStep; |
851 | | |
852 | 149M | } |
853 | | |
854 | 1.88M | sPtr += sRowStep; |
855 | 1.88M | dPtr += dRowStep; |
856 | | |
857 | 1.88M | } |
858 | | |
859 | 68.0k | } |
860 | | |
861 | | /*****************************************************************************/ |
862 | | |
863 | | void RefCopyAreaR32_S16 (const real32 *sPtr, |
864 | | int16 *dPtr, |
865 | | uint32 rows, |
866 | | uint32 cols, |
867 | | uint32 planes, |
868 | | int32 sRowStep, |
869 | | int32 sColStep, |
870 | | int32 sPlaneStep, |
871 | | int32 dRowStep, |
872 | | int32 dColStep, |
873 | | int32 dPlaneStep, |
874 | | uint32 pixelRange) |
875 | 0 | { |
876 | | |
877 | 0 | real32 scale = (real32) pixelRange; |
878 | | |
879 | 0 | for (uint32 row = 0; row < rows; row++) |
880 | 0 | { |
881 | | |
882 | 0 | const real32 *sPtr1 = sPtr; |
883 | 0 | int16 *dPtr1 = dPtr; |
884 | | |
885 | 0 | for (uint32 col = 0; col < cols; col++) |
886 | 0 | { |
887 | | |
888 | 0 | const real32 *sPtr2 = sPtr1; |
889 | 0 | int16 *dPtr2 = dPtr1; |
890 | | |
891 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
892 | 0 | { |
893 | | |
894 | 0 | int32 x = (int32) (Pin_Overrange (*sPtr2) * scale + 0.5f); |
895 | | |
896 | 0 | *dPtr2 = (int16) (x ^ 0x8000); |
897 | | |
898 | 0 | sPtr2 += sPlaneStep; |
899 | 0 | dPtr2 += dPlaneStep; |
900 | | |
901 | 0 | } |
902 | | |
903 | 0 | sPtr1 += sColStep; |
904 | 0 | dPtr1 += dColStep; |
905 | |
|
906 | 0 | } |
907 | | |
908 | 0 | sPtr += sRowStep; |
909 | 0 | dPtr += dRowStep; |
910 | | |
911 | 0 | } |
912 | | |
913 | 0 | } |
914 | | |
915 | | /*****************************************************************************/ |
916 | | |
917 | | void RefRepeatArea8 (const uint8 *sPtr, |
918 | | uint8 *dPtr, |
919 | | uint32 rows, |
920 | | uint32 cols, |
921 | | uint32 planes, |
922 | | int32 rowStep, |
923 | | int32 colStep, |
924 | | int32 planeStep, |
925 | | uint32 repeatV, |
926 | | uint32 repeatH, |
927 | | uint32 phaseV, |
928 | | uint32 phaseH) |
929 | 0 | { |
930 | | |
931 | 0 | const uint8 *sPtr0 = sPtr + phaseV * rowStep + |
932 | 0 | phaseH * colStep; |
933 | | |
934 | 0 | int32 backStepV = (repeatV - 1) * rowStep; |
935 | 0 | int32 backStepH = (repeatH - 1) * colStep; |
936 | | |
937 | 0 | for (uint32 row = 0; row < rows; row++) |
938 | 0 | { |
939 | | |
940 | 0 | const uint8 *sPtr1 = sPtr0; |
941 | 0 | uint8 *dPtr1 = dPtr; |
942 | | |
943 | 0 | uint32 colPhase = phaseH; |
944 | | |
945 | 0 | for (uint32 col = 0; col < cols; col++) |
946 | 0 | { |
947 | | |
948 | 0 | const uint8 *sPtr2 = sPtr1; |
949 | 0 | uint8 *dPtr2 = dPtr1; |
950 | | |
951 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
952 | 0 | { |
953 | | |
954 | 0 | *dPtr2 = *sPtr2; |
955 | | |
956 | 0 | sPtr2 += planeStep; |
957 | 0 | dPtr2 += planeStep; |
958 | | |
959 | 0 | } |
960 | | |
961 | 0 | if (++colPhase == repeatH) |
962 | 0 | { |
963 | 0 | colPhase = 0; |
964 | 0 | sPtr1 -= backStepH; |
965 | 0 | } |
966 | 0 | else |
967 | 0 | { |
968 | 0 | sPtr1 += colStep; |
969 | 0 | } |
970 | | |
971 | 0 | dPtr1 += colStep; |
972 | | |
973 | 0 | } |
974 | | |
975 | 0 | if (++phaseV == repeatV) |
976 | 0 | { |
977 | 0 | phaseV = 0; |
978 | 0 | sPtr0 -= backStepV; |
979 | 0 | } |
980 | 0 | else |
981 | 0 | { |
982 | 0 | sPtr0 += rowStep; |
983 | 0 | } |
984 | | |
985 | 0 | dPtr += rowStep; |
986 | | |
987 | 0 | } |
988 | | |
989 | 0 | } |
990 | | |
991 | | /*****************************************************************************/ |
992 | | |
993 | | void RefRepeatArea16 (const uint16 *sPtr, |
994 | | uint16 *dPtr, |
995 | | uint32 rows, |
996 | | uint32 cols, |
997 | | uint32 planes, |
998 | | int32 rowStep, |
999 | | int32 colStep, |
1000 | | int32 planeStep, |
1001 | | uint32 repeatV, |
1002 | | uint32 repeatH, |
1003 | | uint32 phaseV, |
1004 | | uint32 phaseH) |
1005 | 1.08M | { |
1006 | | |
1007 | 1.08M | const uint16 *sPtr0 = sPtr + phaseV * rowStep + |
1008 | 1.08M | phaseH * colStep; |
1009 | | |
1010 | 1.08M | int32 backStepV = (repeatV - 1) * rowStep; |
1011 | 1.08M | int32 backStepH = (repeatH - 1) * colStep; |
1012 | | |
1013 | 108M | for (uint32 row = 0; row < rows; row++) |
1014 | 107M | { |
1015 | | |
1016 | 107M | const uint16 *sPtr1 = sPtr0; |
1017 | 107M | uint16 *dPtr1 = dPtr; |
1018 | | |
1019 | 107M | uint32 colPhase = phaseH; |
1020 | | |
1021 | 3.72G | for (uint32 col = 0; col < cols; col++) |
1022 | 3.61G | { |
1023 | | |
1024 | 3.61G | const uint16 *sPtr2 = sPtr1; |
1025 | 3.61G | uint16 *dPtr2 = dPtr1; |
1026 | | |
1027 | 7.78G | for (uint32 plane = 0; plane < planes; plane++) |
1028 | 4.17G | { |
1029 | | |
1030 | 4.17G | *dPtr2 = *sPtr2; |
1031 | | |
1032 | 4.17G | sPtr2 += planeStep; |
1033 | 4.17G | dPtr2 += planeStep; |
1034 | | |
1035 | 4.17G | } |
1036 | | |
1037 | 3.61G | if (++colPhase == repeatH) |
1038 | 2.08G | { |
1039 | 2.08G | colPhase = 0; |
1040 | 2.08G | sPtr1 -= backStepH; |
1041 | 2.08G | } |
1042 | 1.53G | else |
1043 | 1.53G | { |
1044 | 1.53G | sPtr1 += colStep; |
1045 | 1.53G | } |
1046 | | |
1047 | 3.61G | dPtr1 += colStep; |
1048 | | |
1049 | 3.61G | } |
1050 | | |
1051 | 107M | if (++phaseV == repeatV) |
1052 | 77.1M | { |
1053 | 77.1M | phaseV = 0; |
1054 | 77.1M | sPtr0 -= backStepV; |
1055 | 77.1M | } |
1056 | 30.5M | else |
1057 | 30.5M | { |
1058 | 30.5M | sPtr0 += rowStep; |
1059 | 30.5M | } |
1060 | | |
1061 | 107M | dPtr += rowStep; |
1062 | | |
1063 | 107M | } |
1064 | | |
1065 | 1.08M | } |
1066 | | |
1067 | | /*****************************************************************************/ |
1068 | | |
1069 | | void RefRepeatArea32 (const uint32 *sPtr, |
1070 | | uint32 *dPtr, |
1071 | | uint32 rows, |
1072 | | uint32 cols, |
1073 | | uint32 planes, |
1074 | | int32 rowStep, |
1075 | | int32 colStep, |
1076 | | int32 planeStep, |
1077 | | uint32 repeatV, |
1078 | | uint32 repeatH, |
1079 | | uint32 phaseV, |
1080 | | uint32 phaseH) |
1081 | 1.66M | { |
1082 | | |
1083 | 1.66M | const uint32 *sPtr0 = sPtr + phaseV * rowStep + |
1084 | 1.66M | phaseH * colStep; |
1085 | | |
1086 | 1.66M | int32 backStepV = (repeatV - 1) * rowStep; |
1087 | 1.66M | int32 backStepH = (repeatH - 1) * colStep; |
1088 | | |
1089 | 39.8M | for (uint32 row = 0; row < rows; row++) |
1090 | 38.2M | { |
1091 | | |
1092 | 38.2M | const uint32 *sPtr1 = sPtr0; |
1093 | 38.2M | uint32 *dPtr1 = dPtr; |
1094 | | |
1095 | 38.2M | uint32 colPhase = phaseH; |
1096 | | |
1097 | 1.58G | for (uint32 col = 0; col < cols; col++) |
1098 | 1.54G | { |
1099 | | |
1100 | 1.54G | const uint32 *sPtr2 = sPtr1; |
1101 | 1.54G | uint32 *dPtr2 = dPtr1; |
1102 | | |
1103 | 3.30G | for (uint32 plane = 0; plane < planes; plane++) |
1104 | 1.75G | { |
1105 | | |
1106 | 1.75G | *dPtr2 = *sPtr2; |
1107 | | |
1108 | 1.75G | sPtr2 += planeStep; |
1109 | 1.75G | dPtr2 += planeStep; |
1110 | | |
1111 | 1.75G | } |
1112 | | |
1113 | 1.54G | if (++colPhase == repeatH) |
1114 | 1.14G | { |
1115 | 1.14G | colPhase = 0; |
1116 | 1.14G | sPtr1 -= backStepH; |
1117 | 1.14G | } |
1118 | 404M | else |
1119 | 404M | { |
1120 | 404M | sPtr1 += colStep; |
1121 | 404M | } |
1122 | | |
1123 | 1.54G | dPtr1 += colStep; |
1124 | | |
1125 | 1.54G | } |
1126 | | |
1127 | 38.2M | if (++phaseV == repeatV) |
1128 | 19.1M | { |
1129 | 19.1M | phaseV = 0; |
1130 | 19.1M | sPtr0 -= backStepV; |
1131 | 19.1M | } |
1132 | 19.1M | else |
1133 | 19.1M | { |
1134 | 19.1M | sPtr0 += rowStep; |
1135 | 19.1M | } |
1136 | | |
1137 | 38.2M | dPtr += rowStep; |
1138 | | |
1139 | 38.2M | } |
1140 | | |
1141 | 1.66M | } |
1142 | | |
1143 | | /*****************************************************************************/ |
1144 | | |
1145 | | void RefShiftRight16 (uint16 *dPtr, |
1146 | | uint32 rows, |
1147 | | uint32 cols, |
1148 | | uint32 planes, |
1149 | | int32 rowStep, |
1150 | | int32 colStep, |
1151 | | int32 planeStep, |
1152 | | uint32 shift) |
1153 | 0 | { |
1154 | | |
1155 | 0 | for (uint32 row = 0; row < rows; row++) |
1156 | 0 | { |
1157 | | |
1158 | 0 | uint16 *dPtr1 = dPtr; |
1159 | | |
1160 | 0 | for (uint32 col = 0; col < cols; col++) |
1161 | 0 | { |
1162 | | |
1163 | 0 | uint16 *dPtr2 = dPtr1; |
1164 | | |
1165 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
1166 | 0 | { |
1167 | | |
1168 | 0 | *dPtr2 >>= shift; |
1169 | | |
1170 | 0 | dPtr2 += planeStep; |
1171 | | |
1172 | 0 | } |
1173 | | |
1174 | 0 | dPtr1 += colStep; |
1175 | |
|
1176 | 0 | } |
1177 | | |
1178 | 0 | dPtr += rowStep; |
1179 | | |
1180 | 0 | } |
1181 | | |
1182 | 0 | } |
1183 | | |
1184 | | /*****************************************************************************/ |
1185 | | |
1186 | | void RefBilinearRow16 (const uint16 *sPtr, |
1187 | | uint16 *dPtr, |
1188 | | uint32 cols, |
1189 | | uint32 patPhase, |
1190 | | uint32 patCount, |
1191 | | const uint32 * kernCounts, |
1192 | | const int32 * const * kernOffsets, |
1193 | | const uint16 * const * kernWeights, |
1194 | | uint32 sShift) |
1195 | 1.44M | { |
1196 | | |
1197 | 41.7M | for (uint32 j = 0; j < cols; j++) |
1198 | 40.2M | { |
1199 | | |
1200 | 40.2M | const uint16 *p = sPtr + (j >> sShift); |
1201 | | |
1202 | 40.2M | uint32 count = kernCounts [patPhase]; |
1203 | | |
1204 | 40.2M | const int32 *offsets = kernOffsets [patPhase]; |
1205 | 40.2M | const uint16 *weights = kernWeights [patPhase]; |
1206 | | |
1207 | 40.2M | if (++patPhase == patCount) |
1208 | 18.2M | { |
1209 | 18.2M | patPhase = 0; |
1210 | 18.2M | } |
1211 | | |
1212 | 40.2M | uint32 total = 128; |
1213 | | |
1214 | 127M | for (uint32 k = 0; k < count; k++) |
1215 | 87.1M | { |
1216 | | |
1217 | 87.1M | int32 offset = offsets [k]; |
1218 | 87.1M | uint32 weight = weights [k]; |
1219 | | |
1220 | 87.1M | uint32 pixel = p [offset]; |
1221 | | |
1222 | 87.1M | total += pixel * weight; |
1223 | | |
1224 | 87.1M | } |
1225 | | |
1226 | 40.2M | dPtr [j] = (uint16) (total >> 8); |
1227 | | |
1228 | 40.2M | } |
1229 | | |
1230 | 1.44M | } |
1231 | | |
1232 | | /*****************************************************************************/ |
1233 | | |
1234 | | void RefBilinearRow32 (const real32 *sPtr, |
1235 | | real32 *dPtr, |
1236 | | uint32 cols, |
1237 | | uint32 patPhase, |
1238 | | uint32 patCount, |
1239 | | const uint32 * kernCounts, |
1240 | | const int32 * const * kernOffsets, |
1241 | | const real32 * const * kernWeights, |
1242 | | uint32 sShift) |
1243 | 1.40M | { |
1244 | | |
1245 | 67.8M | for (uint32 j = 0; j < cols; j++) |
1246 | 66.4M | { |
1247 | | |
1248 | 66.4M | const real32 *p = sPtr + (j >> sShift); |
1249 | | |
1250 | 66.4M | uint32 count = kernCounts [patPhase]; |
1251 | | |
1252 | 66.4M | const int32 *offsets = kernOffsets [patPhase]; |
1253 | 66.4M | const real32 *weights = kernWeights [patPhase]; |
1254 | | |
1255 | 66.4M | if (++patPhase == patCount) |
1256 | 32.8M | { |
1257 | 32.8M | patPhase = 0; |
1258 | 32.8M | } |
1259 | | |
1260 | 66.4M | real32 total = 0.0f; |
1261 | | |
1262 | 219M | for (uint32 k = 0; k < count; k++) |
1263 | 153M | { |
1264 | | |
1265 | 153M | int32 offset = offsets [k]; |
1266 | 153M | real32 weight = weights [k]; |
1267 | | |
1268 | 153M | real32 pixel = p [offset]; |
1269 | | |
1270 | 153M | total += pixel * weight; |
1271 | | |
1272 | 153M | } |
1273 | | |
1274 | 66.4M | dPtr [j] = total; |
1275 | | |
1276 | 66.4M | } |
1277 | | |
1278 | 1.40M | } |
1279 | | |
1280 | | /*****************************************************************************/ |
1281 | | |
1282 | | void RefBaselineABCtoRGB (const real32 *sPtrA, |
1283 | | const real32 *sPtrB, |
1284 | | const real32 *sPtrC, |
1285 | | real32 *dPtrR, |
1286 | | real32 *dPtrG, |
1287 | | real32 *dPtrB, |
1288 | | uint32 count, |
1289 | | const dng_vector &cameraWhite, |
1290 | | const dng_matrix &cameraToRGB) |
1291 | 414k | { |
1292 | | |
1293 | 414k | real32 clipA = (real32) cameraWhite [0]; |
1294 | 414k | real32 clipB = (real32) cameraWhite [1]; |
1295 | 414k | real32 clipC = (real32) cameraWhite [2]; |
1296 | | |
1297 | 414k | real32 m00 = (real32) cameraToRGB [0] [0]; |
1298 | 414k | real32 m01 = (real32) cameraToRGB [0] [1]; |
1299 | 414k | real32 m02 = (real32) cameraToRGB [0] [2]; |
1300 | | |
1301 | 414k | real32 m10 = (real32) cameraToRGB [1] [0]; |
1302 | 414k | real32 m11 = (real32) cameraToRGB [1] [1]; |
1303 | 414k | real32 m12 = (real32) cameraToRGB [1] [2]; |
1304 | | |
1305 | 414k | real32 m20 = (real32) cameraToRGB [2] [0]; |
1306 | 414k | real32 m21 = (real32) cameraToRGB [2] [1]; |
1307 | 414k | real32 m22 = (real32) cameraToRGB [2] [2]; |
1308 | | |
1309 | 49.3M | for (uint32 col = 0; col < count; col++) |
1310 | 48.9M | { |
1311 | | |
1312 | 48.9M | real32 A = sPtrA [col]; |
1313 | 48.9M | real32 B = sPtrB [col]; |
1314 | 48.9M | real32 C = sPtrC [col]; |
1315 | | |
1316 | 48.9M | A = Min_real32 (A, clipA); |
1317 | 48.9M | B = Min_real32 (B, clipB); |
1318 | 48.9M | C = Min_real32 (C, clipC); |
1319 | | |
1320 | 48.9M | real32 r = m00 * A + m01 * B + m02 * C; |
1321 | 48.9M | real32 g = m10 * A + m11 * B + m12 * C; |
1322 | 48.9M | real32 b = m20 * A + m21 * B + m22 * C; |
1323 | | |
1324 | 48.9M | r = Pin_real32 (0.0f, r, 1.0f); |
1325 | 48.9M | g = Pin_real32 (0.0f, g, 1.0f); |
1326 | 48.9M | b = Pin_real32 (0.0f, b, 1.0f); |
1327 | | |
1328 | 48.9M | dPtrR [col] = r; |
1329 | 48.9M | dPtrG [col] = g; |
1330 | 48.9M | dPtrB [col] = b; |
1331 | | |
1332 | 48.9M | } |
1333 | | |
1334 | 414k | } |
1335 | | |
1336 | | /*****************************************************************************/ |
1337 | | |
1338 | | void RefBaselineABCDtoRGB (const real32 *sPtrA, |
1339 | | const real32 *sPtrB, |
1340 | | const real32 *sPtrC, |
1341 | | const real32 *sPtrD, |
1342 | | real32 *dPtrR, |
1343 | | real32 *dPtrG, |
1344 | | real32 *dPtrB, |
1345 | | uint32 count, |
1346 | | const dng_vector &cameraWhite, |
1347 | | const dng_matrix &cameraToRGB) |
1348 | 281k | { |
1349 | | |
1350 | 281k | real32 clipA = (real32) cameraWhite [0]; |
1351 | 281k | real32 clipB = (real32) cameraWhite [1]; |
1352 | 281k | real32 clipC = (real32) cameraWhite [2]; |
1353 | 281k | real32 clipD = (real32) cameraWhite [3]; |
1354 | | |
1355 | 281k | real32 m00 = (real32) cameraToRGB [0] [0]; |
1356 | 281k | real32 m01 = (real32) cameraToRGB [0] [1]; |
1357 | 281k | real32 m02 = (real32) cameraToRGB [0] [2]; |
1358 | 281k | real32 m03 = (real32) cameraToRGB [0] [3]; |
1359 | | |
1360 | 281k | real32 m10 = (real32) cameraToRGB [1] [0]; |
1361 | 281k | real32 m11 = (real32) cameraToRGB [1] [1]; |
1362 | 281k | real32 m12 = (real32) cameraToRGB [1] [2]; |
1363 | 281k | real32 m13 = (real32) cameraToRGB [1] [3]; |
1364 | | |
1365 | 281k | real32 m20 = (real32) cameraToRGB [2] [0]; |
1366 | 281k | real32 m21 = (real32) cameraToRGB [2] [1]; |
1367 | 281k | real32 m22 = (real32) cameraToRGB [2] [2]; |
1368 | 281k | real32 m23 = (real32) cameraToRGB [2] [3]; |
1369 | | |
1370 | 3.39M | for (uint32 col = 0; col < count; col++) |
1371 | 3.11M | { |
1372 | | |
1373 | 3.11M | real32 A = sPtrA [col]; |
1374 | 3.11M | real32 B = sPtrB [col]; |
1375 | 3.11M | real32 C = sPtrC [col]; |
1376 | 3.11M | real32 D = sPtrD [col]; |
1377 | | |
1378 | 3.11M | A = Min_real32 (A, clipA); |
1379 | 3.11M | B = Min_real32 (B, clipB); |
1380 | 3.11M | C = Min_real32 (C, clipC); |
1381 | 3.11M | D = Min_real32 (D, clipD); |
1382 | | |
1383 | 3.11M | real32 r = m00 * A + m01 * B + m02 * C + m03 * D; |
1384 | 3.11M | real32 g = m10 * A + m11 * B + m12 * C + m13 * D; |
1385 | 3.11M | real32 b = m20 * A + m21 * B + m22 * C + m23 * D; |
1386 | | |
1387 | 3.11M | r = Pin_real32 (0.0f, r, 1.0f); |
1388 | 3.11M | g = Pin_real32 (0.0f, g, 1.0f); |
1389 | 3.11M | b = Pin_real32 (0.0f, b, 1.0f); |
1390 | | |
1391 | 3.11M | dPtrR [col] = r; |
1392 | 3.11M | dPtrG [col] = g; |
1393 | 3.11M | dPtrB [col] = b; |
1394 | | |
1395 | 3.11M | } |
1396 | | |
1397 | 281k | } |
1398 | | |
1399 | | /*****************************************************************************/ |
1400 | | |
1401 | | void RefBaselineHueSatMap (const real32 *sPtrR, |
1402 | | const real32 *sPtrG, |
1403 | | const real32 *sPtrB, |
1404 | | real32 *dPtrR, |
1405 | | real32 *dPtrG, |
1406 | | real32 *dPtrB, |
1407 | | uint32 count, |
1408 | | const dng_hue_sat_map &lut, |
1409 | | const dng_1d_table *encodeTable, |
1410 | | const dng_1d_table *decodeTable) |
1411 | 0 | { |
1412 | | |
1413 | 0 | uint32 hueDivisions; |
1414 | 0 | uint32 satDivisions; |
1415 | 0 | uint32 valDivisions; |
1416 | | |
1417 | 0 | lut.GetDivisions (hueDivisions, |
1418 | 0 | satDivisions, |
1419 | 0 | valDivisions); |
1420 | | |
1421 | 0 | real32 hScale = (hueDivisions < 2) ? 0.0f : (hueDivisions * (1.0f / 6.0f)); |
1422 | 0 | real32 sScale = (real32) ((int32) satDivisions - 1); |
1423 | 0 | real32 vScale = (real32) ((int32) valDivisions - 1); |
1424 | | |
1425 | 0 | int32 maxHueIndex0 = (int32) hueDivisions - 1; |
1426 | 0 | int32 maxSatIndex0 = (int32) satDivisions - 2; |
1427 | 0 | int32 maxValIndex0 = (int32) valDivisions - 2; |
1428 | |
|
1429 | 0 | const bool hasEncodeTable = ((encodeTable != NULL) && (encodeTable->Table () != NULL)); |
1430 | 0 | const bool hasDecodeTable = ((decodeTable != NULL) && (decodeTable->Table () != NULL)); |
1431 | |
|
1432 | 0 | const bool hasTable = hasEncodeTable && hasDecodeTable; |
1433 | |
|
1434 | 0 | const dng_hue_sat_map::HSBModify *tableBase = lut.GetConstDeltas (); |
1435 | | |
1436 | 0 | int32 hueStep = satDivisions; |
1437 | 0 | int32 valStep = hueDivisions * hueStep; |
1438 | | |
1439 | | #if 0 // Not required with "2.5D" table optimization. |
1440 | | |
1441 | | if (valDivisions < 2) |
1442 | | { |
1443 | | valStep = 0; |
1444 | | maxValIndex0 = 0; |
1445 | | } |
1446 | | |
1447 | | #endif |
1448 | | |
1449 | 0 | for (uint32 j = 0; j < count; j++) |
1450 | 0 | { |
1451 | | |
1452 | 0 | real32 r = sPtrR [j]; |
1453 | 0 | real32 g = sPtrG [j]; |
1454 | 0 | real32 b = sPtrB [j]; |
1455 | | |
1456 | 0 | real32 h, s, v; |
1457 | |
|
1458 | 0 | DNG_RGBtoHSV (r, g, b, h, s, v); |
1459 | |
|
1460 | 0 | real32 vEncoded = v; |
1461 | |
|
1462 | 0 | real32 hueShift; |
1463 | 0 | real32 satScale; |
1464 | 0 | real32 valScale; |
1465 | | |
1466 | 0 | if (valDivisions < 2) // Optimize most common case of "2.5D" table. |
1467 | 0 | { |
1468 | | |
1469 | 0 | real32 hScaled = h * hScale; |
1470 | 0 | real32 sScaled = s * sScale; |
1471 | | |
1472 | 0 | int32 hIndex0 = (int32) hScaled; |
1473 | 0 | int32 sIndex0 = (int32) sScaled; |
1474 | | |
1475 | 0 | sIndex0 = Min_int32 (sIndex0, maxSatIndex0); |
1476 | | |
1477 | 0 | int32 hIndex1 = hIndex0 + 1; |
1478 | | |
1479 | 0 | if (hIndex0 >= maxHueIndex0) |
1480 | 0 | { |
1481 | 0 | hIndex0 = maxHueIndex0; |
1482 | 0 | hIndex1 = 0; |
1483 | 0 | } |
1484 | | |
1485 | 0 | real32 hFract1 = hScaled - (real32) hIndex0; |
1486 | 0 | real32 sFract1 = sScaled - (real32) sIndex0; |
1487 | | |
1488 | 0 | real32 hFract0 = 1.0f - hFract1; |
1489 | 0 | real32 sFract0 = 1.0f - sFract1; |
1490 | | |
1491 | 0 | const dng_hue_sat_map::HSBModify *entry00 = tableBase + hIndex0 * hueStep + |
1492 | 0 | sIndex0; |
1493 | | |
1494 | 0 | const dng_hue_sat_map::HSBModify *entry01 = entry00 + (hIndex1 - hIndex0) * hueStep; |
1495 | | |
1496 | 0 | real32 hueShift0 = hFract0 * entry00->fHueShift + |
1497 | 0 | hFract1 * entry01->fHueShift; |
1498 | | |
1499 | 0 | real32 satScale0 = hFract0 * entry00->fSatScale + |
1500 | 0 | hFract1 * entry01->fSatScale; |
1501 | | |
1502 | 0 | real32 valScale0 = hFract0 * entry00->fValScale + |
1503 | 0 | hFract1 * entry01->fValScale; |
1504 | |
|
1505 | 0 | entry00++; |
1506 | 0 | entry01++; |
1507 | |
|
1508 | 0 | real32 hueShift1 = hFract0 * entry00->fHueShift + |
1509 | 0 | hFract1 * entry01->fHueShift; |
1510 | | |
1511 | 0 | real32 satScale1 = hFract0 * entry00->fSatScale + |
1512 | 0 | hFract1 * entry01->fSatScale; |
1513 | | |
1514 | 0 | real32 valScale1 = hFract0 * entry00->fValScale + |
1515 | 0 | hFract1 * entry01->fValScale; |
1516 | | |
1517 | 0 | hueShift = sFract0 * hueShift0 + sFract1 * hueShift1; |
1518 | 0 | satScale = sFract0 * satScale0 + sFract1 * satScale1; |
1519 | 0 | valScale = sFract0 * valScale0 + sFract1 * valScale1; |
1520 | | |
1521 | 0 | } |
1522 | | |
1523 | 0 | else |
1524 | 0 | { |
1525 | | |
1526 | 0 | if (hasTable) |
1527 | 0 | { |
1528 | 0 | vEncoded = encodeTable->Interpolate (Pin_real32 (v)); |
1529 | 0 | } |
1530 | |
|
1531 | 0 | real32 hScaled = h * hScale; |
1532 | 0 | real32 sScaled = s * sScale; |
1533 | 0 | real32 vScaled = vEncoded * vScale; |
1534 | | |
1535 | 0 | int32 hIndex0 = (int32) hScaled; |
1536 | 0 | int32 sIndex0 = (int32) sScaled; |
1537 | 0 | int32 vIndex0 = (int32) vScaled; |
1538 | | |
1539 | 0 | sIndex0 = Min_int32 (sIndex0, maxSatIndex0); |
1540 | 0 | vIndex0 = Min_int32 (vIndex0, maxValIndex0); |
1541 | | |
1542 | 0 | int32 hIndex1 = hIndex0 + 1; |
1543 | | |
1544 | 0 | if (hIndex0 >= maxHueIndex0) |
1545 | 0 | { |
1546 | 0 | hIndex0 = maxHueIndex0; |
1547 | 0 | hIndex1 = 0; |
1548 | 0 | } |
1549 | | |
1550 | 0 | real32 hFract1 = hScaled - (real32) hIndex0; |
1551 | 0 | real32 sFract1 = sScaled - (real32) sIndex0; |
1552 | 0 | real32 vFract1 = vScaled - (real32) vIndex0; |
1553 | | |
1554 | 0 | real32 hFract0 = 1.0f - hFract1; |
1555 | 0 | real32 sFract0 = 1.0f - sFract1; |
1556 | 0 | real32 vFract0 = 1.0f - vFract1; |
1557 | | |
1558 | 0 | const dng_hue_sat_map::HSBModify *entry00 = tableBase + vIndex0 * valStep + |
1559 | 0 | hIndex0 * hueStep + |
1560 | 0 | sIndex0; |
1561 | | |
1562 | 0 | const dng_hue_sat_map::HSBModify *entry01 = entry00 + (hIndex1 - hIndex0) * hueStep; |
1563 | | |
1564 | 0 | const dng_hue_sat_map::HSBModify *entry10 = entry00 + valStep; |
1565 | 0 | const dng_hue_sat_map::HSBModify *entry11 = entry01 + valStep; |
1566 | | |
1567 | 0 | real32 hueShift0 = vFract0 * (hFract0 * entry00->fHueShift + |
1568 | 0 | hFract1 * entry01->fHueShift) + |
1569 | 0 | vFract1 * (hFract0 * entry10->fHueShift + |
1570 | 0 | hFract1 * entry11->fHueShift); |
1571 | | |
1572 | 0 | real32 satScale0 = vFract0 * (hFract0 * entry00->fSatScale + |
1573 | 0 | hFract1 * entry01->fSatScale) + |
1574 | 0 | vFract1 * (hFract0 * entry10->fSatScale + |
1575 | 0 | hFract1 * entry11->fSatScale); |
1576 | | |
1577 | 0 | real32 valScale0 = vFract0 * (hFract0 * entry00->fValScale + |
1578 | 0 | hFract1 * entry01->fValScale) + |
1579 | 0 | vFract1 * (hFract0 * entry10->fValScale + |
1580 | 0 | hFract1 * entry11->fValScale); |
1581 | | |
1582 | 0 | entry00++; |
1583 | 0 | entry01++; |
1584 | 0 | entry10++; |
1585 | 0 | entry11++; |
1586 | |
|
1587 | 0 | real32 hueShift1 = vFract0 * (hFract0 * entry00->fHueShift + |
1588 | 0 | hFract1 * entry01->fHueShift) + |
1589 | 0 | vFract1 * (hFract0 * entry10->fHueShift + |
1590 | 0 | hFract1 * entry11->fHueShift); |
1591 | | |
1592 | 0 | real32 satScale1 = vFract0 * (hFract0 * entry00->fSatScale + |
1593 | 0 | hFract1 * entry01->fSatScale) + |
1594 | 0 | vFract1 * (hFract0 * entry10->fSatScale + |
1595 | 0 | hFract1 * entry11->fSatScale); |
1596 | | |
1597 | 0 | real32 valScale1 = vFract0 * (hFract0 * entry00->fValScale + |
1598 | 0 | hFract1 * entry01->fValScale) + |
1599 | 0 | vFract1 * (hFract0 * entry10->fValScale + |
1600 | 0 | hFract1 * entry11->fValScale); |
1601 | | |
1602 | 0 | hueShift = sFract0 * hueShift0 + sFract1 * hueShift1; |
1603 | 0 | satScale = sFract0 * satScale0 + sFract1 * satScale1; |
1604 | 0 | valScale = sFract0 * valScale0 + sFract1 * valScale1; |
1605 | | |
1606 | 0 | } |
1607 | | |
1608 | 0 | hueShift *= (6.0f / 360.0f); // Convert to internal hue range. |
1609 | | |
1610 | 0 | h += hueShift; |
1611 | | |
1612 | 0 | s = Min_real32 (s * satScale, 1.0f); |
1613 | |
|
1614 | 0 | vEncoded = Pin_real32 (vEncoded * valScale); |
1615 | |
|
1616 | 0 | v = hasTable ? decodeTable->Interpolate (vEncoded) : vEncoded; |
1617 | | |
1618 | 0 | DNG_HSVtoRGB (h, s, v, r, g, b); |
1619 | |
|
1620 | 0 | dPtrR [j] = r; |
1621 | 0 | dPtrG [j] = g; |
1622 | 0 | dPtrB [j] = b; |
1623 | | |
1624 | 0 | } |
1625 | | |
1626 | 0 | } |
1627 | | |
1628 | | /*****************************************************************************/ |
1629 | | |
1630 | | void RefBaselineRGBtoGray (const real32 *sPtrR, |
1631 | | const real32 *sPtrG, |
1632 | | const real32 *sPtrB, |
1633 | | real32 *dPtrG, |
1634 | | uint32 count, |
1635 | | const dng_matrix &matrix) |
1636 | 14.6M | { |
1637 | | |
1638 | 14.6M | real32 m00 = (real32) matrix [0] [0]; |
1639 | 14.6M | real32 m01 = (real32) matrix [0] [1]; |
1640 | 14.6M | real32 m02 = (real32) matrix [0] [2]; |
1641 | | |
1642 | 282M | for (uint32 col = 0; col < count; col++) |
1643 | 267M | { |
1644 | | |
1645 | 267M | real32 R = sPtrR [col]; |
1646 | 267M | real32 G = sPtrG [col]; |
1647 | 267M | real32 B = sPtrB [col]; |
1648 | | |
1649 | 267M | real32 g = m00 * R + m01 * G + m02 * B; |
1650 | | |
1651 | 267M | g = Pin_real32 (0.0f, g, 1.0f); |
1652 | | |
1653 | 267M | dPtrG [col] = g; |
1654 | | |
1655 | 267M | } |
1656 | | |
1657 | 14.6M | } |
1658 | | |
1659 | | /*****************************************************************************/ |
1660 | | |
1661 | | void RefBaselineRGBtoRGB (const real32 *sPtrR, |
1662 | | const real32 *sPtrG, |
1663 | | const real32 *sPtrB, |
1664 | | real32 *dPtrR, |
1665 | | real32 *dPtrG, |
1666 | | real32 *dPtrB, |
1667 | | uint32 count, |
1668 | | const dng_matrix &matrix) |
1669 | 30.2M | { |
1670 | | |
1671 | 30.2M | real32 m00 = (real32) matrix [0] [0]; |
1672 | 30.2M | real32 m01 = (real32) matrix [0] [1]; |
1673 | 30.2M | real32 m02 = (real32) matrix [0] [2]; |
1674 | | |
1675 | 30.2M | real32 m10 = (real32) matrix [1] [0]; |
1676 | 30.2M | real32 m11 = (real32) matrix [1] [1]; |
1677 | 30.2M | real32 m12 = (real32) matrix [1] [2]; |
1678 | | |
1679 | 30.2M | real32 m20 = (real32) matrix [2] [0]; |
1680 | 30.2M | real32 m21 = (real32) matrix [2] [1]; |
1681 | 30.2M | real32 m22 = (real32) matrix [2] [2]; |
1682 | | |
1683 | 1.82G | for (uint32 col = 0; col < count; col++) |
1684 | 1.79G | { |
1685 | | |
1686 | 1.79G | real32 R = sPtrR [col]; |
1687 | 1.79G | real32 G = sPtrG [col]; |
1688 | 1.79G | real32 B = sPtrB [col]; |
1689 | | |
1690 | 1.79G | real32 r = m00 * R + m01 * G + m02 * B; |
1691 | 1.79G | real32 g = m10 * R + m11 * G + m12 * B; |
1692 | 1.79G | real32 b = m20 * R + m21 * G + m22 * B; |
1693 | | |
1694 | 1.79G | r = Pin_real32 (0.0f, r, 1.0f); |
1695 | 1.79G | g = Pin_real32 (0.0f, g, 1.0f); |
1696 | 1.79G | b = Pin_real32 (0.0f, b, 1.0f); |
1697 | | |
1698 | 1.79G | dPtrR [col] = r; |
1699 | 1.79G | dPtrG [col] = g; |
1700 | 1.79G | dPtrB [col] = b; |
1701 | | |
1702 | 1.79G | } |
1703 | | |
1704 | 30.2M | } |
1705 | | |
1706 | | /*****************************************************************************/ |
1707 | | |
1708 | | void RefBaseline1DTable (const real32 *sPtr, |
1709 | | real32 *dPtr, |
1710 | | uint32 count, |
1711 | | const dng_1d_table &table) |
1712 | 240M | { |
1713 | | |
1714 | 12.0G | for (uint32 col = 0; col < count; col++) |
1715 | 11.8G | { |
1716 | | |
1717 | 11.8G | real32 x = sPtr [col]; |
1718 | | |
1719 | 11.8G | real32 y = table.Interpolate (x); |
1720 | | |
1721 | 11.8G | dPtr [col] = y; |
1722 | | |
1723 | 11.8G | } |
1724 | | |
1725 | 240M | } |
1726 | | |
1727 | | /*****************************************************************************/ |
1728 | | |
1729 | | void RefBaselineRGBTone (const real32 *sPtrR, |
1730 | | const real32 *sPtrG, |
1731 | | const real32 *sPtrB, |
1732 | | real32 *dPtrR, |
1733 | | real32 *dPtrG, |
1734 | | real32 *dPtrB, |
1735 | | uint32 count, |
1736 | | const dng_1d_table &table) |
1737 | 44.9M | { |
1738 | | |
1739 | 2.10G | for (uint32 col = 0; col < count; col++) |
1740 | 2.05G | { |
1741 | | |
1742 | 2.05G | real32 r = sPtrR [col]; |
1743 | 2.05G | real32 g = sPtrG [col]; |
1744 | 2.05G | real32 b = sPtrB [col]; |
1745 | | |
1746 | 2.05G | real32 rr; |
1747 | 2.05G | real32 gg; |
1748 | 2.05G | real32 bb; |
1749 | | |
1750 | 2.05G | #define RGBTone(r, g, b, rr, gg, bb)\ |
1751 | 2.05G | {\ |
1752 | 30.8M | \ |
1753 | 30.8M | DNG_ASSERT (r >= g && g >= b && r > b, "Logic Error RGBTone");\ |
1754 | 30.8M | \ |
1755 | 30.8M | rr = table.Interpolate (r);\ |
1756 | 30.8M | bb = table.Interpolate (b);\ |
1757 | 30.8M | \ |
1758 | 30.8M | gg = bb + ((rr - bb) * (g - b) / (r - b));\ |
1759 | 30.8M | \ |
1760 | 30.8M | } |
1761 | | |
1762 | 2.05G | if (r >= g) |
1763 | 2.04G | { |
1764 | | |
1765 | 2.04G | if (g > b) |
1766 | 1.58M | { |
1767 | | |
1768 | | // Case 1: r >= g > b |
1769 | | |
1770 | 1.58M | RGBTone (r, g, b, rr, gg, bb); |
1771 | | |
1772 | 1.58M | } |
1773 | | |
1774 | 2.03G | else if (b > r) |
1775 | 2.74M | { |
1776 | | |
1777 | | // Case 2: b > r >= g |
1778 | | |
1779 | 2.74M | RGBTone (b, r, g, bb, rr, gg); |
1780 | | |
1781 | 2.74M | } |
1782 | | |
1783 | 2.03G | else if (b > g) |
1784 | 8.71M | { |
1785 | | |
1786 | | // Case 3: r >= b > g |
1787 | | |
1788 | 8.71M | RGBTone (r, b, g, rr, bb, gg); |
1789 | | |
1790 | 8.71M | } |
1791 | | |
1792 | 2.02G | else |
1793 | 2.02G | { |
1794 | | |
1795 | | // Case 4: r >= g == b |
1796 | | |
1797 | 2.02G | DNG_ASSERT (r >= g && g == b, "Logic Error 2"); |
1798 | | |
1799 | 2.02G | rr = table.Interpolate (r); |
1800 | 2.02G | gg = table.Interpolate (g); |
1801 | 2.02G | bb = gg; |
1802 | | |
1803 | 2.02G | } |
1804 | | |
1805 | 2.04G | } |
1806 | | |
1807 | 17.8M | else |
1808 | 17.8M | { |
1809 | | |
1810 | 17.8M | if (r >= b) |
1811 | 2.13M | { |
1812 | | |
1813 | | // Case 5: g > r >= b |
1814 | | |
1815 | 2.13M | RGBTone (g, r, b, gg, rr, bb); |
1816 | | |
1817 | 2.13M | } |
1818 | | |
1819 | 15.6M | else if (b > g) |
1820 | 1.45M | { |
1821 | | |
1822 | | // Case 6: b > g > r |
1823 | | |
1824 | 1.45M | RGBTone (b, g, r, bb, gg, rr); |
1825 | | |
1826 | 1.45M | } |
1827 | | |
1828 | 14.2M | else |
1829 | 14.2M | { |
1830 | | |
1831 | | // Case 7: g >= b > r |
1832 | | |
1833 | 14.2M | RGBTone (g, b, r, gg, bb, rr); |
1834 | | |
1835 | 14.2M | } |
1836 | | |
1837 | 17.8M | } |
1838 | | |
1839 | 2.05G | #undef RGBTone |
1840 | | |
1841 | 2.05G | dPtrR [col] = rr; |
1842 | 2.05G | dPtrG [col] = gg; |
1843 | 2.05G | dPtrB [col] = bb; |
1844 | | |
1845 | 2.05G | } |
1846 | | |
1847 | 44.9M | } |
1848 | | |
1849 | | /*****************************************************************************/ |
1850 | | |
1851 | | void RefResampleDown16 (const uint16 *sPtr, |
1852 | | uint16 *dPtr, |
1853 | | uint32 sCount, |
1854 | | int32 sRowStep, |
1855 | | const int16 *wPtr, |
1856 | | uint32 wCount, |
1857 | | uint32 pixelRange) |
1858 | 30.7M | { |
1859 | | |
1860 | 1.80G | for (uint32 j = 0; j < sCount; j++) |
1861 | 1.77G | { |
1862 | | |
1863 | 1.77G | int32 total = 8192; |
1864 | | |
1865 | 1.77G | const uint16 *s = sPtr + j; |
1866 | | |
1867 | 26.5G | for (uint32 k = 0; k < wCount; k++) |
1868 | 24.7G | { |
1869 | | |
1870 | 24.7G | total += wPtr [k] * (int32) s [0]; |
1871 | | |
1872 | 24.7G | s += sRowStep; |
1873 | | |
1874 | 24.7G | } |
1875 | | |
1876 | 1.77G | dPtr [j] = (uint16) Pin_int32 (0, |
1877 | 1.77G | total >> 14, |
1878 | 1.77G | pixelRange); |
1879 | | |
1880 | 1.77G | } |
1881 | | |
1882 | 30.7M | } |
1883 | | |
1884 | | /*****************************************************************************/ |
1885 | | |
1886 | | void RefResampleDown32 (const real32 *sPtr, |
1887 | | real32 *dPtr, |
1888 | | uint32 sCount, |
1889 | | int32 sRowStep, |
1890 | | const real32 *wPtr, |
1891 | | uint32 wCount) |
1892 | 13.4M | { |
1893 | | |
1894 | 13.4M | uint32 col; |
1895 | | |
1896 | | // Process first row. |
1897 | | |
1898 | 13.4M | real32 w = wPtr [0]; |
1899 | | |
1900 | 1.37G | for (col = 0; col < sCount; col++) |
1901 | 1.36G | { |
1902 | | |
1903 | 1.36G | dPtr [col] = w * sPtr [col]; |
1904 | | |
1905 | 1.36G | } |
1906 | | |
1907 | 13.4M | sPtr += sRowStep; |
1908 | | |
1909 | | // Process middle rows. |
1910 | | |
1911 | 81.9M | for (uint32 j = 1; j < wCount - 1; j++) |
1912 | 68.5M | { |
1913 | | |
1914 | 68.5M | w = wPtr [j]; |
1915 | | |
1916 | 10.4G | for (col = 0; col < sCount; col++) |
1917 | 10.3G | { |
1918 | | |
1919 | 10.3G | dPtr [col] += w * sPtr [col]; |
1920 | | |
1921 | 10.3G | } |
1922 | | |
1923 | 68.5M | sPtr += sRowStep; |
1924 | | |
1925 | 68.5M | } |
1926 | | |
1927 | | // Process last row. |
1928 | | |
1929 | 13.4M | w = wPtr [wCount - 1]; |
1930 | | |
1931 | 1.37G | for (col = 0; col < sCount; col++) |
1932 | 1.36G | { |
1933 | | |
1934 | 1.36G | dPtr [col] = Pin_real32 (0.0f, |
1935 | 1.36G | dPtr [col] + w * sPtr [col], |
1936 | 1.36G | 1.0f); |
1937 | | |
1938 | 1.36G | } |
1939 | | |
1940 | 13.4M | } |
1941 | | |
1942 | | /******************************************************************************/ |
1943 | | |
1944 | | void RefResampleAcross16 (const uint16 *sPtr, |
1945 | | uint16 *dPtr, |
1946 | | uint32 dCount, |
1947 | | const int32 *coord, |
1948 | | const int16 *wPtr, |
1949 | | uint32 wCount, |
1950 | | uint32 wStep, |
1951 | | uint32 pixelRange) |
1952 | 30.7M | { |
1953 | | |
1954 | 824M | for (uint32 j = 0; j < dCount; j++) |
1955 | 794M | { |
1956 | | |
1957 | 794M | int32 sCoord = coord [j]; |
1958 | | |
1959 | 794M | int32 sFract = sCoord & kResampleSubsampleMask; |
1960 | 794M | int32 sPixel = sCoord >> kResampleSubsampleBits; |
1961 | | |
1962 | 794M | const int16 *w = wPtr + sFract * wStep; |
1963 | 794M | const uint16 *s = sPtr + sPixel; |
1964 | | |
1965 | 794M | int32 total = w [0] * (int32) s [0]; |
1966 | | |
1967 | 6.10G | for (uint32 k = 1; k < wCount; k++) |
1968 | 5.31G | { |
1969 | | |
1970 | 5.31G | total += w [k] * (int32) s [k]; |
1971 | | |
1972 | 5.31G | } |
1973 | | |
1974 | 794M | dPtr [j] = (uint16) Pin_int32 (0, |
1975 | 794M | (total + 8192) >> 14, |
1976 | 794M | pixelRange); |
1977 | | |
1978 | 794M | } |
1979 | | |
1980 | 30.7M | } |
1981 | | |
1982 | | /******************************************************************************/ |
1983 | | |
1984 | | void RefResampleAcross32 (const real32 *sPtr, |
1985 | | real32 *dPtr, |
1986 | | uint32 dCount, |
1987 | | const int32 *coord, |
1988 | | const real32 *wPtr, |
1989 | | uint32 wCount, |
1990 | | uint32 wStep) |
1991 | 13.4M | { |
1992 | | |
1993 | 978M | for (uint32 j = 0; j < dCount; j++) |
1994 | 965M | { |
1995 | | |
1996 | 965M | int32 sCoord = coord [j]; |
1997 | | |
1998 | 965M | int32 sFract = sCoord & kResampleSubsampleMask; |
1999 | 965M | int32 sPixel = sCoord >> kResampleSubsampleBits; |
2000 | | |
2001 | 965M | const real32 *w = wPtr + sFract * wStep; |
2002 | 965M | const real32 *s = sPtr + sPixel; |
2003 | | |
2004 | 965M | real32 total = w [0] * s [0]; |
2005 | | |
2006 | 6.50G | for (uint32 k = 1; k < wCount; k++) |
2007 | 5.53G | { |
2008 | | |
2009 | 5.53G | total += w [k] * s [k]; |
2010 | | |
2011 | 5.53G | } |
2012 | | |
2013 | 965M | dPtr [j] = Pin_real32 (0.0f, total, 1.0f); |
2014 | | |
2015 | 965M | } |
2016 | | |
2017 | 13.4M | } |
2018 | | |
2019 | | /*****************************************************************************/ |
2020 | | |
2021 | | bool RefEqualBytes (const void *sPtr, |
2022 | | const void *dPtr, |
2023 | | uint32 count) |
2024 | 0 | { |
2025 | | |
2026 | 0 | return memcmp (dPtr, sPtr, count) == 0; |
2027 | | |
2028 | 0 | } |
2029 | | |
2030 | | /*****************************************************************************/ |
2031 | | |
2032 | | bool RefEqualArea8 (const uint8 *sPtr, |
2033 | | const uint8 *dPtr, |
2034 | | uint32 rows, |
2035 | | uint32 cols, |
2036 | | uint32 planes, |
2037 | | int32 sRowStep, |
2038 | | int32 sColStep, |
2039 | | int32 sPlaneStep, |
2040 | | int32 dRowStep, |
2041 | | int32 dColStep, |
2042 | | int32 dPlaneStep) |
2043 | 0 | { |
2044 | | |
2045 | 0 | for (uint32 row = 0; row < rows; row++) |
2046 | 0 | { |
2047 | | |
2048 | 0 | const uint8 *sPtr1 = sPtr; |
2049 | 0 | const uint8 *dPtr1 = dPtr; |
2050 | | |
2051 | 0 | for (uint32 col = 0; col < cols; col++) |
2052 | 0 | { |
2053 | | |
2054 | 0 | const uint8 *sPtr2 = sPtr1; |
2055 | 0 | const uint8 *dPtr2 = dPtr1; |
2056 | | |
2057 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
2058 | 0 | { |
2059 | | |
2060 | 0 | if (*dPtr2 != *sPtr2) |
2061 | 0 | return false; |
2062 | | |
2063 | 0 | sPtr2 += sPlaneStep; |
2064 | 0 | dPtr2 += dPlaneStep; |
2065 | | |
2066 | 0 | } |
2067 | | |
2068 | 0 | sPtr1 += sColStep; |
2069 | 0 | dPtr1 += dColStep; |
2070 | |
|
2071 | 0 | } |
2072 | | |
2073 | 0 | sPtr += sRowStep; |
2074 | 0 | dPtr += dRowStep; |
2075 | | |
2076 | 0 | } |
2077 | | |
2078 | 0 | return true; |
2079 | |
|
2080 | 0 | } |
2081 | | |
2082 | | /*****************************************************************************/ |
2083 | | |
2084 | | bool RefEqualArea16 (const uint16 *sPtr, |
2085 | | const uint16 *dPtr, |
2086 | | uint32 rows, |
2087 | | uint32 cols, |
2088 | | uint32 planes, |
2089 | | int32 sRowStep, |
2090 | | int32 sColStep, |
2091 | | int32 sPlaneStep, |
2092 | | int32 dRowStep, |
2093 | | int32 dColStep, |
2094 | | int32 dPlaneStep) |
2095 | 0 | { |
2096 | | |
2097 | 0 | for (uint32 row = 0; row < rows; row++) |
2098 | 0 | { |
2099 | | |
2100 | 0 | const uint16 *sPtr1 = sPtr; |
2101 | 0 | const uint16 *dPtr1 = dPtr; |
2102 | | |
2103 | 0 | for (uint32 col = 0; col < cols; col++) |
2104 | 0 | { |
2105 | | |
2106 | 0 | const uint16 *sPtr2 = sPtr1; |
2107 | 0 | const uint16 *dPtr2 = dPtr1; |
2108 | | |
2109 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
2110 | 0 | { |
2111 | | |
2112 | 0 | if (*dPtr2 != *sPtr2) |
2113 | 0 | return false; |
2114 | | |
2115 | 0 | sPtr2 += sPlaneStep; |
2116 | 0 | dPtr2 += dPlaneStep; |
2117 | | |
2118 | 0 | } |
2119 | | |
2120 | 0 | sPtr1 += sColStep; |
2121 | 0 | dPtr1 += dColStep; |
2122 | |
|
2123 | 0 | } |
2124 | | |
2125 | 0 | sPtr += sRowStep; |
2126 | 0 | dPtr += dRowStep; |
2127 | | |
2128 | 0 | } |
2129 | | |
2130 | 0 | return true; |
2131 | |
|
2132 | 0 | } |
2133 | | |
2134 | | /*****************************************************************************/ |
2135 | | |
2136 | | bool RefEqualArea32 (const uint32 *sPtr, |
2137 | | const uint32 *dPtr, |
2138 | | uint32 rows, |
2139 | | uint32 cols, |
2140 | | uint32 planes, |
2141 | | int32 sRowStep, |
2142 | | int32 sColStep, |
2143 | | int32 sPlaneStep, |
2144 | | int32 dRowStep, |
2145 | | int32 dColStep, |
2146 | | int32 dPlaneStep) |
2147 | 0 | { |
2148 | | |
2149 | 0 | for (uint32 row = 0; row < rows; row++) |
2150 | 0 | { |
2151 | | |
2152 | 0 | const uint32 *sPtr1 = sPtr; |
2153 | 0 | const uint32 *dPtr1 = dPtr; |
2154 | | |
2155 | 0 | for (uint32 col = 0; col < cols; col++) |
2156 | 0 | { |
2157 | | |
2158 | 0 | const uint32 *sPtr2 = sPtr1; |
2159 | 0 | const uint32 *dPtr2 = dPtr1; |
2160 | | |
2161 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
2162 | 0 | { |
2163 | | |
2164 | 0 | if (*dPtr2 != *sPtr2) |
2165 | 0 | return false; |
2166 | | |
2167 | 0 | sPtr2 += sPlaneStep; |
2168 | 0 | dPtr2 += dPlaneStep; |
2169 | | |
2170 | 0 | } |
2171 | | |
2172 | 0 | sPtr1 += sColStep; |
2173 | 0 | dPtr1 += dColStep; |
2174 | |
|
2175 | 0 | } |
2176 | | |
2177 | 0 | sPtr += sRowStep; |
2178 | 0 | dPtr += dRowStep; |
2179 | | |
2180 | 0 | } |
2181 | | |
2182 | 0 | return true; |
2183 | |
|
2184 | 0 | } |
2185 | | |
2186 | | /*****************************************************************************/ |
2187 | | |
2188 | | void RefVignetteMask16 (uint16 *mPtr, |
2189 | | uint32 rows, |
2190 | | uint32 cols, |
2191 | | int32 rowStep, |
2192 | | int64 offsetH, |
2193 | | int64 offsetV, |
2194 | | int64 stepH, |
2195 | | int64 stepV, |
2196 | | uint32 tBits, |
2197 | | const uint16 *table) |
2198 | 0 | { |
2199 | | |
2200 | 0 | uint32 tShift = 32 - tBits; |
2201 | 0 | uint32 tRound = (1 << (tShift - 1)); |
2202 | 0 | uint32 tLimit = 1 << tBits; |
2203 | | |
2204 | 0 | for (uint32 row = 0; row < rows; row++) |
2205 | 0 | { |
2206 | | |
2207 | 0 | int64 baseDelta = (offsetV + 32768) >> 16; |
2208 | | |
2209 | 0 | baseDelta = baseDelta * baseDelta + tRound; |
2210 | | |
2211 | 0 | int64 deltaH = offsetH + 32768; |
2212 | | |
2213 | 0 | for (uint32 col = 0; col < cols; col++) |
2214 | 0 | { |
2215 | | |
2216 | 0 | int64 temp = deltaH >> 16; |
2217 | | |
2218 | 0 | int64 delta = baseDelta + (temp * temp); |
2219 | | |
2220 | 0 | uint32 index = Min_uint32 ((uint32) (delta >> tShift), tLimit); |
2221 | | |
2222 | 0 | mPtr [col] = table [index]; |
2223 | | |
2224 | 0 | deltaH += stepH; |
2225 | | |
2226 | 0 | } |
2227 | | |
2228 | 0 | offsetV += stepV; |
2229 | | |
2230 | 0 | mPtr += rowStep; |
2231 | | |
2232 | 0 | } |
2233 | | |
2234 | 0 | } |
2235 | | |
2236 | | /*****************************************************************************/ |
2237 | | |
2238 | | void RefVignette16 (int16 *sPtr, |
2239 | | const uint16 *mPtr, |
2240 | | uint32 rows, |
2241 | | uint32 cols, |
2242 | | uint32 planes, |
2243 | | int32 sRowStep, |
2244 | | int32 sPlaneStep, |
2245 | | int32 mRowStep, |
2246 | | uint32 mBits) |
2247 | 0 | { |
2248 | | |
2249 | 0 | const uint32 mRound = 1 << (mBits - 1); |
2250 | |
|
2251 | 0 | switch (planes) |
2252 | 0 | { |
2253 | | |
2254 | 0 | case 1: |
2255 | 0 | { |
2256 | | |
2257 | 0 | for (uint32 row = 0; row < rows; row++) |
2258 | 0 | { |
2259 | | |
2260 | 0 | for (uint32 col = 0; col < cols; col++) |
2261 | 0 | { |
2262 | | |
2263 | 0 | uint32 s = sPtr [col] + 32768; |
2264 | | |
2265 | 0 | uint32 m = mPtr [col]; |
2266 | | |
2267 | 0 | s = (s * m + mRound) >> mBits; |
2268 | | |
2269 | 0 | s = Min_uint32 (s, 65535); |
2270 | | |
2271 | 0 | sPtr [col] = (int16) (s - 32768); |
2272 | | |
2273 | 0 | } |
2274 | | |
2275 | 0 | sPtr += sRowStep; |
2276 | | |
2277 | 0 | mPtr += mRowStep; |
2278 | | |
2279 | 0 | } |
2280 | |
|
2281 | 0 | break; |
2282 | | |
2283 | 0 | } |
2284 | | |
2285 | 0 | case 3: |
2286 | 0 | { |
2287 | |
|
2288 | 0 | int16 *rPtr = sPtr; |
2289 | 0 | int16 *gPtr = rPtr + sPlaneStep; |
2290 | 0 | int16 *bPtr = gPtr + sPlaneStep; |
2291 | | |
2292 | 0 | for (uint32 row = 0; row < rows; row++) |
2293 | 0 | { |
2294 | | |
2295 | 0 | for (uint32 col = 0; col < cols; col++) |
2296 | 0 | { |
2297 | | |
2298 | 0 | uint32 r = rPtr [col] + 32768; |
2299 | 0 | uint32 g = gPtr [col] + 32768; |
2300 | 0 | uint32 b = bPtr [col] + 32768; |
2301 | | |
2302 | 0 | uint32 m = mPtr [col]; |
2303 | | |
2304 | 0 | r = (r * m + mRound) >> mBits; |
2305 | 0 | g = (g * m + mRound) >> mBits; |
2306 | 0 | b = (b * m + mRound) >> mBits; |
2307 | | |
2308 | 0 | r = Min_uint32 (r, 65535); |
2309 | 0 | g = Min_uint32 (g, 65535); |
2310 | 0 | b = Min_uint32 (b, 65535); |
2311 | | |
2312 | 0 | rPtr [col] = (int16) (r - 32768); |
2313 | 0 | gPtr [col] = (int16) (g - 32768); |
2314 | 0 | bPtr [col] = (int16) (b - 32768); |
2315 | | |
2316 | 0 | } |
2317 | | |
2318 | 0 | rPtr += sRowStep; |
2319 | 0 | gPtr += sRowStep; |
2320 | 0 | bPtr += sRowStep; |
2321 | | |
2322 | 0 | mPtr += mRowStep; |
2323 | | |
2324 | 0 | } |
2325 | |
|
2326 | 0 | break; |
2327 | | |
2328 | 0 | } |
2329 | | |
2330 | 0 | case 4: |
2331 | 0 | { |
2332 | | |
2333 | 0 | int16 *aPtr = sPtr; |
2334 | 0 | int16 *bPtr = aPtr + sPlaneStep; |
2335 | 0 | int16 *cPtr = bPtr + sPlaneStep; |
2336 | 0 | int16 *dPtr = cPtr + sPlaneStep; |
2337 | | |
2338 | 0 | for (uint32 row = 0; row < rows; row++) |
2339 | 0 | { |
2340 | | |
2341 | 0 | for (uint32 col = 0; col < cols; col++) |
2342 | 0 | { |
2343 | | |
2344 | 0 | uint32 a = aPtr [col] + 32768; |
2345 | 0 | uint32 b = bPtr [col] + 32768; |
2346 | 0 | uint32 c = cPtr [col] + 32768; |
2347 | 0 | uint32 d = dPtr [col] + 32768; |
2348 | | |
2349 | 0 | uint32 m = mPtr [col]; |
2350 | | |
2351 | 0 | a = (a * m + mRound) >> mBits; |
2352 | 0 | b = (b * m + mRound) >> mBits; |
2353 | 0 | c = (c * m + mRound) >> mBits; |
2354 | 0 | d = (d * m + mRound) >> mBits; |
2355 | | |
2356 | 0 | a = Min_uint32 (a, 65535); |
2357 | 0 | b = Min_uint32 (b, 65535); |
2358 | 0 | c = Min_uint32 (c, 65535); |
2359 | 0 | d = Min_uint32 (d, 65535); |
2360 | | |
2361 | 0 | aPtr [col] = (int16) (a - 32768); |
2362 | 0 | bPtr [col] = (int16) (b - 32768); |
2363 | 0 | cPtr [col] = (int16) (c - 32768); |
2364 | 0 | dPtr [col] = (int16) (d - 32768); |
2365 | | |
2366 | 0 | } |
2367 | | |
2368 | 0 | aPtr += sRowStep; |
2369 | 0 | bPtr += sRowStep; |
2370 | 0 | cPtr += sRowStep; |
2371 | 0 | dPtr += sRowStep; |
2372 | | |
2373 | 0 | mPtr += mRowStep; |
2374 | | |
2375 | 0 | } |
2376 | |
|
2377 | 0 | break; |
2378 | | |
2379 | 0 | } |
2380 | | |
2381 | 0 | default: |
2382 | 0 | { |
2383 | | |
2384 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
2385 | 0 | { |
2386 | |
|
2387 | 0 | int16 *planePtr = sPtr; |
2388 | |
|
2389 | 0 | const uint16 *maskPtr = mPtr; |
2390 | | |
2391 | 0 | for (uint32 row = 0; row < rows; row++) |
2392 | 0 | { |
2393 | | |
2394 | 0 | for (uint32 col = 0; col < cols; col++) |
2395 | 0 | { |
2396 | |
|
2397 | 0 | uint32 s = planePtr [col] + 32768; |
2398 | | |
2399 | 0 | uint32 m = maskPtr [col]; |
2400 | | |
2401 | 0 | s = (s * m + mRound) >> mBits; |
2402 | | |
2403 | 0 | s = Min_uint32 (s, 65535); |
2404 | | |
2405 | 0 | planePtr [col] = (int16) (s - 32768); |
2406 | |
|
2407 | 0 | } |
2408 | | |
2409 | 0 | planePtr += sRowStep; |
2410 | | |
2411 | 0 | maskPtr += mRowStep; |
2412 | |
|
2413 | 0 | } |
2414 | |
|
2415 | 0 | sPtr += sPlaneStep; |
2416 | | |
2417 | 0 | } |
2418 | |
|
2419 | 0 | break; |
2420 | | |
2421 | 0 | } |
2422 | | |
2423 | 0 | } |
2424 | | |
2425 | 0 | } |
2426 | | |
2427 | | /*****************************************************************************/ |
2428 | | |
2429 | | void RefVignette32 (real32 *sPtr, |
2430 | | const uint16 *mPtr, |
2431 | | uint32 rows, |
2432 | | uint32 cols, |
2433 | | uint32 planes, |
2434 | | int32 sRowStep, |
2435 | | int32 sPlaneStep, |
2436 | | int32 mRowStep, |
2437 | | uint32 mBits) |
2438 | 0 | { |
2439 | | |
2440 | 0 | const real32 kNorm = 1.0f / (1 << mBits); |
2441 | |
|
2442 | 0 | switch (planes) |
2443 | 0 | { |
2444 | | |
2445 | 0 | case 1: |
2446 | 0 | { |
2447 | | |
2448 | 0 | for (uint32 row = 0; row < rows; row++) |
2449 | 0 | { |
2450 | | |
2451 | 0 | for (uint32 col = 0; col < cols; col++) |
2452 | 0 | { |
2453 | | |
2454 | 0 | real32 s = sPtr [col]; |
2455 | |
|
2456 | 0 | uint16 m = mPtr [col]; |
2457 | |
|
2458 | 0 | real32 scale = m * kNorm; |
2459 | | |
2460 | 0 | s = Min_real32 (s * scale, 1.0f); |
2461 | | |
2462 | 0 | sPtr [col] = s; |
2463 | | |
2464 | 0 | } |
2465 | | |
2466 | 0 | sPtr += sRowStep; |
2467 | | |
2468 | 0 | mPtr += mRowStep; |
2469 | | |
2470 | 0 | } |
2471 | |
|
2472 | 0 | break; |
2473 | | |
2474 | 0 | } |
2475 | | |
2476 | 0 | case 3: |
2477 | 0 | { |
2478 | |
|
2479 | 0 | real32 *rPtr = sPtr; |
2480 | 0 | real32 *gPtr = rPtr + sPlaneStep; |
2481 | 0 | real32 *bPtr = gPtr + sPlaneStep; |
2482 | | |
2483 | 0 | for (uint32 row = 0; row < rows; row++) |
2484 | 0 | { |
2485 | | |
2486 | 0 | for (uint32 col = 0; col < cols; col++) |
2487 | 0 | { |
2488 | | |
2489 | 0 | real32 r = rPtr [col]; |
2490 | 0 | real32 g = gPtr [col]; |
2491 | 0 | real32 b = bPtr [col]; |
2492 | | |
2493 | 0 | uint16 m = mPtr [col]; |
2494 | | |
2495 | 0 | real32 scale = m * kNorm; |
2496 | |
|
2497 | 0 | r = Min_real32 (r * scale, 1.0f); |
2498 | 0 | g = Min_real32 (g * scale, 1.0f); |
2499 | 0 | b = Min_real32 (b * scale, 1.0f); |
2500 | | |
2501 | 0 | rPtr [col] = r; |
2502 | 0 | gPtr [col] = g; |
2503 | 0 | bPtr [col] = b; |
2504 | | |
2505 | 0 | } |
2506 | | |
2507 | 0 | rPtr += sRowStep; |
2508 | 0 | gPtr += sRowStep; |
2509 | 0 | bPtr += sRowStep; |
2510 | | |
2511 | 0 | mPtr += mRowStep; |
2512 | | |
2513 | 0 | } |
2514 | |
|
2515 | 0 | break; |
2516 | | |
2517 | 0 | } |
2518 | | |
2519 | 0 | case 4: |
2520 | 0 | { |
2521 | | |
2522 | 0 | real32 *aPtr = sPtr; |
2523 | 0 | real32 *bPtr = aPtr + sPlaneStep; |
2524 | 0 | real32 *cPtr = bPtr + sPlaneStep; |
2525 | 0 | real32 *dPtr = cPtr + sPlaneStep; |
2526 | | |
2527 | 0 | for (uint32 row = 0; row < rows; row++) |
2528 | 0 | { |
2529 | | |
2530 | 0 | for (uint32 col = 0; col < cols; col++) |
2531 | 0 | { |
2532 | |
|
2533 | 0 | real32 a = aPtr [col]; |
2534 | 0 | real32 b = bPtr [col]; |
2535 | 0 | real32 c = cPtr [col]; |
2536 | 0 | real32 d = dPtr [col]; |
2537 | | |
2538 | 0 | uint16 m = mPtr [col]; |
2539 | |
|
2540 | 0 | real32 scale = m * kNorm; |
2541 | |
|
2542 | 0 | a = Min_real32 (a * scale, 1.0f); |
2543 | 0 | b = Min_real32 (b * scale, 1.0f); |
2544 | 0 | c = Min_real32 (c * scale, 1.0f); |
2545 | 0 | d = Min_real32 (d * scale, 1.0f); |
2546 | | |
2547 | 0 | aPtr [col] = a; |
2548 | 0 | bPtr [col] = b; |
2549 | 0 | cPtr [col] = c; |
2550 | 0 | dPtr [col] = d; |
2551 | | |
2552 | 0 | } |
2553 | | |
2554 | 0 | aPtr += sRowStep; |
2555 | 0 | bPtr += sRowStep; |
2556 | 0 | cPtr += sRowStep; |
2557 | 0 | dPtr += sRowStep; |
2558 | | |
2559 | 0 | mPtr += mRowStep; |
2560 | | |
2561 | 0 | } |
2562 | |
|
2563 | 0 | break; |
2564 | | |
2565 | 0 | } |
2566 | | |
2567 | 0 | default: |
2568 | 0 | { |
2569 | | |
2570 | 0 | for (uint32 plane = 0; plane < planes; plane++) |
2571 | 0 | { |
2572 | |
|
2573 | 0 | real32 *planePtr = sPtr; |
2574 | |
|
2575 | 0 | const uint16 *maskPtr = mPtr; |
2576 | | |
2577 | 0 | for (uint32 row = 0; row < rows; row++) |
2578 | 0 | { |
2579 | | |
2580 | 0 | for (uint32 col = 0; col < cols; col++) |
2581 | 0 | { |
2582 | |
|
2583 | 0 | real32 s = planePtr [col]; |
2584 | | |
2585 | 0 | uint16 m = maskPtr [col]; |
2586 | |
|
2587 | 0 | real32 scale = m * kNorm; |
2588 | | |
2589 | 0 | s = Min_real32 (s * scale, 1.0f); |
2590 | | |
2591 | 0 | planePtr [col] = s; |
2592 | |
|
2593 | 0 | } |
2594 | | |
2595 | 0 | planePtr += sRowStep; |
2596 | | |
2597 | 0 | maskPtr += mRowStep; |
2598 | |
|
2599 | 0 | } |
2600 | |
|
2601 | 0 | sPtr += sPlaneStep; |
2602 | | |
2603 | 0 | } |
2604 | |
|
2605 | 0 | break; |
2606 | | |
2607 | 0 | } |
2608 | | |
2609 | 0 | } |
2610 | | |
2611 | 0 | } |
2612 | | |
2613 | | /******************************************************************************/ |
2614 | | |
2615 | | void RefMapArea16 (uint16 *dPtr, |
2616 | | uint32 count0, |
2617 | | uint32 count1, |
2618 | | uint32 count2, |
2619 | | int32 step0, |
2620 | | int32 step1, |
2621 | | int32 step2, |
2622 | | const uint16 *map) |
2623 | 0 | { |
2624 | | |
2625 | 0 | if (step2 == 1 && count2 >= 32) |
2626 | 0 | { |
2627 | | |
2628 | 0 | for (uint32 index0 = 0; index0 < count0; index0++) |
2629 | 0 | { |
2630 | | |
2631 | 0 | uint16 *d1 = dPtr; |
2632 | | |
2633 | 0 | for (uint32 index1 = 0; index1 < count1; index1++) |
2634 | 0 | { |
2635 | | |
2636 | 0 | uint16 *d2 = d1; |
2637 | | |
2638 | 0 | uint32 count = count2; |
2639 | | |
2640 | | // Get the data 32-bit aligned if it is not. |
2641 | | |
2642 | 0 | if (!IsAligned32 (dPtr)) |
2643 | 0 | { |
2644 | | |
2645 | 0 | d2 [0] = map [d2 [0]]; |
2646 | | |
2647 | 0 | count--; |
2648 | | |
2649 | 0 | d2++; |
2650 | | |
2651 | 0 | } |
2652 | | |
2653 | | // Use 32-bit reads and writes for bulk processing. |
2654 | | |
2655 | 0 | uint32 *dPtr32 = (uint32 *) d2; |
2656 | | |
2657 | | // Process in blocks of 16 pixels. |
2658 | | |
2659 | 0 | uint32 blocks = count >> 4; |
2660 | | |
2661 | 0 | count -= blocks << 4; |
2662 | 0 | d2 += blocks << 4; |
2663 | | |
2664 | 0 | while (blocks--) |
2665 | 0 | { |
2666 | | |
2667 | 0 | uint32 x0, x1, x2, x3, x4, x5, x6, x7; |
2668 | 0 | uint32 p0, p1, p2, p3, p4, p5, p6, p7; |
2669 | | |
2670 | | // Use 32 bit reads & writes, and pack and unpack the 16-bit values. |
2671 | | // This results in slightly higher performance. |
2672 | | |
2673 | | // Note that this code runs on both little-endian and big-endian systems, |
2674 | | // since the pixels are either never swapped or double swapped. |
2675 | | |
2676 | 0 | x0 = dPtr32 [0]; |
2677 | 0 | x1 = dPtr32 [1]; |
2678 | 0 | x2 = dPtr32 [2]; |
2679 | 0 | x3 = dPtr32 [3]; |
2680 | | |
2681 | 0 | p0 = map [x0 >> 16 ]; |
2682 | 0 | p1 = map [x0 & 0x0FFFF]; |
2683 | 0 | p2 = map [x1 >> 16 ]; |
2684 | 0 | p3 = map [x1 & 0x0FFFF]; |
2685 | 0 | p4 = map [x2 >> 16 ]; |
2686 | 0 | p5 = map [x2 & 0x0FFFF]; |
2687 | 0 | p6 = map [x3 >> 16 ]; |
2688 | 0 | p7 = map [x3 & 0x0FFFF]; |
2689 | | |
2690 | 0 | x0 = (p0 << 16) | p1; |
2691 | 0 | x1 = (p2 << 16) | p3; |
2692 | 0 | x2 = (p4 << 16) | p5; |
2693 | 0 | x3 = (p6 << 16) | p7; |
2694 | | |
2695 | 0 | x4 = dPtr32 [4]; |
2696 | 0 | x5 = dPtr32 [5]; |
2697 | 0 | x6 = dPtr32 [6]; |
2698 | 0 | x7 = dPtr32 [7]; |
2699 | | |
2700 | 0 | dPtr32 [0] = x0; |
2701 | 0 | dPtr32 [1] = x1; |
2702 | 0 | dPtr32 [2] = x2; |
2703 | 0 | dPtr32 [3] = x3; |
2704 | | |
2705 | 0 | p0 = map [x4 >> 16 ]; |
2706 | 0 | p1 = map [x4 & 0x0FFFF]; |
2707 | 0 | p2 = map [x5 >> 16 ]; |
2708 | 0 | p3 = map [x5 & 0x0FFFF]; |
2709 | 0 | p4 = map [x6 >> 16 ]; |
2710 | 0 | p5 = map [x6 & 0x0FFFF]; |
2711 | 0 | p6 = map [x7 >> 16 ]; |
2712 | 0 | p7 = map [x7 & 0x0FFFF]; |
2713 | | |
2714 | 0 | x4 = (p0 << 16) | p1; |
2715 | 0 | x5 = (p2 << 16) | p3; |
2716 | 0 | x6 = (p4 << 16) | p5; |
2717 | 0 | x7 = (p6 << 16) | p7; |
2718 | | |
2719 | 0 | dPtr32 [4] = x4; |
2720 | 0 | dPtr32 [5] = x5; |
2721 | 0 | dPtr32 [6] = x6; |
2722 | 0 | dPtr32 [7] = x7; |
2723 | | |
2724 | 0 | dPtr32 += 8; |
2725 | | |
2726 | 0 | } |
2727 | | |
2728 | | // Process remaining columns. |
2729 | | |
2730 | 0 | for (uint32 j = 0; j < count; j++) |
2731 | 0 | { |
2732 | | |
2733 | 0 | d2 [j] = map [d2 [j]]; |
2734 | | |
2735 | 0 | } |
2736 | | |
2737 | 0 | d1 += step1; |
2738 | | |
2739 | 0 | } |
2740 | | |
2741 | 0 | dPtr += step0; |
2742 | | |
2743 | 0 | } |
2744 | | |
2745 | 0 | } |
2746 | | |
2747 | 0 | else |
2748 | 0 | { |
2749 | | |
2750 | 0 | for (uint32 index0 = 0; index0 < count0; index0++) |
2751 | 0 | { |
2752 | | |
2753 | 0 | uint16 *d1 = dPtr; |
2754 | | |
2755 | 0 | for (uint32 index1 = 0; index1 < count1; index1++) |
2756 | 0 | { |
2757 | | |
2758 | 0 | uint16 *d2 = d1; |
2759 | | |
2760 | 0 | for (uint32 index2 = 0; index2 < count2; index2++) |
2761 | 0 | { |
2762 | | |
2763 | 0 | d2 [0] = map [d2 [0]]; |
2764 | | |
2765 | 0 | d2 += step2; |
2766 | | |
2767 | 0 | } |
2768 | | |
2769 | 0 | d1 += step1; |
2770 | | |
2771 | 0 | } |
2772 | | |
2773 | 0 | dPtr += step0; |
2774 | | |
2775 | 0 | } |
2776 | | |
2777 | 0 | } |
2778 | | |
2779 | 0 | } |
2780 | | |
2781 | | /*****************************************************************************/ |