// Copyright (C) 1999-2017 // Smithsonian Astrophysical Observatory, Cambridge, MA, USA // For conditions of distribution and use, see copyright notice in "copyright" #include "colorbarrgb.h" #include "util.h" #include "ps.h" ColorbarRGB::ColorbarRGB(Tcl_Interp* i,Tk_Canvas c,Tk_Item* item) : ColorbarBase(i,c,item) { channel = 0; for (int i=0; i<3; i++) { bias[i] = .5; contrast[i] = 1.0; } } int ColorbarRGB::calcContrastBias(int i, float bb, float cc) { // if default (contrast = 1.0 && bias = .5) return if (fabs(bb - 0.5) < 0.0001 && fabs(cc - 1.0) < 0.0001) return i; // map i to range of 0 to 1.0 // shift by bias (if invert, bias = 1-bias) // multiply by contrast // shift to center of region // expand back to number of dynamic colors float b = invert ? 1-bb : bb; int r = (int)(((((float)i / colorCount) - b) * cc + .5 ) * colorCount); // clip to bounds if out of range if (r < 0) return 0; else if (r >= colorCount) return colorCount-1; else return r; } void ColorbarRGB::psHorz(ostream& str, Filter& filter, int width, int height) { // red for (int jj=0; jj<(int)(height/3.); jj++) { for (int ii=0; iiorientation) { // blue for (int jj=0; jj<(int)(height/3.); jj++) for (int ii=0; iiorientation) { // blue for (int jj=0; jj<(int)(height/3.); jj++) { for (int ii=0; ii