13 |
|
#include "RtraceSimulManager.h" |
14 |
|
#include "view.h" |
15 |
|
#include "depthcodec.h" |
16 |
– |
#include "abitmap.h" |
16 |
|
|
17 |
|
/// Data type flags for pixel access and output |
18 |
|
enum RenderDataType { |
42 |
|
long rowStride; // # values to next y position |
43 |
|
int dtyp; // data type flags |
44 |
|
RGBPRIMP primp; // color primaries if tristimulus |
45 |
+ |
bool swap2d; // need to swap 16-bit depths? |
46 |
|
const COLORV * CF3(int x, int y) const { |
47 |
|
return pbase.f + (rowStride*y + x)*3; |
48 |
|
} |
67 |
|
COLRV * SCB(int x, int y) { |
68 |
|
return pbase.b + (rowStride*y + x)*(NCSAMP+1); |
69 |
|
} |
70 |
+ |
void EncodeDepth16(int x, int y, float z) { |
71 |
+ |
short * sp = dbase.s + rowStride*y + x; |
72 |
+ |
*sp = depth2code(z, refDepth); |
73 |
+ |
if (swap2d) swap16((char *)sp, 1); |
74 |
+ |
} |
75 |
+ |
float DecodeDepth16(int x, int y) const { |
76 |
+ |
short sv = dbase.s[rowStride*y + x]; |
77 |
+ |
if (swap2d) swap16((char *)&sv, 1); |
78 |
+ |
return code2depth(sv, refDepth); |
79 |
+ |
} |
80 |
|
public: |
81 |
|
double refDepth; // reference depth |
82 |
|
PixelAccess() { |
83 |
|
refDepth = 1.; |
84 |
+ |
swap2d = !nativebigendian(); |
85 |
|
Init(); |
86 |
|
} |
87 |
|
PixelAccess(COLORV *rp, int ystride, float *zp=NULL) { |
88 |
|
refDepth = 1.; |
89 |
+ |
swap2d = !nativebigendian(); |
90 |
|
Init(rp, ystride, zp); |
91 |
|
} |
92 |
|
PixelAccess(COLRV *bp, int ystride, float *zp=NULL) { |
93 |
|
refDepth = 1.; |
94 |
+ |
swap2d = !nativebigendian(); |
95 |
|
Init(bp, ystride, zp); |
96 |
|
} |
97 |
|
PixelAccess(COLRV *bp, int ystride, short *dp) { |
98 |
|
refDepth = 1.; |
99 |
+ |
swap2d = !nativebigendian(); |
100 |
|
Init(bp, ystride, dp); |
101 |
|
} |
102 |
|
PixelAccess(COLORV *rp, int ystride, short *dp) { |
103 |
|
refDepth = 1.; |
104 |
+ |
swap2d = !nativebigendian(); |
105 |
|
Init(rp, ystride, dp); |
106 |
|
} |
107 |
|
void Init() { |
194 |
|
scolor_scolr(SCB(x,y), pv); |
195 |
|
else |
196 |
|
copyscolor(SCF(x,y), pv); |
197 |
< |
if (RDTdepthT(dtyp) == RDTdfloat) |
197 |
> |
if (DepthType() == RDTdfloat) |
198 |
|
dbase.f[rowStride*y + x] = z; |
199 |
< |
else if (RDTdepthT(dtyp) == RDTdshort) |
200 |
< |
dbase.s[rowStride*y + x] = depth2code(z, refDepth); |
199 |
> |
else if (DepthType() == RDTdshort) |
200 |
> |
EncodeDepth16(x, y, z); |
201 |
|
return true; |
202 |
|
} |
203 |
|
/// Retrieve pixel color (& depth) -- may convert either/both |
212 |
|
else |
213 |
|
copyscolor(pv, SCF(x,y)); |
214 |
|
if (!zp) return true; |
215 |
< |
if (RDTdepthT(dtyp) == RDTdfloat) |
215 |
> |
if (DepthType() == RDTdfloat) |
216 |
|
*zp = dbase.f[rowStride*y + x]; |
217 |
< |
else if (RDTdepthT(dtyp) == RDTdshort) |
218 |
< |
*zp = code2depth(dbase.s[rowStride*y + x], refDepth); |
217 |
> |
else if (DepthType() == RDTdshort) |
218 |
> |
*zp = DecodeDepth16(x, y); |
219 |
|
else |
220 |
|
*zp = .0f; |
221 |
|
return true; |
233 |
|
copyscolr(SCB(dx,dy), SCB(sx,sy)); |
234 |
|
else |
235 |
|
copyscolor(SCF(dx,dy), SCF(sx,sy)); |
236 |
< |
switch (RDTdepthT(dtyp)) { |
236 |
> |
switch (DepthType()) { |
237 |
|
case RDTdfloat: |
238 |
|
dbase.f[rowStride*dy + dx] = |
239 |
|
dbase.f[rowStride*sy + sx]; |
309 |
|
bool AddHeader(int ac, char *av[]) { |
310 |
|
return RtraceSimulManager::AddHeader(ac, av); |
311 |
|
} |
312 |
+ |
/// Get current header length in bytes |
313 |
+ |
int GetHeadLen() const { |
314 |
+ |
return RtraceSimulManager::GetHeadLen(); |
315 |
+ |
} |
316 |
|
/// Get header lines if any |
317 |
< |
const char * GetHeader() const { |
318 |
< |
return RtraceSimulManager::GetHeader(); |
317 |
> |
const char * GetHeadStr() const { |
318 |
> |
return RtraceSimulManager::GetHeadStr(); |
319 |
|
} |
320 |
+ |
/// Look for specific header keyword, return value |
321 |
+ |
const char * GetHeadStr(const char *key, bool inOK = false) const { |
322 |
+ |
return RtraceSimulManager::GetHeadStr(key, inOK); |
323 |
+ |
} |
324 |
|
/// Set number of computation threads (0 => #cores) |
325 |
|
int SetThreadCount(int nt = 0) { |
326 |
|
return RtraceSimulManager::SetThreadCount(nt); |
416 |
|
RenderDataType ResumeFrame(const char *pfname, |
417 |
|
const char *dfname=NULL); |
418 |
|
/// Prepare new picture (and depth) output |
419 |
< |
/// Called by RenderFrame() |
419 |
> |
/// Called by RenderFrame() after NewFrame() |
420 |
|
RenderDataType NewOutput(FILE *pdfp[2], const char *pfname, |
421 |
|
RenderDataType dt=RDTrgbe, |
422 |
|
const char *dfname=NULL); |