Page MenuHomec4science

pmutil.c
No OneTemporary

File Metadata

Created
Fri, Oct 18, 11:38

pmutil.c

#ifndef lint
static const char RCSid[] = "$Id: pmutil.c,v 2.5 2020/04/08 15:14:21 rschregle Exp $";
#endif
/*
======================================================================
Auxiliary photon map utilities
Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
(c) Fraunhofer Institute for Solar Energy Systems,
(c) Lucerne University of Applied Sciences and Arts,
supported by the Swiss National Science Foundation (SNSF, #147053)
======================================================================
$Id: pmutil.c,v 2.5 2020/04/08 15:14:21 rschregle Exp $
*/
#include "pmutil.h"
#if NIX
#include <fcntl.h>
#endif
void colorNorm (COLOR c)
/* Normalise colour channels to average of 1 */
{
const float avg = colorAvg(c);
if (!avg)
return;
c [0] /= avg;
c [1] /= avg;
c [2] /= avg;
}
void cleanUpPmaps (PhotonMap **pmaps)
{
unsigned t;
for (t = 0; t < NUM_PMAP_TYPES; t++) {
if (pmaps [t]) {
deletePhotons(pmaps [t]);
free(pmaps [t]);
}
}
}
#if NIX
void shmLock (int shmFile, int type)
/* Set/release record lock on shared memory file,
where type is either F_RDLCK, F_WRLCK or F_UNLCK*/
{
struct flock lock;
lock.l_type = type;
lock.l_whence = SEEK_SET;
lock.l_start = lock.l_len = 0;
/* F_SETLKW waits until file is released by other process. A loop
* handles interrupt by a signal (error EINTR). */
do
if (fcntl(shmFile, F_SETLKW, &lock) >= 0)
/* Okie dokie */
return;
while (errno == EINTR);
error(SYSTEM,
"failed to (un)lock shared memory in distribPhotonContrib()"
);
}
#endif

Event Timeline