--- ray/src/rt/RpictSimulManager.h 2024/08/19 16:41:40 2.4 +++ ray/src/rt/RpictSimulManager.h 2024/10/10 21:02:52 2.10 @@ -1,4 +1,4 @@ -/* RCSid $Id: RpictSimulManager.h,v 2.4 2024/08/19 16:41:40 greg Exp $ */ +/* RCSid $Id: RpictSimulManager.h,v 2.10 2024/10/10 21:02:52 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); @@ -275,7 +291,7 @@ class RpictSimulManager : protected RtraceSimulManager frameNo = 0; } ~RpictSimulManager() { - NewBar(); + delete [] barPix; delete [] barDepth; } /// Load octree and prepare renderer bool LoadOctree(const char *octn) { @@ -294,9 +310,13 @@ class RpictSimulManager : protected RtraceSimulManager return RtraceSimulManager::AddHeader(ac, av); } /// 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); @@ -381,7 +401,7 @@ class RpictSimulManager : protected RtraceSimulManager const int *tile=NULL); /// Render and write a frame to the named file /// Include any header lines set prior to call - /// Picture file must not already exist + /// Picture file must not exist /// Write pixels to stdout if !pfname /// Write depth to a command if dfname[0]=='!' RenderDataType RenderFrame(const char *pfname, @@ -390,6 +410,16 @@ class RpictSimulManager : protected RtraceSimulManager /// Resume partially finished rendering /// Picture file must exist with valid header RenderDataType ResumeFrame(const char *pfname, + const char *dfname=NULL); + /// Prepare new picture (and depth) output + /// Called by RenderFrame() after NewFrame() + RenderDataType NewOutput(FILE *pdfp[2], const char *pfname, + RenderDataType dt=RDTrgbe, + const char *dfname=NULL); + /// Reopen existing picture (and depth) file + /// Called by ResumeFrame() + /// File pointers @ end of header (before res.) + RenderDataType ReopenOutput(FILE *pdfp[2], const char *pfname, const char *dfname=NULL); /// Close octree, free data, return status int Cleanup(bool everything = false) {