Public Member Functions

Palette Class Reference

Represents a palette used to draw a spectrogram. More...

#include <spectrogram.hpp>

List of all members.

Public Member Functions

 Palette ()
 Default constructor -- 8-bit grayscale palette.
 Palette (const QImage &img)
 Creates a palette from an image.
int get_color (float val) const
 Mapping of intensity values from <0,1> to an index or RGB value.
float get_intensity (QRgb color) const
 Inverse mapping of color values to intensity, used for spectrogram synthesis.
bool has_color (QRgb color) const
 Returns true if the palette contains the given color, false otherwise.
QImage make_canvas (int width, int height) const
 Creates a QImage with an appropriate color mode and dimensions.
bool indexable () const
 Used to determine if the palette is indexed or RGB.
QPixmap preview (int width, int height) const
 Generate a preview of the palette suitable for display in a widget.
int numColors () const
 Returns the number of colors in the palette.

Detailed Description

Represents a palette used to draw a spectrogram.

It is basically a mapping of intensity values from the interval <0,1> to a set of colors (the palette), where 0 represents zero intensity of the pixel and 1 represents maximum intensity. Ideally, the mapping is 1:1 (bijection), otherwise there will be ambiguity in the synthesis process and quality will be affected. Both the Intensity -> Color and Color -> Intensity mappings are implemented by the Palette::get_color() and Palette::get_intensity() functions respectively.

For optimal image sizes, the palette will be either indexed or RGB, depending on how many colors it contains. If there are 256 or less colors (eg. in the default grayscale case), the palette will be 8-bit indexed, otherwise it's RGB (24-bit, no index).

This is transparent in usage because in both cases the make_canvas() function will create a QImage with the appropriate color mode and QImage::setPixel() then takes the same parameter type as the Palette::get_color() function returns.

Definition at line 40 of file spectrogram.hpp.


Constructor & Destructor Documentation

Palette::Palette (  ) 

Default constructor -- 8-bit grayscale palette.

Definition at line 525 of file spectrogram.cpp.

Palette::Palette ( const QImage &  img  ) 

Creates a palette from an image.

This constructor takes an image and fills the palette with colors from the first row of an image.

Parameters:
img The image used to generate the palette.

Definition at line 518 of file spectrogram.cpp.


Member Function Documentation

int Palette::get_color ( float  val  )  const

Mapping of intensity values from <0,1> to an index or RGB value.

Parameters:
val A float where 0 <= val <= 1
Returns:
Index of the color for an indexed palette or RGB value.

Definition at line 533 of file spectrogram.cpp.

float Palette::get_intensity ( QRgb  color  )  const

Inverse mapping of color values to intensity, used for spectrogram synthesis.

Returns:
Corresponding intensity, a value from <0,1>.

Definition at line 550 of file spectrogram.cpp.

bool Palette::has_color ( QRgb  color  )  const

Returns true if the palette contains the given color, false otherwise.

Definition at line 544 of file spectrogram.cpp.

bool Palette::indexable (  )  const

Used to determine if the palette is indexed or RGB.

Returns:
true if the palette is indexed, otherwise false.

Definition at line 575 of file spectrogram.cpp.

QImage Palette::make_canvas ( int  width,
int  height 
) const

Creates a QImage with an appropriate color mode and dimensions.

The resulting QImage will have the specified dimensions and color mode depending on the number of colors in the palette. For 256 or less colors, it will be indexed, otherwise RGB.

Definition at line 558 of file spectrogram.cpp.

int Palette::numColors (  )  const

Returns the number of colors in the palette.

Definition at line 591 of file spectrogram.cpp.

QPixmap Palette::preview ( int  width,
int  height 
) const

Generate a preview of the palette suitable for display in a widget.

Definition at line 580 of file spectrogram.cpp.


The documentation for this class was generated from the following files: