50346ffbe1973d1f4ed96da63ed36ee70ea07f03 kent Tue Mar 26 23:01:16 2013 -0700 Removing magic number per Kate's suggestion. Ref #10370 diff --git src/hg/hgTracks/multiWig.c src/hg/hgTracks/multiWig.c index 14b6e45..fa54dc4 100644 --- src/hg/hgTracks/multiWig.c +++ src/hg/hgTracks/multiWig.c @@ -57,54 +57,60 @@ } void floatPicSet(struct floatPic *pic, float r, float g, float b) /* Set full image to a single color */ { long totalSize = pic->width * pic->height; float *p = pic->image; while (--totalSize >= 0) { *p++ = r; *p++ = g; *p++ = b; } } +// The value below is useful when scaling between floating point 0-1 representation +// and 0-255 fit-in-a-byte representation. If you use 256, then a valid 1.0 wraps +// to an invalid 256 value in the byte. If you use 255 then even 0.999999 maps +// to 254, which is a waste of space. +#define FLOAT_FOR_BIGGEST_BYTE 255.9 + void vLineViaFloat(void *image, int x, int y, int height, Color color) /* A vertical line drawer that works via floatPic. */ { struct floatPic *pic = image; /* First do some clipping */ if (x < 0 || x > pic->width) return; if (y < 0) { height += y; y = 0; } int yEnd = y + height; if (yEnd > pic->height) { yEnd = pic->height; height = yEnd - y; } if (height <= 0) return; int hOffset = x*3; -const float scaleColor = 1/255.9; +const float scaleColor = 1/FLOAT_FOR_BIGGEST_BYTE; float r = COLOR_32_RED(color) * scaleColor; float g = COLOR_32_GREEN(color) * scaleColor; float b = COLOR_32_BLUE(color) * scaleColor; while (--height >= 0) { float *p = pic->lines[y++] + hOffset; p[0] *= r; p[1] *= g; p[2] *= b; } } struct wigGraphOutput *wigGraphOutputTransparent(struct floatPic *image) /* Get appropriate wigGraphOutput for non-transparent rendering */ @@ -132,33 +138,33 @@ void floatPicIntoHvg(struct floatPic *pic, int xOff, int yOff, struct hvGfx *hvg) /* Copy float pic into hvg image at given offset. */ { int width = pic->width, height = pic->height; Color *lineBuf; AllocArray(lineBuf, width); int y; for (y=0; y<height; ++y) { float *fp = pic->lines[y]; Color *cp = lineBuf; int i = width; while (--i >= 0) { - int red = fp[0]*255.9; - int green = fp[1]*255.9; - int blue = fp[2]*255.9; + int red = fp[0]*FLOAT_FOR_BIGGEST_BYTE; + int green = fp[1]*FLOAT_FOR_BIGGEST_BYTE; + int blue = fp[2]*FLOAT_FOR_BIGGEST_BYTE; *cp++ = MAKECOLOR_32(red, green, blue); fp += 3; } if (hvg->rc) reverseLineOfColors(lineBuf, width); hvGfxVerticalSmear(hvg, xOff, y + yOff, width, 1, lineBuf, TRUE); } freez(&lineBuf); } static void minMaxVals(struct slRef *refList, double *retMin, double *retMax, enum wiggleAlwaysZeroEnum alwaysZero) /* Figure out min/max of everything in list. The refList contains pointers to * preDrawContainers */