Commit 4661bae1 authored by Will Schroeder's avatar Will Schroeder
Browse files

EBH: Support rgba.

parent 693b4260
......@@ -53,42 +53,45 @@ public:
// vlColorScalar interface.
unsigned char *GetColor(int id);
void GetColor(int id, unsigned char rgb[3]);
void SetColor(int id, unsigned char ga[2]);
void InsertColor(int id, unsigned char ga[2]);
int InsertNextColor(unsigned char ga[2]);
void GetColor(int id, unsigned char rgba[4]);
void SetColor(int id, unsigned char rgba[4]);
void InsertColor(int id, unsigned char rgba[4]);
int InsertNextColor(unsigned char rgba[4]);
protected:
vlCharArray S;
};
// Description:
// Set a intensity/alpha value at a particular array location. Does not do
// Set a rgba color value at a particular array location. Does not do
// range checking.
inline void vlAGraymap::SetColor(int i, unsigned char ga[2])
inline void vlAGraymap::SetColor(int i, unsigned char rgba[4])
{
i *= 2;
this->S[i] = ga[0];
this->S[i+1] = ga[1];
this->S[i] = (rgba[0] > rgba[1] ? (rgba[0] > rgba[2] ? rgba[0] : rgba[2]) :
(rgba[1] > rgba[2] ? rgba[1] : rgba[2]));
this->S[i+1] = rgba[3];
}
// Description:
// Insert a intensity/alpha value at a particular array location. Does range
// Insert a rgba color value at a particular array location. Does range
// checking and will allocate additional memory if necessary.
inline void vlAGraymap::InsertColor(int i, unsigned char *ga)
inline void vlAGraymap::InsertColor(int i, unsigned char rgba[4])
{
this->S.InsertValue(2*i+1, ga[1]);
this->S[2*i] = ga[0];
this->S.InsertValue(2*i+1, rgba[3]);
this->S[2*i] = (rgba[0] > rgba[1] ? (rgba[0] > rgba[2] ? rgba[0] : rgba[2]) :
(rgba[1] > rgba[2] ? rgba[1] : rgba[2]));
}
// Description:
// Insert a intensity/alpha value at the next available slot in the array. Will
// Insert a rgba color value at the next available slot in the array. Will
// allocate memory if necessary.
inline int vlAGraymap::InsertNextColor(unsigned char *ga)
inline int vlAGraymap::InsertNextColor(unsigned char rgba[4])
{
int id = this->S.GetMaxId() + 1;
this->S.InsertValue(id,ga[1]);
this->S[id-1] = ga[0];
this->S.InsertValue(id,rgba[3]);
this->S[id-1] = (rgba[0] > rgba[1] ? (rgba[0] > rgba[2] ? rgba[0] : rgba[2]) :
(rgba[1] > rgba[2] ? rgba[1] : rgba[2]));
return id/2;
}
......
......@@ -61,6 +61,13 @@ protected:
vlCharArray S;
};
// Description:
// Return a rgba color at array location i.
inline unsigned char *vlAPixmap::GetColor(int i)
{
return this->S.GetPtr(4*i);
}
// Description:
// Get pointer to rgba data at location "id" in the array. Meant for reading
// data.
......
......@@ -50,10 +50,10 @@ public:
// vlColorScalar interface.
unsigned char *GetColor(int id);
void GetColor(int id, unsigned char rgb[3]);
void SetColor(int id, unsigned char b[1]);
void InsertColor(int id, unsigned char b[1]);
int InsertNextColor(unsigned char b[1]);
void GetColor(int id, unsigned char rgba[4]);
void SetColor(int id, unsigned char rgba[4]);
void InsertColor(int id, unsigned char rgba[4]);
int InsertNextColor(unsigned char rgba[4]);
protected:
vlBitArray S;
......
......@@ -20,24 +20,21 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
// In order to be a vlScalar subclass, vlColorScalars must be able to
// return a single value given a point id. By default, this operation is
// performed by computing intensity as the single value. Concrete subclasses
// of vlColorScalars may have additional methods to convert multi-dimensional
// of vlColorScalars may have additional methods to convert multi-dimensional
// color information into a single scalar value.
// .SECTION Caveats
// Derived classes of vlColorScalars loosely interpret the meaning of "rgb".
// For example, when inserting a grayscale value, the "r" value is interpreted
// as the gray value. However, when getting the color, each of "r", "g", and
// "b" is set to the gray value. Thus when getting color, assume that the rgb
// value is correct.
// The derived class vlAPixmap must be used with caution. It operates on
// rgba[4] data. If you might be using this class, make sure that the array
// rgb is dimensioned to [4] to avoid memory corruption.
// Derived classes of vlColorScalars treat colors differently. All derived
// classes will return a rgba (red-green-blue-alpha transparency) array in
// response to "GetColor()" methods. However, when setting colors, the rgba
// data may be converted to internal form. For example, a vlGrayMap just
// takes the maximum component of rgb and uses that as its gray value.
#ifndef __vlColorScalars_h
#define __vlColorScalars_h
#include "Scalars.hh"
class vlPixmap;
class vlAPixmap;
class vlColorScalars : public vlScalars
{
......@@ -58,34 +55,35 @@ public:
int GetNumberOfColors() {return this->GetNumberOfScalars();};
// Description:
// Return a unsigned char rgb for a particular point id.
// Return a unsigned char rgba for a particular point id.
virtual unsigned char *GetColor(int id) = 0;
// Description:
// Copy rgb components into user provided array rgb[3] for specified
// point id.
virtual void GetColor(int id, unsigned char rgb[3]) = 0;
// Copy color components into user provided array rgba[4] for specified
// point id. The number of components returned is the number of values
// per point.
virtual void GetColor(int id, unsigned char rgba[4]) = 0;
// Description:
// Insert color into object. No range checking performed (fast!).
virtual void SetColor(int id, unsigned char rgb[3]) = 0;
virtual void SetColor(int id, unsigned char rgba[4]) = 0;
// Description:
// Insert color into object. Range checking performed and memory
// allocated as necessary.
virtual void InsertColor(int id, unsigned char rgb[3]) = 0;
virtual void InsertColor(int id, unsigned char rgba[4]) = 0;
// Description:
// Insert color into next available slot. Returns point id of slot.
virtual int InsertNextColor(unsigned char rgb[3]) = 0;
virtual int InsertNextColor(unsigned char rgba[4]) = 0;
void GetColors(vlIdList& ptId, vlPixmap& p);
void GetColors(vlIdList& ptId, vlAPixmap& ap);
};
// These include files are placed here so that if CoScalar.hh is included
// all other classes necessary for compilation are also included.
#include "IdList.hh"
#include "Pixmap.hh"
#include "APixmap.hh"
#endif
......@@ -51,10 +51,10 @@ public:
// vlColorScalar interface.
unsigned char *GetColor(int id);
void GetColor(int id, unsigned char rgb[3]);
void SetColor(int id, unsigned char g[1]);
void InsertColor(int id, unsigned char g[1]);
int InsertNextColor(unsigned char g[1]);
void GetColor(int id, unsigned char rgba[4]);
void SetColor(int id, unsigned char rgba[4]);
void InsertColor(int id, unsigned char rgba[4]);
int InsertNextColor(unsigned char rgba[4]);
protected:
vlCharArray S;
......
......@@ -51,54 +51,50 @@ public:
// vlColorScalar interface.
unsigned char *GetColor(int id);
void GetColor(int id, unsigned char rgb[3]);
void SetColor(int id, unsigned char rgb[3]);
void InsertColor(int id, unsigned char rgb[3]);
int InsertNextColor(unsigned char rgb[3]);
void GetColor(int id, unsigned char rgba[4]);
void SetColor(int id, unsigned char rgba[4]);
void InsertColor(int id, unsigned char rgba[4]);
int InsertNextColor(unsigned char rgba[4]);
protected:
vlCharArray S;
};
// Description:
// Return a rgb triplet at array location i.
inline unsigned char *vlPixmap::GetColor(int i) {return this->S.GetPtr(3*i);};
// Description:
// Set a rgb value at a particular array location. Does not do range
// Set a rgba color value at a particular array location. Does not do range
// checking.
inline void vlPixmap::SetColor(int i, unsigned char rgb[3])
inline void vlPixmap::SetColor(int i, unsigned char rgba[4])
{
i *= 3;
this->S[i] = rgb[0];
this->S[i+1] = rgb[1];
this->S[i+2] = rgb[2];
this->S[i] = rgba[0];
this->S[i+1] = rgba[1];
this->S[i+2] = rgba[2];
}
// Description:
// Insert a rgb value at a particular array location. Does range checking
// and will allocate additional memory if necessary.
inline void vlPixmap::InsertColor(int i, unsigned char *rgb)
// Insert a rgba color value at a particular array location. Does range
// checking and will allocate additional memory if necessary.
inline void vlPixmap::InsertColor(int i, unsigned char rgba[4])
{
this->S.InsertValue(3*i+2, rgb[2]);
this->S[3*i] = rgb[0];
this->S[3*i+1] = rgb[1];
this->S.InsertValue(3*i+2, rgba[2]);
this->S[3*i] = rgba[0];
this->S[3*i+1] = rgba[1];
}
// Description:
// Insert a rgb value at the next available slot in the array. Will allocate
// Insert a rgba value at the next available slot in the array. Will allocate
// memory if necessary.
inline int vlPixmap::InsertNextColor(unsigned char *rgb)
inline int vlPixmap::InsertNextColor(unsigned char *rgba)
{
int id = this->S.GetMaxId() + 3;
this->S.InsertValue(id,rgb[2]);
this->S[id-2] = rgb[0];
this->S[id-1] = rgb[1];
this->S.InsertValue(id,rgba[2]);
this->S[id-2] = rgba[0];
this->S[id-1] = rgba[1];
return id/3;
}
// Description:
// Get pointer to rgb data at location "id" in the array. Meant for reading
// Get pointer to rgba data at location "id" in the array. Meant for reading
// data.
inline unsigned char *vlPixmap::GetPtr(const int id)
{
......@@ -108,7 +104,7 @@ inline unsigned char *vlPixmap::GetPtr(const int id)
// Description:
// Get pointer to data. Useful for direct writes into object. MaxId is bumped
// by number (and memory allocated if necessary). Id is the locaation you
// wish to write into; number is the number of rgb triplets to write.
// wish to write into; number is the number of rgba triplets to write.
inline unsigned char *vlPixmap::WritePtr(const int id, const int number)
{
return this->S.WritePtr(3*id,3*number);
......
......@@ -21,22 +21,23 @@ vlScalars *vlAGraymap::MakeObject(int sze, int ext)
}
// Description:
// Return a unsigned char gray for a particular point id.
// (Note: gray value converted into full rgb triplet.)
// Return a unsigned char rgba color value for a particular point id.
unsigned char *vlAGraymap::GetColor(int id)
{
static unsigned char rgb[3];
rgb[0] = rgb[1] = rgb[2] = this->S[2*id];
return rgb;
static unsigned char rgba[4];
rgba[0] = rgba[1] = rgba[2] = this->S[2*id];
rgba[3] = this->S[2*id+1];
return rgba;
}
// Description:
// Copy gray components into user provided array for specified
// Copy rgba color value components into user provided array for specified
// point id.
// (Note: gray value converted into full rgb triplet.)
void vlAGraymap::GetColor(int id, unsigned char rgb[3])
void vlAGraymap::GetColor(int id, unsigned char rgba[3])
{
rgb[0] = rgb[1] = rgb[2] = this->S[2*id];
rgba[0] = rgba[1] = rgba[2] = this->S[2*id];
rgba[3] = this->S[2*id+1];
}
// Description:
......
......@@ -28,15 +28,6 @@ vlAPixmap& vlAPixmap::operator=(const vlAPixmap& fs)
return *this;
}
// Description:
// Return a unsigned char rgba for a particular point id.
// (Note: this interface varies from superclass vlColorScalars.
// A pointer to four values are returned: rgba.)
unsigned char *vlAPixmap::GetColor(int id)
{
return this->S.GetPtr(4*id);
}
// Description:
// Copy rgba components into user provided array rgba[4] for specified
// point id. (Note: this interface varies from superclass vlColorScalars.
......
......@@ -29,50 +29,46 @@ vlBitmap& vlBitmap::operator=(const vlBitmap& fs)
}
// Description:
// Return a color for a particular point id.
// (Note: gray value converted into full rgb triplet.)
// Return a rgba color for a particular point id.
unsigned char *vlBitmap::GetColor(int id)
{
static unsigned char rgb[3];
rgb[0] = rgb[1] = rgb[2] = this->S.GetValue(id);
return rgb;
static unsigned char rgba[4];
rgba[0] = rgba[1] = rgba[2] = this->S.GetValue(id);
rgba[3] = 255;
return rgba;
}
// Description:
// Copy gray components into user provided array for specified
// point id.
// (Note: gray value converted into full rgb triplet.)
void vlBitmap::GetColor(int id, unsigned char rgb[3])
// Get rgba color value for id indicated.
void vlBitmap::GetColor(int id, unsigned char rgba[4])
{
rgb[0] = rgb[1] = rgb[2] = this->S.GetValue(id);
rgba[0] = rgba[1] = rgba[2] = this->S.GetValue(id);
rgba[3] = 255;
}
// Description:
// Insert gray value into object. No range checking performed (fast!).
// (Note: interface varies from superclass vlColorScalars. Only first
// component of rgb[3] (here b[1]) is inserted.)
void vlBitmap::SetColor(int id, unsigned char b[1])
// Insert rgba color value into object. No range checking performed (fast!).
void vlBitmap::SetColor(int id, unsigned char rgba[4])
{
this->S.SetValue(id,b[0]);
unsigned char b=rgba[0]|rgba[1]|rgba[2];
this->S.SetValue(id,b);
}
// Description:
// Insert gray value into object. Range checking performed and memory
// Insert rgba color value into object. Range checking performed and memory
// allocated as necessary.
// (Note: interface varies from superclass vlColorScalars. Only first
// component of rgb[3] (here b[1]) is inserted.)
void vlBitmap::InsertColor(int id, unsigned char b[1])
void vlBitmap::InsertColor(int id, unsigned char rgba[4])
{
this->S.InsertValue(id,b[0]);
unsigned char b=rgba[0]|rgba[1]|rgba[2];
this->S.InsertValue(id,b);
}
// Description:
// Insert gray value into next available slot. Returns point id of slot.
// (Note: interface varies from superclass vlColorScalars. Only first
// component of rgb[3] (here b[1]) is inserted.)
int vlBitmap::InsertNextColor(unsigned char b[1])
// Insert rgba color value into next available slot. Returns point id of slot.
int vlBitmap::InsertNextColor(unsigned char rgba[4])
{
int id = this->S.InsertNextValue(b[0]);
unsigned char b=rgba[0]|rgba[1]|rgba[2];
int id = this->S.InsertNextValue(b);
return id;
}
......@@ -55,7 +55,7 @@ int vlColorScalars::InsertNextScalar(float s)
// Description:
// Given list of point id's, return colors for each point.
void vlColorScalars::GetColors(vlIdList& ptId, vlPixmap& p)
void vlColorScalars::GetColors(vlIdList& ptId, vlAPixmap& p)
{
for (int i=0; i<ptId.GetNumberOfIds(); i++)
{
......
......@@ -29,50 +29,52 @@ vlGraymap& vlGraymap::operator=(const vlGraymap& fs)
}
// Description:
// Return a unsigned char gray for a particular point id.
// (Note: gray value converted into full rgb triplet.)
// Return a rgba color for a particular point id.
// (Note: gray value converted into full rgba. )
unsigned char *vlGraymap::GetColor(int id)
{
static unsigned char rgb[3];
rgb[0] = rgb[1] = rgb[2] = this->S[id];
return rgb;
static unsigned char rgba[4];
rgba[0] = rgba[1] = rgba[2] = this->S[id];
rgba[3] = 255;
return rgba;
}
// Description:
// Copy gray components into user provided array for specified
// point id.
// (Note: gray value converted into full rgb triplet.)
void vlGraymap::GetColor(int id, unsigned char rgb[3])
// point id. (Note: gray value converted into full rgba color value.)
void vlGraymap::GetColor(int id, unsigned char rgba[4])
{
rgb[0] = rgb[1] = rgb[2] = this->S[id];
rgba[0] = rgba[1] = rgba[2] = this->S[id];
rgba[3] = 255;
}
// Description:
// Insert gray value into object. No range checking performed (fast!).
// (Note: interface varies from superclass vlColorScalars. Only first
// component of rgb[3] (here g[1]) is inserted.)
void vlGraymap::SetColor(int id, unsigned char g[1])
// (Note: rgba color value converted to grayscale).
void vlGraymap::SetColor(int id, unsigned char rgba[4])
{
this->S[id] = g[0];
this->S[id] = (rgba[0] > rgba[1] ? (rgba[0] > rgba[2] ? rgba[0] : rgba[2]) :
(rgba[1] > rgba[2] ? rgba[1] : rgba[2]));
}
// Description:
// Insert gray value into object. Range checking performed and memory
// allocated as necessary.
// (Note: interface varies from superclass vlColorScalars. Only first
// component of rgb[3] (here g[1]) is inserted.)
void vlGraymap::InsertColor(int id, unsigned char g[1])
// Insert rgba color value into object. Range checking performed and memory
// allocated as necessary. (Note: rgba converted to gray value).
void vlGraymap::InsertColor(int id, unsigned char rgba[4])
{
this->S.InsertValue(id,g[0]);
unsigned char g=(rgba[0] > rgba[1] ? (rgba[0] > rgba[2] ? rgba[0] : rgba[2]) :
(rgba[1] > rgba[2] ? rgba[1] : rgba[2]));
this->S.InsertValue(id,g);
}
// Description:
// Insert gray value into next available slot. Returns point id of slot.
// (Note: interface varies from superclass vlColorScalars. Only first
// component of rgb[3] (here g[1]) is inserted.)
int vlGraymap::InsertNextColor(unsigned char g[1])
// Insert rgba color value into next available slot. Returns point id of slot.
// (Note: rgba converted to gray value).
int vlGraymap::InsertNextColor(unsigned char rgba[4])
{
int id = this->S.InsertNextValue(g[0]);
unsigned char g=(rgba[0] > rgba[1] ? (rgba[0] > rgba[2] ? rgba[0] : rgba[2]) :
(rgba[1] > rgba[2] ? rgba[1] : rgba[2]));
int id = this->S.InsertNextValue(g);
return id;
}
......@@ -29,15 +29,30 @@ vlPixmap& vlPixmap::operator=(const vlPixmap& fs)
}
// Description:
// Copy rgba components into user provided array rgb[3] for specified
// point id. (Note: this interface varies from superclass vlColorScalars.
// Four values are returned: rgb.)
void vlPixmap::GetColor(int id, unsigned char rgb[3])
// Return a rgba color at array location i.
unsigned char *vlPixmap::GetColor(int i)
{
static unsigned char rgba[4];
unsigned char *_rgb;
_rgb = this->S.GetPtr(3*i);
rgba[0] = _rgb[0];
rgba[1] = _rgb[1];
rgba[2] = _rgb[2];
rgba[3] = 255;
return rgba;
}
// Description:
// Copy rgba components into user provided array rgb[4] for specified
// point id.
void vlPixmap::GetColor(int id, unsigned char rgba[4])
{
unsigned char *_rgb;
_rgb = this->S.GetPtr(3*id);
rgb[0] = _rgb[0];
rgb[1] = _rgb[1];
rgb[2] = _rgb[2];
rgba[0] = _rgb[0];
rgba[1] = _rgb[1];
rgba[2] = _rgb[2];
rgba[3] = 255;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment