| 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]; |
| 266 |
|
COLORV * barPix; // current render bar pixels |
| 267 |
|
float * barDepth; // current render bar depths |
| 268 |
|
bool SetTile(const int ti[2]); |
| 269 |
< |
bool RenderRect(); |
| 269 |
> |
bool RenderRect(const int x0 = 0, const int y0 = 0); |
| 270 |
|
bool ComputePixel(int x, int y); |
| 271 |
< |
bool BelowSampThresh(int x, int y, const int noff[4][2]) const; |
| 271 |
> |
bool BelowSampThresh(const int x, const int y, |
| 272 |
> |
const int noff[4][2]) const; |
| 273 |
|
void FillSquare(const int x, const int y, const int noff[4][2]); |
| 274 |
|
void NewBar(int ht = 0); |
| 275 |
|
bool LowerBar(int v, int ytop); |
| 310 |
|
return RtraceSimulManager::AddHeader(ac, av); |
| 311 |
|
} |
| 312 |
|
/// Get header lines if any |
| 313 |
< |
const char * GetHeader() const { |
| 314 |
< |
return RtraceSimulManager::GetHeader(); |
| 313 |
> |
const char * GetHeadStr() const { |
| 314 |
> |
return RtraceSimulManager::GetHeadStr(); |
| 315 |
|
} |
| 316 |
+ |
/// Look for specific header keyword, return value |
| 317 |
+ |
const char * GetHeadStr(const char *key, bool inOK = false) const { |
| 318 |
+ |
return RtraceSimulManager::GetHeadStr(key, inOK); |
| 319 |
+ |
} |
| 320 |
|
/// Set number of computation threads (0 => #cores) |
| 321 |
|
int SetThreadCount(int nt = 0) { |
| 322 |
|
return RtraceSimulManager::SetThreadCount(nt); |
| 412 |
|
RenderDataType ResumeFrame(const char *pfname, |
| 413 |
|
const char *dfname=NULL); |
| 414 |
|
/// Prepare new picture (and depth) output |
| 415 |
< |
/// Writes current render size as resolution |
| 415 |
> |
/// Called by RenderFrame() after NewFrame() |
| 416 |
|
RenderDataType NewOutput(FILE *pdfp[2], const char *pfname, |
| 417 |
|
RenderDataType dt=RDTrgbe, |
| 418 |
|
const char *dfname=NULL); |
| 419 |
|
/// Reopen existing picture (and depth) file |
| 420 |
+ |
/// Called by ResumeFrame() |
| 421 |
|
/// File pointers @ end of header (before res.) |
| 422 |
|
RenderDataType ReopenOutput(FILE *pdfp[2], const char *pfname, |
| 423 |
|
const char *dfname=NULL); |