| 10 |
|
#include "copyright.h" |
| 11 |
|
|
| 12 |
|
#include <stdio.h> |
| 13 |
+ |
#include <stdlib.h> |
| 14 |
|
#include <string.h> |
| 15 |
|
#include <math.h> |
| 16 |
|
#include <time.h> |
| 17 |
|
|
| 17 |
– |
#include "tmprivat.h" |
| 18 |
– |
#include "resolu.h" |
| 18 |
|
#ifdef PCOND |
| 19 |
|
#include "rtprocess.h" |
| 20 |
|
#endif |
| 21 |
+ |
#include "tmprivat.h" |
| 22 |
+ |
#include "resolu.h" |
| 23 |
|
|
| 24 |
< |
#define GAMTSZ 1024 |
| 24 |
> |
#define GAMTSZ 4096 |
| 25 |
|
|
| 26 |
|
typedef struct { |
| 27 |
|
BYTE gamb[GAMTSZ]; /* gamma lookup table */ |
| 39 |
|
}; |
| 40 |
|
static int colrReg = -1; /* our package registration number */ |
| 41 |
|
|
| 42 |
< |
#define LOGISZ 260 |
| 42 |
< |
static TMbright logi[LOGISZ]; |
| 42 |
> |
static TMbright logi[256]; |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
int |
| 53 |
|
{ |
| 54 |
|
static const char funcName[] = "tmCvColrs"; |
| 55 |
|
int cmon[4]; |
| 56 |
< |
register COLRDATA *cd; |
| 57 |
< |
register int i, j, li, bi; |
| 58 |
< |
int32 vl; |
| 56 |
> |
COLRDATA *cd; |
| 57 |
> |
int i, j, bi; |
| 58 |
> |
int32 li, vl; |
| 59 |
|
|
| 60 |
|
if (tms == NULL) |
| 61 |
|
returnErr(TM_E_TMINVAL); |
| 67 |
|
returnErr(TM_E_CODERR1); |
| 68 |
|
for (i = 256; i--; ) |
| 69 |
|
logi[i] = TM_BRTSCALE*log((i+.5)/256.) - .5; |
| 70 |
– |
for (i = 256; i < LOGISZ; i++) |
| 71 |
– |
logi[i] = 0; |
| 70 |
|
tmMkMesofact(); |
| 71 |
|
} |
| 72 |
|
if ((cd = (COLRDATA *)tmPkgData(tms,colrReg)) == NULL) |
| 84 |
|
} else |
| 85 |
|
copycolr(cmon, scan[i]); |
| 86 |
|
/* world luminance */ |
| 87 |
< |
li = cd->clfb[RED]*cmon[RED] + |
| 88 |
< |
cd->clfb[GRN]*cmon[GRN] + |
| 89 |
< |
cd->clfb[BLU]*cmon[BLU] ; |
| 90 |
< |
if (li >= 0xff00) li = 255; |
| 91 |
< |
else li >>= 8; |
| 87 |
> |
li = cd->clfb[RED]*(int32)cmon[RED] + |
| 88 |
> |
cd->clfb[GRN]*(int32)cmon[GRN] + |
| 89 |
> |
cd->clfb[BLU]*(int32)cmon[BLU] ; |
| 90 |
> |
if (li >= 1L<<(12+8)) li = 255; |
| 91 |
> |
else li >>= 12; |
| 92 |
|
bi = BRT2SCALE(cmon[EXP]-COLXS) + cd->inpsfb; |
| 93 |
|
if (li > 0) |
| 94 |
|
bi += logi[li]; |
| 121 |
|
for (j = 3; j--; ) |
| 122 |
|
if (cmon[j] < 0) cmon[j] = 0; |
| 123 |
|
} |
| 124 |
< |
bi = ( (int32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 8; |
| 124 |
> |
bi = ( (uint32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 12; |
| 125 |
|
cs[3*i ] = bi>=GAMTSZ ? 255 : cd->gamb[bi]; |
| 126 |
< |
bi = ( (int32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 8; |
| 126 |
> |
bi = ( (uint32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 12; |
| 127 |
|
cs[3*i+1] = bi>=GAMTSZ ? 255 : cd->gamb[bi]; |
| 128 |
< |
bi = ( (int32)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 8; |
| 128 |
> |
bi = ( (uint32)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 12; |
| 129 |
|
cs[3*i+2] = bi>=GAMTSZ ? 255 : cd->gamb[bi]; |
| 130 |
|
} |
| 131 |
|
returnOK; |
| 147 |
|
|
| 148 |
|
static int |
| 149 |
|
headline( /* grok a header line */ |
| 150 |
< |
register char *s, |
| 150 |
> |
char *s, |
| 151 |
|
void *vrh |
| 152 |
|
) |
| 153 |
|
{ |
| 154 |
|
char fmt[32]; |
| 155 |
< |
register struct radhead *rh = vrh; |
| 155 |
> |
struct radhead *rh = vrh; |
| 156 |
|
|
| 157 |
|
if (formatval(fmt, s)) { |
| 158 |
|
if (!strcmp(fmt, COLRFMT)) |
| 272 |
|
TMstruct *tms = NULL; |
| 273 |
|
char cmdbuf[1024]; |
| 274 |
|
FILE *infp; |
| 275 |
< |
register COLR *scan; |
| 276 |
< |
register BYTE *rp; |
| 275 |
> |
COLR *scan; |
| 276 |
> |
BYTE *rp; |
| 277 |
|
int y; |
| 278 |
< |
register int x; |
| 278 |
> |
int x; |
| 279 |
|
/* set up gamma correction */ |
| 280 |
|
if (setcolrcor(pow, 1./gamval) < 0) |
| 281 |
|
returnErr(TM_E_NOMEM); |
| 421 |
|
|
| 422 |
|
static void |
| 423 |
|
colrNewSpace(tms) /* color space changed for tone mapping */ |
| 424 |
< |
register TMstruct *tms; |
| 424 |
> |
TMstruct *tms; |
| 425 |
|
{ |
| 426 |
< |
register COLRDATA *cd; |
| 426 |
> |
COLRDATA *cd; |
| 427 |
|
double d; |
| 428 |
|
int i, j; |
| 429 |
|
|
| 430 |
|
cd = (COLRDATA *)tms->pd[colrReg]; |
| 431 |
|
for (i = 3; i--; ) |
| 432 |
< |
cd->clfb[i] = 0x100*tms->clf[i] + .5; |
| 433 |
< |
d = TM_BRTSCALE*log(tms->inpsf); |
| 436 |
< |
cd->inpsfb = d<0. ? d-.5 : d+.5; |
| 432 |
> |
cd->clfb[i] = 0x1000*tms->clf[i] + .5; |
| 433 |
> |
cd->inpsfb = tmCvLuminance(tms->inpsf); |
| 434 |
|
for (i = 3; i--; ) |
| 435 |
|
for (j = 3; j--; ) { |
| 436 |
|
d = tms->cmat[i][j] / tms->inpsf; |
| 441 |
|
|
| 442 |
|
static MEM_PTR |
| 443 |
|
colrInit(tms) /* initialize private data for tone mapping */ |
| 444 |
< |
register TMstruct *tms; |
| 444 |
> |
TMstruct *tms; |
| 445 |
|
{ |
| 446 |
< |
register COLRDATA *cd; |
| 447 |
< |
register int i; |
| 446 |
> |
COLRDATA *cd; |
| 447 |
> |
int i; |
| 448 |
|
/* allocate our data */ |
| 449 |
|
cd = (COLRDATA *)malloc(sizeof(COLRDATA)); |
| 450 |
|
if (cd == NULL) |