#============================================================================== # # Project: SharpImage # Module: ImagePalette.py # Language: IronPython # Author: Dan Mueller # Date: $Date$ # Revision: $Revision$ # # Copyright (c) Queensland University of Technology (QUT) 2007. # All rights reserved. # # This software is distributed WITHOUT ANY WARRANTY; without even # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the above copyright notices for more information. # #============================================================================== # Import the base script class import Script from Script import * class ImagePaletteScript(ScriptObject): # ------------------------------------------------------------------------- Name = "ImagePalette" Help = """Sets the image palette.""" Parameters = """(String) Palette = "Greyscale", "GreyscaleBands", "HueRange", or "HueBands". ("GreyscaleBands") (int) NumberOfBands = the number of bands for banded palettes. (25) (double) RangeMin = the minimum value of the range. (0.0) (double) RangeMax = the maximum value of the range (1.0)""" Palette = "GreyscaleBands" NumberOfBands = 25 RangeMin = 0.0 RangeMax = 1.0 # ------------------------------------------------------------------------- def Run(self): """ The entry-point for this script. """ self.Initialise() self.Input = self.ParentApplication.CurrentRenderer.Inputs[0] # Check Palette is not None if (self.Palette == None): self.WriteLineToConsole( "WARNING: Defaulting to Greyscale due to invalid palette: None." ) self.Palette = "Greyscale" # Create lookup table ignoreCase = True lut = siGdiLookupTable( ) lut.SetTableRange( self.Input, 256 ) if (String.Compare( self.Palette, "Greyscale", ignoreCase) == 0): lut.SetTableToGreyscale( ) elif (String.Compare( self.Palette, "GreyscaleBands", ignoreCase) == 0): lut.SetTableToGreyscaleBands( self.NumberOfBands ) elif (String.Compare( self.Palette, "HueRange", ignoreCase) == 0): lut.SetTableToHueRange( self.RangeMin, self.RangeMax ) elif (String.Compare( self.Palette, "HueBands", ignoreCase) == 0): lut.SetTableToHueBands( self.RangeMin, self.RangeMax, self.NumberOfBands ) else: self.WriteLineToConsole( "WARNING: Defaulting to Greyscale due to unknown palette: '" + self.Palette + "'" ) lut.SetTableToGreyscale( ) # Set lookup table self.Input.Metadata["LookupTable0"] = lut # Finish self.ParentApplication.CurrentRenderer.InitialiseInputs() self.ParentApplication.CurrentRenderer.Repaint() self.Finalise()