From: <kin...@us...> - 2004-01-16 16:10:30
|
Update of /cvsroot/teem/teem/src/bin In directory sc8-pr-cvs1:/tmp/cvs-serv4082 Modified Files: overrgb.c Log Message: now accepts -bi option for given a background image to composite against Index: overrgb.c =================================================================== RCS file: /cvsroot/teem/teem/src/bin/overrgb.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** overrgb.c 7 Jan 2004 15:34:28 -0000 1.9 --- overrgb.c 16 Jan 2004 16:10:27 -0000 1.10 *************** *** 23,35 **** #include <teem/nrrd.h> ! char *overInfo = ("Composites an RGBA nrrd over " ! "a background color, after doing gamma correction, " ! "then quantizes to an 8-bit ppm. Actually, the " ! "input nrrd can have more than 4 values per pixel, " ! "but only the first four are used. If the RGBA nrrd " ! "is floating point, the values are taken at face value; " ! "if it is fixed point, the values interpreted as having " ! "been quantized (so that 8-bit RGBA images will act as " ! "you expect)."); int --- 23,36 ---- #include <teem/nrrd.h> ! char *overInfo = ( ! "Composites an RGBA nrrd over " ! "a background color (or image), after doing gamma correction, " ! "then quantizes to an 8-bit image. Actually, the " ! "input nrrd can have more than 4 values per pixel, " ! "but only the first four are used. If the RGBA nrrd " ! "is floating point, the values are taken at face value; " ! "if it is fixed point, the values interpreted as having " ! "been quantized (so that 8-bit RGBA images will act as " ! "you expect)."); int *************** *** 38,47 **** Nrrd *nin, *nout, /* initial input and final output */ *ninD, /* input converted to double */ *nrgbaD; /* rgba input as double */ char *me, *outS, *errS; double gamma, back[3], *rgbaD, r, g, b, a; airArray *mop; ! int E, N, min[3], max[3], i, rI, gI, bI; ! unsigned char *outUC; me = argv[0]; --- 39,49 ---- Nrrd *nin, *nout, /* initial input and final output */ *ninD, /* input converted to double */ + *nbg, /* background image (optional) */ *nrgbaD; /* rgba input as double */ char *me, *outS, *errS; double gamma, back[3], *rgbaD, r, g, b, a; airArray *mop; ! int E, min[3], max[3], i, rI, gI, bI, sx, sy; ! unsigned char *outUC, *bgUC; me = argv[0]; *************** *** 54,57 **** --- 56,62 ---- "background color to composite against; white is " "1 1 1, not 255 255 255."); + hestOptAdd(&hopt, "bi", "nbg", airTypeOther, 1, 1, &nbg, "", + "8-bit RGB background image to composite against", + NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &outS, NULL, "file to write output PPM image to"); *************** *** 66,74 **** } if (nrrdTypeBlock == nin->type) { ! fprintf(stderr, "%s: can't use a %s nrrd", me, airEnumStr(nrrdType, nrrdTypeBlock)); airMopError(mop); return 1; } ninD = nrrdNew(); airMopAdd(mop, ninD, (airMopper)nrrdNuke, airMopAlways); --- 71,93 ---- } if (nrrdTypeBlock == nin->type) { ! fprintf(stderr, "%s: can't use a %s nrrd\n", me, airEnumStr(nrrdType, nrrdTypeBlock)); airMopError(mop); return 1; } + sx = nin->axis[1].size; + sy = nin->axis[2].size; + if (nbg) { + if (!(3 == nbg->dim + && 3 == nbg->axis[0].size + && sx == nbg->axis[1].size + && sy == nbg->axis[2].size + && nrrdTypeUChar == nbg->type)) { + fprintf(stderr, "%s: background image not %dx%d 8-bit RGB\n", + me, sx, sy); + airMopError(mop); return 1; + } + } + ninD = nrrdNew(); airMopAdd(mop, ninD, (airMopper)nrrdNuke, airMopAlways); *************** *** 88,95 **** min[0] = min[1] = min[2] = 0; max[0] = 3; ! max[1] = nin->axis[1].size-1; ! max[2] = nin->axis[2].size-1; if (!E) E |= nrrdCrop(nrgbaD, ninD, min, max); ! if (!E) E |= nrrdPPM(nout, nin->axis[1].size, nin->axis[2].size); if (E) { fprintf(stderr, "%s: trouble:\n%s", me, errS = biffGetDone(NRRD)); --- 107,114 ---- min[0] = min[1] = min[2] = 0; max[0] = 3; ! max[1] = sx-1; ! max[2] = sy-1; if (!E) E |= nrrdCrop(nrgbaD, ninD, min, max); ! if (!E) E |= nrrdPPM(nout, sx, sy); if (E) { fprintf(stderr, "%s: trouble:\n%s", me, errS = biffGetDone(NRRD)); *************** *** 98,104 **** outUC = (unsigned char*)nout->data; rgbaD = (double *)nrgbaD->data; ! N = nin->axis[1].size * nin->axis[2].size; ! for (i=0; i<N; i++) { r = AIR_CLAMP(0, rgbaD[0], 1); g = AIR_CLAMP(0, rgbaD[1], 1); --- 117,123 ---- outUC = (unsigned char*)nout->data; + bgUC = nbg ? nbg->data : NULL; rgbaD = (double *)nrgbaD->data; ! for (i=0; i<sx*sy; i++) { r = AIR_CLAMP(0, rgbaD[0], 1); g = AIR_CLAMP(0, rgbaD[1], 1); *************** *** 108,114 **** g = pow(g, 1.0/gamma); b = pow(b, 1.0/gamma); ! r = a*r + (1-a)*back[0]; ! g = a*g + (1-a)*back[1]; ! b = a*b + (1-a)*back[2]; AIR_INDEX(0.0, r, 1.0, 256, rI); AIR_INDEX(0.0, g, 1.0, 256, gI); --- 127,139 ---- g = pow(g, 1.0/gamma); b = pow(b, 1.0/gamma); ! if (bgUC) { ! r = a*r + (1-a)*back[0]; ! g = a*g + (1-a)*back[1]; ! b = a*b + (1-a)*back[2]; ! } else { ! r = a*r + (1-a)*bgUC[0 + 3*i]/255; ! g = a*g + (1-a)*bgUC[0 + 3*i]/255; ! b = a*b + (1-a)*bgUC[0 + 3*i]/255; ! } AIR_INDEX(0.0, r, 1.0, 256, rI); AIR_INDEX(0.0, g, 1.0, 256, gI); |