--- ray/src/rt/RpictSimulManager.h 2024/08/21 23:52:24 2.6 +++ ray/src/rt/RpictSimulManager.h 2024/10/23 23:40:41 2.11 @@ -1,4 +1,4 @@ -/* RCSid $Id: RpictSimulManager.h,v 2.6 2024/08/21 23:52:24 greg Exp $ */ +/* RCSid $Id: RpictSimulManager.h,v 2.11 2024/10/23 23:40:41 greg Exp $ */ /* * RpictSimulManager.h * @@ -13,7 +13,6 @@ #include "RtraceSimulManager.h" #include "view.h" #include "depthcodec.h" -#include "abitmap.h" /// Data type flags for pixel access and output enum RenderDataType { @@ -43,6 +42,7 @@ class PixelAccess { long rowStride; // # values to next y position int dtyp; // data type flags RGBPRIMP primp; // color primaries if tristimulus + bool swap2d; // need to swap 16-bit depths? const COLORV * CF3(int x, int y) const { return pbase.f + (rowStride*y + x)*3; } @@ -67,26 +67,41 @@ class PixelAccess { COLRV * SCB(int x, int y) { return pbase.b + (rowStride*y + x)*(NCSAMP+1); } + void EncodeDepth16(int x, int y, float z) { + short * sp = dbase.s + rowStride*y + x; + *sp = depth2code(z, refDepth); + if (swap2d) swap16((char *)sp, 1); + } + float DecodeDepth16(int x, int y) const { + short sv = dbase.s[rowStride*y + x]; + if (swap2d) swap16((char *)&sv, 1); + return code2depth(sv, refDepth); + } public: double refDepth; // reference depth PixelAccess() { refDepth = 1.; + swap2d = !nativebigendian(); Init(); } PixelAccess(COLORV *rp, int ystride, float *zp=NULL) { refDepth = 1.; + swap2d = !nativebigendian(); Init(rp, ystride, zp); } PixelAccess(COLRV *bp, int ystride, float *zp=NULL) { refDepth = 1.; + swap2d = !nativebigendian(); Init(bp, ystride, zp); } PixelAccess(COLRV *bp, int ystride, short *dp) { refDepth = 1.; + swap2d = !nativebigendian(); Init(bp, ystride, dp); } PixelAccess(COLORV *rp, int ystride, short *dp) { refDepth = 1.; + swap2d = !nativebigendian(); Init(rp, ystride, dp); } void Init() { @@ -179,10 +194,10 @@ class PixelAccess { scolor_scolr(SCB(x,y), pv); else copyscolor(SCF(x,y), pv); - if (RDTdepthT(dtyp) == RDTdfloat) + if (DepthType() == RDTdfloat) dbase.f[rowStride*y + x] = z; - else if (RDTdepthT(dtyp) == RDTdshort) - dbase.s[rowStride*y + x] = depth2code(z, refDepth); + else if (DepthType() == RDTdshort) + EncodeDepth16(x, y, z); return true; } /// Retrieve pixel color (& depth) -- may convert either/both @@ -197,10 +212,10 @@ class PixelAccess { else copyscolor(pv, SCF(x,y)); if (!zp) return true; - if (RDTdepthT(dtyp) == RDTdfloat) + if (DepthType() == RDTdfloat) *zp = dbase.f[rowStride*y + x]; - else if (RDTdepthT(dtyp) == RDTdshort) - *zp = code2depth(dbase.s[rowStride*y + x], refDepth); + else if (DepthType() == RDTdshort) + *zp = DecodeDepth16(x, y); else *zp = .0f; return true; @@ -218,7 +233,7 @@ class PixelAccess { copyscolr(SCB(dx,dy), SCB(sx,sy)); else copyscolor(SCF(dx,dy), SCF(sx,sy)); - switch (RDTdepthT(dtyp)) { + switch (DepthType()) { case RDTdfloat: dbase.f[rowStride*dy + dx] = dbase.f[rowStride*sy + sx]; @@ -251,9 +266,10 @@ class RpictSimulManager : protected RtraceSimulManager COLORV * barPix; // current render bar pixels float * barDepth; // current render bar depths bool SetTile(const int ti[2]); - bool RenderRect(); + bool RenderRect(const int x0 = 0, const int y0 = 0); bool ComputePixel(int x, int y); - bool BelowSampThresh(int x, int y, const int noff[4][2]) const; + bool BelowSampThresh(const int x, const int y, + const int noff[4][2]) const; void FillSquare(const int x, const int y, const int noff[4][2]); void NewBar(int ht = 0); bool LowerBar(int v, int ytop); @@ -293,10 +309,18 @@ class RpictSimulManager : protected RtraceSimulManager bool AddHeader(int ac, char *av[]) { return RtraceSimulManager::AddHeader(ac, av); } + /// Get current header length in bytes + int GetHeadLen() const { + return RtraceSimulManager::GetHeadLen(); + } /// Get header lines if any - const char * GetHeader() const { - return RtraceSimulManager::GetHeader(); + const char * GetHeadStr() const { + return RtraceSimulManager::GetHeadStr(); } + /// Look for specific header keyword, return value + const char * GetHeadStr(const char *key, bool inOK = false) const { + return RtraceSimulManager::GetHeadStr(key, inOK); + } /// Set number of computation threads (0 => #cores) int SetThreadCount(int nt = 0) { return RtraceSimulManager::SetThreadCount(nt); @@ -392,7 +416,7 @@ class RpictSimulManager : protected RtraceSimulManager RenderDataType ResumeFrame(const char *pfname, const char *dfname=NULL); /// Prepare new picture (and depth) output - /// Called by RenderFrame() + /// Called by RenderFrame() after NewFrame() RenderDataType NewOutput(FILE *pdfp[2], const char *pfname, RenderDataType dt=RDTrgbe, const char *dfname=NULL);