27 |
|
#define RDTcolorT(f) RenderDataType((f) & RDTcolorM) |
28 |
|
#define RDTdepthT(f) RenderDataType((f) & RDTdepthM) |
29 |
|
#define RDTcommonE(f) (RDTcolorT(f) >= RDTscolr) |
30 |
< |
#define RDTnewCT(f,c) RenderDataType((f) & ~RDTcolorM | (c)) |
31 |
< |
#define RDTnewDT(f,d) RenderDataType((f) & ~RDTdepthM | (d)) |
30 |
> |
#define RDTnewCT(f,c) RenderDataType((f) & ~RDTcolorM | (c) & RDTcolorM) |
31 |
> |
#define RDTnewDT(f,d) RenderDataType((f) & ~RDTdepthM | (d) & RDTdepthM) |
32 |
|
|
33 |
|
/// Pixel accessor (read/write to caller's buffer with possible conversion) |
34 |
|
class PixelAccess { |
43 |
|
long rowStride; // # values to next y position |
44 |
|
int dtyp; // data type flags |
45 |
|
RGBPRIMP primp; // color primaries if tristimulus |
46 |
< |
COLORMAT xyz2myrgbmat; // custom color conversion matrix |
46 |
> |
const COLORV * CF3(int x, int y) const { |
47 |
> |
return pbase.f + (rowStride*y + x)*3; |
48 |
> |
} |
49 |
|
COLORV * CF3(int x, int y) { |
50 |
|
return pbase.f + (rowStride*y + x)*3; |
51 |
|
} |
52 |
< |
COLORV * GetCF3(int x, int y) const { |
53 |
< |
return const_cast<COLORV *>(pbase.f + (rowStride*y + x)*3); |
52 |
> |
const COLRV * CB3(int x, int y) const { |
53 |
> |
return pbase.b + (rowStride*y + x)*4; |
54 |
|
} |
53 |
– |
COLORV * SCF(int x, int y) { |
54 |
– |
return pbase.f + (rowStride*y + x)*NCSAMP; |
55 |
– |
} |
56 |
– |
COLORV * GetSCF(int x, int y) const { |
57 |
– |
return const_cast<COLORV *>(pbase.f + (rowStride*y + x)*NCSAMP); |
58 |
– |
} |
55 |
|
COLRV * CB3(int x, int y) { |
56 |
|
return pbase.b + (rowStride*y + x)*4; |
57 |
|
} |
58 |
< |
COLRV * GetCB3(int x, int y) const { |
59 |
< |
return const_cast<COLRV *>(pbase.b + (rowStride*y + x)*4); |
58 |
> |
const COLORV * SCF(int x, int y) const { |
59 |
> |
return pbase.f + (rowStride*y + x)*NCSAMP; |
60 |
|
} |
61 |
+ |
COLORV * SCF(int x, int y) { |
62 |
+ |
return pbase.f + (rowStride*y + x)*NCSAMP; |
63 |
+ |
} |
64 |
+ |
const COLRV * SCB(int x, int y) const { |
65 |
+ |
return pbase.b + (rowStride*y + x)*(NCSAMP+1); |
66 |
+ |
} |
67 |
|
COLRV * SCB(int x, int y) { |
68 |
|
return pbase.b + (rowStride*y + x)*(NCSAMP+1); |
69 |
|
} |
68 |
– |
COLRV * GetSCB(int x, int y) const { |
69 |
– |
return const_cast<COLRV *>(pbase.b + (rowStride*y + x)*(NCSAMP+1)); |
70 |
– |
} |
70 |
|
public: |
71 |
|
double refDepth; // reference depth |
72 |
|
PixelAccess() { |
85 |
|
refDepth = 1.; |
86 |
|
Init(bp, ystride, dp); |
87 |
|
} |
88 |
+ |
PixelAccess(COLORV *rp, int ystride, short *dp) { |
89 |
+ |
refDepth = 1.; |
90 |
+ |
Init(rp, ystride, dp); |
91 |
+ |
} |
92 |
|
void Init() { |
93 |
|
pbase.f = NULL; dbase.f = NULL; |
94 |
|
rowStride = 0; |
126 |
|
} |
127 |
|
if (dp) dtyp |= RDTdshort; |
128 |
|
} |
129 |
+ |
void Init(COLORV *rp, int ystride, short *dp) { |
130 |
+ |
pbase.f = rp; dbase.s = dp; |
131 |
+ |
rowStride = ystride; |
132 |
+ |
if (NCSAMP > 3) { |
133 |
+ |
dtyp = RDTscolor; primp = NULL; |
134 |
+ |
} else { |
135 |
+ |
dtyp = RDTrgb; primp = stdprims; |
136 |
+ |
} |
137 |
+ |
if (dp) dtyp |= RDTdshort; |
138 |
+ |
} |
139 |
|
/// Set color space after non-empty initialization |
140 |
|
bool SetColorSpace(RenderDataType cs, RGBPRIMP pr=NULL); |
141 |
|
/// Get color space |
189 |
|
bool GetPixel(int x, int y, COLORV *pv, float *zp=NULL) const { |
190 |
|
if (NC() == 3) { |
191 |
|
if (RDTcommonE(dtyp)) |
192 |
< |
colr_color(pv, GetCB3(x,y)); |
192 |
> |
colr_color(pv, CB3(x,y)); |
193 |
|
else |
194 |
< |
copycolor(pv, GetCF3(x,y)); |
194 |
> |
copycolor(pv, CF3(x,y)); |
195 |
|
} else if (RDTcommonE(dtyp)) |
196 |
< |
scolr_scolor(pv, GetSCB(x,y)); |
196 |
> |
scolr_scolor(pv, SCB(x,y)); |
197 |
|
else |
198 |
< |
copyscolor(pv, GetSCF(x,y)); |
198 |
> |
copyscolor(pv, SCF(x,y)); |
199 |
|
if (!zp) return true; |
200 |
|
if (RDTdepthT(dtyp) == RDTdfloat) |
201 |
|
*zp = dbase.f[rowStride*y + x]; |
211 |
|
const int nc = NC(); |
212 |
|
if (nc == 3) { |
213 |
|
if (RDTcommonE(dtyp)) |
214 |
< |
copycolr(CB3(dx,dy), GetCB3(sx,sy)); |
214 |
> |
copycolr(CB3(dx,dy), CB3(sx,sy)); |
215 |
|
else |
216 |
< |
copycolor(CF3(dx,dy), GetCF3(sx,sy)); |
216 |
> |
copycolor(CF3(dx,dy), CF3(sx,sy)); |
217 |
|
} else if (RDTcommonE(dtyp)) |
218 |
< |
copyscolr(SCB(dx,dy), GetSCB(sx,sy)); |
218 |
> |
copyscolr(SCB(dx,dy), SCB(sx,sy)); |
219 |
|
else |
220 |
< |
copyscolor(SCF(dx,dy), GetSCF(sx,sy)); |
220 |
> |
copyscolor(SCF(dx,dy), SCF(sx,sy)); |
221 |
|
switch (RDTdepthT(dtyp)) { |
222 |
|
case RDTdfloat: |
223 |
|
dbase.f[rowStride*dy + dx] = |
254 |
|
bool RenderRect(); |
255 |
|
bool ComputePixel(int x, int y); |
256 |
|
bool BelowSampThresh(int x, int y, const int noff[4][2]) const; |
257 |
< |
void FillSquare(int x, int y, const int noff[4][2]); |
257 |
> |
void FillSquare(const int x, const int y, const int noff[4][2]); |
258 |
|
void NewBar(int ht = 0); |
259 |
< |
bool LowerBar(int v); |
259 |
> |
bool LowerBar(int v, int ytop); |
260 |
|
bool RenderBelow(int ytop, const int vstep, FILE *pfp, |
261 |
|
const int dt, FILE *dfp=NULL); |
262 |
|
public: |
339 |
|
/// Increments frameNo if >0 |
340 |
|
bool NewFrame(const VIEW &v, int xydim[2], double *ap=NULL, |
341 |
|
const int *tgrid=NULL); |
342 |
+ |
/// Get current view if set |
343 |
+ |
const VIEW * GetView() const { |
344 |
+ |
if (!vw.type) return NULL; |
345 |
+ |
return &vw; |
346 |
+ |
} |
347 |
+ |
/// Writeable previous view (for motion blur) |
348 |
+ |
VIEW & PreView() { |
349 |
+ |
return pvw; |
350 |
+ |
} |
351 |
|
/// Get current picture width |
352 |
|
int GetWidth() const { |
353 |
|
return hvres[0]; |
376 |
|
/// Same but also use 16-bit encoded depth buffer |
377 |
|
bool RenderTile(COLRV *bp, int ystride, short *dp, |
378 |
|
const int *tile=NULL); |
379 |
+ |
/// Back to float color with 16-bit depth |
380 |
+ |
bool RenderTile(COLORV *rp, int ystride, short *dp, |
381 |
+ |
const int *tile=NULL); |
382 |
|
/// Render and write a frame to the named file |
383 |
|
/// Include any header lines set prior to call |
384 |
|
/// Picture file must not already exist |
385 |
< |
/// Picture to stdout if pfname==NULL |
386 |
< |
/// Depth written to a command if dfname[0]=='!' |
385 |
> |
/// Write pixels to stdout if !pfname |
386 |
> |
/// Write depth to a command if dfname[0]=='!' |
387 |
|
RenderDataType RenderFrame(const char *pfname, |
388 |
|
RenderDataType dt=RDTrgbe, |
389 |
|
const char *dfname=NULL); |