//------------------------------------------------------------------------------ // gso_Palette class -- // (C) Piero Giubilato 2008-1010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gso_Palette.cpp" // [Author] "Piero Giubilato" // [Version] "0.5" // [Modified by] "Piero Giubilato" // [Last revision] "22 Jan 2009" // [Language] "C++" // [Compiler] "Visual C++ 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gso_Palette class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Standard component #include // Application component #include "global.h" #include "gso_Palette.h" // CINT Preprocessor class import definition ClassImp(gso_Palette) //______________________________________________________________________________ gso_Palette::gso_Palette(const TGWindow* window, UInt_t width, UInt_t height) :TGFrame(window, width, height, 0) { // Default constructor dbg_Print("gso_Palette::gso_Palette:(default)", DBG_LVL_ZERO); // Initializes the palette (range and colors) UInt_t col[] = {0xFFFFFF, 0x000000}; color_Set(col, 2); // Sets up the graphic context for the palette painting frame_gc_Set = new GCValues_t(); frame_gc_Set->fMask = kGCClipMask | kGCClipXOrigin | kGCClipYOrigin; frame_gc_Set->fClipMask = kNone; frame_gc_Set->fClipXOrigin = 0; frame_gc_Set->fClipYOrigin = 0; frame_gc_Hnd = gVirtualX->CreateGC(GetId(), frame_gc_Set); // Clears the pixmap reference frame_PxMap = 0; } //______________________________________________________________________________ gso_Palette::~gso_Palette() { // Default destructor dbg_Print("gso_Palette::~gso_Palette:()", DBG_LVL_ZERO); // Removes the frame dc delete frame_gc_Set; // Removes the old PixMap if any if (frame_PxMap) gVirtualX->DeletePixmap(frame_PxMap); } //______________________________________________________________________________ void gso_Palette::Draw() { // Draws the current palette dbg_Print("gso_Palette::fill:()", DBG_LVL_FLOW); // SpeedUp pivots UInt_t width = GetWidth(); UInt_t height = GetHeight(); // Removes the old PixMap in case if (frame_PxMap) gVirtualX->DeletePixmap(frame_PxMap); // Creates the PixMap reference where to store the palette image. UInt_t* chr_Array = new UInt_t[GetWidth() * GetHeight()]; // Updates the pal array with the palette colors for (UInt_t y = 1; y <= height; y++) { for (UInt_t x = 0; x < width; x++) { chr_Array[x + (height - y) * width] = pal_Value[(UInt_t)((Float_t)y / height * 255)]; } } // Converts the filled char pixmap into a PxMap frame_PxMap = gVirtualX->CreatePixmapFromData((UChar_t*)chr_Array, width, height); // Delete the pivot char array delete chr_Array; // Show the palette DoRedraw(); } //______________________________________________________________________________ void gso_Palette::color_Set(UInt_t* col_List, UInt_t col_Count) { // Sets the palette values. 'col-List' is an array of standard RGB colors, // described in the usual way 0xRRGGBB. The function takes this color list // and generates a 256 colors palettes interpolating between the different // colors. dbg_Print("gso_Palette::colors_Set:(UInt, UInt)", DBG_LVL_FLOW); // Check for the minimum number of colors if (col_Count < 2) { dbg_Print("gso_Palette::colors_Set: at least 2 color are needed to define a palette!", DBG_LVL_PLAY); return; } // SpeedUp pivots UInt_t R, G, B; Float_t iPos, iRel; UInt_t iCol; for (UInt_t i = 0; i < 256; i++) { // Gets where we are inside the color ramp iPos = ((Float_t)i/255)*(Float_t)(col_Count - 1); iCol = (UInt_t)floor(iPos); iRel = iPos - floor(iPos); // Interpolates color if (iRel < 1) { R = (UInt_t)((col_List[iCol] & 0xFF0000) * (1 - iRel) + (col_List[iCol + 1] & 0xFF0000) * iRel) & 0xFF0000; G = (UInt_t)((col_List[iCol] & 0x00FF00) * (1 - iRel) + (col_List[iCol + 1] & 0x00FF00) * iRel) & 0x00FF00; B = (UInt_t)((col_List[iCol] & 0x0000FF) * (1 - iRel) + (col_List[iCol + 1] & 0x0000FF) * iRel) & 0x0000FF; } else { R = (col_List[iCol] & 0xFF0000); G = (col_List[iCol] & 0x00FF00); B = (col_List[iCol] & 0x0000FF); } // Stores the palette as 4 bytes UInt_t in the ordere required by // the PxMap (BGRA). Note how the color are already correctly shifted. pal_Value[i] = B + G + R + 0; } // Shows the new palette Draw(); } /* //______________________________________________________________________________ void gso_Palette::range_Set(Double_t max, Double_t min) { // Sets the palette range dbg_Print("gso_Palette::range_Set: setting palette range", DBG_LVL_ZERO); // Sets range limits if (min <= max) {pal_range_Min = min; pal_range_Max = max;} else {pal_range_Max = min; pal_range_Min = max;} // Refill the palette fill(); } //______________________________________________________________________________ void gso_Palette::range_Get(const Double_t* max, const Double_t* min) const { // Returns the palette range dbg_Print("gso_Palette::range_get: retriving palette range", DBG_LVL_ZERO); // Sets range limits max = &pal_range_Max; min = &pal_range_Min; } //______________________________________________________________________________ Double_t gso_Palette::range_Max() const { // Returns the palette range maximum dbg_Print("gso_Palette::range_Max: retriving palette range maximum", DBG_LVL_ZERO); return pal_range_Max; } //______________________________________________________________________________ Double_t gso_Palette::range_Min() const { // Returns the palette range minimum dbg_Print("gso_Palette::range_Min: retriving palette range minimum", DBG_LVL_ZERO); return pal_range_Min; } //______________________________________________________________________________ Double_t gso_Palette::range_Max(Double_t max) { // sets the palette range maximum dbg_Print("gso_Palette::range_Max: setting palette range maximum", DBG_LVL_ZERO); range_Set(max, pal_range_Min); // Returns the value return pal_range_Min; } //______________________________________________________________________________ Double_t gso_Palette::range_Min(Double_t min) { // Sets the palette range minimum dbg_Print("gso_Palette::range_Min: setting palette range minimum", DBG_LVL_ZERO); range_Set(pal_range_Max, min); // Returns the value return pal_range_Min; } */ //______________________________________________________________________________ UInt_t gso_Palette::color_Value(UInt_t col_Id) const { // Returns the value of the Id's color of the palette. This is a safe // but slow access. For fast access use the pal_Front pointer method. dbg_Print("gso_Palette::pal_Value:(UInt)", DBG_LVL_FLOW); // Check if (col_Id < 0) col_Id = 0; if (col_Id > 255) col_Id = 255; // Return return pal_Value[col_Id]; } //______________________________________________________________________________ const UInt_t* gso_Palette::color_Front() const { // Returns the pointer to the first element of the palette color array. // The array is 256 elements wide, be careful!! return pal_Value; } //______________________________________________________________________________ void gso_Palette::MoveResize(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Overloaded move and resize function. dbg_Print("gso_Palette::MoveResize:(default)", DBG_LVL_FLOW); // Moves and resizes the palette frame. Tthis will call a DoRedraw in case of need TGFrame::MoveResize(left, top, width, height); } //______________________________________________________________________________ void gso_Palette::DoRedraw() { // Draws the current palette to the palette frame. This function // overloads the TGFrame original one. dbg_Print("gso_Palette::DoRedraw:()", DBG_LVL_FLOW); // Redraws the palette map if any available if (frame_PxMap) gVirtualX->CopyArea(frame_PxMap, GetId(), frame_gc_Hnd, 0, 0, GetWidth(), GetHeight(), 0, 0); }